cancel
Showing results for 
Search instead for 
Did you mean: 

Perform GR EWM as abap

paulocsilva
Explorer
0 Kudos

Hello,

I need to make a good receipt to inbound delivery, I'm looking for many things, but nothing works, can someone help me with this, I'll put my code here.

Something is missing, if anyone can help me, thank you.

DATA: lo_sp_prd_in TYPE REF TO /scdl/cl_sp_prd_inb,
lo_message_box TYPE REF TO /scdl/cl_sp_message_box,
lt_sp_a_head TYPE /scdl/t_sp_a_head,
ls_sp_a_head TYPE /scdl/s_sp_a_head,
ls_sp_k_head TYPE /scdl/s_sp_k_head,
lt_sp_k_head TYPE /scdl/t_sp_k_head,
ls_sp_a_hu TYPE /scdl/s_sp_a_hu,
lt_sp_a_hu TYPE /scdl/t_sp_a_hu,
lv_rejected TYPE boolean,
lt_return_codes TYPE /scdl/t_sp_return_code,
ls_sp_a_hu_scwm TYPE /scwm/s_sp_a_hu,
lt_sp_a_hu_scwm TYPE /scwm/t_sp_a_hu,
ls_sp_a_myhu_scwm TYPE /scwm/s_sp_a_hu,
ls_sp_k_hu_scwm TYPE /scwm/s_sp_k_hu,
lt_sp_k_hu_scwm TYPE /scwm/t_sp_k_hu.

DATA:
lv_docnum TYPE /scdl/dl_docno_int,
lv_itemno TYPE /scdl/dl_itemno.

lv_docnum = 'XXXXXXXXXX'. "Inbound develivery'.
lv_docnum = |{ lv_docnum ALPHA = IN }|.

lv_itemno = '10'. " Inbound develivery Item
lv_itemno = |{ lv_itemno ALPHA = IN }|.

SELECT SINGLE *
FROM /scdl/db_proci_i
INTO @DATA(ls_proci_i)
WHERE docno = @lv_docnum
AND itemno = @lv_itemno.

"Create service provider for inbound delivery
CREATE OBJECT lo_sp_prd_in
EXPORTING
io_message_box = lo_message_box. " Service Provider Nachrichtenverwaltung

ls_sp_k_head-docid = ls_proci_i-docid.

APPEND ls_sp_k_head TO lt_sp_k_head.

"select delivery head data
CALL METHOD lo_sp_prd_in->/scdl/if_sp1_aspect~select
EXPORTING
inkeys = lt_sp_k_head
aspect = /scdl/if_sp_c=>sc_asp_head
IMPORTING
outrecords = lt_sp_a_head
rejected = lv_rejected
return_codes = lt_return_codes.

"Lock delivery
CALL METHOD lo_sp_prd_in->/scdl/if_sp1_locking~lock
EXPORTING
inkeys = lt_sp_k_head
aspect = /scdl/if_sp_c=>sc_asp_head
lockmode = 'E'
IMPORTING
rejected = lv_rejected
return_codes = lt_return_codes.

"If lock has been successful
IF lv_rejected = abap_false.

"select hu data from delivery
CALL METHOD lo_sp_prd_in->/scdl/if_sp1_aspect~select_by_relation
EXPORTING
relation = /scwm/if_sp_c=>sc_rel_head_to_hu
inrecords = lt_sp_k_head
aspect = /scdl/if_sp_c=>sc_asp_head
IMPORTING
outrecords = lt_sp_a_hu_scwm
rejected = lv_rejected
return_codes = lt_return_codes.


zcl_ewm_utilities=>get_hu_details_from_hu(
EXPORTING
iv_appl = 'WME'
iv_huident = 'HU NUMBER'
IMPORTING
es_huhdr = DATA(gs_huhdr_src)
et_huref = DATA(gt_huref_src)
et_huitm = DATA(gt_huitm_src) ).

LOOP AT lt_sp_a_hu_scwm INTO ls_sp_a_hu_scwm.
"determine hu data which has to be moved.
IF ls_sp_a_hu_scwm-huno = gs_huhdr_src-huident.
ls_sp_a_myhu_scwm = ls_sp_a_hu_scwm.
MOVE-CORRESPONDING ls_sp_a_hu_scwm TO ls_sp_k_hu_scwm.
APPEND ls_sp_k_hu_scwm TO lt_sp_k_hu_scwm.
EXIT.
ENDIF.
ENDLOOP.

CLEAR lt_sp_a_hu_scwm.
CLEAR lt_sp_a_head.

"execute action hu goods movement
CALL METHOD lo_sp_prd_in->/scdl/if_sp1_action~execute
EXPORTING
aspect = /scwm/if_sp_c=>sc_asp_hu " Aspect Name
inkeys = lt_sp_k_hu_scwm " Objects to Act On
action = /scwm/if_sp_c=>sc_act_hu_post_gm " Name of Action
relation_inkey = ls_sp_k_head " Key for Target Aspect
relation = /scwm/if_sp_c=>sc_rel_head_to_hu " Name of Relation
IMPORTING
outrecords = lt_sp_a_hu_scwm " Changed Aspect Objects
rejected = lv_rejected " Error on Back End
return_codes = lt_return_codes " Table of Return Codes
relation_outrecord = lt_sp_a_head. " Changed Target Aspect Line

"Save changes
CALL METHOD lo_sp_prd_in->/scdl/if_sp1_transaction~save
EXPORTING
synchronously = abap_true
IMPORTING
rejected = lv_rejected.

"remove lock

CALL METHOD lo_sp_prd_in->/scdl/if_sp1_transaction~cleanup
EXPORTING
reason = 'END'.
ENDIF.

Accepted Solutions (0)

Answers (1)

Answers (1)

paulocsilva
Explorer
0 Kudos

Guys, I wrote the post but I found the solution and we don't need anything this, put on this information and everthng will work.

DATA(lo_delivery) = /scwm/cl_dlv_management_prd=>get_instance( ).

/scwm/cl_goods_movement=>post_hu(
EXPORTING
it_hu = lt_gm_hu
iv_gmcat = /scwm/if_docflow_c=>sc_gr
IMPORTING
eo_message = DATA(lo_message) ).
TRY.
lo_delivery->save(
EXPORTING
iv_synchronously = abap_false
iv_do_commit_work = abap_true
iv_wait = abap_false
IMPORTING
et_message = DATA(lt_messages) ).
ENDTRY.