2007 Jul 11 10:33 PM
Hi,
I am trying to use BAPI_SALESORDER_CHANGE to modify the contents of the sales order item quantity. but the below code was not working, can any one correct the below program.
I have seen the same type of post few months back but no one provided the solution till now. I hope experts can correct my program. Surely i will reward.
regards
jaya
-
REPORT y_bapi1 .
TABLES: vbap.
DATA:
bapichdr LIKE bapisdh1,
bapichdrx LIKE bapisdh1x,
bapirtn LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
bapiitm LIKE bapisditm OCCURS 0 WITH HEADER LINE,
bapiitmx LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
DATA: s_vbap LIKE vbap.
PARAMETERS: p_vbeln LIKE vbap-vbeln DEFAULT '40486',
p_posnr LIKE vbap-posnr DEFAULT '20'.
start-of-selection.
START-OF-SELECTION.
PERFORM get_data_4m_vbap.
PERFORM fill_header_in.
PERFORM fill_header_inx.
PERFORM fill_item_in.
PERFORM fill_item_inx.
PERFORM call_bapi_so_change.
PERFORM call_bapi_commit.
&----
*& Form get_data_4m_vbap
&----
text
----
FORM get_data_4m_vbap.
SELECT SINGLE * FROM
vbap
INTO s_vbap
WHERE vbeln = p_vbeln
AND posnr = p_posnr.
ENDFORM. " get_data_4m_vbap
&----
*& Form fill_header_in
&----
text
----
FORM fill_header_in.
*bapichdr
ENDFORM. " fill_header_in
&----
*& Form fill_header_inx
&----
text
----
FORM fill_header_inx.
bapichdrx-updateflag = 'U'.
ENDFORM. " fill_header_inx
&----
*& Form fill_item_in
&----
text
----
FORM fill_item_in.
bapiitm-itm_number = p_posnr.
bapiitm-target_qty = s_vbap-kwmeng + 5.
APPEND bapiitm.
CLEAR bapiitm.
ENDFORM. " fill_item_in
&----
*& Form fill_item_inx
&----
text
----
FORM fill_item_inx.
bapiitmx-itm_number = p_posnr.
bapiitmx-updateflag = 'U'. " I for insert & D for Delete
bapiitmx-TARGET_QTY = 'X'.
APPEND bapiitmx.
CLEAR bapiitmx.
bapiitmx-itm_number = p_posnr.
bapiitmx-updateflag = 'I'. " I for insert & D for Delete
bapiitmx-target_qty = 'X'.
APPEND bapiitmx.
CLEAR bapiitmx.
ENDFORM. " fill_item_inx
&----
*& Form call_bapi_SO_change
&----
text
----
FORM call_bapi_so_change.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_vbeln
order_header_in = bapichdr
order_header_inx = bapichdrx
SIMULATION =
BEHAVE_WHEN_ERROR = ' '
INT_NUMBER_ASSIGNMENT = ' '
LOGIC_SWITCH =
NO_STATUS_BUF_INIT = ' '
TABLES
return = bapirtn
order_item_in = bapiitm
order_item_inx = bapiitmx
PARTNERS =
PARTNERCHANGES =
PARTNERADDRESSES =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
SCHEDULE_LINES =
SCHEDULE_LINESX =
ORDER_TEXT =
ORDER_KEYS =
CONDITIONS_IN =
CONDITIONS_INX =
EXTENSIONIN =
.
READ TABLE bapirtn WITH KEY id = 'V1' number = '311'.
IF sy-subrc <> 0.
PERFORM bapi_errorlist.
ENDIF.
ENDFORM. " call_bapi_SO_change
&----
*& Form call_bapi_commit
&----
text
----
FORM call_bapi_commit.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN =
.
ENDFORM. " call_bapi_commit
&----
*& Form bapi_errorlist
&----
text
----
FORM bapi_errorlist.
DATA: bapierr TYPE c,
string TYPE string,
i TYPE i.
bapierr = 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LEAVE TO LIST-PROCESSING.
SET PF-STATUS 'LIST'.
FORMAT INTENSIFIED ON.
WRITE: / 'BAPI ERROR OCCURED' COLOR COL_NEGATIVE INVERSE ON.
SKIP 1.
LOOP AT bapirtn.
CONCATENATE bapirtn-type bapirtn-number '(' bapirtn-id ')'
INTO string.
WRITE: / string.
i = strlen( bapirtn-message ).
WRITE bapirtn-message(i).
ENDLOOP.
LEAVE TO SCREEN 0100.
ENDFORM. " bapi_errorlist
-
2007 Jul 11 10:47 PM
Hello Jaya,
The problem would be you are not using SCHEDULE_LINES ,so try to use.
see the below program for referenec:
REPORT ZTRIALBAPICHANGE message-id z3d .
DATA:I_HEADER1 TYPE BAPISDH1.
DATA:I_HEADER1X TYPE BAPISDH1X.
DATA:I_PART1 LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE.
DATA:I_ITEMS1 LIKE BAPISDITM OCCURS 0 WITH HEADER LINE.
DATA:I_ITEMS1X LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA:I_SCH1 LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE.
DATA:I_SCH1X LIKE BAPISCHDLX OCCURS 0 WITH HEADER LINE.
data:err like bapiret2 occurs 0 with header line.
DATA:RETSALES LIKE VBAK-VBELN.
DATA:R(4).
R = '609'.
I_HEADER1-SALES_ORG = '0001'.
I_HEADER1-DISTR_CHAN = '01'.
I_HEADER1-DIVISION = '01'.
MOVE:'U' TO I_HEADER1X-UPDATEFLAG.
MOVE:'X' TO I_HEADER1X-SALES_ORG.
MOVE:'X' TO I_HEADER1X-DISTR_CHAN.
MOVE:'X' TO I_HEADER1X-DIVISION.
*********************************************************
**PARTNER
********************************************************
CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
EXPORTING
INPUT = 'SP'
IMPORTING
OUTPUT = I_PART1-PARTN_ROLE.
I_PART1-PARTN_NUMB = '0000000011'.
APPEND I_PART1.
*********************************************************
**ITEM DETAILS
********************************************************
I_ITEMS1-MATERIAL = '000000000000000011'.
I_ITEMS1-ITM_NUMBER = '000011'.
APPEND I_ITEMS1.
MOVE:'U' TO I_ITEMS1X-UPDATEFLAG.
MOVE:'X' TO I_ITEMS1X-MATERIAL.
APPEND I_ITEMS1X.
*********************************************************
**SCHEDULE LINE
********************************************************
I_SCH1-ITM_NUMBER = '000011'.
I_SCH1-REQ_QTY = '100'.
I_SCH1-SCHED_LINE = '0000'.
APPEND I_SCH1.
MOVE:'U' TO I_SCH1X-UPDATEFLAG.
MOVE:'X' TO I_SCH1X-ITM_NUMBER.
MOVE:'X' TO I_SCH1X-REQ_QTY.
MOVE:'X' TO I_SCH1X-SCHED_LINE.
APPEND I_SCH1.
UNPACK R TO RETSALES.
.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = RETSALES
ORDER_HEADER_IN = I_HEADER1
order_header_inx = I_HEADER1X
SIMULATION = 'X'
BEHAVE_WHEN_ERROR = ' '
INT_NUMBER_ASSIGNMENT = ' '
LOGIC_SWITCH =
tables
return = ERR
ORDER_ITEM_IN = I_ITEMS1
ORDER_ITEM_INX = I_ITEMS1X
PARTNERS = I_PART1
PARTNERCHANGES =
PARTNERADDRESSES =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
SCHEDULE_LINES = I_SCH1
SCHEDULE_LINESX = I_SCH1X
ORDER_TEXT =
ORDER_KEYS =
CONDITIONS_IN =
CONDITIONS_INX =
EXTENSIONIN =
.
loop at err.
format color 4.
write:/ err-type,
err-id,
err-number,
err-message,
err-log_no,
err-log_msg_no,
err-message_v1,
err-message_v2,
err-message_v3,
err-message_v4,
err-parameter,
err-row,
err-field,
err-system.
*WRITE:/10 ERR-MESSAGE.
endloop.
IF ERR-TYPE <> 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
MESSAGE S101 WITH RETSALES.
ELSE.
MESSAGE S100.
ENDIF.
Thanks
Seshu
2007 Jul 11 10:47 PM
Hello Jaya,
The problem would be you are not using SCHEDULE_LINES ,so try to use.
see the below program for referenec:
REPORT ZTRIALBAPICHANGE message-id z3d .
DATA:I_HEADER1 TYPE BAPISDH1.
DATA:I_HEADER1X TYPE BAPISDH1X.
DATA:I_PART1 LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE.
DATA:I_ITEMS1 LIKE BAPISDITM OCCURS 0 WITH HEADER LINE.
DATA:I_ITEMS1X LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA:I_SCH1 LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE.
DATA:I_SCH1X LIKE BAPISCHDLX OCCURS 0 WITH HEADER LINE.
data:err like bapiret2 occurs 0 with header line.
DATA:RETSALES LIKE VBAK-VBELN.
DATA:R(4).
R = '609'.
I_HEADER1-SALES_ORG = '0001'.
I_HEADER1-DISTR_CHAN = '01'.
I_HEADER1-DIVISION = '01'.
MOVE:'U' TO I_HEADER1X-UPDATEFLAG.
MOVE:'X' TO I_HEADER1X-SALES_ORG.
MOVE:'X' TO I_HEADER1X-DISTR_CHAN.
MOVE:'X' TO I_HEADER1X-DIVISION.
*********************************************************
**PARTNER
********************************************************
CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
EXPORTING
INPUT = 'SP'
IMPORTING
OUTPUT = I_PART1-PARTN_ROLE.
I_PART1-PARTN_NUMB = '0000000011'.
APPEND I_PART1.
*********************************************************
**ITEM DETAILS
********************************************************
I_ITEMS1-MATERIAL = '000000000000000011'.
I_ITEMS1-ITM_NUMBER = '000011'.
APPEND I_ITEMS1.
MOVE:'U' TO I_ITEMS1X-UPDATEFLAG.
MOVE:'X' TO I_ITEMS1X-MATERIAL.
APPEND I_ITEMS1X.
*********************************************************
**SCHEDULE LINE
********************************************************
I_SCH1-ITM_NUMBER = '000011'.
I_SCH1-REQ_QTY = '100'.
I_SCH1-SCHED_LINE = '0000'.
APPEND I_SCH1.
MOVE:'U' TO I_SCH1X-UPDATEFLAG.
MOVE:'X' TO I_SCH1X-ITM_NUMBER.
MOVE:'X' TO I_SCH1X-REQ_QTY.
MOVE:'X' TO I_SCH1X-SCHED_LINE.
APPEND I_SCH1.
UNPACK R TO RETSALES.
.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = RETSALES
ORDER_HEADER_IN = I_HEADER1
order_header_inx = I_HEADER1X
SIMULATION = 'X'
BEHAVE_WHEN_ERROR = ' '
INT_NUMBER_ASSIGNMENT = ' '
LOGIC_SWITCH =
tables
return = ERR
ORDER_ITEM_IN = I_ITEMS1
ORDER_ITEM_INX = I_ITEMS1X
PARTNERS = I_PART1
PARTNERCHANGES =
PARTNERADDRESSES =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
SCHEDULE_LINES = I_SCH1
SCHEDULE_LINESX = I_SCH1X
ORDER_TEXT =
ORDER_KEYS =
CONDITIONS_IN =
CONDITIONS_INX =
EXTENSIONIN =
.
loop at err.
format color 4.
write:/ err-type,
err-id,
err-number,
err-message,
err-log_no,
err-log_msg_no,
err-message_v1,
err-message_v2,
err-message_v3,
err-message_v4,
err-parameter,
err-row,
err-field,
err-system.
*WRITE:/10 ERR-MESSAGE.
endloop.
IF ERR-TYPE <> 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
MESSAGE S101 WITH RETSALES.
ELSE.
MESSAGE S100.
ENDIF.
Thanks
Seshu
2007 Jul 11 10:56 PM
Hi Seshu,
Thanks for your information, but what is the need of using schedule lines, is it mandatory for BAPI, i dont think so.
When we go to VA02 and change the line item quantity, it will change successfully without changing anything in the schedule lines. So why cant we do the same changes through BAPI.
Can you please clarify me the issue & solution.
Regards
jaya
2007 Jul 11 11:04 PM
Hi jaya,
When you create sales order,you give qty in normal way,system will take schdule qty default,but when you create sales order using BAPI,then you need to fill otherwise it will not update.
Check the BAPI Documentation ..
Thanks
Seshu
2007 Jul 12 3:35 AM