cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to split a WHO with multiple WTs inside and create new entries in the table /SCWM/WHOHU in EWM?

mustafa_74199
Participant
0 Kudos
1,216

Hi everyone,

We are trying to split a WHO with multiple WTs inside to multiple new WHOs. This is the case;

Assume that there are 10 WTs inside a WHO and these 10 WTs are combined with 3 different HUs in total.

Step 1: We read the existing WHO with the FM /SCWM/WHO_GET.

Step 2: Based on the HUs inside, we split the WHO into 3 newly created WHOs with the FM /SCWM/WHO_SPLIT. In the new WHOs there will be 3 WTs, 3 WTs and 4 WTs respectively.

But now we need to create new entries in the table /SCWM/WHOHU to be able to see the correlation between the newly created WHOs and HUs inside. To do this we tried the FM /SCWM/WHO_WHOHU_MAINT but it didn't create entries in the table. Below you can find the sample code.

REPORT zmc_test_001.

DATA: gt_to TYPE /scwm/tt_tanum,
gv_severity TYPE bapi_mtype,
gv_severity_maint TYPE bapi_mtype,
gt_bapiret TYPE bapirettab,
gt_bapiret_maint TYPE bapirettab,
gt_msg_all TYPE bapirettab,
gt_msg_all_maint TYPE bapirettab,
gt_who TYPE /scwm/tt_who_int,
gt_whohu TYPE /scwm/tt_whohu_int,
gt_whohu_maint_exp TYPE /scwm/tt_whohu_int,
gt_ordim_o TYPE /scwm/tt_ordim_o,
gt_ordim_os TYPE /scwm/tt_ordim_os,
gt_ordim_c TYPE /scwm/tt_ordim_c,
gv_commit VALUE abap_true,
gt_whohu_maint TYPE /scwm/tt_whohu_maint,
gv_hukng TYPE i.

SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME NO INTERVALS.
PARAMETERS: p_wh TYPE /scwm/lgnum,
p_who TYPE /scwm/de_who.
SELECTION-SCREEN END OF BLOCK a1.

TRY.
CALL FUNCTION '/SCWM/WHO_GET'
EXPORTING
iv_lgnum = p_wh
iv_to = abap_true
* iv_lock_who = abap_true
* iv_lock_to = abap_true
iv_whoid = p_who
IMPORTING
* es_who = gs_who
et_whohu = gt_whohu
et_ordim_o = gt_ordim_o
et_ordim_os = gt_ordim_os
et_ordim_c = gt_ordim_c.

CATCH /scwm/cx_core.
RETURN.
ENDTRY.

IF sy-subrc IS NOT INITIAL.
RETURN.
ENDIF.

IF gt_ordim_o IS INITIAL.
MESSAGE 'No WT inside WHO.' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.

LOOP AT gt_ordim_o INTO DATA(gs_ordim_o) GROUP BY ( huid = gs_ordim_o-huid ) ASCENDING ASSIGNING FIELD-SYMBOL(<gr_huid>).

LOOP AT GROUP <gr_huid> INTO DATA(gs_wt).
APPEND gs_wt-tanum TO gt_to.
ENDLOOP.

CALL FUNCTION '/SCWM/WHO_SPLIT'
EXPORTING
iv_lgnum = p_wh
iv_who = p_who
* IV_WCR = ''
* IV_REASON_CODE =
* IV_UPDATE = 'X'
* iv_commit = abap_true
it_to = gt_to
IMPORTING
ev_severity = gv_severity
et_bapiret = gt_bapiret
et_who = gt_who.

IF sy-subrc IS NOT INITIAL.
CLEAR: gv_commit.
EXIT.
ENDIF.

gt_msg_all = VALUE #( BASE gt_msg_all FOR gs_bapiret IN gt_bapiret ( gs_bapiret ) ).

LOOP AT gt_who INTO DATA(gs_who).
IF gs_who-who NE p_who.
EXIT.
ENDIF.
ENDLOOP.

LOOP AT gt_whohu INTO DATA(gs_whohu) WHERE huid = <gr_huid>-huid.
gv_hukng = gv_hukng + 1.

APPEND INITIAL LINE TO gt_whohu_maint ASSIGNING FIELD-SYMBOL(<gs_whohu_maint>).
<gs_whohu_maint>-hukng = gv_hukng.
<gs_whohu_maint>-pmat_guid = gs_whohu-pmat_guid.
<gs_whohu_maint>-huident = gs_whohu-huident.
<gs_whohu_maint>-updkz = 'I'.
ENDLOOP.

CALL FUNCTION '/SCWM/WHO_WHOHU_MAINT'
EXPORTING
iv_lgnum = p_wh
iv_who = gs_who-who
* IV_SIMULATE = ' '
it_whohu = gt_whohu_maint
IMPORTING
ev_severity = gv_severity_maint
et_bapiret = gt_bapiret_maint
et_whohu = gt_whohu_maint_exp.

CLEAR: gt_whohu_maint, gt_to, gv_hukng.

gt_msg_all_maint = VALUE #( BASE gt_msg_all_maint FOR gs_bapiret_maint IN gt_bapiret_maint ( gs_bapiret_maint ) ).

ENDLOOP.

IF gv_commit IS NOT INITIAL.
COMMIT WORK.
LOOP AT gt_msg_all INTO DATA(gs_msg_all).
WRITE: / gs_msg_all-message.
ENDLOOP.

SKIP 2.
WRITE: 'Results of WHOHU Maintaining.'.
LOOP AT gt_msg_all_maint INTO DATA(gs_msg_all_maint).
WRITE: / gs_msg_all_maint-message.
ENDLOOP.
ELSE.
WRITE: 'Transaction failed!'.
ENDIF.

Accepted Solutions (0)

Answers (0)