Skip to Content
0
Former Member
Mar 14, 2007 at 09:40 AM

problem in 'BAPI_MATERIAL_SAVEDATA'

17 Views

Hi, When i run the below program, i am not able to create a material, what is the problem in code ? points for sure

when i run this program,its giving the below message

<b>The field MARA-MEINS/ BAPI-BASE_UOM(_IOS) is defined as required field, it does not contain an entry</b>

my text file is

mat001 M ROH matdesc KG

-


REPORT ZYC_BAPI_MATERIAL_CREATE .

**********************************************************************

  • STRUCTURE DECLARATIONS *

**********************************************************************

TABLES: BAPIMATHEAD, "Headerdata

BAPI_MARA, "Clientdata

BAPI_MAKT, "Material description

BAPIRET2. "Return messages

data : bapi_mara1 LIKE bapi_mara. "Client Data

DATA:V_FILE TYPE STRING.

DATA:

BEGIN OF LSMW_MATERIAL_MASTER,

MATNR(018) TYPE C, "Material number

MBRSH(001) TYPE C, "Industry sector

MTART(004) TYPE C, "Material type

MAKTX(040) TYPE C, "Material description

MEINS(003) TYPE C, "Base unit of measure

END OF LSMW_MATERIAL_MASTER.

**********************************************************************

  • INTERNAL TABLE DECLARATIONS *

**********************************************************************

*to store the input data

DATA: BEGIN OF it_matmaster OCCURS 0.

INCLUDE STRUCTURE LSMW_MATERIAL_MASTER.

DATA: END OF it_matmaster.

*for material description

DATA:BEGIN OF IT_MATERIALDESC OCCURS 0.

INCLUDE STRUCTURE BAPI_MAKT .

DATA:END OF IT_MATERIALDESC.

*to return messages

DATA:BEGIN OF IT_RETURN OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA:END OF IT_RETURN.

************************************************************************

  • SELECTION SCREEN

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS:P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1 .

************************************************************************

  • AT SELECTION SCREEN

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

**********************************************************************

  • TO UPLOAD THE DATA *

**********************************************************************

START-OF-SELECTION.

V_FILE = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = IT_MATMASTER

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.

**********************************************************************

  • DATA POPULATIONS *

**********************************************************************

LOOP AT IT_MATMASTER.

BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.

BAPIMATHEAD-IND_SECTOR = IT_MATMASTER-Mbrsh.

BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-MTART.

BAPIMATHEAD-BASIC_VIEW = 'X'.

refresh it_materialdesc.

IT_MATERIALDESC-matl_desc = IT_MATMASTER-maktx.

append IT_materialdesc.

bapi_mara1-base_uom = it_matmaster-meins.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

  • CLIENTDATAX = BAPI_MARAx

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC

.

WRITE:/ IT_RETURN-TYPE,

2 IT_RETURN-ID,

22 IT_RETURN-NUMBER,

25 IT_RETURN-MESSAGE.

ENDLOOP.

Thanks