Application Development and Automation 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: 
Read only

BAPI_SALES_ORDER_CHANGE

Former Member
0 Likes
1,074

All,

We are using BAPI_SALES_ORDER_CHANGE to add new line items to an existing Sales order, but are encountering some issues based on the way we are using this:

a) Our sales orders have over 5000 lines items and hence the BAPI call is extremely slow ( over 10 minutes for each line item ~)

b) When we are sending mutiple line items together for a sales order, if one line item has error the whole call is failing; but we donot know which line item has issue, rather we get only the business error message.

c) The BAPI does a bunch of post save processing like ATP etc., is there a way to override some of the checks by call parameters etc.

I am sure many of you may had similar situations, wanted to know how did you overcome the performance issue and also are there any settings that could always provide the line item that failed when we make the BAPI call or do we even need to use a different BAPI

Thanks,

Ashish

All,

We are using BAPI_SALES_ORDER_CHANGE to add new line items to an existing Sales order, but are encountering some issues based on the way we are using this:

a) Our sales orders have over 5000 lines items and hence the BAPI call is extremely slow ( over 10 minutes for each line item ~)

b) When we are sending mutiple line items together for a sales order, if one line item has error the whole call is failing; but we donot know which line item has issue, rather we get only the business error message.

c) The BAPI does a bunch of post save processing like ATP etc., is there a way to override some of the checks by call parameters etc.

I am sure many of you may had similar situations, wanted to know how did you overcome the performance issue and also are there any settings that could always provide the line item that failed when we make the BAPI call or do we even need to use a different BAPI

Thanks,

Ashish

3 REPLIES 3
Read only

Former Member
0 Likes
785

Hi Ashish,

See the sample report using the same BAPI

and change the code as per your logic

REPORT Z_SALES_ORDER_CHANGE

NO STANDARD PAGE HEADING

LINE-SIZE 132

LINE-COUNT 65(0)

MESSAGE-ID ZZ.

TABLES: VBAP.

DATA:

V_FILEIN(90) TYPE C,

V_RECIN TYPE I,

V_RECVBAP TYPE I,

V_RECORDER TYPE I,

V_VBELN LIKE VBAP-VBELN,

ORDERHEADERINX LIKE BAPISDH1X.

DATA: BEGIN OF I_ORDERS OCCURS 0,

VBELN LIKE VBAK-VBELN,

POSNR LIKE VBAP-POSNR,

BRGEW(18) TYPE C,

VOLUM(18) TYPE C,

END OF I_ORDERS.

DATA: BEGIN OF I_OUTPUT OCCURS 0,

VBELN LIKE VBAK-VBELN,

POSNR LIKE VBAP-POSNR,

  • GEWEI LIKE VBAP-GEWEI,

BRGEW LIKE VBAP-BRGEW,

VOLUM LIKE VBAP-VOLUM,

CKWGT TYPE C,

CKVOL TYPE C,

END OF I_OUTPUT.

DATA: BEGIN OF ORDERITEMIN OCCURS 0.

INCLUDE STRUCTURE BAPISDITM.

DATA: END OF ORDERITEMIN.

DATA: BEGIN OF ORDERITEMINX OCCURS 0.

INCLUDE STRUCTURE BAPISDITMX.

DATA: END OF ORDERITEMINX.

DATA: BEGIN OF RETURN OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA: END OF RETURN.

DATA: BEGIN OF BAPIRETURN OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA: END OF BAPIRETURN.

PARAMETERS:

P_PATH(45) TYPE C DEFAULT '/usr/users/ftpsapom/' LOWER CASE,

P_FNAME(32) TYPE C DEFAULT '/sweetjo.txt' LOWER CASE.

START-OF-SELECTION.

  • CONCATENATE PATH AND FILE NAME INTO ONE VARIABLE

CONCATENATE P_PATH P_FNAME INTO V_FILEIN.

  • OPEN DATASET

IF V_FILEIN IS INITIAL.

MESSAGE E002 WITH 'FILE' V_FILEIN 'DOES NOT CONTAIN ANY DATA!'.

  • & & & &

ELSE.

OPEN DATASET V_FILEIN

FOR INPUT

IN TEXT MODE.

IF SY-SUBRC = 0.

  • READ DATASET

DO.

READ DATASET V_FILEIN INTO I_ORDERS.

IF SY-SUBRC = 0.

APPEND I_ORDERS.

ELSE.

EXIT.

ENDIF.

ENDDO.

  • CLOSE DATASET

CLOSE DATASET V_FILEIN.

IF SY-SUBRC <> 0.

MESSAGE E002 WITH 'ERROR - CLOSING' V_FILEIN.

  • & & & &

ENDIF.

ELSE.

MESSAGE E002 WITH 'ERROR - COULD NOT OPEN' V_FILEIN.

  • & & & &

ENDIF.

ENDIF.

  • SORT AND REMOVE DUPLICATES FROM I_ORDERS

SORT I_ORDERS BY VBELN POSNR.

DELETE ADJACENT DUPLICATES FROM I_ORDERS.

  • POPULATE I_OUTPUT

LOOP AT I_ORDERS.

SHIFT I_ORDERS-POSNR LEFT DELETING LEADING SPACE.

CONCATENATE '0' I_ORDERS-POSNR INTO I_ORDERS-POSNR.

SELECT SINGLE BRGEW VOLUM

FROM VBAP

INTO (VBAP-BRGEW, VBAP-VOLUM)

WHERE VBELN = I_ORDERS-VBELN

AND POSNR = I_ORDERS-POSNR.

IF SY-SUBRC = 0.

IF VBAP-BRGEW = 0.

I_OUTPUT-CKWGT = 'X'.

ENDIF.

IF VBAP-VOLUM = 0.

I_OUTPUT-CKVOL = 'X'.

ENDIF.

I_OUTPUT-VBELN = I_ORDERS-VBELN.

I_OUTPUT-POSNR = I_ORDERS-POSNR.

  • I_OUTPUT-GEWEI = 'ST'.

I_OUTPUT-BRGEW = I_ORDERS-BRGEW.

I_OUTPUT-VOLUM = I_ORDERS-VOLUM.

APPEND I_OUTPUT.

CLEAR: I_OUTPUT.

ENDIF.

V_RECIN = V_RECIN + 1.

ENDLOOP.

  • POPULATE BAPI DATA AND RUN BAPI

CLEAR: ORDERHEADERINX, ORDERITEMIN, ORDERITEMINX,

RETURN, BAPIRETURN.

REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.

ORDERHEADERINX-UPDATEFLAG = 'U'.

LOOP AT I_OUTPUT WHERE CKWGT = 'X' OR CKVOL = 'X'.

V_RECVBAP = V_RECVBAP + 1.

IF I_OUTPUT-VBELN <> V_VBELN AND SY-TABIX <> 1.

V_RECORDER = V_RECORDER + 1.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = V_VBELN

ORDER_HEADER_INX = ORDERHEADERINX

TABLES

RETURN = RETURN

ORDER_ITEM_IN = ORDERITEMIN

ORDER_ITEM_INX = ORDERITEMINX.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

IMPORTING

RETURN = BAPIRETURN.

  • WRITE OUT RETURN

LOOP AT RETURN.

WRITE: / RETURN.

ENDLOOP.

WRITE: / BAPIRETURN.

SKIP.

CLEAR: ORDERITEMIN, ORDERITEMINX,

RETURN, BAPIRETURN.

REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.

ENDIF.

ORDERITEMIN-ITM_NUMBER = I_OUTPUT-POSNR.

  • ORDERITEMIN-UNTOF_WGHT = I_OUTPUT-GEWEI.

IF NOT I_OUTPUT-CKWGT IS INITIAL.

ORDERITEMIN-GROSS_WGHT = I_OUTPUT-BRGEW.

ORDERITEMINX-GROSS_WGHT = 'X'.

ENDIF.

IF NOT I_OUTPUT-CKVOL IS INITIAL.

ORDERITEMIN-VOLUME = I_OUTPUT-VOLUM.

ORDERITEMINX-VOLUME = 'X'.

ENDIF.

APPEND ORDERITEMIN.

ORDERITEMINX-ITM_NUMBER = I_OUTPUT-POSNR.

  • ORDERITEMINX-UNTOF_WGHT = 'X'.

ORDERITEMINX-UPDATEFLAG = 'U'.

APPEND ORDERITEMINX.

V_VBELN = I_OUTPUT-VBELN.

ENDLOOP.

  • RUN BAPI ON LAST ORDER

IF NOT ORDERITEMIN IS INITIAL.

V_RECORDER = V_RECORDER + 1.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = V_VBELN

ORDER_HEADER_INX = ORDERHEADERINX

TABLES

RETURN = RETURN

ORDER_ITEM_IN = ORDERITEMIN

ORDER_ITEM_INX = ORDERITEMINX.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

IMPORTING

RETURN = BAPIRETURN.

  • WRITE OUT RETURN

LOOP AT RETURN.

WRITE: / RETURN.

ENDLOOP.

WRITE: / BAPIRETURN.

SKIP.

ENDIF.

  • WRITE OUT RECORD COUNT FROM FILE

WRITE: / 'RECORD COUNT FROM FILE ', V_RECIN.

SKIP.

  • WRITE OUT RECORD COUNT FROM FILE

WRITE: / 'RECORD COUNT OF LINES TO CHANGE ', V_RECVBAP.

SKIP.

  • WRITE OUT RECORD COUNT FROM FILE

WRITE: / 'RECORD COUNT OF ORDERS TO CHANGE ', V_RECORDER.

SKIP.

  • TOP OF PAGE

TOP-OF-PAGE.

WRITE:/1(5) TEXT-H01, 6(8) SY-DATUM MM/DD/YY,

100(8) TEXT-H02, 126(8) SY-PAGNO.

WRITE:/1(5) TEXT-H03, 6(8) SY-UZEIT USING EDIT MASK '__:__:__',

20(77) TEXT-H04,

100(8) TEXT-H05, 108(25) SY-REPID.

WRITE:/1(6) TEXT-H06, 8(12) SY-UNAME,

20(4) TEXT-H07, 25(32) SY-HOST,

100(13) TEXT-H08, 121(8) SY-SYSID,

129 '/', 130(3) SY-MANDT.

ULINE.

SKIP.

Hope this may be helpful.....

Regards

sana.

Read only

Former Member
0 Likes
785

Maybe I should have clarified. We did use the BAPI for each line item individually, but for sales order with over 1000 line items, this process crawls. So we are clubbing all the individual line items for the sales order and calling them once. but in this case if one single line item fails validation, the entire bunch is rejected and the error message does not pinpoint to the line item where the error occured. Wanted to know if you have faced with a similar limitations and how you possibly resolved this ?

Read only

0 Likes
785

All,

We have used the <b>behave_when_error</b> parameter on the BAPI call to achieve what we really intended to do. Setting the parameter to "P", processes all valid items and gives individual errors for each invalidate item.

this has solved my problem.

thx

Ashish