Skip to Content
0
Former Member
Dec 20, 2006 at 11:21 AM

Creating Material using BAPI ( Some Problem)

31 Views

Hi Frendz, i am not able to create material using BAPI, can u give any idea where is the problem in code?

I am uploading 5 fields Matno Mattype Indsec matdesc and meins

Thanks in Advance.

Points for sure

Vijaya

REPORT ZYC_BAPI_MATERIAL_CREATE

TABLES: mara, "General Material Data

makt. "Material Descriptions

DATA: bapi_head LIKE bapimathead,

bapi_makt LIKE bapi_makt, "Material Description

bapi_mara1 LIKE bapi_mara, "Client Data

bapi_marax LIKE bapi_marax,

bapi_return LIKE bapiret2.

DATA: BEGIN OF int_makt OCCURS 100.

INCLUDE STRUCTURE bapi_makt.

DATA: END OF int_makt.

DATA: BEGIN OF int_mat OCCURS 100,

matnr(18), "Material number

mtart(4), "Material type

mbrsh(1), "Industry sector

maktx(40), "Material description

meins(3), "Base unit of measure

END OF int_mat.

*to return messages

DATA:BEGIN OF it_return OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA:END OF it_return.

PARAMETER: f_file LIKE rlgrap-filename,

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

IF upddata = 'X'.

PERFORM upload_file.

PERFORM update_mm.

ENDIF.

----


*& Form UPLOAD_FILE

&----


  • text

----


FORM upload_file.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = f_file

filetype = 'DAT'

  • FILETYPE = 'WK1'

TABLES

data_tab = int_mat

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10.

IF sy-subrc = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Upload Successfully from your local harddisk'.

SKIP.

ENDIF.

ENDFORM. "UPLOAD_FILE

&----


*& Form UPDATE_MM

&----


  • 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'.

  • Material Description

REFRESH int_makt.

  • int_makt-langu = int_mat-spras.

int_makt-matl_desc = int_mat-maktx.

APPEND int_makt.

  • Client Data - Basic

bapi_mara1-base_uom = int_mat-meins.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = bapi_head

clientdata = bapi_mara1

clientdatax = bapi_marax

IMPORTING

return = bapi_return

TABLES

materialdescription = int_makt.

WRITE:/ it_return-type,

2 it_return-id,

22 it_return-number,

25 it_return-message.

ENDLOOP.

endform.