cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Outbound Delivery Order in EWM and Outbound Delivery in S4

mpecoraro
Participant

Hi SAP Experts,

I am working on Embeded EWM system and the client would like zero out both the quantities in the ODO in EWM and Outbound Delivery in S4 for orders that they do not have enough stock for.

Here is the process I would like to automate:

Begin of process the Delivery is distributed to EWM.

The warehouse releases the waves and realize theres not enough stock to fulfill this delivery so they must zero out the delivery as the business cannot wait for the warehouse to receive more stock they will simply order from another vendor. The warehouse must now Zero out the odo by assigning the below process code and minus sign to zero it out with process code.

In S4 although the process code has been assigned to the ODO item the OD in S4 is still not zeroed out.

To zero out the quantity the user must:

Now check s4 delivery:

I have created the below program however, it only works for one delivery number and is not working for multiple and does not update the OD in S4. Can someone please help me with the above points to be able to process multiple document numbers and update the quanitity in the OD in S4?

*&---------------------------------------------------------------------*

*& Report ZMWM1002

*&---------------------------------------------------------------------*

*&

*&---------------------------------------------------------------------*

report ZMWM1002 message-id 28.

data PT_DATA type /SCDL/DB_PROCI_O occurs 0.

data: LS_DATA type /SCDL/DB_PROCI_O.

data:

LO_SP type ref to /SCDL/CL_SP_PRD_OUT,

LO_MESSAGE_BOX type ref to /SCDL/CL_SP_MESSAGE_BOX,

LS_ACTION type /SCDL/S_SP_ACT_ACTION,

LT_A_HEAD type /SCDL/T_SP_A_HEAD,

LT_A_HEAD_INCOTERMS_OUT type /SCDL/T_SP_A_HEAD_INCOTERMS,

LT_A_HEAD_INCOTERMS type /SCDL/T_SP_A_HEAD_INCOTERMS,

LS_A_HEAD_INCOTERMS type /SCDL/S_SP_A_HEAD_INCOTERMS,

LT_A_ITEM type /SCDL/T_SP_A_ITEM,

LV_REJECTED type BOOLE_D,

LT_RETURN_CODES type /SCDL/T_SP_RETURN_CODE,

LT_MESSAGES type /SCDL/DM_MESSAGE_TAB.

data: LS_SP_K_HEAD type /SCDL/S_SP_K_HEAD,

LT_SP_K_HEAD type /SCDL/T_SP_K_HEAD,

LS_PRCODES_IN type /SCDL/S_SP_A_ITEM_PRCODES,

LT_PRCODES_IN type /SCDL/T_SP_A_ITEM_PRCODES,

LT_PRCODES_OUT type /SCDL/T_SP_A_ITEM_PRCODES.

field-symbols: <LS_PRCODES_IN> type /SCDL/S_SP_A_ITEM_PRCODES.

data PV_ERROR(1) type C.

constants : begin of B1,

DOCNO type /SCDL/DB_PROCI_O-DOCNO value is initial,

ITEMNO type /SCDL/DL_ITEMNO value is initial,

end of B1.

select-options: S_DOCNO for B1-DOCNO obligatory,

S_ITEMNO for B1-ITEMNO.

parameters: P_QTY_UI type /SCWM/DE_UI_QUAN.

start-of-selection.

if S_DOCNO[] is not initial.

perform AUTOCLEANDLV.

else.

message I999 with 'Doc Number Required'.

endif.

form AUTOCLEANDLV.

refresh PT_DATA.

select * into table @PT_DATA

from /SCDL/DB_PROCI_O

where DOCNO in @S_DOCNO[]

and ITEMNO in @S_ITEMNO[].

clear PV_ERROR.

try.

create object LO_MESSAGE_BOX.

create object LO_SP

exporting

IO_MESSAGE_BOX = LO_MESSAGE_BOX

IV_DOCCAT = /SCDL/IF_DL_DOC_C=>SC_DOCCAT_OUT_PRD

IV_MODE = /SCDL/CL_SP=>SC_MODE_CLASSIC.

catch /SCDL/CX_SP_MESSAGE_BOX.

PV_ERROR = 'X'.

exit.

endtry.

select DOCID ITEMID QTY UOM

from /SCDL/DB_PROCI_O

into corresponding fields of table LT_PRCODES_IN

for all entries in PT_DATA

where DOCCAT = 'PDO'

and DOCNO = PT_DATA-DOCNO " 1 docno

and ITEMNO = PT_DATA-ITEMNO " Could have multiple items we're splitting off

and QTY gt 0 " Just in case the user tries to reprocess the same data twice!

and DOCNO in S_DOCNO[]

and ITEMNO in S_ITEMNO[].

if SY-SUBRC ne 0.

exit.

endif.

* Lock the ODO

read table LT_PRCODES_IN into LS_PRCODES_IN index 1.

LS_SP_K_HEAD-DOCID = LS_PRCODES_IN-DOCID.

append LS_SP_K_HEAD to LT_SP_K_HEAD.

clear: LT_RETURN_CODES, LV_REJECTED.

LO_SP->LOCK(

exporting

INKEYS = LT_SP_K_HEAD

ASPECT = /SCDL/IF_SP_C=>SC_ASP_HEAD

LOCKMODE = /SCDL/IF_SP1_LOCKING=>SC_EXCLUSIVE_LOCK

importing

REJECTED = LV_REJECTED

RETURN_CODES = LT_RETURN_CODES ).

read table LT_RETURN_CODES transporting no fields with key FAILED = ABAP_TRUE.

if SY-SUBRC = 0 or LV_REJECTED = ABAP_TRUE.

PV_ERROR = ABAP_TRUE.

message S998 with 'Unable to Lock ODO' LS_DATA-DOCNO display like 'E'.

exit.

endif.

* Add the process code(s) and update the new quantity!

data: LV_QTY type /SCDL/DL_QUANTITY.

loop at LT_PRCODES_IN assigning <LS_PRCODES_IN>.

LV_QTY = 0.

<LS_PRCODES_IN>-PRCODE = 'O001'.

select sum( QTY ) as QTY into LV_QTY

from /SCDL/DB_PRCODES

where DOCID = <LS_PRCODES_IN>-DOCID

and ITEMID = <LS_PRCODES_IN>-ITEMID

and PRCODE = 'O001'.

if LV_QTY > 0.

<LS_PRCODES_IN>-QTY = LV_QTY + P_QTY_UI - <LS_PRCODES_IN>-QTY .

else.

<LS_PRCODES_IN>-QTY = P_QTY_UI - <LS_PRCODES_IN>-QTY.

endif.

endloop.

clear: LT_RETURN_CODES, LV_REJECTED.

LO_SP->UPDATE(

exporting

INRECORDS = LT_PRCODES_IN

ASPECT = /SCDL/IF_SP_C=>SC_ASP_ITEM_PRCODES

importing

OUTRECORDS = LT_PRCODES_OUT

REJECTED = LV_REJECTED

RETURN_CODES = LT_RETURN_CODES ).

read table LT_RETURN_CODES transporting no fields with key FAILED = ABAP_TRUE.

if SY-SUBRC = 0 or LV_REJECTED = ABAP_TRUE.

PV_ERROR = ABAP_TRUE.

message S999 with 'ODO Update Error' display like 'E'.

exit.

endif.

* Save the data (we still need a commit, but that will happen all or none at the end)

LO_SP->SAVE( importing REJECTED = LV_REJECTED ).

if LV_REJECTED = ABAP_TRUE.

message S999 with 'ODO Save Error'.

PV_ERROR = ABAP_TRUE.

else.

commit work.

endif.

endform.

Thank you,

Marco

Accepted Solutions (0)

Answers (2)

Answers (2)

Hi!

You can see example in fm /SCWM/WHRITEM_OUT_QUANT_ADJ_OD

BR, Alex.

Daniil
Active Contributor
0 Kudos

The warehouse releases the waves and realize theres not enough stock to fulfill this delivery so they must zero out the delivery as the business cannot wait for the warehouse to receive more stock they will simply order from another vendor. The warehouse must now Zero out the odo by assigning the below process code and minus sign to zero it out with process code.

you can maybe use Pick Denial for this.