‎2005 Jan 11 5:22 AM
Hello ,
I am trying to use the bapi : BAPI_GOODSMVT_CREATE for creating a material document for a Goods Movement 501 which is categorized as other goods receipt.
Please can anyone tell me how can i use this bapi to post the characteristics of the material also.
For ex. if my material is Leather i want to add characteristics color, purity, other contents etc. This characteristics are maintained by the user and i use MB1C for goods recipts.
Please reply soon.
Regards
Swanand.
‎2005 Jan 11 8:01 AM
Hi Swanand:
This is an example of how i implemented:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = matnr
IMPORTING
output = matnr.
MOVE: sy-datum TO it_head-pstng_date, "F.contab. doc.
sy-datum TO it_head-doc_date, "F.doc. en documento
sy-uname TO it_head-pr_uname. "Nombre de usuario
CONCATENATE 'Procesado en el Turno #:' turno INTO
it_head-header_txt SEPARATED BY space. "Tex.cabec. documento
MOVE: '05' TO it_code-gm_code, "Asig.cód.trans.mov.mcÃa
matnr TO it_item-material, "Material
werks TO it_item-plant, "Centro
lgort TO it_item-stge_loc, "Almacen
cant TO it_item-entry_qnt, "Cant.Uni.med.entr
'521' TO it_item-move_type, "Cl.mov.(gest.stocks)
' ' TO it_item-stck_type. "Tipo stock
APPEND it_item.
CLEAR it_item.
Bapi que realiza la salida o entrada al almacen
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = it_head
goodsmvt_code = it_code
IMPORTING
goodsmvt_headret = it_headr
materialdocument = mat_doc
matdocumentyear = doc_year
TABLES
goodsmvt_item = it_item
return = it_bapir.
‎2005 Jan 11 1:59 PM
hello ,
I know how to use the FM : BAPI_GOODSMVT_CREATE. but i need to know how to save the characteristics of the material as stored in the table AUSP using this bapi. or is there any other bapi for that.
Regards
Swanand
‎2005 Jan 11 2:13 PM
I'm not sure which classication object type you are working with. However I have done this before with Class Type 022 (Batch Classification). Before I load the inventory with BAPI_GOODSMVT_CREATE, I create the batches and then create the classification values using BAPI_OBJCL_CREATE_KEY. This is a generic BAPI for working with Classification and not specific to any one class type. This might help you with what you are doing. The following is a little code sample. I first have to lookup what class is attached to my material for class type 022 (I have two different possible classes). I then create my Key for the classification object. I can then fill my characteristics/values and write them into the classification.
method keps_create_batch_class.
types: begin of t_batch,
pack_id type zzem_matdoc_label_serial,
matnr type matnr,
batch type charg_d,
l_batch type zzem_legacy_batch_or_date_code,
mfrpn type mfrpn,
lifnr type lifnr,
end of t_batch.
data: ibatch type table of t_batch.
field-symbols: <wa_batch> like line of ibatch.
select pack_id matnr batch l_batch mfrpn lifnr from zem_keps_inv
into table ibatch
where werks = me->werks
and lgnum = me->lgnum
and batch is not null.
data: batch_active type xchpf.
data: alloclist type table of bapi1003_alloc_list.
field-symbols: <wa_class> like line of alloclist.
data: objnum type objnum.
data: return type table of bapiret2.
field-symbols: <wa_return> like line of return.
data: guid type bapi1003_key-object_guid.
data: value_num type table of bapi1003_alloc_values_num.
field-symbols <wa_value_num> like line of value_num.
data: value_char type table of bapi1003_alloc_values_char.
field-symbols: <wa_value_char> like line of value_char.
data: ampl_size type i.
loop at ibatch assigning <wa_batch>.
clear batch_active.
select single xchpf from marc
into batch_active
where matnr = <wa_batch>-matnr
and werks = me->werks.
check batch_active = 'X'.
clear alloclist.
objnum = <wa_batch>-matnr.
call function 'BAPI_OBJCL_GETCLASSES'
exporting
objectkey_imp = objnum
objecttable_imp = 'MARA'
classtype_imp = '022'
tables
alloclist = alloclist
return = return.
if alloclist[] is initial.
write: / 'No Class Allocation for Material: ',
<wa_batch>-matnr, <wa_batch>-pack_id.
continue.
endif.
data: objectname type bapi1003_key-object.
move <wa_batch>-matnr to objectname.
move me->werks to objectname+18(4).
move <wa_batch>-batch to objectname+22(10).
clear guid.
call function 'BAPI_OBJCL_GET_KEY_OF_OBJECT'
exporting
objectname = objectname
objecttable = 'MCHA'
classtype = '022'
create_missing_key = 'X'
importing
clobjectkeyout = guid
tables
return = return.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
if guid is initial.
write: / 'Error Reading Object Key for Material: ',
<wa_batch>-matnr, <wa_batch>-pack_id.
continue.
endif.
read table alloclist assigning <wa_class>
index 1.
clear: value_num, value_char.
if <wa_class>-classnum = 'MFR_LOT_DATA'.
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MANUFACTURER_LOT_NUMBER' to <wa_value_char>-charact.
move <wa_batch>-l_batch to <wa_value_char>-value_char.
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MANUFACTURER_NUMBER' to <wa_value_char>-charact.
move <wa_batch>-lifnr to <wa_value_char>-value_char.
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MANUFACTURER_DATE_CODE' to <wa_value_char>-charact.
move 'LEGACY' to <wa_value_char>-value_char.
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MANUFACTURER_NAME' to <wa_value_char>-charact.
select single name1 from lfa1 into <wa_value_char>-value_char
where lifnr = <wa_batch>-lifnr.
clear ampl_size.
ampl_size = strlen( <wa_batch>-mfrpn ).
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MFR_NUMBER_AMPL' to <wa_value_char>-charact.
move <wa_batch>-mfrpn to <wa_value_char>-value_char.
if ampl_size > 30.
append initial line to value_char.
read table value_char assigning <wa_value_char>
index sy-tabix.
move 'MFR_NUMBER_AMPL2' to <wa_value_char>-charact.
move <wa_batch>-mfrpn+30 to <wa_value_char>-value_char.
endif.
elseif <wa_class>-classnum = 'ASSEMBLY_BATCH'.
else.
write: / 'Unknown Class Allocation for Material: ',
<wa_batch>-matnr, <wa_batch>-pack_id,
<wa_class>-classnum.
continue.
endif.
call function 'BAPI_OBJCL_CREATE_KEY'
exporting
clobjectkey_new = guid
classnum_new = <wa_class>-classnum
tables
allocvaluesnum = value_num
allocvalueschar = value_char
return = return.
loop at return assigning <wa_return>.
if <wa_return>-type = 'E'.
write: / <wa_batch>-matnr, <wa_batch>-batch,
<wa_return>-message.
endif.
endloop.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
endloop.
endmethod.
‎2005 Jan 11 2:33 PM
hello thomas,
can u please send me all the code used by you.
Regards
Swanand
‎2005 Jan 11 2:37 PM
‎2005 Jan 11 2:40 PM
hello thomas,
can u plz send me the code of creating classification using bapi and then creating the material documents using bapi method. both the code in sync, so that i can refer and build the logic.
if required u can send me that code on swanand76@yahoo.co.in
Regards
swanand
‎2005 Jan 11 2:55 PM
Well I already posted all the code for creating the classification. This classification is then stored as part of the Batch. Notice that I supplied the Material, Plant and Batch Number when I generated the Classification Key.
Maybe a little information on the whole application is in order. This is a data migration application. The legacy system sends me a file with inventory (by serial number). This data contains the external batch number (and the data I need to create my classification). I store all of this information in a Z-Table. I then create new SAP batches and assign the classification values to it. The user then has a RF transaction in which they scan the inventory on the floor. At this time we post the inventory and assign the batch to it.
Now the following is the code that I use to create my Batches.
method keps_create_batches.
types: begin of t_batch,
pack_id type zzem_matdoc_label_serial,
matnr type matnr,
lwedt type lwedt,
mhd_io type mhd_io,
iprkz type dattp,
l_batch type zzem_legacy_batch_or_date_code,
lifnr type lifnr,
end of t_batch.
data: ibatch type table of t_batch.
field-symbols: <wa_batch> like line of ibatch.
select pack_id matnr lwedt mhd_io iprkz l_batch lifnr
from zem_keps_inv
into table ibatch
where werks = me->werks
and lgnum = me->lgnum
and l_batch is not null.
data: batch_active type xchpf.
data: n_batch type charg_d.
data: attrib type bapibatchatt.
data: batch type charg_d.
data: return type table of bapiret2.
field-symbols: <wa_return> like line of return.
data: r_batch type range of charg_d.
field-symbols: <wa_rbatch> like line of r_batch.
append initial line to r_batch.
read table r_batch assigning <wa_rbatch>
index sy-tabix.
<wa_rbatch>-sign = 'I'.
<wa_rbatch>-option = 'NE'.
loop at ibatch assigning <wa_batch>.
clear batch_active.
select single xchpf from marc
into batch_active
where matnr = <wa_batch>-matnr
and werks = me->werks.
check batch_active = 'X'.
clear n_batch.
select single batch from zem_keps_inv
into n_batch
where
pack_id ne <wa_batch>-pack_id
and werks = me->werks
and lgnum = me->lgnum
and matnr = <wa_batch>-matnr
and lwedt = <wa_batch>-lwedt
and mhd_io = <wa_batch>-mhd_io
and iprkz = <wa_batch>-iprkz
and l_batch = <wa_batch>-l_batch
and lifnr = <wa_batch>-lifnr
and batch in r_batch.
if sy-subrc = 0.
update zem_keps_inv set batch = n_batch
where pack_id = <wa_batch>-pack_id.
else.
clear attrib.
if <wa_batch>-mhd_io is initial.
else.
attrib-expirydate = <wa_batch>-mhd_io.
endif.
if <wa_batch>-lwedt is initial.
else.
attrib-lastgrdate = <wa_batch>-lwedt.
endif.
clear batch.
call function 'BAPI_BATCH_CREATE'
exporting
material = <wa_batch>-matnr
plant = me->werks
batchattributes = attrib
importing
batch = batch
tables
return = return.
if not batch is initial.
update zem_keps_inv set batch = batch
where pack_id = <wa_batch>-pack_id.
else.
write: / 'Error creating Batch for Package ID: ',
<wa_batch>-pack_id.
loop at return assigning <wa_return>.
write: /5 <wa_return>-message.
endloop.
endif.
endif.
endloop.
endmethod.
Finally this is the code that I use to post my inventory.
****BAPI Structures
data: gm_head type bapi2017_gm_head_01 .
data: gm_code type bapi2017_gm_code .
data: l_lenum type lenum.
****BAPI Item Table
data: gm_item type bapi2017_gm_item_create occurs 0 with header line.
****BAPI Return - Error Table
data: ireturn type bapiret2 occurs 0 with header line.
****BAPI Error Flag
data: bapi_error(1) type c.
move zem_keps_inv-lgpla to
zem_rf_errors-lgpbe.
clear zem_keps_inv.
select single * from zem_keps_inv
where pack_id = zem_stor_loc_to_stor_loc-pack_id.
move zem_rf_errors-lgpbe to zem_keps_inv-lgpla.
****Set the transaction dates off of the system date.
move sy-datum to
gm_head-pstng_date.
move zem_keps_inv-lwedt to
gm_head-doc_date.
****Set the transaction code type
move '04' to gm_code-gm_code.
****Move screen values into the BAPI structures
move zem_keps_inv-matnr to gm_item-material.
move zem_keps_inv-matnr to zem_rf_errors-matnr.
move zem_keps_inv-werks to gm_item-plant.
move zem_keps_inv-werks to zem_rf_errors-werks.
move zem_keps_inv-quantity to gm_item-entry_qnt.
move zem_keps_inv-quantity to zem_rf_errors-entry_qnt.
move movement_type to gm_item-move_type.
move movement_type to zem_rf_errors-move_type.
move zem_keps_inv-lgort
to gm_item-stge_loc.
move zem_keps_inv-lgort
to zem_rf_errors-move_stloc.
clear lagp.
select single lgtyp from lagp into lagp-lgtyp
where lgnum = wa_lgnum
and lgpla = zem_keps_inv-lgpla.
move lagp-lgtyp to zem_keps_inv-lgtyp.
move zem_keps_inv-batch to gm_item-batch.
append gm_item.
****Call the Goods Movement BAPI
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gm_head
goodsmvt_code = gm_code
importing
materialdocument = zem_keps_inv-mblnr
matdocumentyear = zem_keps_inv-mjahr
tables
goodsmvt_item = gm_item
return = ireturn.
****Read the return structure from the BAPI and check for Error
****condition
loop at ireturn.
if ireturn-type = 'E' or
ireturn-type = 'A'.
move 'X' to bapi_error.
endif.
endloop.
Some of this code is still taken out of context from the larger application, but it does show how I interact with all the SAP BAPIs.
‎2008 Jun 03 12:20 PM
Hi,
I require a BDC for CL20N(njoy SAP) transaction to add characteristic value to manufacturing plant for class type 053(ippe node). When I try to record thru SHDB it is exiting from the middle, but when I run the transaction without SHDB its working perfectly.
I can't use CL20 because it is saying its obsolete, do not use.
‎2005 Dec 28 3:45 PM
Hi!
I have the same problem, I´m using BAPI BAPI_GOODSMVT_CREATE to receipt goods but the material is categorized with class 022 with batches.
But when I executed the bapi with tx se37 the return code is ...
T ID NUM MESSAGE
E M7 036 Para el pedido 4500199903 00001 no es posible efectuar una EM(for the purchase order 4500199903 00001 is not possible to do EM)
I don't know if the problem is because the material is categorized with batches or is because I 'm forgetting to enter other values.
With the tx mb01 for good receipt when I finalize to enter all the data for the receipt appears other dynpro for completing the characteristic of the batch class 022.
Anyone can help me with this?
Is there a way to trace the error of the bapi? exclude debugging.