Create Sales Order.docx

Embed Size (px)

Citation preview

  • 7/29/2019 Create Sales Order.docx

    1/13

    Create Sales Order (BAPI_SALESORDER_CREATEFROMDAT2) with BAPIExtension

    By Ugur Baris Turkeli, Istanbul

    Our client had a requirement to create customer sales orders using BAPI function moduleBAPI_SALESORDER_CREATEFROMDAT2 with using custom fields (ZZ* or YY* fields) which areappended on VBAP table with using append structure.

    We can easily create sales order with using standard fields via BAPI but as per requirement we need touse extension ofBAPI_SALESORDER_CREATEFROMDAT2for 13 customize fields.

    Steps for BAPI Extension:

    Append ZAVBAP structure in VBAP table with 13 customize fields. Fields must begin with ZZ* or YY*naming .

  • 7/29/2019 Create Sales Order.docx

    2/13

    In BAPI_SALESORDER_CREATEFROMDAT2 we need to use EXTENSIONIN parameter for BAPIextension

    You can use this parameter to transfer user-specific enhancements to a BAPI. The customer has tocomplete the EXTENSION structure and the system automatically continues processing it. If you have notdefined any user-specific fields, then you can transfer a blank EXTENSIONIN structure. You can use alsothis extension VBAK, VBAP, VBEP tables.

  • 7/29/2019 Create Sales Order.docx

    3/13

    Because the BAPIs work with checkboxes, you must also define a customize structure(ZABAPE_VBAPX) checkbox for the customer structure. It should be structured like this

    Define these customer structures in the structures VBAPKOZ and VBAPKOZX using INCLUDE orAPPEND.

  • 7/29/2019 Create Sales Order.docx

    4/13

  • 7/29/2019 Create Sales Order.docx

    5/13

    Add the customer structures to the BAPE_VBAP and BAPE_VBAPX BAPI structures using the APPENDtechnique.

  • 7/29/2019 Create Sales Order.docx

    6/13

    Create Sales Order (BAPI_SALESORDER_CREATEFROMDAT2) with BAPIExtension

    ...Previous

    http://saptechnical.com/Tutorials/BAPI/SalesOrder/Index.htmhttp://saptechnical.com/Tutorials/BAPI/SalesOrder/Index.htmhttp://saptechnical.com/Tutorials/BAPI/SalesOrder/Index.htmhttp://saptechnical.com/Tutorials/BAPI/SalesOrder/Index.htm
  • 7/29/2019 Create Sales Order.docx

    7/13

  • 7/29/2019 Create Sales Order.docx

    8/13

  • 7/29/2019 Create Sales Order.docx

    9/13

    Adjust the following structures for customer enhancements to table VBAP:

    a) VBAPKOZ

    b) VBAPKOZX

    c) BAPE_VBAP

    d) BAPE_VBAPX

    If you need to use custom fields for VBAK you must adjust the following structures for customerenhancements to table VBAK:

    a) VBAKKOZ

  • 7/29/2019 Create Sales Order.docx

    10/13

    b) VBAKKOZX

    c) BAPE_VBAK

    d) BAPE_VBAKX

    If you need to use custom fields for VBEP you must adjust the following structures for customerenhancements to table VBEP:

    a) VBEPKOZ

    b) VBEPKOZX

    c) BAPE_VBEP

    d) BAPE_VBEPX

    Generally, the data should be added to the BAPI interface in the internal communication structures

    (VBAKKOM, and so on). There, you can process the data in the SD tables (VBAK, and so on).

    If the EXTENSIONIN parameter contains customer data, you must complete at least the key fields in therelevant standard parameters.

    This is a simple ABAP code how to use extension table with BAPI

    data: lv_salesdocument like bapivbeln-vbeln,ls_order_header_in type bapisdhd1 ,

    ls_order_header_inx type bapisdhd1x,lt_return type table of bapiret2 with header line,lt_items_in type table of bapisditm with header line,lt_items_inx type table of bapisditmx with header line,

    lt_partners type table of bapiparnr with header line,lt_schedules_in type table of bapischdl with header line,lt_schedules_inx type table of bapischdlx with header line,lt_order_conditions_in type table of bapicond with header line,lt_order_conditions_inx type table of bapicondx with header line,lt_extensionin type table of bapiparex with header line,lwa_extensionin type bapiparex ,lt_bape_vbap type table of bape_vbap with header line,lwa_bape_vbap type bape_vbap,lt_bape_vbapx type table of bape_vbapx with header line,lwa_bape_vbapx type bape_vbapx.

    ls_order_header_in-doc_type = 'Z001'.

    ls_order_header_in-sales_org = '1000'.ls_order_header_in-distr_chan = '20'.ls_order_header_in-division = '01'.ls_order_header_in-sales_off = '0010'.ls_order_header_in-purch_no_c = '10000001'.ls_order_header_inx-updateflag = 'I'.ls_order_header_inx-doc_type = 'X'.ls_order_header_inx-sales_org = 'X'.ls_order_header_inx-distr_chan = 'X'.

  • 7/29/2019 Create Sales Order.docx

    11/13

    ls_order_header_inx-division = 'X'.ls_order_header_inx-sales_off = 'X'.ls_order_header_inx-purch_no_c = 'X'.

    lt_partners-partn_role = 'AG'.lt_partners-partn_numb = '0000004000'.

    append lt_partners.

    lt_items_in-itm_number = '000010'.lt_items_in-material = '000000000300000040'.lt_items_in-sales_unit = 'ST'.

    append lt_items_in.

    lt_items_inx-itm_number = '000010'.lt_items_inx-material = 'X'.lt_items_inx-sales_unit = 'X'.

    append lt_items_inx.

    lt_schedules_in-itm_number = '000010'.

    lt_schedules_in-sched_line = '0001'.lt_schedules_in-req_qty = 1000.lt_schedules_in-req_date = sy-datum.append lt_schedules_in.

    lt_schedules_inx-itm_number = '000010'.lt_schedules_inx-sched_line = '0001'.lt_schedules_inx-req_qty = 'X'.lt_schedules_inx-req_date = 'X'.append lt_schedules_inx.

    lwa_bape_vbap-vbeln = space.lwa_bape_vbap-posnr = '000010'.

    lwa_bape_vbap-zztuketf = 0.lwa_bape_vbap-zztukets = 0.lwa_bape_vbap-zzklt1 = '45GRAM'.lwa_bape_vbap-zzsyf1 = 16.lwa_bape_vbap-zzklt2 = '49GRAM'.lwa_bape_vbap-zzsyf2 = 0.lwa_bape_vbap-zzklt3 = '52GRAM'.lwa_bape_vbap-zzsyf3 = 0.lwa_bape_vbap-zz45g = space.lwa_bape_vbap-zz49g = space.lwa_bape_vbap-zzsbs = 8.lwa_bape_vbap-zztss = 8.lwa_bape_vbap-zzrss = 16.

    lwa_bape_vbapx-vbeln = space.lwa_bape_vbapx-posnr = wa_outtab-posnr.lwa_bape_vbapx-zztuketf = space.lwa_bape_vbapx-zztukets = space.lwa_bape_vbapx-zzklt1 = 'X'.lwa_bape_vbapx-zzsyf1 = 'X'.lwa_bape_vbapx-zzklt2 = 'X'.lwa_bape_vbapx-zzsyf2 = 'X'.lwa_bape_vbapx-zzklt3 = 'X'.

  • 7/29/2019 Create Sales Order.docx

    12/13

    lwa_bape_vbapx-zzsyf3 = 'X'.lwa_bape_vbapx-zz45g = 'X'.lwa_bape_vbapx-zz49g = 'X'.lwa_bape_vbapx-zzsbs = 'X'.lwa_bape_vbapx-zztss = 'X'.lwa_bape_vbapx-zzrss = 'X'.

    move 'BAPE_VBAP' to lwa_extensionin-structure.

    call method cl_abap_container_utilities=>fill_container_cexporting

    im_value = lwa_bape_vbapimporting

    ex_container = lwa_extensionin-valuepart1.

    append lwa_extensionin to lt_extensionin.

    clear lwa_extensionin.clear lt_extensionin.

    move 'BAPE_VBAPX' to lwa_extensionin-structure.move lwa_bape_vbapx to lwa_extensionin-valuepart1.append lwa_extensionin to lt_extensionin.clear lt_extensionin.

    call function 'BAPI_SALESORDER_CREATEFROMDAT2'exporting

    * salesdocumentin = lv_salesdocumentorder_header_in = ls_order_header_inorder_header_inx = ls_order_header_inx

    * SENDER =* BINARY_RELATIONSHIPTYPE =* INT_NUMBER_ASSIGNMENT =

    * BEHAVE_WHEN_ERROR =* LOGIC_SWITCH =* TESTRUN =* CONVERT = ' 'importing

    salesdocument = lv_salesdocumenttablesreturn = lt_returnorder_items_in = lt_items_inorder_items_inx = lt_items_inxorder_partners = lt_partnersorder_schedules_in = lt_schedules_inorder_schedules_inx = lt_schedules_inx

    order_conditions_in = lt_order_conditions_inorder_conditions_inx = lt_order_conditions_inx

    * ORDER_CFGS_REF =* ORDER_CFGS_INST =* ORDER_CFGS_PART_OF =* ORDER_CFGS_VALUE =* ORDER_CFGS_BLOB =* ORDER_CFGS_VK =* ORDER_CFGS_REFINST =* ORDER_CCARD =

  • 7/29/2019 Create Sales Order.docx

    13/13

    * ORDER_TEXT =* ORDER_KEYS =

    extensionin = lt_extensionin* PARTNERADDRESSES =

    .call function 'BAPI_TRANSACTION_COMMIT'

    exportingwait = 'X'.

    Follow this steps for the field in the extension:

    1. Append one structure in BAPE_VBAK with the fields which need to be changed.

    E.g. append strucutre name ZZAPE_VBAK and fields ZZ_Z1 and ZZ_Z2 with its original type.

    2. Append one structure in BAPE_VBAKX with the fields with one character fields.

    E.g. append strucutre name ZZAPE_VBAKX. Here Fields ZZ_Z1 and ZZ_Z2 must be of type CHAR1.

    3. Append the same fields of the structure which was appended in the BAPE_VBAK to VBAKKOZ.

    E.g. Append strucutre Name ZZ_VBAKKOZ and fields ZZ_Z1 and ZZ_Z2 with its original type.

    4. Append the same structure which was appended in the BAPE_VBAKX to VBAKKOZX.

    E.g. Append strucutre Name ZZ_VBAKKOZX. Here Fields ZZ_Z1 and ZZ_Z2 must be of type CHAR1.

    To use it in the program:

    * Fill the ZZ fields

    t_ext-structure = 'BAPE_VBAK'. "Structure with the fields

    t_ext-valuepart1+0(10) = v_vbeln.

    t_ext-valuepart1+10(10) = V_ZZ1 . " value of the ZZ_Z1 field

    append t_ext.

    * Mark for changes

    t_ext-structure = 'BAPE_VBAKX'. " Structure with the flags

    t_ext-valuepart1+0(10) = v_vbeln.

    t_ext-valuepart1+10(1) = 'X'.

    append t_ext.