04-19-2006 6:42 AM
hello
i m using movement type 309.
in the second screen they are entering batch..so based on that batch i m getting matnr and quantity in that batch.
In my ZBAPI ..
SELECT matnr clabs FROM mchb
INTO TABLE it_mb1b
WHERE werks = plant
AND lgort = send_stloc
AND charg = batch.
In the second line item..They are entering scrap material which the data has to get from MARD table. There is no batch exists for this second line item.
i m writing query to get the data from mard like this:-
SELECT matnr labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr LIKE '%-SCRAP'
AND werks = plant
AND lgort = '2200'.
So, how to fill this second line item in BAPI.
For the first line item i m using it_gmitem-entry_qnt in the BAPI item list. This is for the first item in second screen.
Similarly how to fill the second line item in BAPI_GOODSMVT_CREATE.
04-19-2006 8:01 AM
please help as this is urgent.
How to fill the second line item in second screen of MB1B in the BAPI_GOODSMVT_CREATE ???
For first line item i m using entry_qnt in the bapi item list.
04-19-2006 8:11 AM
Similarly for second line item u have to pass IT_MARD-LABST to it_gmitem-entry_qnt
04-19-2006 8:24 AM
It is taking only 1 line item..either the first one or second one.
04-19-2006 8:51 AM
can u please post the portion of code where you are populating the bapi tables?
04-19-2006 9:17 AM
FUNCTION zbapi_mb1b_new.
*"----
""Local interface:
*" IMPORTING
*" VALUE(MOVE_TYPE) LIKE BAPI2017_GM_ITEM_CREATE-MOVE_TYPE DEFAULT
*" '309'
*" VALUE(PLANT) LIKE BAPI2017_GM_ITEM_CREATE-PLANT DEFAULT '2000'
*" VALUE(SEND_STLOC) LIKE BAPI2017_GM_ITEM_CREATE-STGE_LOC
*" VALUE(RECV_STLOC) LIKE BAPI2017_GM_ITEM_CREATE-MOVE_STLOC
*" VALUE(MOVE_PLANT) LIKE BAPI2017_GM_ITEM_CREATE-MOVE_PLANT
*" DEFAULT '2000'
*" VALUE(BATCH) LIKE BAPI2017_GM_ITEM_CREATE-BATCH
*" VALUE(QUAN_MEASURE) LIKE BAPI2017_GM_ITEM_CREATE-QUANTITY
*" EXPORTING
*" VALUE(MAT_DOC) LIKE BAPI2017_GM_HEAD_RET-MAT_DOC
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*"----
DATA : ls_quan1 TYPE p DECIMALS 3,
ls_quan2 TYPE p DECIMALS 3,
ls_quan3 TYPE p DECIMALS 3,
ls_quan4 TYPE p DECIMALS 3,
ls_quan5 TYPE p DECIMALS 3,
ls_quan6 TYPE p DECIMALS 3.
DATA : it_mard LIKE mard OCCURS 0 WITH HEADER LINE.
gmhead-pstng_date = sy-datum. "Posting date defaulted to system date
gmhead-doc_date = sy-datum. "Document date defaulted to system date
gmcode-gm_code = '04'. "Transfer Posting (MB1B)
SELECT matnr clabs FROM mchb
INTO TABLE it_mb1b
WHERE werks = plant "Plant
AND lgort = send_stloc "Storage location
AND charg = batch. "Batch Number
SELECT matnr labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr LIKE '%-SCRAP'
AND werks = plant "Plant
AND lgort = '2200'. "2094 in production
LOOP AT it_mb1b INTO wa_mb1b.
ls_quan2 = ( 5 / 100 ) * wa_mb1b-clabs.
ls_quan3 = wa_mb1b-clabs + ls_quan2.
ls_quan4 = wa_mb1b-clabs - ls_quan2.
IF ( quan_measure EQ wa_mb1b-clabs ).
ls_quan6 = wa_mb1b-clabs.
ELSEIF ( quan_measure > wa_mb1b-clabs AND quan_measure <= ls_quan3 ).
ls_quan5 = quan_measure - wa_mb1b-clabs. "difference
READ TABLE it_mard WITH KEY matnr0(3) = wa_mb1b-matnr0(3).
IF sy-subrc EQ 0.
it_mard-labst = it_mard-labst - ls_quan5.
MODIFY it_mard TRANSPORTING labst WHERE
matnr0(3) = wa_mb1b-matnr0(3).
ELSE.
ENDIF.
MODIFY mard FROM TABLE it_mard.
CLEAR it_mard.
ls_quan6 = wa_mb1b-clabs + ls_quan5.
ELSEIF ( quan_measure < wa_mb1b-clabs AND quan_measure <= ls_quan4 ).
ls_quan5 = wa_mb1b-clabs - quan_measure.
it_mard-labst = it_mard-labst + ls_quan5.
MODIFY it_mard TRANSPORTING labst WHERE
matnr0(3) = wa_mb1b-matnr0(3).
MODIFY mard FROM it_mard.
ls_quan6 = wa_mb1b-clabs.
ENDIF.
it_gmitem-move_type = move_type. "Movement type
it_gmitem-plant = plant. "Plant
it_gmitem-stge_loc = send_stloc. "Storage Location
it_gmitem-move_plant = move_plant. "Receiving Plant
it_gmitem-move_stloc = recv_stloc. "Receiving storage location
it_gmitem-batch = batch. "Batch Number
it_gmitem-material = wa_mb1b-matnr. "Material Number
it_gmitem-move_mat = wa_mb1b-matnr. "Receiving/issuing material
it_gmitem-entry_qnt = ls_quan6. "Quantity in unit of entry
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
.
IF NOT mat_doc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN =
.
ELSE.
ENDIF.
ENDFUNCTION.