*&---------------------------------------------------------------------*
*& Report ZEWM_RQEVAC50
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZEWM_RQEVAC50.
TABLES: qals.
SELECT-OPTIONS: r_prfls FOR qals-prueflos OBLIGATORY.
PARAMETERS: p_budat TYPE mkpf-budat DEFAULT sy-datum OBLIGATORY,
p_mtib TYPE xfeld AS CHECKBOX. "Move to initial bin
START-OF-SELECTION.
DATA: lt_item TYPE /scwm/tt_gmitem,
lt_result TYPE /scwm/tt_spresult,
lt_return_gm TYPE bapirettab,
lt_return_to TYPE bapirettab,
lt_return_all TYPE bapirettab,
lt_create TYPE /scwm/tt_to_create_int,
lt_ltap_vb TYPE /scwm/tt_ltap_vb,
lv_call TYPE char1 VALUE wmegc_call_post_change,
lv_tanum TYPE /scwm/ordim_c-tanum,
lv_tabix TYPE syst-tabix,
lv_severity TYPE bapi_mtype,
lv_tanum_gm TYPE /scwm/tanum,
lv_count TYPE i,
lv_message TYPE bapiret2-message.
SELECT * FROM qals INTO TABLE @DATA(lt_qals)
WHERE prueflos IN @r_prfls.
LOOP AT lt_qals INTO DATA(ls_qals).
CLEAR lt_item.
SELECT jest~stat, tj02t~txt04, tj02t~txt30 INTO TABLE @DATA(lt_jest)
FROM jest LEFT JOIN tj02t ON tj02t~istat EQ jest~stat
AND tj02t~spras EQ @sy-langu
WHERE jest~objnr EQ @ls_qals-objnr
AND jest~inact EQ @space.
IF NOT line_exists( lt_jest[ stat = 'I0297' ] ). "KKGA Kullanım kararı geri alındı
MESSAGE 'Before GM reversal, UD should be reversed' TYPE 'E'.
ENDIF.
SELECT SINGLE whnumwme FROM /scwm/tmapwhnum INTO @DATA(lv_lgnum)
WHERE whnumerp EQ @ls_qals-lgnum.
"Reverse PGIs from EWM
* PERFORM reverse_adgi USING lv_lgnum.
SELECT SINGLE * FROM mchb INTO @DATA(ls_mchb)
WHERE matnr EQ @ls_qals-matnr
AND werks EQ @ls_qals-werk
AND charg EQ @ls_qals-charg
AND NOT EXISTS ( SELECT * FROM t320 WHERE werks EQ mchb~werks
AND lgort EQ mchb~lgort ).
IF sy-subrc IS INITIAL.
MESSAGE |Stock for { ls_mchb-matnr ALPHA = OUT }-{ ls_mchb-charg
} exists in SLoc { ls_mchb-lgort }!|
TYPE 'E'.
ENDIF.
"EWM Relevant
SELECT * FROM /scwm/ordim_c INTO TABLE @DATA(lt_ud_oc)
WHERE inspid EQ @ls_qals-lot_guid
AND trart EQ '7'.
IF sy-subrc IS NOT INITIAL.
MESSAGE |There is no EWM relevant Stock Movement for InspLot { ls_qals-prueflos }|
TYPE 'E'.
ENDIF.
"If UD Reverse and again UD has done earlier, there will be more than 1 WTs
"If there are more than 1 WT, consider the last one.
SORT lt_ud_oc BY tanum DESCENDING tapos ASCENDING.
DATA(ls_ud_oc) = lt_ud_oc[ 1 ].
IF ls_ud_oc-rdocid IS NOT INITIAL.
"If the reference delivery is stuck in Queue,
"GM reverse will create more issues
SELECT SINGLE * FROM /scdl/db_proch_i INTO @DATA(ls_proch)
WHERE docid EQ @ls_ud_oc-rdocid.
DATA: lv_spe_mdnum_ewm TYPE /spe/mdnum_ewm .
lv_spe_mdnum_ewm = |{ ls_ud_oc-lgnum }{ ls_ud_oc-tanum }|.
SELECT SINGLE mkpf~*, mseg~* INTO @DATA(ls_mseg)
FROM mkpf INNER JOIN mseg ON mkpf~mblnr EQ mseg~mblnr
AND mkpf~mjahr EQ mseg~mjahr
WHERE mkpf~spe_mdnum_ewm EQ @lv_spe_mdnum_ewm.
IF ls_mseg IS INITIAL.
MESSAGE |Delivery { ls_proch-docno } is stuck in ERP queue!|
TYPE 'E'.
ENDIF.
ENDIF.
SELECT SINGLE * FROM mara INTO @DATA(ls_mara) WHERE matnr EQ @ls_qals-matnr.
SELECT SINGLE * FROM mcha INTO @DATA(ls_mcha) WHERE matnr EQ @ls_qals-matnr
AND charg EQ @ls_qals-charg.
LOOP AT lt_ud_oc INTO ls_ud_oc.
NEW /scwm/cl_mon_stock( iv_lgnum = lv_lgnum )->get_physical_stock(
EXPORTING
it_huident_r = VALUE #( ( sign = 'I' option = 'EQ' low = ls_ud_oc-vlenr ) )
it_matnr_r = VALUE #( ( sign = 'I' option = 'EQ' low = ls_qals-matnr ) )
it_charg_r = VALUE #( ( sign = 'I' option = 'EQ' low = ls_qals-charg ) )
IMPORTING et_stock_mon = DATA(lt_stock_mon) ) .
IF lt_stock_mon IS INITIAL.
MESSAGE |Stock for { lv_lgnum }{ ls_ud_oc-vlenr ALPHA = OUT }-{
ls_qals-matnr ALPHA = OUT }-{ ls_qals-charg
} is not in the warehouse| TYPE 'E'.
ELSEIF lines( lt_stock_mon ) GT 1.
MESSAGE |There are multiple Stocks for {
lv_lgnum }{ ls_ud_oc-vlenr ALPHA = OUT }-{
ls_qals-matnr ALPHA = OUT }-{ ls_qals-charg }|
TYPE 'E'.
ENDIF.
ADD 1 TO lv_tabix.
DATA(ls_stock_mon) = lt_stock_mon[ 1 ].
SELECT SINGLE * FROM /scwm/ordim_o INTO @DATA(ls_oo)
WHERE lgnum EQ @ls_stock_mon-lgnum
AND guid_stock EQ @ls_stock_mon-guid_stock
AND ( vlenr EQ @ls_stock_mon-huident OR
nlenr EQ @ls_stock_mon-huident ).
IF sy-subrc IS INITIAL.
MESSAGE |There is Open Warehouse Task { ls_oo-tanum }| TYPE 'E'.
ENDIF.
IF ls_stock_mon-quan NE ls_ud_oc-nistm.
MESSAGE |Current stock quantity is not same with UD quantity for {
lv_lgnum }{ ls_ud_oc-vlenr ALPHA = OUT }-{
ls_qals-matnr ALPHA = OUT }-{ ls_qals-charg }|
TYPE 'E'.
ENDIF.
APPEND VALUE #( id = lv_tabix
id_group = lv_tabix
direction = 'T' "I/O/T
procty = 'UDRV' "Usage Decision reverse
* SQUANT_SET = 'X'
* GUID_HU =
* reason = 'NWLO' "/SCWM/TIMBWA table
* reason_wm = ''
huident = ls_stock_mon-huident
loc-idx_loc = 'W01' "for table /SCWM/LOC_IW01
loc-lgnum = ls_stock_mon-lgnum
loc-lgtyp = ls_stock_mon-lgtyp
loc-lgpla = ls_stock_mon-lgpla
meins = ls_stock_mon-meins
source_s = CORRESPONDING #( ls_stock_mon )
dest_s = CORRESPONDING #( ls_ud_oc )
t_quan = VALUE #( ( quan = ls_ud_oc-nistm
unit = ls_ud_oc-meins ) )
) TO lt_item ASSIGNING FIELD-SYMBOL(<lfs_item>).
CLEAR: <lfs_item>-dest_s-guid_stock,
<lfs_item>-dest_s-qdoccat,
<lfs_item>-dest_s-qdocid,
<lfs_item>-dest_s-qitmid,
<lfs_item>-dest_s-guid_stock0,
lt_stock_mon.
ENDLOOP.
DATA(ls_header) = VALUE /scwm/s_gmheader( lgnum = lv_lgnum
code = wmegc_gmcode_chg_stcat "wmegc_gmcode_qm "wmegc_gmcode_post
compl = 'X'
post = 'X' "Post Document Directly
simulate = space ).
CONVERT DATE p_budat TIME sy-uzeit INTO TIME STAMP ls_header-created_at TIME ZONE sy-zonlo.
/scwm/cl_tm=>cleanup( ).
/scwm/cl_tm=>set_lgnum( iv_lgnum = lv_lgnum ).
DATA: lv_quan_t TYPE /scwm/ordim_c-nistm.
LOOP AT lt_item INTO DATA(ls_item).
lv_quan_t = lv_quan_t + ls_item-t_quan[ 1 ]-quan .
ENDLOOP.
IF lv_quan_t NE ls_qals-losmenge.
MESSAGE |Batch Stock Quantity of { ls_qals-matnr ALPHA = OUT }-{ ls_qals-charg
} is not equal with Quantity of InspLot { ls_qals-prueflos }!|
TYPE 'E'.
ENDIF.
TRY.
CALL FUNCTION '/SCWM/GM_CREATE'
EXPORTING
iv_call = lv_call
is_header = ls_header
it_item = lt_item[]
* IT_HUNDEL = lt_hundel[]
IMPORTING
ev_tanum = lv_tanum
et_result = lt_result
et_bapiret = lt_return_gm[]
ev_severity = lv_severity
EXCEPTIONS
error_message = 1
OTHERS = 2.
CATCH /scwm/cx_core.
ENDTRY.
LOOP AT lt_return_gm TRANSPORTING NO FIELDS WHERE type CA 'EAX'. ENDLOOP.
IF sy-subrc IS INITIAL OR lv_severity CA 'EAX'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
APPEND LINES OF lt_return_gm TO lt_return_all.
CONTINUE.
ENDIF.
"Move Stock to initial Bin
CHECK p_mtib IS NOT INITIAL.
LOOP AT lt_result INTO DATA(ls_result).
READ TABLE lt_item ASSIGNING <lfs_item>
WITH KEY id = ls_result-rid
id_group = ls_result-id_group.
READ TABLE lt_ud_oc INTO ls_ud_oc
WITH KEY vlenr = <lfs_item>-huident.
IF <lfs_item>-loc-lgpla NE ls_ud_oc-nlpla.
APPEND VALUE #( procty = 'UDRV'
vltyp = <lfs_item>-loc-lgtyp
vlpla = <lfs_item>-loc-lgpla
nltyp = ls_ud_oc-vltyp
nlpla = ls_ud_oc-vlpla
anfme = <lfs_item>-t_quan[ 1 ]-quan
altme = <lfs_item>-t_quan[ 1 ]-unit
squit = 'X'
squant_set = 'X'
negat = 'X'
nolock = 'X'
no_stock_det = 'X'
) TO lt_create ASSIGNING FIELD-SYMBOL(<lfs_tocr>).
MOVE-CORRESPONDING <lfs_item>-dest_s TO <lfs_tocr> .
<lfs_tocr>-guid_stock = ls_result-dguid_stock.
ENDIF.
ENDLOOP.
IF lt_create IS NOT INITIAL .
CALL FUNCTION '/SCWM/TO_CREATE'
EXPORTING
iv_lgnum = lv_lgnum
iv_update_task = ''
iv_commit_work = ''
* IV_WTCODE =
* IV_BNAME = SY-UNAME
* IS_RFC_QUEUE =
it_create = lt_create[]
* IT_CREATE_EXC =
* IV_PROCESSOR_DET = ' '
IMPORTING
ev_tanum = lv_tanum
et_ltap_vb = lt_ltap_vb
et_bapiret = lt_return_to
ev_severity = lv_severity.
ENDIF.
LOOP AT lt_return_to TRANSPORTING NO FIELDS WHERE type CA 'EAX'. ENDLOOP.
IF sy-subrc IS INITIAL OR lv_severity CA 'EAX'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
APPEND LINES OF lt_return_gm TO lt_return_all.
APPEND LINES OF lt_return_to TO lt_return_all.
CONTINUE.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.
ENDLOOP.
IF lt_return_all IS NOT INITIAL.
cl_msr_vrm_data=>convert_symessage2bapiret2( CHANGING ct_bapiret2 = lt_return_all[] ).
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |