Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

order reason update in vbak not working when using bapi_salesorder_change

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.

Tags:
Former Member
Former Member replied

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

WA_ORDER_HEADER_INX-ORD_REASON = 'X;

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question