Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Error in BAPI

Hello ,

While using the BAPI 'BAPI_MATERIAL_SAVEDATA', to extend material from one plant to another my code is throwing an error 'Currency initial v,current amount 6,000.0000 in MOVING_PR was transferred without a currency'

Enter a material number'

I have incorporated mbew-peinh, even then its throwing the same error.

I snd copy of my code.

report zmm_r018 .

.

*& Prog to copy n create the existing material using bapi .

&----


*&

*&

&----


tables: t001l, "Storage Locations

mara, "General Material Data

makt, "Material Descriptions

mbew, "Material Valuation

marc, "Plant Data for Material

mltx. "Purchase Order Descriptions

**parameters : new_mat like mara-matnr,

    • desc like makt-maktx,

*data: ref_mat like mara-matnr.

*

*data: xmara type mara.

**data: wamatnr like mara-matnr.

data: potext type string."Purchase Order Desc

*

*

data : ihead_data type bapimathead,

iclient_data type bapi_mara, "Client Data

iclient_datax type bapi_marax,

  • imakt like bapi_makt, "Mat Description

iplant_data like bapi_marc, "Plant View

iplant_datax like bapi_marcx,

iltxt type table of bapi_mltx with header line, "Pur Order Text

istoragelocationdata type bapi_mard, "Storage Location

istoragelocationdatax type bapi_mardx,

iaccounting_data like bapi_mbew, "Accounting View

iaccounting_datax like bapi_mbewx,

bapiret like bapiret2,

returnm type table of bapi_matreturn2 with header line.

**Internal Table to hold the records in the text file

types:begin of it,

matnr(18), " Material number

mbrsh(1), " Industry sector

mtart(4), " Material type

werks(4), " Plant

lgort_d(4), "Storage Location

maktx(40), " Material description

meins(3), " Base unit of measure

matkl(9) , " Material group

bismt(18), " Old Material number

spart(2), " Division

gewei(3), " Weight Unit

text1(30), " Purchasr Order Text

text2(30),

text3(30),

text4(30),

text5(30),

text6(30),

dzeinr(22), " Document

ekgrp(3), " Purchasing group

ekwsl(4), " Purchase Value Key

webaz(3), " Goods receipt processing time in days

dismm(2), " MRP Type

minbe(13), "Reorder point

dispo(3), " MRP Controller

disls(2), "Lot size (materials planning)

mabst(13), "Maximum stock level

plifz(3), " Planned delivery time in days

webaz1(3), " Goods receipt processing time in days

fhori(3), "Scheduling Margin Key for Floats

eisbe(13), "Safety stock

mtvfp(2), "Checking Group for Availability Check

lgpbe(10), "Storage Bin

qmatauth(6),"Material Authorization Group for Activities in QM

qmpur(1), " QM in Procurement is Active

qsspur(8), "Control Key for Quality Management in Procurement

bklas(4), " Valuation Class

bwtty_d(1), "Valuation Category

vprsv(1), " Price control indicator

verpr_bapi(23), "Moving average price/periodic unit price

peinh(5), "Price Unit

end of it.

data: it_data type table of it,

wa_data like line of it_data.

*Decalraing flag

data: v_flag value ''.

*DECLARING WORK AREAs TO BE PASSED TO THE FUNCTION MODULE.

data: bapi_head like bapimathead,

bapi_clientdata like bapi_mara,

bapi_clientdatax like bapi_marax,

bapi_plantdata like bapi_marc,

bapi_plantdatax like bapi_marcx,

bapi_storagelocationdata like bapi_mard,

bapi_storagelocationdatax like bapi_mardx,

bapi_salesdata like bapi_mvke,

bapi_salesdatax like bapi_mvkex,

bapi_makt like bapi_makt,

bapi_return like bapiret2.

*INTERNAL TABLE TO HOLD THE MATERIAL DESCRIPTION

data: begin of it_makt occurs 0.

include structure bapi_makt.

data end of it_makt.

data:begin of it_ret occurs 0.

include structure bapiret2.

data end of it_ret.

*INTERNAL TABLE TO HOLD HEADER DATA

data: it_excel type alsmex_tabline occurs 0 with header line.

*SELECTION-SCREEN ELEMENTS

selection-screen begin of block b1 with frame title text-001.

parameter: fname type rlgrap-filename default 'c:\supplies.xls'.

parameters: p_begcol type i default '1' no-display,

p_begrow type i default '2' no-display,

p_endcol type i default '200' no-display,

p_endrow type i default '2500' no-display.

*perform f_get_data.

selection-screen end of block b1.

*DECLARATION OF EXCELAL TABLE

at selection-screen on value-request for fname.

perform f_get_file using fname.

start-of-selection.

perform f_xls_itab using fname

changing it_excel.

perform f_move_data.

perform f_get_data.

perform f_call_bapi.

&----


*& Form F_GET_FILE

&----


  • text

----


  • -->P_FNAME text

  • <--P_SY_SUBRC text

----


form f_get_file using p_fname like fname.

call function 'KD_GET_FILENAME_ON_F4'

exporting

program_name = syst-repid

dynpro_number = syst-dynnr

  • FIELD_NAME = ' '

  • STATIC = ' '

  • MASK = ' '

changing

file_name = p_fname

  • EXCEPTIONS

  • MASK_TOO_LONG = 1

  • OTHERS = 2

.

if sy-subrc <> 0.

message e006(zhnc).

endif.

endform. " F_GET_FILE

&----


*& Form F_XLS_ITAB

&----


  • text

----


  • -->P_FNAME text

  • <--P_IT_EXCEL text

----


form f_xls_itab using p_fname

changing p_it_excel.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = 'c:\supplies.xls'

i_begin_col = p_begcol

i_begin_row = p_begrow

i_end_col = p_endcol

i_end_row = p_endrow

tables

intern = it_excel

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " F_XLS_ITAB

&----


*& Form F_MOVE_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f_move_data .

data : lv_index type i.

field-symbols <fs>.

*--- Sorting the internal table

sort it_excel by row col.

clear it_excel.

loop at it_excel.

move it_excel-col to lv_index.

*--- Assigning the each record to an internal table row

assign component lv_index of structure wa_data to <fs>.

*--- Asigning the field value to a field symbol

move it_excel-value to <fs>.

at end of row.

append wa_data to it_data.

clear wa_data.

endat.

endloop.

*

endform. " F_MOVE_DATA

form f_get_data .

loop at it_data into wa_data.

move-corresponding wa_data to ihead_data.

*

  • Header

ihead_data-material = wa_data-matnr.

ihead_data-ind_sector = wa_data-mbrsh.

ihead_data-matl_type = wa_data-mtart.

ihead_data-basic_view = 'X'.

ihead_data-purchase_view = 'X'.

ihead_data-mrp_view = 'X'.

ihead_data-storage_view = 'X'.

ihead_data-quality_view = 'X'.

ihead_data-account_view = 'X'.

move-corresponding wa_data to iclient_data.

  • Material Description

refresh it_makt.

it_makt-langu = 'EN'.

it_makt-matl_desc = wa_data-maktx.

append it_makt.

  • Purchase Order Description

clear:iltxt,iltxt[].

concatenate wa_data-text1 wa_data-text2 wa_data-text3 wa_data-text4

wa_data-text5 wa_data-text6 into potext

separated by space.

iltxt-applobject = 'MATERIAL'.

iltxt-text_name = wa_data-matnr.

iltxt-text_id = 'BEST'.

iltxt-langu = sy-langu.

iltxt-langu_iso = 'EN'.

iltxt-format_col = space.

iltxt-text_line = potext.

append iltxt.

  • Client Data - Basic

iclient_data-matl_group = wa_data-matkl.

iclient_data-old_mat_no = wa_data-bismt.

iclient_data-base_uom = wa_data-meins.

iclient_data-document = wa_data-dzeinr.

iclient_data-unit_of_wt = wa_data-gewei.

iclient_data-division = wa_data-spart.

iclient_data-qm_procmnt = wa_data-qmpur.

iclient_data-pur_valkey = wa_data-ekwsl.

iclient_datax-matl_group = 'X'.

iclient_datax-old_mat_no = 'X'.

iclient_datax-base_uom = 'X'.

iclient_datax-po_unit = 'X'.

iclient_datax-document = 'X'.

iclient_datax-unit_of_wt = 'X'.

iclient_datax-division = 'X'.

iclient_datax-var_ord_un = 'X'.

iclient_data-pur_valkey = 'X'.

move-corresponding wa_data to iplant_data.

  • Plant - Purchasing

iplant_data-plant = wa_data-werks.

iplant_data-pur_group = wa_data-ekgrp.

iplant_data-gr_pr_time = wa_data-webaz.

iplant_datax-plant = wa_data-werks.

iplant_data-pur_group = 'X'.

iplant_datax-gr_pr_time = 'X'.

*MRP1 View

iplant_data-mrp_type = wa_data-dismm.

iplant_data-reorder_pt = wa_data-minbe.

iplant_data-mrp_ctrler = wa_data-dispo.

iplant_data-lotsizekey = wa_data-disls.

iplant_data-max_stock = wa_data-mabst .

iplant_datax-mrp_type = 'X'.

iplant_datax-reorder_pt = 'X'.

iplant_datax-mrp_ctrler = 'X'.

iplant_datax-lotsizekey = 'X'.

iplant_datax-max_stock = 'X'.

*MRP2 View

iplant_data-plnd_delry = wa_data-plifz.

iplant_data-sm_key = wa_data-fhori.

iplant_data-ctrl_key = wa_data-qsspur.

iplant_data-availcheck = wa_data-mtvfp.

iplant_datax-plnd_delry = 'X'.

iplant_datax-sm_key = 'X'.

iplant_data-ctrl_key = 'X'.

iplant_datax-availcheck = 'X'.

*MRP3 View

iplant_data-safety_stk = wa_data-eisbe.

iplant_data-qm_authgrp = wa_data-qmatauth.

iplant_datax-safety_stk = 'X'.

iplant_data-qm_authgrp = 'X'.

move-corresponding wa_data to istoragelocationdata.

  • Storage View

istoragelocationdata-plant = wa_data-werks.

istoragelocationdata-stge_loc = wa_data-lgort_d.

istoragelocationdata-stge_bin = wa_data-lgpbe.

istoragelocationdatax-plant = wa_data-werks.

istoragelocationdatax-stge_loc = wa_data-lgort_d.

istoragelocationdatax-stge_bin = 'X'.

  • Accounting

iaccounting_data-val_area = wa_data-werks.

iaccounting_data-price_ctrl = wa_data-vprsv.

iaccounting_data-moving_pr = wa_data-verpr_bapi.

iaccounting_data-price_unit = wa_data-peinh.

iaccounting_data-val_class = wa_data-bklas.

iaccounting_data-val_cat = wa_data-bwtty_d.

iaccounting_datax-val_area = wa_data-werks.

iaccounting_datax-price_ctrl = 'X'.

iaccounting_datax-moving_pr = 'X'.

iaccounting_datax-price_unit = 'X'.

iaccounting_datax-val_class = 'X'.

iaccounting_datax-val_cat = 'X'.

clear it_ret.

refresh it_ret.

perform f_call_bapi.

read table it_ret with key type = 'S'.

if sy-subrc eq 0.

perform f_bapi_commit.

write:/ 'MATERIAL CREATED OR UPDATED SUCESSFULLY WITH MATERIAL NO',

wa_data-matnr.

else.

*message e000(zhnc) with 'ERROR IN CREATING THE MATERIAL'.

*

*WRITE: / 'ERROR IN CREATIN MATERIAL',IT_RET-MESSAGE.

*PERFORM F_DOWNLOAD.

endif.

*ENDIF.

endloop.

endform. " F_GET_DATA

&----


*& Form F_CALL_BAPI

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f_call_bapi .

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

headdata = ihead_data

clientdata = iclient_data

clientdatax = iclient_datax

plantdata = iplant_data

plantdatax = iplant_datax

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

storagelocationdata = istoragelocationdata

storagelocationdatax = istoragelocationdatax

valuationdata = iaccounting_data

valuationdatax = iaccounting_datax

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA = istoragelocationdata

  • STORAGETYPEDATAX = istoragelocationdatax

  • FLAG_ONLINE = ' '

  • FLAG_CAD_CALL = ' '

  • NO_DEQUEUE = ' '

  • NO_ROLLBACK_WORK = ' '

importing

return = it_ret

tables

materialdescription = it_makt

  • UNITSOFMEASURE = it_uom

  • UNITSOFMEASUREX = it_uomx

  • INTERNATIONALARTNOS =

materiallongtext = iltxt

  • TAXCLASSIFICATIONS =

returnmessages = returnm.

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

append it_ret.

write: it_ret-message .

endform. " F_CALL_BAPI

&----


*& Form F_BAPI_COMMIT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f_bapi_commit .

call function 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

endform. " F_BAPI_COMMIT

Plz suggest some solution.

Best Regards,

Ravi

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question