Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
kevin_wilson2
Contributor

To do so you first need to ensure that the following 5 tables are in synch.

1) VBAP: In your append structure you specify your ZZFIELD with the data type as needed

2) BAPE_VBAP: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters

3) BAPE_VBAPX: In the append structure add the field ZZFIELD of type BAPIUPDATE

(NOTE: (2) and (3) must have the same number of fields in the same order)

4) VBAPKOZ: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters

5) VBAPKOZX: In the append structure add the field ZZFIELD of type BAPIUPDATE

(NOTE: (4) and (5) must have the same number of fields in the same order)

(Note: A great tip from Hendrik Maas: Use Data element CHAR1 instead of BAPIUPDATE as it will not work for BAPI_SALESDOCUMENT_CHANGE)

Similarly do for VBAK, BAPE_VBAK, BAPE_VBAKX, VBAKKOZ and VBAKKOZX.

Next we get to the code to fill in the structure EXTENSIONIN
I will demonstrate how to call the create sales order BAPI with custom fields.

* Local definitions
  DATA: wa_extensionin TYPE bapiparex,
        wa_bape_vbap   TYPE bape_vbap,
        wa_bape_vbapx  TYPE bape_vbapx,
        wa_bape_vbak   TYPE bape_vbak,
        wa_bape_vbakx  TYPE bape_vbakx,
        lv_posnr       TYPE posnr.

* Processing the header extension
  CLEAR wa_bape_vbak.
  wa_bape_vbak-ZZFIELD     = 'HDRTEST'.
  wa_extensionin-structure = 'BAPE_VBAK'.
  wa_extensionin+30(960)   = wa_bape_vbak.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

* Processing the line extension
LOOP AT line_items INTO wa_lineitems.

  ADD 10 TO lv_posnr.   
  CLEAR wa_bape_vbap.
  wa_bape_vbap-ZZFIELD     = 'TEST'.
  wa_extensionin-structure = 'BAPE_VBAP'.
  wa_bape_vbap-posnr       = lv_posnr.
  wa_extensionin+30(960)   = wa_bape_vbap.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

  CLEAR wa_bape_vbapx.
  wa_bape_vbapx-ZZFIELD    = 'X'.
  wa_extensionin-structure = 'BAPE_VBAPX'.
  wa_bape_vbapx-posnr      = lv_posnr.
  wa_extensionin+30(960)   = wa_bape_vbapx.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

ENDLOOP.

* Then the call to the BAPI
      CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
        EXPORTING
          order_header_in  = ls_order_header_in
          order_header_inx = ls_order_header_inx
        IMPORTING
          salesdocument    = lv_salesdocument
        TABLES
          return           = lt_ret2
          order_items_in   = lt_order_items_in
          order_items_inx  = lt_order_items_inx
          order_partners   = lt_order_partners
          order_keys       = lt_order_keys
          extensionin      = lt_extensionin.

Note: If you have a need to force a different Business Object type or wish to see the extension return fields then use the function SD_SALESDOCUMENT_CREATE instead.

      CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
        EXPORTING
          sales_header_in     = ls_order_header_in
          sales_header_inx    = ls_order_header_inx
          business_object     = 'BUS2032'
        IMPORTING
          salesdocument_ex    = lv_salesdocument
          sales_header_out    = lv_sales_header_out
          sales_header_status = lv_sales_header_status
        TABLES
          return              = lt_ret2
          sales_items_in      = lt_order_items_in
          sales_items_inx     = lt_order_items_inx
          sales_partners      = lt_order_partners
          sales_keys          = lt_order_keys
          extensionin         = lt_extensionin
          incomplete_log      = lt_incomplete_log
          extensionex         = lt_extensionex.

13 Comments
naimesh_patel
Active Contributor
Hello Kevin,

It looks like you haven't searched enough:
Create Salesorder throw BAPI_SALESORDER_CREATEFROMDATA2 USING EXTENSIOIN
(Code is for the BAPI BAPI_SALESORDER_CHANGE but the way we fill the extension structure remains same)

Regards,
Naimesh Patel
kevin_wilson2
Contributor
With all due respect Naimesh, that blog comes closer than I have seen but still it has shortcomings. It does not have the code to support a solution for more than 1 field of length 4 by using the statement it_ext-valuepart1+11(4) = 'TEST'. It should me more generic showing how to add multiple fields... They hardcode valuepart1 in there and that's not how you do it. It's much better to do wa_extensionin+30(960)   = wa_bape_vbapx. That way you get many more fields catered for.
Also the link is incorrect and should be Create Salesorder throw BAPI_SALESORDER_CREATEFROMDATA2 USING EXTENSIOIN
Thank you for your comments
Former Member
0 Kudos
Hi Kevin,

your way might work with BAPI BAPI_SALESORDER_CREATEFROMDAT2 but won't work with BAPI BAPI_SALESDOCUMENT_CHANGE (Release here is 6.40).

Within Form GET_CHANGEABLE_FIELDS (LVBAKF0G) is a check implemented which only allow the data element CHAR1 or CHAR01 in structure VB**KOMX structure. It won't work with data element BAPIUPDATE. I spend a lot of time with debuging to find out this special check.

Hopefully my first post on SDN will help some other.

Regards
kevin_wilson2
Contributor
0 Kudos
Thank you Hendrik for the great trip. It's good to know. I have updated the blog to include your tip. Thank you
Joseph_BERTHE
Active Contributor
0 Kudos

Kevin, Big Thanks :smile: It works.

I would defenitively not found it alone 

Great job.

Former Member
0 Kudos

Kevin,

You made my day. After tiresome hours of debugging , tried the below tip  and it worked like a charm :smile:

(Note: A great tip from Hendrik Maas: Use Data element CHAR1 instead of BAPIUPDATE as it will not work for BAPI_SALESDOCUMENT_CHANGE)

Thanks for Sharing.

Cheers.

0 Kudos

Thank you very much, Kevin, this helped me  solve one misterious dump while using BAPI_SALESORDER_CREATE. One of the structures you mention (VBAPKOZ) had two customer fields missing. I followed your instructions and voila!

Really valuable info!.

GSerfiotis
Participant
0 Kudos
I don't know whether it is an issue of ERP's version but I had to append the Z-fields also to structures VBAKKOM & VBAKKOMX for VBAK to be updated through SD_SALESDOCUMENT_CREATE
Former Member
0 Kudos
Thank you, You saved me lot of time today. This solution worked 1000%
pacoga
Newcomer
0 Kudos
Thanks Kevin. This post has been very helpful.

Regards

 
hugoluizsouzajunior
Discoverer
0 Kudos
Thanks Kevin. This post has been very helpful.

Regards
former_member382625
Participant
0 Kudos
Thanks Kevin. You have mentioned that the value should be CHAR1 for the BAPI_SALESORDER_CHANGE.

We are using the fiori screens to create these fields which automatically enhanced the standard extensions. However, the extension are not created as CHAR1. So, we are unable to use BAPI_SALESORDER_CHANGE to update Z fields.

Are you aware of the recommended behaviour? Should data types be changed manually?
adityaw
Participant

Great Blog!
Just wanted to add, if using FM BAPI_CUSTOMERRETURN_CREATE or SD_SALESDOCUMENT_CREATE (not tested for BAPI_SALESORDER_CREATEFROMDAT2) and if we have custom header (VBAK) fields, then we need to add custom header fields in the following structures/tables:

  1. VBAK

  2. BAPE_VBAK

  3. BAPE_VBAKX

  4. VBAKKOM

  5. VBAKKOMX

I had not added in the last two and BAPI was not automatically passing the extension fields to custom fields.