cancel
Showing results for 
Search instead for 
Did you mean: 

EWM | Set status "Blocked for customs" via RFC

sebastian-kley
Discoverer
0 Kudos

Dear community,

we have a customs scenario where the ERP system is leading as it is connected to the customs system. EWM is not connected to the customs system.


ERP activities

ERP sends customs relevant information to the customs system via Idoc after receiving from EWM that the last HU of a delivery was packed (inbound and outbound deliveries). At the same time the ERP delivery gets a delivery block (set by the customs Idoc creation routine) to prevent any activities before customs has cleared the delivery.


EWM activities

As said, the packing of the last HU should trigger the information transfer to the customs system. To enable ERP to do this, EWM replicates the packing data to ERP after the last HU of the delivery was packed. Also, the EWM delivery should be blocked to prevent any further activities before customs has cleared the delivery.


Challenge(s)

1. During creation of the Idoc to the customs system, the ERP system needs to call the EWM system to set the block "Blocked for Customs" in EWM.


2. After customs clearence, there is another Idoc process that has to delete the block, meaning "Set Status to Release".


I have tried to use /SCDL/CL_BO_PROC_ACTION->PERFORM_STM_ACTIVITY (lt_bo_id contains DOCID and DOCCAT of the affected delivery)

  /SCDL/CL_BO_PROC_ACTION=>perform_stm_activity(
it_bo_id = lt_bo_id
iv_activity = 'DWN8' ).



and /SCDL/IF_AF_STATUS_MANAGEMENT->SET_STATUS

  CALL METHOD /scdl/cl_bo_proc_action=>xhlp_fill_stm_table
EXPORTING
it_bo_id = lt_bo_id
IMPORTING
et_stm_component = lt_stm_component
eo_message = lo_message_service_stm.
      lo_service_stm->set_status(
it_stm_component = lt_stm_component
iv_activity = 'DWN8' ).


to set the status but without success. Also saving via /SCWM/CL_DLV_MANAGEMENT_PRD->SAVE after setting the status via above mentioned methods did not help.

  lo_delivery->save( EXPORTING
iv_do_commit_work = abap_true
IMPORTING
et_message = lt_message
ev_rejected = lv_rejected
).


Any idea how to set the status?


Many thanks upfront for input!

Accepted Solutions (0)

Answers (1)

Answers (1)

mudassir_saad
Explorer

Hello Sebastian,

Hope you are doing well, if i understood your requirement correctly then you wanted to set the block on delivery and release it based on IDOC or button. To achive this you will have to implement one BADI "/SCWM/EX_DLV_VAL_VALIDATE" this handles the setting of Block status and release status. here you will get Check_header method in which you will have to compare the changes with Database state and current state. if you find the document relevant then collect the key in output parameter.

Second method is execute_header in this you will have to fill the error message in CT_messages if you find the relevant record.

i have given code snippet below, here i had added one custom field on header structure of delivery and based on value of that field i am blocking and unblocking the delivery.

you will have to declare attribute in this implementing class as below.

METHOD /scwm/if_ex_dlv_val_validate~check_header.
DATA: lo_bom TYPE REF TO /scdl/cl_bo_management,
lo_bo TYPE REF TO /scdl/if_bo,
lo_header TYPE REF TO /scdl/cl_dl_header_prd,
lo_header_old TYPE REF TO /scdl/cl_dl_header_prd,
ls_eew TYPE /SCDL/INCL_EEW_DLV_HEAD_STR,
ls_eew_old TYPE /SCDL/INCL_EEW_DLV_HEAD_STR.
DATA: lv_laststate TYPE /scdl/dl_object_state,
lv_laststate2 TYPE /scdl/dl_object_state.
FIELD-SYMBOLS: <ls_keys> TYPE /scwm/dlv_docid_str.
* clear relevant keys.
CLEAR mt_val_relevant_keys.
* set that the check_item was executed. this is to differentiate in the execute_item whether
* the validation was called due to a change or if e.g. "check" button was used and all validation
* should be executed mv_val_check_executed = abap_true.
* get bom
lo_bom = /scdl/cl_bo_management=>get_instance( ).
* define states for reading of objects
lv_laststate = /scdl/if_dl_object_c=>sc_object_state_valid.
lv_laststate2 = /scdl/if_dl_object_c=>sc_object_state_db.
* process the items
LOOP AT it_keys ASSIGNING <ls_keys>.
CLEAR ls_eew.
* 23
* get BO
lo_bo = lo_bom->get_bo_by_id( iv_docid = <ls_keys>-docid ).
IF lo_bo IS NOT BOUND.
CONTINUE.
ENDIF.
* get current header
lo_header ?= lo_bo->get_header( ).
* get header before the last determination (old state)
lo_header_old ?= lo_bo->get_header( iv_objectstate = lv_laststate ).
IF lo_header_old IS NOT BOUND.
lo_header_old ?= lo_bo->get_header( iv_objectstate = lv_laststate2 ).
ENDIF.
IF lo_header IS BOUND.
ls_eew = lo_header->get_eew( ).
ENDIF.
IF lo_header_old IS BOUND.
ls_eew_old = lo_header_old->get_eew( ).
ENDIF.
IF ls_eew-zpending_workflow <> ls_eew_old-zpending_workflow .
* append to relevant keys. note that this parameter is used for all BADI implementations.
* therefore you must not remove entries, but only add entries
COLLECT <ls_keys> INTO ct_relevant_keys.
* append relevant keys. This parameter is only for this BADI instance, therefore it indicates
* which keys are relevant for exactely this BADI (and is also cleared at the beginning)
COLLECT <ls_keys> INTO mt_val_relevant_keys.
ENDIF.
ENDLOOP.
ENDMETHOD.
 METHOD /scwm/if_ex_dlv_val_validate~execute_header.
DATA: lo_bom TYPE REF TO /scdl/cl_bo_management,
lo_bo TYPE REF TO /scdl/if_bo,
lo_item TYPE REF TO /scdl/cl_dl_item,
lo_header TYPE REF TO /scdl/cl_dl_header_prd,
lv_dummymsg TYPE bapi_msg, ls_symsg TYPE symsg,
ls_messages TYPE /scwm/dlv_detval_msg_str,
ls_eew TYPE /SCDL/INCL_EEW_DLV_HEAD_STR,
lv_qty_is_allowed TYPE boole_d.
FIELD-SYMBOLS: <ls_keys> TYPE /scwm/dlv_docid_str.
* get BOM
lo_bom = /scdl/cl_bo_management=>get_instance( ).
* process the items
LOOP AT it_relevant_keys ASSIGNING <ls_keys>.
* if the CHECK_ITEM was called (and mv_val_check_executed is set)
* differentiate for which items a change exists. Otherwise check all items
IF mv_val_check_executed = abap_true.
* the reading of mt_det_relevant_keys which was set in the CHECK_ITEM method
* ensures that this method is only processed for the relevant keys
* This is necessary in case of multiple BADI implementations, as it could happen that
* an other implementation added more keys to IT_RELEVANT_KEYS
READ TABLE mt_val_relevant_keys TRANSPORTING NO FIELDS WITH KEY docid = <ls_keys>-docid.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
ENDIF.
* get BO
lo_bo = lo_bom->get_bo_by_id( iv_docid = <ls_keys>-docid ).
IF lo_bo IS NOT BOUND.
CONTINUE.
ENDIF.

* get current header
lo_header ?= lo_bo->get_header( ).
IF lo_header IS BOUND.
ls_eew = lo_header->get_eew( ).
ENDIF.
* get current product and quantity information
* lo_item ?= lo_bo->get_item( iv_itemid = <ls_keys>-itemid ).
* ls_qty = lo_item->get_qty( ).
* ls_product = lo_item->get_product( ).
* now a customer specific function could be called which
* uses the quantity and product information to check whether the
* quantity is allowed for the product lv_qty_is_allowed = call_my_function( ls_qty ls_product ).
* if change is not allowed return a message so that delivery item gets blocked
IF ls_eew-zpending_workflow = icon_led_red.
MESSAGE ID 'ZWM_HU_LABEL' TYPE /scwm/cl_dm_message_no=>sc_msgty_error
NUMBER '013' INTO lv_dummymsg.
ls_symsg = /scwm/cl_dm_message_no=>get_symsg_fields( ).

ls_messages-docid = <ls_keys>-docid.
* ls_messages-itemid = <ls_keys>-itemid.
ls_messages-msg = ls_symsg.
APPEND ls_messages TO ct_messages.
ENDIF.

ENDLOOP.
* clear the attribute so that it does not influence the next call
CLEAR mv_val_check_executed.
ENDMETHOD.

Please let me know if you need any further help.. All the best 🙂

Regards,

Saad.