‎2006 Apr 18 8:55 AM
Hello friends,
In mb1b second screen, they are entering second line item which is called scrap(eg: M03-SCRAP).This is updated in MARD table as the scrap materials doesn't belong to any batch.
So, they are entering matnr and labst (quantity in second line item).
How to identify this particular scrap material from mard table.
I m writing query like this:-
SELECT matnr labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr = 'M03-SCRAP'
AND werks = plant
AND lgort = '2200'.
How to get this material number without hardcoding bcoz this ll be vary for different material numbers.
‎2006 Apr 18 9:00 AM
Hi
You can use LIKE option in your select if you know how it should be the material code.
DATA: V_MATNR TYPE MATNR VALUE '%SCRAP%'.
SELECT matnr labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr like v_matnr
AND werks = plant
AND lgort = '2200'.
In this way it can bw extracted all records where material code has the string SCRAP.
So I think you can do something only if there's a rule to find that kind of material.
Max
‎2006 Apr 18 9:30 AM
Hello max,
scrap field they enter like "M03-SCRAP".
They said that if first 3 letters of scrap = first 3 letters of receiving material.
then data has to pick from mard-labst and to be added to the first line item of material and mard should be updated.
please luk into my coding(function module):-
DATA : ls_quan2 TYPE p DECIMALS 3,
ls_quan3 TYPE p DECIMALS 3.
DATA : it_mard LIKE mard OCCURS 0 WITH HEADER LINE.
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmcode-gm_code = '04'. "Transfer Posting (MB1B)
SELECT matnr clabs FROM mchb
INTO TABLE it_mb1b
WHERE werks = plant
AND lgort = send_stloc
AND charg = batch.
SELECT matnr labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr like '%SCRAP'
AND werks = plant
AND lgort = '2200'.
LOOP AT it_mb1b INTO wa_mb1b.
it_gmitem-move_type = move_type.
it_gmitem-plant = plant.
it_gmitem-stge_loc = send_stloc.
it_gmitem-move_plant = move_plant.
it_gmitem-move_stloc = recv_stloc.
it_gmitem-batch = batch.
it_gmitem-material = wa_mb1b-matnr.
ls_quan2 = quan_measure - wa_mb1b-clabs.
IF ls_quan2 LE 0.
ls_quan3 = wa_mb1b-clabs.
ELSE.
ls_quan3 = wa_mb1b-clabs + ls_quan2.
it_mard-labst = it_mard-labst - ls_quan2.
MODIFY table it_mard TRANSPORTING labst.
<b>MODIFY it_mard TRANSPORTING labst WHERE matnr = 'M03-SCRAP'.</b> MODIFY mard. " FROM TABLE it_mard.
ENDIF.
<b>" Here how we know that matnr only update in mard.</b>
it_gmitem-entry_qnt = ls_quan3.
APPEND it_gmitem.
ENDLOOP.
CLEAR return.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gmhead
goodsmvt_code = gmcode
TESTRUN = 'X'
IMPORTING
GOODSMVT_HEADRET =
materialdocument = mat_doc
MATDOCUMENTYEAR =
TABLES
goodsmvt_item = it_gmitem
GOODSMVT_SERIALNUMBER =
return = return
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN =
.
‎2006 Apr 18 9:47 AM
Hi
so you you should check the material code before updating MARD:
MODIFY it_mard TRANSPORTING labst WHERE matnr(3) = wa_mb1b-matnr(3).
Anyway are you sure you can directly update std table MARD?
Max
‎2006 Apr 18 9:53 AM
max,
can't we directly update standard tables.
If we should not do directly.. how to do this?
bcoz..all this code i am writing in BAPI
‎2006 Apr 18 9:59 AM
You can use the BAPI BAPI_MATERIAL_SAVEDATA to update material master data.
Max