Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi for material creation

former_member197281
Active Participant
0 Kudos
583

Hi all,

when i am using bapi for material creation 'BAPI_MATERIAL_SAVEDATA.',

i got an error specifying that 'The parameter kz_prf does not contain a valid value'.*

Thanks in advance,

Jinesh.

3 REPLIES 3

Former Member
0 Kudos
144

hi,

the below is the example

'BAPI_MATERIAL_SAVEDATA'

TABLES:T001L, "STORAGE LOCATIONS

MARA, "GENERAL MATERIAL DATA

MAKT, "MATERIAL DISCRIPTIONS

MBEW, "MATERIAL VALUATION

MARC. "PLANT DATA FOR MATERIAL

DATA: BAPI_HEAD LIKE BAPIMATHEAD,

BAPI_MAKT LIKE BAPI_MAKT, "MATERIAL DISCRIPTION

BAPI_MARA1 LIKE BAPI_MARA, "MATERIAL DATA AT CLIENT LEVEL

BAPI_MARAX LIKE BAPI_MARAX, "CHECKBOX STRUCTURE FOR BAPI_MARA

BAPI_MARC1 LIKE BAPI_MARC, "MATERIAL DATA AT PLANT LEVEL

BAPI_MARCX LIKE BAPI_MARCX, "CHECKBOS STRUCTURE FOR BAPI_MARC

BAPI_MBEW1 LIKE BAPI_MBEW, "VALUATION DATA

BAPI_MBEWX LIKE BAPI_MBEWX, "CHECKBOX STRUCTURE FOR BAPI_MBEW

BAPI_RETURN LIKE BAPIRET2. "RETURN PARAMETER

DATA: BEGIN OF INT_MAKT OCCURS 100.

INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF INT_MAKT.

DATA: BEGIN OF INT_MAT OCCURS 100,

MATNR TYPE MATNR, "Material number

MBRSH TYPE MBRSH, "Industry sector

MTART TYPE MTART, "Material type

WERKS TYPE WERKS_D, "Plant

MAKTX TYPE MAKTX, "Material description

MEINS TYPE MEINS, "Base unit of measure

MATKL TYPE MATKL, "Material group

VPRSV TYPE VPRSV, "Price control indicator

VERPR TYPE VERPR, "MOVING price

END OF INT_MAT.

DATA:FILENAME TYPE STRING VALUE 'D:\Documents and Settings\lz60nd\Desktop\MM01.TXT'.

SELECT-OPTIONS:

PLANT FOR MARC-WERKS , "OBLIGATORY MEMORY ID PLT,

MATERIAL FOR MARA-MATNR MEMORY ID MAT,

MATLTYPE FOR MARA-MTART MEMORY ID MTY,

DIVISION FOR MARA-SPART MEMORY ID DIV.

PARAMETERS: F_FILE LIKE RLGRAP-FILENAME DEFAULT 'D:\Documents and Settings\lz60nd\Desktop\MM01.TXT' MEMORY ID F_FILE,

GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR F_FILE.

*PERFORM GETDATA.

IF GETDATA = 'X'.

PERFORM DOWNLOAD_DATA.

PERFORM DOWNLOAD_FILE.

ENDIF.

IF UPDDATA = 'X'.

PERFORM UPLOAD_FILE.

PERFORM UPDATE_MM.

ENDIF.

*ENDIF.

&----


*& Form DOWNLOAD_DATA

&----


text

-


--> p1 text

<-- p2 text

-


FORM DOWNLOAD_DATA .

SELECT * FROM MARC WHERE LVORM EQ ' '

AND WERKS IN PLANT

AND MATNR IN MATERIAL.

CLEAR MARA.

SELECT SINGLE * FROM MARA WHERE MATNR = MARC-MATNR.

*CHECK MATLTYPE.

*CHECK DIVISION.

CLEAR MBEW.

SELECT SINGLE * FROM MBEW WHERE MATNR = MARC-MATNR

AND BWKEY = MARC-WERKS.

CLEAR MAKT.

SELECT SINGLE * FROM MAKT WHERE SPRAS = 'EN'

AND MATNR = MARC-MATNR.

*WRITE:/ MARC-WERKS, "Plant

MARA-MTART, "Material type

MARA-MATNR, "Material number

MARA-MATKL, "Material group

MARA-MBRSH, "Industry sector

MARA-MEINS, "Base unit of measure

MARA-GEWEI, "Weight Unit

MARA-SPART, "Division

MARC-EKGRP, "Purchasing group

MBEW-VPRSV, "Price control indicator

MBEW-STPRS, "Standard price

MBEW-PEINH, "Price unit

MAKT-SPRAS, "Language key

MAKT-MAKTX. "Material description

INT_MAT-WERKS = MARC-WERKS. "Plant

INT_MAT-MTART = MARA-MTART. "Material type

INT_MAT-MATNR = MARA-MATNR. "Material number

INT_MAT-MATKL = MARA-MATKL. "Material group

INT_MAT-MBRSH = MARA-MBRSH. "Industry sector

INT_MAT-MEINS = MARA-MEINS. "Base unit of measure

*INT_MAT-GEWEI = MARA-GEWEI. "Weight Unit

*INT_MAT-SPART = MARA-SPART. "Division

*INT_MAT-EKGRP = MARC-EKGRP. "Purchasing group

INT_MAT-VPRSV = MBEW-VPRSV. "Price control indicator

*INT_MAT-STPRS = MBEW-STPRS. "Standard price

*INT_MAT-PEINH = MBEW-PEINH. "Price unit

INT_MAT-VERPR = MBEW-VERPR. " MOVING price

*INT_MAT-SPRAS = MAKT-SPRAs. "Language key

INT_MAT-MAKTX = MAKT-MAKTX. "Material description

APPEND INT_MAT.

CLEAR INT_MAT.

ENDSELECT.

ENDFORM. " DOWNLOAD_DATA

&----


*& Form DOWNLOAD_FILE

&----


text

-


--> p1 text

<-- p2 text

-


*FILENAME = F_FILE.

FORM DOWNLOAD_FILE .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE =

FILENAME = FILENAME

FILETYPE = 'ASC'

APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

HEADER = '00'

TRUNC_TRAILING_BLANKS = ' '

WRITE_LF = 'X'

COL_SELECT = ' '

COL_SELECT_MASK = ' '

DAT_MODE = ' '

CONFIRM_OVERWRITE = ' '

NO_AUTH_CHECK = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

WRITE_BOM = ' '

TRUNC_TRAILING_BLANKS_EOL = 'X'

WK1_N_FORMAT = ' '

WK1_N_SIZE = ' '

WK1_T_FORMAT = ' '

WK1_T_SIZE = ' '

WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

IMPORTING

FILELENGTH =

TABLES

DATA_TAB = INT_MAT

FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

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. " DOWNLOAD_FILE

*&----


**& Form GETDATA

**&----


text

*----


--> p1 text

<-- p2 text

*----


*FORM GETDATA .

*

*CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

IMPORTING

FILE_NAME = F_FILE

.

*ENDFORM. " GETDATA

&----


*& Form UPLOAD_FILE

&----


text

-


--> p1 text

<-- p2 text

-


FORM UPLOAD_FILE .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = FILENAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

CHECK_BOM = ' '

VIRUS_SCAN_PROFILE =

NO_AUTH_CHECK = ' '

IMPORTING

FILELENGTH =

HEADER =

TABLES

DATA_TAB = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

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. " UPLOAD_FILE

&----


*& Form UPDATE_MM

&----


text

-


--> p1 text

<-- p2 text

-


FORM UPDATE_MM .

LOOP AT INT_MAT.

*****************Header

BAPI_HEAD-MATERIAL = INT_MAT-MATNR.

BAPI_HEAD-IND_SECTOR = INT_MAT-MBRSH.

BAPI_HEAD-MATL_TYPE = INT_MAT-MTART.

BAPI_HEAD-BASIC_VIEW = 'X'.

BAPI_HEAD-PURCHASE_VIEW = 'X'.

BAPI_HEAD-ACCOUNT_VIEW = 'X'.

*****************Material Description

REFRESH INT_MAKT.

INT_MAKT-LANGU = SY-LANGU.

INT_MAKT-MATL_DESC = INT_MAT-MAKTX.

APPEND INT_MAKT.

******************Client Data - Basic

BAPI_MARA1-MATL_GROUP = INT_MAT-MATKL.

BAPI_MARA1-BASE_UOM = INT_MAT-MEINS.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

*******************Plant - Purchasing

BAPI_MARC1-PLANT = INT_MAT-WERKS.

BAPI_MARCX-PLANT = INT_MAT-WERKS.

**********************Accounting

BAPI_MBEW1-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEW1-PRICE_CTRL = INT_MAT-VPRSV.

BAPI_MBEW1-MOVING_PR = INT_MAT-VERPR.

BAPI_MBEWX-PRICE_CTRL = 'X'.

BAPI_MBEWX-STD_PRICE = 'X'.

BAPI_MBEWX-VAL_AREA = INT_MAT-WERKS.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_MARA1

CLIENTDATAX = BAPI_MARAX

PLANTDATA = BAPI_MARC1

PLANTDATAX = BAPI_MARCX

*FORECASTPARAMETERS =

*FORECASTPARAMETERSX =

*PLANNINGDATA =

*PLANNINGDATAX =

*STORAGELOCATIONDATA =

*STORAGELOCATIONDATAX =

VALUATIONDATA = BAPI_MBEW1

VALUATIONDATAX = BAPI_MBEWX

*

*WAREHOUSENUMBERDATA =

*WAREHOUSENUMBERDATAX =

*SALESDATA = BAPI_MVKE1

*SALESDATAX = BAPI_MBEWX "BAPI_MVKEX

*STORAGETYPEDATA =

*STORAGETYPEDATAX =

IMPORTING

RETURN = BAPI_RETURN

TABLES

MATERIALDESCRIPTION = INT_MAKT

*UNITSOFMEASURE =

*UNITSOFMEASUREX =

*INTERNATIONALARTNOS =

*MATERIALLONGTEXT =

*TAXCLASSIFICATIONS =

*RETURNMESSAGES =

*PRTDATA =

*PRTDATAX =

*EXTENSIONIN =

*EXTENSIONINX =

.

ENDLOOP.

IF BAPI_RETURN-TYPE = 'E'.

WRITE 😕 BAPI_RETURN-MESSAGE.

ELSEIF BAPI_RETURN-TYPE = 'S'.

WRITE 😕 BAPI_RETURN-MESSAGE.

ENDIF.

ENDFORM.

see this may be useful

reward if useful,

thanks and regards.

raymond_giuseppi
Active Contributor
0 Kudos
144

This field comes from HEADDATA-INP_FLD_CHECK, give a correct value.

(Look at function module MATERIAL_MAINTAIN_DARK parameter KZ_PRF description if BAPI_MATERIAL_SAVEDATA parameter HEADDATA field INP_FLD_CHECK documentation and domain values are not clear enough)

This parameter describes the reaction of the program to non-input field. (basically a message type E, W, I, space for no message)

Regards

Former Member
0 Kudos
144

Hi

This field is related to field which are incative so it requires the valuse as below .

Check the data element N_EING_F

E E message (error)

W W message (warning)

I I message (information)

space No message

Please reward if useful.