Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
cancel
Showing results for 
Search instead for 
Did you mean: 
Objective: To adjust delivery quantity of Inbound Delivery using ABAP programming

Context:

To create/change/delete a delivery, concept of "Aspects" is used. Each logical section in a delivery is classified as a different aspect. For example, Header Partners, Item Reference Documents, Item Quantity and so on. In SAP EWM, we need to use service provider classes provided by SAP to modify the functionality of deliveries.

Most commonly used class for Inbound Delivery: /SCWM/CL_SP_PRD_INB

Steps:

  1. Set warehouse number for the transaction using /SCWM/CL_TM=>SET_LGNUM. This is used in entire transaction that you're going to perform next.

  2. Instantiate the class /SCWM/CL_SP_PRD_INB by passing IO_MESSAGE_BOX. This stores the messages generated during the process.

  3. Call method /SCDL/IF_SP1_ASPECT~SELECT as described in below screenshot. Here the aspect selected is "Item Quantity" and pass DOCID and ITEMID in INKEYS.

  4. Quantity should be added or subtracted to quantity selected in OUTRECORDS. Final quantity is passed using /SCDL/IF_SP1_ASPECT~UPDATE method.

  5. Record should be locked before update using /SCDL/IF_SP1_LOCKING~LOCK method.

  6. After UPDATE method is called, /SCDL/IF_SP1_ACTION~EXECUTE method is used to trigger process codes. This step is essential to trigger process code to perform delivery adjustment. Sample code is given below.



7. Point to Note: Everything is saved until /SCDL/IF_SP1_TRANSACTION~SAVE is called. This method can be used to save the transactions in update task also.

8. In the end, it is important to clear the memory by calling /SCWM/CL_TM=>CLEANUP. If we're running multiple transactions, not clearing the memory may interfere with the processes and cause dumps.

Similarly, /SCWM/CL_SP_PRD_OUT is used for outbound deliveries. Similar methods are provided in this class for Outbound Delivery functionalities.

Summary:

EWM classes are built on business objects framework and hence, above mentioned coding steps need to be used. All the processes are carried out in similar way. You can create / change/ delete any aspect of a delivery using same steps.

Please feel free to provide any feedback or clarifications if needed. Please visit the link https://answers.sap.com/tags/674879738150278190016884561790060 for submitting further questions.
16 Comments
Correction: Nothing is saved until SAVE TRANSACTION is called.
0 Kudos
It would be better if you could also place a sample code with declarations for our refernce .
0 Kudos
Could you please write the sample code for outbound delivery ..its quite urgent
0 Kudos
Same steps you need to follow as same methods exist in /SCWM/CL_SP_PRD_OUT - class for outbound deliveries.

  1. /SCWM/CL_TM=>SET_LGNUM.

  2. DATA(lo_ref_spNEW /scwm/cl_sp_prd_out).

  3. lo_ref_sp->/SCDL/IF_SP1_ASPECT~SELECT( ).

  4. lo_ref_sp->/SCDL/IF_SP1_ASPECT~UPDATE().

  5. lo_ref_sp->/SCDL/IF_SP1_LOCKING~LOCK().

  6. lo_ref_sp->/SCDL/IF_SP1_ACTION~EXECUTE().

  7. lo_ref_sp->/SCDL/IF_SP1_TRANSACTION~SAVE().

0 Kudos
Currently i am using this Code,but getting the error in the execute method (/scwm/delivery_md message number 006)

PARAMETERS: iv_dlvno TYPE /scdl/db_refdoc-refdocno OBLIGATORY.

DATA: lt_k_item TYPE /scdl/t_sp_k_item,
lv_lfr TYPE /scdl/dl_docid,
lv_qty TYPE /scdl/db_proci_o-qty,
wa_k_item LIKE LINE OF lt_k_item,
ls_action TYPE /scdl/s_sp_act_action,
ls_prcode TYPE /scwm/dlv_prcode_add_str,
lo_prd_out TYPE REF TO /scdl/cl_sp_prd_out,
lt_a_item TYPE /scdl/t_sp_a_item,
lv_rejected TYPE boole_d,
lo_message_box TYPE REF TO /scdl/cl_sp_message_box,
lt_a_head TYPE /scdl/t_sp_a_head,
lt_k_head TYPE /scdl/t_sp_k_head,
wa_k_head LIKE LINE OF lt_k_head,
lt_return_codes TYPE /scdl/t_sp_return_code.

FIELD-SYMBOLS: <fs_action_control>.
ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add.
CREATE DATA ls_action-action_control TYPE /scwm/dlv_prcode_add_str.

* Delivery
SELECT SINGLE docid INTO lv_lfr FROM /scdl/db_refdoc WHERE refdocno EQ iv_dlvno AND refdoccat EQ 'ODR'.
SELECT docid INTO wa_k_item-docid
FROM /scdl/db_proch_o
WHERE docid = lv_lfr.
* WHERE docno = lv_lfr.
ENDSELECT.
SELECT itemid FROM /scdl/db_proci_o INTO wa_k_item-itemid
WHERE docid = lv_lfr.
* WHERE docno = lv_lfr.
* AND itemno = '0000000040'.
ENDSELECT.

IF sy-subrc NE 0.
MESSAGE s038(/scdl/bo_action) DISPLAY LIKE 'E'.
"No delivery found
ENDIF.
APPEND wa_k_item TO lt_k_item.


IF lo_prd_out IS INITIAL.
CREATE OBJECT lo_message_box.
CREATE OBJECT lo_prd_out
EXPORTING
io_message_box = lo_message_box
iv_mode = /scdl/cl_sp=>sc_mode_classic
iv_doccat = /scdl/if_dl_doc_c=>sc_doccat_out_prd.
ENDIF.

* Select Delivery
wa_k_head-docid = wa_k_item-docid.
APPEND wa_k_head TO lt_k_head.

CLEAR lv_rejected.
REFRESH lt_return_codes.
lo_prd_out->/scdl/if_sp1_aspect~select(
EXPORTING
inkeys = lt_k_head
aspect = /scdl/if_sp_c=>sc_asp_head
IMPORTING
outrecords = lt_a_head
rejected = lv_rejected
return_codes = lt_return_codes ).

* Lock Delivery
CLEAR lv_rejected.
REFRESH lt_return_codes.
lo_prd_out->lock(
EXPORTING
inkeys = lt_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 ).
* check if any error occurred
"mcr_fill_error 'Lock delivery failed'.

* adjust delivery
CLEAR lv_rejected.
REFRESH lt_return_codes.

*lo_prd_out->/scdl/if_sp1_aspect~update(
* EXPORTING
** inkeys = lt_k_item
* aspect = /scdl/if_sp_c=>sc_asp_item
*
** action = /scdl/if_sp_c=>sc_act_execute_action
* IMPORTING
* outrecords = lt_a_item
* rejected = lv_rejected
* return_codes = lt_return_codes ).
** check if any error occurred
* CLEAR lv_rejected.
* REFRESH lt_return_codes.

ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add.
CREATE DATA ls_action-action_control TYPE /scwm/dlv_prcode_add_str.
ASSIGN ls_action-action_control->* TO <fs_action_control>.
ls_prcode-prcode = 'O001'.
ls_prcode-qty = -1.
ls_prcode-uom = 'ST'.

<fs_action_control> = ls_prcode.
lo_prd_out->/scdl/if_sp1_action~execute(
EXPORTING
aspect = /scdl/if_sp_c=>sc_asp_item
inkeys = lt_k_item
inparam = ls_action
action = /scdl/if_sp_c=>sc_act_execute_action
IMPORTING
outrecords = lt_a_item
rejected = lv_rejected
return_codes = lt_return_codes ).
* check if any error occurred
IF lv_rejected IS NOT INITIAL.
" or line_exists( lt_return_codes[ failed = 'x'] ).
" rollback work.
" mcr_fill_error 'delivery qty adjust failed'.
ELSE.
lo_prd_out->save( ).
COMMIT WORK AND WAIT.
" ls_odo-msgtxt = 'delivery qty adjust successfully'.
ENDIF.
/scwm/cl_tm=>cleanup( ).
0 Kudos

I am getting error in execute method

Update quantity in below step 4:

"Quantity should be added or subtracted to quantity selected in OUTRECORDS. Final quantity is passed using /SCDL/IF_SP1_ASPECT~UPDATE method."

 

You are passing quantity in execute action. Desktop transaction behaves this way but code doesn't. Update your quantity in update method and then execute process code.
0 Kudos

I am getting this error , could you please write the code for update method with exporting and importing parameter for my referenc


 
0 Kudos
I can see you're trying to update Item quantity, then pass inkeys for item (not for header). It should have columns DOCID and ITEMID.
0 Kudos

I have passed docid and item id but still i am getting the rejected flag "X".

lt_a_item data also gets cleared when it comes out of the method .

0 Kudos
It is marking rejected as 'X' as there is no data in inrecords table as highlighted below.

0 Kudos
I have made some correction, now update method is working fine but i am still getting the error in execute method.

I am passing docid , itemid in lt_k_item But in importing parameter lt_return_codes i am getting error (Failed = 'X')

 

0 Kudos
Thanks Harshita for your support, i am able to solve my issue with your guidance.
0 Kudos
Hi Rajesh,

I tried updating values at Item level but is is setting error flag. Could you please share the code snippet. I have similar requirement.

 

Thanks !!
paulocsilva
Explorer
0 Kudos
hi,

harshita.garg

Can you give us an full example, because I'm implementing the steps but in the first one I have a problem.

I need to perform ADJUST QUANTITY.

 


 

Thank you very much.
srujanam
Explorer
0 Kudos

Hi ,

I am trying to perform the quantity adjustment along for a serialized material, hence I require to delete the serial numbers first and then update the quantity accordingly. I tried to use Class /SCWM/CL_SP_DR_IBD  method /SCMB/IF_SP_ASPECT~DELETE for deleting the serial numbers. But it does not work. 

Any suggestion please?