Skip to Content

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

*BAPI_SALESORDER_CHANGE*

Hi Gurus ,

Please tell me where i have to do the changes to update the vbeln field using bapi BAPI_SALESORDER_CHANGE ,,,,

pls c the following code ....

&----


*& Report ZTEST *

*& *

&----


*& *

*& *

&----


REPORT ZTEST .

type-pools: slis.

tables: VBAK , "Sales Document: Header Data

VBBE , "Sales Requirements: Indiv Recs

VBUP . "Sales Document: Item Status

=====================================================================

  • SELECTION-SCREEN *

=====================================================================

selection-screen: begin of block blk1 with frame title TEXT-001.

select-options: s_email FOR VBAK-ZREQ_EMAIL obligatory no intervals,

S_LFGSA for VBUP-LFGSA default 'A' TO 'B' ,

S_AUART for VBBE-AUART default 'ZPYX' no intervals.

selection-screen: end of block blk1.

=====================================================================

  • INTERNAL TABLES *

=====================================================================

data: begin of i_header occurs 0,

VBELN like VBAK-VBELN,

  • BNAME like VBAK-BNAME,

ZREQ_EMAIL like VBAK-ZREQ_EMAIL,

LFGSA like VBUP-LFGSA,

AUART like VBBE-AUART,

end of i_header.

data: begin of i_vbup occurs 0,

VBELN like VBUP-VBELN,

LFGSA like VBUP-LFGSA,

end of i_vbup.

Data: begin of i_vbbe occurs 0,

VBELN like VBBE-VBELN,

AUART like VBBE-AUART,

end of i_vbbe.

Data: begin of i_bo_alerts occurs 0,

VBELN like VBAK-VBELN,

  • BNAME like VBAK-BNAME,

ZREQ_EMAIL like VBAK-ZREQ_EMAIL,

end of i_bo_alerts.

DATA: W_ORD_H like BAPISDH1,

W_ORD_HX like BAPISDH1X,

wa_salesorder LIKE vbak-vbeln,

gt_extn like bapiparex occurs 0 with header line.

data: begin of IT_DATA occurs 0,

VBELN like VBAK-VBELN,

  • BNAME like VBAK-BNAME,

ZREQ_EMAIL like vbak-ZREQ_EMAIL,

  • LFGSA like VBUP-LFGSA,

  • AUART like VBBE-AUART,

end of IT_DATA.

DATA: w_upd_err_cnt like sy-index.

data: w_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: wa_ret2 TYPE BAPIRET2,

l_msgno LIKE t100-msgnr,

l_msgtxt(255) TYPE c,

lt_cont LIKE soli OCCURS 0 WITH HEADER LINE,

glin like sy-tabix.

data: wa_email(200) type c.

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

  • C O N S T A N T S *

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

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

  • V A R I A B L E S *

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

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

  • I N C L U D E S

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

INCLUDE zcaut_alv_reports.

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

  • I N I T I A L I Z A T I O N *

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

INITIALIZATION.

ASSIGN IT_data[] TO <IT_data>.

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

  • AT SELECTION SCREEN.

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

PERFORM fill_bapi_header.

PERFORM FILL_BAPI_data.

PERFORM FILL_BAPI_EXTN.

PERFORM UPDATE_SALES_ORDER .

*&----


*& Form fill_bapi_header

*&----


FORM fill_bapi_header .

*-Set the update indicator for header version to 'X'

w_ord_hx-updateflag = 'U'.

w_ord_hx-VERSION = 'X'.

ENDFORM. " fill_bapi_header

*&----


*& Form FILL_BAPI_data

*&----


FORM FILL_BAPI_data .

SELECT aVBELN aZREQ_EMAIL

b~LFGSA

C~AUART

INTO TABLE i_header

FROM VBAK AS a INNER JOIN VBUP AS b

ON aVBELN = bVBELN

INNER JOIN VBBE AS c

ON bVBELN = cVBELN

WHERE a~ZREQ_EMAIL IN s_email

and b~LFGSA IN s_LFGSA

AND c~AUART IN s_AUART.

if sy-subrc = 0.

  • IF NOT i_header[] IS INITIAL .

  • SORT i_header BY VBELN .

SELECT VBELN LFGSA FROM VBUP

INTO TABLE I_VBUP

  • FOR ALL ENTRIES IN I_HEADER

WHERE VBELN = I_HEADER-VBELN

AND LFGSA IN S_LFGSA.

if sy-subrc = 0.

SELECT VBELN AUART FROM VBBE

INTO TABLE I_VBBE

WHERE VBELN = 'ZPYX'

AND AUART in S_AUART.

ENDIF.

  • endif.

endif.

SORT IT_data BY VBELN ZREQ_EMAIL .

  • SORT IT_data BY VBELN ZREQ_EMAIL auart lfgsa.

LOOP AT i_header.

at new ZREQ_EMAIL.

MOVE: i_header-VBELN TO it_data-VBELN,

  • i_header-BNAME TO it_data-BNAME,

i_header-ZREQ_EMAIL TO it_data-ZREQ_EMAIL.

  • i_header-LFGSA TO it_data-LFGSA,

  • i_header-AUART TO it_data-AUART.

APPEND it_data.

move it_data[] to gt_extn[].

CLEAR i_header.

endat.

ENDLOOP.

ENDFORM. " FILL_BAPI_data

*&----


*& Form FILL_BAPI_EXTN

*&----


FORM FILL_BAPI_EXTN .

gt_extn-structure = 'BAPE_VBAK'.

gt_extn-VALUEPART1 = wa_salesorder.

gt_extn-VALUEPART1+10(60) = wa_email.

APPEND gt_extn.

CLEAR gt_extn.

gt_extn-structure = 'BAPE_VBAKX'.

gt_extn-VALUEPART1 = it_data-vbeln.

gt_extn-VALUEPART1+10(1) = 'X'.

APPEND gt_extn.

CLEAR gt_extn.

ENDFORM. " FILL_BAPI_EXTN

*&----


*& Form UPDATE_SALES_ORDER

*&----


FORM UPDATE_SALES_ORDER .

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = wa_salesorder

order_header_inx = w_ord_hx

TABLES

return = w_return

EXTENSIONIN = gt_extn."Requestor e-mail.

LOOP AT w_return.

IF w_return-type = 'E'. "Error

PERFORM format_error_messages.

ENDIF.

ENDLOOP.

ENDFORM. " UPDATE_SALES_ORDER

*&----


*& Form format_error_messages

*&----


FORM format_error_messages .

ADD 1 TO w_upd_err_cnt.

l_msgno = w_return-number.

CALL FUNCTION 'MESSAGE_PREPARE'

EXPORTING

language = sy-langu

msg_id = w_return-id

msg_no = l_msgno

msg_var1 = w_return-message_v1

msg_var2 = w_return-message_v2

msg_var3 = w_return-message_v3

msg_var4 = w_return-message_v4

IMPORTING

msg_text = l_msgtxt

EXCEPTIONS

function_not_completed = 1

message_not_found = 2

OTHERS = 3.

IF sy-subrc = 0.

CONCATENATE w_return-type w_return-id w_return-number

l_msgtxt INTO lt_cont+5(*) SEPARATED BY space.

move: l_msgtxt to w_return-message.

modify w_return.

ENDIF.

ENDFORM. " format_error_messages

Thanks

Peter

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