Current Position:Home > Issue in creating sales order using BAPI's...?

Issue in creating sales order using BAPI's...?

Update:10-11Source: network consolidation
Advertisement
Hi Guru's,
i had generated the sales order using the BAPI..but could please guide me how to declare the data declaratin same fields as globally and how to move internal table and how to append ....
thanks in advance...
REPORT z_bapi_salesorder_create.
Sales document type
PARAMETERS: p_auart TYPE auart OBLIGATORY.
Sales organization
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
Distribution channel
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
Division.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
Sold-to
PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
Ship-to
PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
Material
PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
Quantity.
PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
Plant
PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
Data declarations.
DATA: v_vbeln            LIKE vbak-vbeln.
DATA: header             LIKE bapisdhead1.
DATA: headerx            LIKE bapisdhead1x.
DATA: item               LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
DATA: itemx              LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner            LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
DATA: return             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.
Start-of-selection.
START-OF-SELECTION.
Header data
Sales document type
  header-doc_type = p_auart.
  headerx-doc_type = 'X'.
Sales organization
  header-sales_org = p_vkorg.
  headerx-sales_org = 'X'.
Distribution channel
  header-distr_chan  = p_vtweg.
  headerx-distr_chan = 'X'.
Division
  header-division = p_spart.
  headerx-division = 'X'.
  headerx-updateflag = 'I'.
Partner data
Sold to
  partner-partn_role = 'AG'.
  partner-partn_numb = p_sold.
  APPEND partner.
Ship to
  partner-partn_role = 'WE'.
  partner-partn_numb = p_ship.
  APPEND partner.
ITEM DATA
  itemx-updateflag = 'I'.
Line item number.
  item-itm_number = '000010'.
  itemx-itm_number = 'X'.
Material
  item-material = p_matnr.
  itemx-material = 'X'.
Plant
  item-plant    = p_plant.
  itemx-plant   = 'X'.
Quantity
  item-target_qty = p_menge.
  itemx-target_qty = 'X'.
  APPEND item.
  APPEND itemx.
  Fill schedule lines
  lt_schedules_in-itm_number = '000010'.
  lt_schedules_in-sched_line = '0001'.
  lt_schedules_in-req_qty    = p_menge.
  APPEND lt_schedules_in.
  Fill schedule line flags
  lt_schedules_inx-itm_number  = '000010'.
  lt_schedules_inx-sched_line  = '0001'.
  lt_schedules_inx-updateflag  = 'X'.
  lt_schedules_inx-req_qty     = 'X'.
  APPEND lt_schedules_inx.
Call the BAPI to create the sales order.
  CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
    EXPORTING
      sales_header_in     = header
      sales_header_inx    = headerx
    IMPORTING
      salesdocument_ex    = v_vbeln
    TABLES
      return              = return
      sales_items_in      = item
      sales_items_inx     = itemx
      sales_schedules_in  = lt_schedules_in
      sales_schedules_inx = lt_schedules_inx
      sales_partners      = partner.
Check the return table.
  LOOP AT return WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.
  IF sy-subrc = 0.
    WRITE: / 'Error in creating document'.
  ELSE.
Commit the work.
   COMMIT WORK AND WAIT.
     call FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    WRITE: / 'Document ', v_vbeln, ' created'.
  ENDIF.

The Best Answer

Advertisement
*& Report  ZAREPAS30
REPORT  zarepas30.
DATA : gs_vbeln                   TYPE  vbak-vbeln,
       gs_order_header_in         TYPE  bapisdhd1,
       gs_order_header_inx        TYPE  bapisdhd1x,
       gt_order_items_in          TYPE  STANDARD TABLE OF bapisditm,
       gwa_itab1                  TYPE  bapisditm,
       gt_order_items_inx         TYPE  STANDARD TABLE OF bapisditmx,
       gwa_itab2                  TYPE  bapisditmx,
       gt_order_partners          TYPE  STANDARD TABLE OF bapiparnr,
       gwa_itab3                  TYPE  bapiparnr,
       gt_return                  TYPE  STANDARD TABLE OF bapiret2,
       gwa_itab4                  TYPE  bapiret2.
Sales document type
  PARAMETERS: p_auart TYPE auart OBLIGATORY.
Sales organization
  PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
Distribution channel
  PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
Division.
  PARAMETERS: p_spart TYPE spart OBLIGATORY.
Requested Delivery Date
  PARAMETERS: p_edatu  TYPE edatu OBLIGATORY.
Sold-to
  PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
Ship-to
  PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
Material
  PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
Quantity.
  PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
Plant
  PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
Start-of-selection.
  START-OF-SELECTION.
Header data
Sales document type
  gs_order_header_in-doc_type = p_auart.
  gs_order_header_inx-doc_type = 'X'.
Sales organization
  gs_order_header_in-sales_org = p_vkorg.
  gs_order_header_inx-sales_org = 'X'.
Distribution channel
  gs_order_header_in-distr_chan  = p_vtweg.
  gs_order_header_inx-distr_chan = 'X'.
Division
  gs_order_header_in-division = p_spart.
  gs_order_header_inx-division = 'X'.
Reguested Delivery Date
  gs_order_header_in-req_date_h = p_edatu.
  gs_order_header_inx-req_date_h = 'X'.
  gs_order_header_inx-updateflag = 'I'.
Partner data
Sold to
  gwa_itab3-partn_role = 'AG'.
  gwa_itab3-partn_numb = p_sold.
  APPEND gwa_itab3 TO  gt_order_partners .
ship to
  gwa_itab3-partn_role = 'WE'.
  gwa_itab3-partn_numb = p_ship.
  APPEND gwa_itab3 TO  gt_order_partners .
ITEM DATA
  gwa_itab2-updateflag = 'I'.
Line item number.
  gwa_itab1-itm_number = '000010'.
  gwa_itab2-itm_number = 'X'.
Material
  gwa_itab1-material = p_matnr.
  gwa_itab2-material = 'X'.
Plant
  gwa_itab1-plant    = p_plant.
  gwa_itab2-plant   = 'X'.
Quantity
  gwa_itab1-target_qty = p_menge.
  gwa_itab2-target_qty = 'X'.
  APPEND gwa_itab1 TO gt_order_items_in.
  APPEND gwa_itab2 TO gt_order_items_inx.
Line item number.
  gwa_itab1-itm_number = '000020'.
  gwa_itab2-itm_number = 'X'.
Material
  gwa_itab1-material = p_matnr.
  gwa_itab2-material = 'X'.
Plant
  gwa_itab1-plant    = p_plant.
  gwa_itab2-plant   = 'X'.
Quantity
  gwa_itab1-target_qty = p_menge.
  gwa_itab2-target_qty = 'X'.
  APPEND gwa_itab1 TO gt_order_items_in.
  APPEND gwa_itab2 TO gt_order_items_inx.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
  EXPORTING
    order_header_in               = gs_order_header_in
    ORDER_HEADER_INX              = gs_order_header_inx
  IMPORTING
    SALESDOCUMENT                 = gs_vbeln
  tables
    RETURN                        = gt_return
    ORDER_ITEMS_IN                = gt_order_items_in
    ORDER_ITEMS_INX               = gt_order_items_inx
    order_partners                = gt_order_partners.
Check the return table.
  LOOP AT gt_return into gwa_itab4 WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.
  IF sy-subrc = 0.
    WRITE: / 'Error occured while creating sales order '.
  ELSE.
Commit the work.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    WRITE: / 'Document ', gs_vbeln, ' created'.
  ENDIF.
  • ISSUE ON CREATE SALES ORDER USING BAPI Update:10-11

    Hi,    I am creating a sales order using bapi BAPI_SALESORDER_CREATEFROMDAT2.But it it fails to create a sales order abd below is my code pls check and correct me to create a sales order. LOOP AT DATA_TAB. clear: l_order_header_in,        l_salesdocu

  • Issue in creating sales order using BAPI's...? Update:10-11

    Hi Guru's, i had generated the sales order using the BAPI..but could please guide me how to declare the data declaratin same fields as globally and how to move internal table and how to append .... thanks in advance... REPORT z_bapi_salesorder_create

  • Confirmation Quantity issue while creating Sales order using BAPI Update:10-11

    Hi SDN, Can anyone of you help mein the below issue: I have a program to create a sales order using upload file. for this i use "BAPI_SALESORDER_CREATEFROMDAT2" & for changing existing "BAPI_SALESORDER_CHANGE". Now If the upload fi

  • Setting user specific contract data while creating sales order using BAPI Update:10-11

    Hi all, I am creating sales order using BAPI - BAPI_SALESORDER_CREATEFROMDAT2. Now my problem is that there is no structure for contract data (i.e. VEDA), system automatically set contract data using customization values. I am doing some validations

  • Issue when creating sales order with Sold-to/Ship-to Party's state Update:10-11

    Hi All, we have issue while creating Sales Order with picking up of State tax for Ship-to-party & Sold-to-party. <b>When we create a sales order, for the sold to party 140052732 and ship to party 140052733 it is picking state tax. Which should n

  • Issue when creating sales order with Sold-to/Ship-to Party's state tax Update:10-11

    Hi All, we have issue while creating Sales Order with picking up of State tax for Ship-to-party & Sold-to-party. <b>When we create a sales order, for the sold to party 140052732 and ship to party 140052733 it is picking state tax. Which should n

  • Creating sales order using bapi Update:10-11

    while creating sales order using bapi serial no is added in dat but its not saving. plz replyHi See tha sample code for sales order creation SALES ORDER INPUT CREATION. PARAMETERS: p_auart TYPE auart OBLIGATORY. PARAMETERS: p_vkorg TYPE vkorg OBLIGAT

  • TO CREATE SALES ORDER USING BAPI PROBLEM Update:11-30

    I am trying to create Sales Order using bapi function, this is giving me error as mentioned below *Please enter SHIP-TO-PARTY OR SOLD TO PARTY *SALES DOCUMENT WAS NOT CHANGED. it does not GIVE ME THE SALES DOCUMENT NO . The BAPI I am using is BAPI_SA

  • Create sales order using BAPI Update:11-30

    HI, I need to create sales orders using BAPI. these sales orders are different sales order type and it need to upload from excel file. anyone send me some sample programs for this one. kathir.use this code to create salesorder using bapi. REPORT z_ba

  • Creating sales order through Bapi Update:11-30

    Hi all, I am trying to create sales order through bapi. Now my problem is mapping sales order fields with bapi structure fields. 1.'Overall Order status' field in the 'Status' tab of the header in VA02. 2.'Tax'feild in the 'conditions' tab of the hea