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: 

change of open sales order : using BAPI

Former Member
0 Kudos
171

Hi

this is ravi

can any one help me on this topic

1)change of open sales order using BAPI .With appropriate reason( like header level reason)

thanks & regards

2 REPLIES 2

Former Member
0 Kudos
75

hI,

chk this FM BAPI_SALESORDER_PROXY_UPLOAD how the FM BAPI_SALESORDER_CHANGE was used

Check this code,

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

<b>Reward points</b>

Regards

0 Kudos
75

hi ,

thanks a lot for giving me the reply , it is very help ful for me

thanks & regards