Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

order reason update in vbak not working when using bapi_salesorder_change

Former Member
0 Kudos

I am able to update 'reason for code' at the item level and am not able to update 'order reason' at headr level. And the bapi return message says success:

message S V4 233

ORDER_HEADER_IN has been processed successfully

message S V4 233

ITEM_IN has been processed successfully

message S V1 311

XXXXXXXXX xxxxxxxxx Order 10087153 has been saved

*****************************************************************

Any help is greatly appreciated.

Following is the code for reference.

  • * For Calling the BAPI Function *------------------------------------------

DATA: z_osales TYPE BAPIVBELN-VBELN VALUE '0010087153', "sales order number

z_oposnr TYPE POSNR_VA VALUE '000010', "item number

WA_ORDER_HEADER_IN LIKE BAPISDH1,

WA_ORDER_HEADER_INX LIKE BAPISDH1X,

IT_ORDER_header_IN LIKE TABLE OF BAPISDH1,

IT_ORDER_ITEM_IN LIKE TABLE OF bapisditm,

WA_ORDER_ITEM_IN LIKE line of IT_ORDER_ITEM_IN,

IT_ORDER_ITEM_INX LIKE TABLE OF BAPISDITMX ,

WA_ORDER_ITEM_INX LIKE LINE OF IT_ORDER_ITEM_INX,

IT_SCHEDULE_LINES LIKE TABLE OF BAPISCHDL ,

WA_SCHEDULE_LINES LIKE LINE OF IT_SCHEDULE_LINES,

IT_SCHEDULE_LINESX LIKE TABLE OF BAPISCHDLX ,

WA_SCHEDULE_LINESX LIKE LINE OF IT_SCHEDULE_LINESX,

IT_RETURN_CHG LIKE TABLE OF BAPIRET2,

WA_RETURN_CHG LIKE LINE OF IT_RETURN_CHG,

IT_RETURN_CT LIKE BAPIRET2.

***********internal table and work area for item level fields***********

DATA: BEGIN OF WA,

werks TYPE BAPISDITM-plant,

matNR type BAPISDITM-material,

poSEX type BAPISDITM-po_itm_no,

ARKTX type BAPISDITM-short_text,

kdmat type BAPISDITM-cust_mat35,

posnr type BAPISDITM-po_itm_no,

netwr type BAPISDITM-target_val,

augru type bapisdh1-ord_reason,

end of WA,

it like table of wa.

*********select those entries which need to be changed**********

Select posnr matnr arktx werks posex kdmat augru from

( VBAP inner join vbak ON vbapvbeln = vbakvbeln )

into corresponding fields of TABLE it

where vbap~VBELN = z_osales and posnr = z_oposnr.

write: / 'sy-subrc', sy-subrc.

******************update the bapi structure****************

loop at it into wa.

wa_ORDER_ITEM_IN-ITM_NUMBER = wa-posnr.

WA_ORDER_ITEM_IN-plant = wa-werks.

WA_ORDER_ITEM_IN-material = wa-matnr.

WA_ORDER_ITEM_IN-short_text = wa-arktx.

WA_ORDER_ITEM_IN-cust_mat35 = wa-kdmat.

WA_ORDER_ITEM_IN-target_val = wa-netwr.

WA_ORDER_ITEM_IN-REASON_REJ = '06'. "THIS IS BEING CHANGED

WA_ORDER_HEADER_IN-ORD_REASON = '027'. "THIS IS NOT BEING CHANGED

APPEND WA_ORDER_ITEM_IN TO IT_ORDER_ITEM_IN.

endloop.

PERFORM SOHEADERINDEX .

perform soheader.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = z_osales

ORDER_HEADER_INX = WA_ORDER_HEADER_INX

ORDER_HEADER_IN = wa_ORDER_HEADER_IN

TABLES

RETURN = IT_RETURN_CHG

ORDER_ITEM_IN = IT_ORDER_ITEM_IN.

LOOP AT IT_RETURN_CHG INTO WA_RETURN_CHG.

WRITE: / 'message ', WA_RETURN_CHG-type, WA_RETURN_CHG-id, WA_RETURN_CHG-number, WA_RETURN_CHG-message.

ENDLOOP.

write: / '*****************************************************************'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = space

IMPORTING

RETURN = i_cret2.

if sy-subrc ne 0.

message i005 with z_osales.

stop.

endif.

&----


*& Form SOHEADERINDEX

&----


  • text

----


FORM SOHEADERINDEX .

WA_ORDER_HEADER_INX-UPDATEFLAG = 'U'.

  • s("ORDER_HEADER_IN").Value("REQ_DATE_H") = 20080606

ENDFORM. " SOHeaderIndex

&----


*& Form SOHEADERINDEX

&----


  • text

----


FORM SOHEADER.

WA_ORDER_HEADER_IN-ORD_REASON = '011'.

ENDFORM.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

you need to specify order_item_inx too to denote which fields are you updating, I dont see any vlaues going in that one as well as in ORDER_HEADER_INX

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = z_osales

ORDER_HEADER_INX = WA_ORDER_HEADER_INX

ORDER_HEADER_IN = wa_ORDER_HEADER_IN

TABLES

RETURN = IT_RETURN_CHG

ORDER_ITEM_IN = IT_ORDER_ITEM_IN.

4 REPLIES 4

Former Member
0 Kudos

you need to specify order_item_inx too to denote which fields are you updating, I dont see any vlaues going in that one as well as in ORDER_HEADER_INX

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = z_osales

ORDER_HEADER_INX = WA_ORDER_HEADER_INX

ORDER_HEADER_IN = wa_ORDER_HEADER_IN

TABLES

RETURN = IT_RETURN_CHG

ORDER_ITEM_IN = IT_ORDER_ITEM_IN.

0 Kudos

order_item_inx is at item level and it has only "reason for rejection" which is already being updated. I want a modification of "order reason" filed at header level.

After your suggestion, I added WA_ORDER_HEADER_INX-ORD_REASON = '011' but still it is not being updated

FORM SOHEADERINDEX .

WA_ORDER_HEADER_INX-UPDATEFLAG = 'U'.

WA_ORDER_HEADER_INX-ORD_REASON = '011'. "ADDED THIS NOW

ENDFORM. " SOHeaderIndex

0 Kudos

it has to be 'X' not 011 or the actual value

WA_ORDER_HEADER_INX-ORD_REASON = 'X;

0 Kudos

Thanks a bunch.