on 05-06-2015 9:43 AM
Dear experts,
could you give some tipps how I can perform the posting change in EWM in the best way? Any FM or class with methods?
Many thanks in advance
BR
Denis
I will be copying the answer i gave in this thread:
I had this same exact problem but specifically to update the stock type after a Goods receive what i used was the function module /SCWM/STOCK_CHANGE and /SCWM/GM_POST, i can provide the method i used for modification depending on the requirements.
If the following code adjusted to your requirements doesn't work i recommend opening the transaction SAAB and activate the break point /SCWM/GM, following that do your posting using the transaction /n/SCWM/POST and find the Function module /SCWM/STOCK_CHANGE and see what the Standart code is passing in the importing structures and tables regarding your example, i believe if you change to use just what standart uses as i did in my case it will work.
Good Luck,
Alex.
METHOD update_stock_type.
DATA lt_aqua TYPE STANDARD TABLE OF /scwm/aqua.
DATA it_item TYPE /scwm/tt_spitem.
DATA is_item TYPE /scwm/s_spitem.
DATA lt_bapiret TYPE bapiret2_t.
DATA lv_severity TYPE bapi_mtype.
DATA is_quan TYPE /scwm/s_quan.
DATA lt_ordim_c TYPE STANDARD TABLE OF /scwm/ordim_c.
DATA lv_cat TYPE /lime/stock_category.
"There will be necessary to exist a internal table with the HUs we want to update for my case and for the sake of just showing an example consider it is lt_hus
"gets information regarding the HU on aqua
SELECT *
FROM /scwm/aqua
INTO TABLE lt_aqua
FOR ALL ENTRIES IN lt_hus
WHERE lgnum EQ lv_lgnum
AND huident EQ lt_hus-huident.
IF sy-subrc <> 0.
"Implement your own logic when no data is found
ENDIF.
"Gets the item information updated
SELECT *
FROM /scdl/db_proci_i
INTO TABLE @DATA(lt_proci_update)
WHERE docid EQ @gs_screen_items-proci-docid.
IF sy-subrc <> 0.
CLEAR lt_proci_update.
"Implement your own logic when no data is found
ENDIF.
"Gets the task created for the HU by POSTING
SELECT *
FROM /scwm/ordim_c
INTO TABLE lt_ordim_c
FOR ALL ENTRIES IN lt_ewmt021
WHERE lgnum EQ gs_screen_header-lgnum
AND dguid_hu EQ lt_ewmt021-guid_hu.
IF sy-subrc <> 0.
CLEAR: lt_ewmt021, lt_proci_update, lt_ordim_c.
"Implement your own logic when no data is found
ENDIF.
LOOP AT lt_hus ASSIGNING FIELD-SYMBOL(<fs_hus>).
READ TABLE lt_aqua WITH KEY huident = <fs_hus>-huident ASSIGNING FIELD-SYMBOL(<fs_aqua>).
IF <fs_aqua> IS NOT ASSIGNED.
CONTINUE.
ENDIF.
READ TABLE lt_proci_update WITH KEY docid = <fs_hus>-docid
itemid = <fs_hus>-itemid ASSIGNING FIELD-SYMBOL(<fs_proci>).
IF <fs_proci> IS NOT ASSIGNED.
CONTINUE.
ENDIF.
READ TABLE lt_ordim_c WITH KEY dguid_hu = <fs_hus>-guid_hu ASSIGNING FIELD-SYMBOL(<fs_ordim_c>).
IF <fs_ordim_c> IS NOT ASSIGNED.
CONTINUE.
ENDIF.
"In this case the update will be to change the stock type from blocked to Unblocked
"Stock Type to be updated
MOVE <fs_aqua>-cat TO lv_cat.
REPLACE ALL OCCURRENCES OF 'B' IN lv_cat WITH 'F'.
"Gets QUAN information
SELECT SINGLE *
FROM /scwm/quan
INTO @DATA(ls_quan)
WHERE guid_stock EQ @<fs_aqua>-guid_stock
AND guid_parent EQ @<fs_aqua>-guid_parent.
"Sets the ID using the current line iterator
is_item-id = sy-tabix.
is_item-id_group = sy-tabix + 1.
is_item-direction = 'T'.
is_item-squant_set = abap_true.
is_item-procty = <fs_proci>-/scwm/procty.
is_item-guid_hu = <fs_hus>-guid_hu.
is_item-huident = <fs_hus>-huident.
"Quantity of stock saved on the HU
is_quan-unit = <fs_hus>-uom.
is_quan-quan = <fs_hus>-qty.
APPEND is_quan TO is_item-t_quan.
"Information regarding the HU in the Wharehouse
is_item-loc-lgnum = gs_screen_header-lgnum.
is_item-loc-lgtyp = <fs_aqua>-lgtyp.
is_item-loc-lgpla = <fs_aqua>-lgpla.
"Passes the current information of the HU
is_item-source_s-idx_stock = ls_quan-idx_stock.
is_item-source_s-guid_stock = <fs_aqua>-guid_stock.
is_item-source_s-matid = <fs_aqua>-matid.
is_item-source_s-cat = <fs_aqua>-cat.
is_item-source_s-owner = <fs_aqua>-owner.
is_item-source_s-owner_role = <fs_aqua>-owner_role.
is_item-source_s-entitled = <fs_aqua>-entitled.
is_item-source_s-entitled_role = <fs_aqua>-entitled_role.
is_item-source_s-qdoccat = <fs_proci>-doccat.
is_item-source_s-qdocid = <fs_proci>-docid.
is_item-source_s-qitmid = <fs_proci>-itemid.
"Passes the information with the modifications we want made to the stock
is_item-dest_s-matid = <fs_aqua>-matid.
is_item-dest_s-cat = lv_cat. "What we will want to modifiy
is_item-dest_s-matid = <fs_aqua>-matid.
is_item-dest_s-qdoccat = <fs_proci>-doccat.
is_item-dest_s-qdocid = <fs_proci>-docid.
is_item-dest_s-qitmid = <fs_proci>-itemid.
is_item-dest_s-owner = <fs_aqua>-owner.
is_item-dest_s-owner_role = <fs_aqua>-owner_role.
is_item-dest_s-entitled = <fs_aqua>-entitled.
is_item-dest_s-entitled_role = <fs_aqua>-entitled_role.
APPEND is_item TO it_item.
CLEAR is_item.
ENDLOOP.
"Calls Stock Change function module to proceed to update the HU
CALL FUNCTION '/SCWM/STOCK_CHANGE'
EXPORTING
is_header = VALUE /scwm/s_gmheader( lgnum = gs_screen_header-lgnum
created_by = <fs_ordim_c>-created_by
created_at = <fs_ordim_c>-created_at
code = '/SCWM/POST' )
it_item = it_item
IMPORTING
et_bapiret = lt_bapiret
ev_severity = lv_severity.
LOOP AT lt_bapiret ASSIGNING FIELD-SYMBOL(<fs_bapiret>).
IF <fs_bapiret>-type EQ 'E'.
CALL FUNCTION 'YOUR_MESSAGE_FUNCTION'
EXPORTING
iv_id = <fs_bapiret>-id
iv_number = <fs_bapiret>-number
iv_typ = <fs_bapiret>-type
iv_var1 = <fs_bapiret>-message_v1
iv_var2 = <fs_bapiret>-message_v2
iv_var3 = <fs_bapiret>-message_v3
iv_var4 = <fs_bapiret>-message_v4.
CLEAR: lt_proci_update, lt_ordim_c.
"implementar rotina de erro
ENDIF.
ENDLOOP.
"Will try to POST the changes and for that the function module will generate a new task
TRY.
DATA lv_tanum TYPE /scwm/tanum.
CALL FUNCTION '/SCWM/GM_POST'
IMPORTING
ev_tanum = lv_tanum
et_bapiret = lt_bapiret
ev_severity = lv_severity.
CATCH /scwm/cx_core.
LOOP AT lt_bapiret ASSIGNING <fs_bapiret>.
IF <fs_bapiret>-type EQ 'E'.
CALL FUNCTION 'YOUR_MESSAGE_FUNCTION'
EXPORTING
iv_id = <fs_bapiret>-id
iv_number = <fs_bapiret>-number
iv_typ = <fs_bapiret>-type
iv_var1 = <fs_bapiret>-message_v1
iv_var2 = <fs_bapiret>-message_v2
iv_var3 = <fs_bapiret>-message_v3
iv_var4 = <fs_bapiret>-message_v4.
CLEAR: lt_proci_update, lt_ordim_c.
"Implement your own logic for when theres an error
ENDIF.
ENDLOOP.
ENDTRY.
COMMIT WORK AND WAIT.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Normally you can perform posting change with direction transaction /n/scwm/post. I am not clear the best way mean..can you elaborate your question.
Regards
Sastry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
it should be possible using function module
/SCWM/GM_CREATE
Petr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.