Supply Chain Management Blogs by Members
Learn about SAP SCM software from firsthand experiences of community members. Share your own post and join the conversation about supply chain management.
cancel
Showing results for 
Search instead for 
Did you mean: 
Introduction

Recently I had been working on a requirement of creating an Outbound Delivery in EWM. I searched online and found one beautiful link which gave a start to a journey to achieve this requirement. Journey because I spent 5 days on this and after hours and hours of debugging I was able to bring all pieces together and solve this puzzle. Since I don't want anyone to spend 5 days to get this, I am writing a detailed step by step process.

 

Step 1.

Most important class for achieving this requirement is /SCWM/CL_SP_PRD_OUT. Create a subclass of this class. Complete this step by creating a constructor method to set some default values as below.


super->constructor(
EXPORTING
io_attribute_handler mo_attribute_handler
io_message_handler   mo_message_handler
iv_mode              iv_mode
).

me->ms_default-lgnum '1710'.
me->ms_default-shipping_office 'WH1710'.
me->ms_default-entitled 'BP1710'.
me->mv_tzone 'PST'.

 

Step 2.

Create an executable program where you will instantiate the newly created class and call its methods. The sequence of call is given in the below steps.

 

Step 3.

Instantiate the class and again set some defaults


TRY.
CREATE OBJECT lo_message_box.
CREATE OBJECT lo_sp
EXPORTING
iv_mode /scdl/cl_sp=>sc_mode_classic.
ENDTRY.

*set warehouse that is used
/scwm/cl_tm=>set_lgnum'<Your Warehouse No.>' ).

 

Step 4.

Call Insert method. This method creates a DOCID of the OBD. Read more about aspects, key aspects to understand the process better


CALL METHOD lo_sp->/scmb/if_sp_aspect~insert
EXPORTING
inrecords    lt_a_head "lt_head_inrecords "
aspect       '/SCWM/S_SP_A_HEAD'
IMPORTING
outrecords   lt_a_head_out "lt_head_outrecords "
rejected     lv_rejected
return_codes lt_return_codes.

 

Step 5.

Call Select method. This is required to get party details. In our case, the party-role we obtain is STPRT which is Ship-to-Party


APPEND INITIAL LINE TO lt_sp_k_head ASSIGNING FIELD-SYMBOL(<lfs_sp_k_head>).
<lfs_sp_k_head>-docid lt_a_head_out[ ]-docid.

APPEND INITIAL LINE TO lt_head_party_inkeys ASSIGNING FIELD-SYMBOL(<lfs_head_party_inkeys>).
<lfs_head_party_inkeys>-docid lt_a_head_out[ ]-docid.
<lfs_head_party_inkeys>-party_role 'STPRT'.

lo_sp->select(
EXPORTING
inkeys       lt_head_party_inkeys                 " Restricting Input Keys
aspect       /scwm/if_sp_c=>sc_asp_head_party    " Aspect Name to Be Read from "/scdl/if_sp_c=>sc_asp_head_partyloc : Gives dump
IMPORTING
outrecords   lt_head_party_out                 " Result Aspects
rejected     lv_rejected                 " Error on Back End
return_codes lt_return_codes                 " Table of Return Codes
).

 

Step 6.

As we get one records from above step, now we just have to update the party detail with the party number. Note that we haven't passed counter in the above step, but in this step inorder to update the record, we are passing the counter as one which we received in the out table of previous step. Read more about value indicator. This is a very important step, but if we miss to pass this value indicator you would never be able to achieve this requirement.


LOOP AT lt_head_party_out ASSIGNING FIELD-SYMBOL(<lfs_head_party_out>).
APPEND INITIAL LINE TO lt_head_party_inrecords ASSIGNING FIELD-SYMBOL(<lfs_head_party_inrecords>).
MOVE-CORRESPONDING <lfs_head_party_out> TO <lfs_head_party_inrecords>.
<lfs_head_party_inrecords>-partyno '001000010'.
<lfs_head_party_inrecords>-value_ind 'M'.     "Figured out after tons and tons of debugging
ENDLOOP.

CLEAR lt_head_party_out,lv_rejected,lt_return_codes.

CALL METHOD lo_sp->/scmb/if_sp_aspect~update
EXPORTING
aspect       /scwm/if_sp_c=>sc_asp_head_party                 " Aspect that should make change
inrecords    lt_head_party_inrecords                 " Full Record Update
IMPORTING
outrecords   lt_head_party_out
rejected     lv_rejected
return_codes lt_return_codes.

 

Step 7.

Once you get success in above step, next step is to assign HU to the delivery. For this we use Insert method.


ls_sp_k_head-docid lt_a_head_out[ ]-docid.

ls_sp_hu-docid lt_a_head_out[ ]-docid.
ls_sp_hu-huno '00112345678000004023'.
ls_sp_hu-lgnum '1710'.
ls_sp_hu-itemtype 'ODPG'.
ls_sp_hu-doccat 'PDO'.
ls_sp_hu-doctype 'OPIG'.
APPEND ls_sp_hu TO lt_sp_hu.

CALL METHOD lo_sp->/scmb/if_sp_aspect~insert
EXPORTING
inrecords      lt_sp_hu
aspect         '/SCWM/S_SP_A_HU'
relation       '/SCWM/HEAD_TO_HU'
relation_inkey ls_sp_k_head
IMPORTING
outrecords     lt_sp_hu_out
rejected       lv_rejected
return_codes   lt_return_codes.

 

Step 8.

Once this step also gives you a success, then go ahead to save the transaction. This is the last step and your OBD gets created.


CALL METHOD lo_sp->/scmb/if_sp_transaction~save
IMPORTING
rejected lv_rejected.
*
IF lv_rejected EQ abap_false.
COMMIT WORK AND WAIT.
BREAK-POINT.
/scwm/cl_tm=>cleanup)"clear buffers and release locks
ENDIF.

 

Done!!!

Conclusion

At step no. 6, you can also call insert after update if you have any more party details to be updated.

I would still say to spend some time debugging so that you would understand the underlying design.

Happy coding!!!
5 Comments
Labels in this area