Create Sales Order

Preview:

DESCRIPTION

sap webdynpro sales order

Citation preview

Create Sales Order (BAPI_SALESORDER_CREATEFROMDAT2) with BAPI Extension

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 are appended 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 to use extension of BAPI_SALESORDER_CREATEFROMDAT2 for 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 .

In BAPI_SALESORDER_CREATEFROMDAT2 we need to use EXTENSIONIN parameter for BAPI extension

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

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 or APPEND.

Add the customer structures to the BAPE_VBAP and BAPE_VBAPX BAPI structures using the APPEND technique.

 

 

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 customer enhancements to table VBAK:

a) VBAKKOZ

b) VBAKKOZX

c) BAPE_VBAK

d) BAPE_VBAKX

If you need to use custom fields for VBEP you must adjust the following structures for customer enhancements 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 the relevant 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'.

        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'.

     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_c    exporting      im_value = lwa_bape_vbap      importing      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_salesdocument    order_header_in               = ls_order_header_in    order_header_inx              = ls_order_header_inx*   SENDER                        =*   BINARY_RELATIONSHIPTYPE       =*   INT_NUMBER_ASSIGNMENT         =*   BEHAVE_WHEN_ERROR             =*   LOGIC_SWITCH                  =*   TESTRUN                       =*   CONVERT                       = ' ' importing   salesdocument                  = lv_salesdocument  tables   return                         = lt_return   order_items_in                 = lt_items_in   order_items_inx                = lt_items_inx    order_partners                = lt_partners   order_schedules_in            = lt_schedules_in   order_schedules_inx           = lt_schedules_inx   order_conditions_in           = lt_order_conditions_in   order_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                   =

*   ORDER_TEXT                    =*   ORDER_KEYS                    =   extensionin                    = lt_extensionin*   PARTNERADDRESSES              =

          .

    call function 'BAPI_TRANSACTION_COMMIT'   exporting     wait          = 'X'.

Recommended