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: 
oguzhans
Explorer

Introduction


Usage decision changes the stock type of the stock and releases the stock from the inspection lot. But when the user needs to cancel the usage decision, stock will not be relinked to the Inspection Lot due to the EWM capabilities.

For MM stock, SAP has the solution with the program RQEVAC50 (SAP Note 175842), but for EWM there is not any solution.

The report below can be used for GM Reversing for Inspection Lot EWM stock.

 

Details


EWM Stock management is very complex and has many possibilities. This report does not cover all the scenerios.

The restrictions below should be active.

  1. Inspection lot quantity should be equal to Material+Batch stock quantity.

  2. Stock can be in different bins, HUs, Stock types. But the totals should match.

  3. All the stock should be HU managed. Non-HU stock is not covered.


 

NOTE: If the requirement is more flexible (like non-hu management, include MM stock, Stock split, etc..), please contact with me..

 

Move Stock to Initial Bin

This parameter is for resetting the stock location. If the stock has been moved to the warehouse, the user can ask the report to take the stock back to the initial bin, or leave it where ever it is. In both scenerioes, stock will be assigned back to the Inspection Lot.

 

Report Coding


It is a simple executable report, you can just copy and paste to SE38 and run it.

 
*&---------------------------------------------------------------------*
*& 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.

 

Notes


If the requirement is more flexible (like non-hu management, include MM stock, Stock split, etc..), you can contact with me..

 

Conclusion


I hope this program solves an cronic issue of EWM that many of the companies struggling.

 

If you have any question, please ask. I will be checking the blog for Q&A. I am eager to share and learn.
9 Comments
DominikTylczyn
Active Contributor
0 Kudos
I wonder if SAP addresses this issue in standard?
oguzhans
Explorer

I hope so, I can help for standardization of this solution.

DominikTylczyn
Active Contributor
0 Kudos
Why don't you open an ticket to SAP support about that issue?

You may also submit an improvement proposal with SAP Customer Influence program, opportunity SAP S/4HANA Cloud for Supply Chain Logistics, public edition Please share the link to the improvement proposal once you submit it, so I can vote for it.
oguzhans
Explorer
I have done already, SAP simply returns as "it is not covered by SAP Standard" to such tickets.

I was not aware of such a program, will check..
DominikTylczyn
Active Contributor
I love those responses...
maria_dalpont
Newcomer
0 Kudos
Hello!!

Thank you for your contribution, it's an incredible code.

The first validation of the code is the status I0297 Usage decision reset.
But how do I get an inspection lot to this status?

As I have already released the inspectionl lot, I have a status "Usage decision has been made".

Thanks!
oguzhans
Explorer
0 Kudos
You can reset the UD status with QA12.
0 Kudos
Hello,

I tried to reset the status in QA12 and it gives a message the status cannot be changed. Any clue please?

We are using inspection lot origin 17 in EWM.

 

Regards,

Dev.
oguzhans
Explorer
0 Kudos
The cause of this error can be many issues. I can not help about that, sorry. A QM consultant that knows your system must check.
Labels in this area