Application Development and Automation 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: 
Read only

bapi

Former Member
0 Likes
426

write a bapi to update the material data into database?

4 REPLIES 4
Read only

Former Member
0 Likes
409

BAPI_MATERIAL_SAVEDATA will help you create/Change/Update material master data.

Hope this helps

Vinodh Balakrishnan

Read only

Former Member
0 Likes
409

Hi,

use the BAPI FM to update are change are create the data

BAPI_MATERIAL_SAVEDATA.

Goto se37 and give the bapi_material_savedata u can see the mandatory parameters are there.Give that parameters in ur program. it will work to .

it helps to u.

satish.

Read only

Former Member
0 Likes
409

Hi this will help u.

REPORT zmm_mat_master_non_stock

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF i_mat OCCURS 0,

  • mbrsh(001), " Industry Sector

  • mtart(004), " Material Type

  • Views

  • Organization Levels

  • werks(004), " Plant

  • Basic Data1 View

maktx(040), " Material Description

  • meins(003), " Unit of Measure

matkl(009), " Material Group

  • MTPOS_MARA(004), " Gen Item Category

  • Purchasing

ekgrp(003), " Purchasing Group

END OF i_mat.

  • Data Variables & Constants

CONSTANTS : c_x VALUE 'X'. " Flag

  • Parameters

PARAMETERS: p_file LIKE ibipparms-path. " Filename

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start of Selection

START-OF-SELECTION.

  • Open the BDC Session

PERFORM open_group.

  • Upload the File into internal Table

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_mat

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7.

IF sy-subrc <> 0.

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

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

ENDIF.

  • Upload the Data from Internal Table

LOOP AT i_mat.

  • Basic Screen

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MBRSH'

'C'."i_mat-mbrsh.

PERFORM bdc_field USING 'RMMG1-MTART'

'NLAG'."i_mat-mtart.

  • Views Selection

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(08)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

c_x."i_mat-kzsel_01.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(02)'

c_x."i_mat-kzsel_02.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(08)'

c_x."i_mat-kzsel_08.

  • Organization Levels

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-WERKS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS'

'2000'."i_mat-werks.

  • Basic data1 View

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'MAKT-MAKTX'

i_mat-maktx.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-MTPOS_MARA'.

PERFORM bdc_field USING 'MARA-MEINS'

'EA'."i_mat-meins.

PERFORM bdc_field USING 'MARA-MATKL'

i_mat-matkl.

PERFORM bdc_field USING 'MARA-MTPOS_MARA'

'NLAG'."i_mat-mtpos_mara.

  • Basic data2 View

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MAKT-MAKTX'.

  • Purchasing View

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'MARC-EKGRP'

i_mat-ekgrp.

  • Call The Transaction

PERFORM bdc_transaction USING 'MM01'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

with regards,

Hema Sundara.

pls reward if helpful.

Read only

Former Member
0 Likes
409

Hi this will help u.

REPORT zmm_longtext

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Internal Table for Upload of Long Texts Data

DATA: BEGIN OF itab1 OCCURS 0,

matnr LIKE mara-matnr, " Material

text LIKE tline-tdline, " Long Text

END OF itab1.

  • Internal Table for Upload of Long Texts Data

DATA: BEGIN OF itab OCCURS 0,

matnr LIKE mara-matnr, " Material

text LIKE tline-tdline, " Long Text

END OF itab.

  • To create Long Text lines for CREATE_TEXT function module

DATA:BEGIN OF dt_lines OCCURS 0.

INCLUDE STRUCTURE tline. " Long Text

DATA:END OF dt_lines.

  • Variable declarations for CREATE_TEXT function module

DATA : dl_name TYPE thead-tdname, " Object Name

dl_lan TYPE thead-tdspras, " Language

gv_matnr TYPE matnr.

  • Constants

CONSTANTS:

  • Object ID for Long Text of Material Basic Data 1

c_best TYPE thead-tdid VALUE 'GRUN',

c_material TYPE thead-tdobject VALUE 'MATERIAL'. " Object

  • Parameters

PARAMETERS p_file LIKE rlgrap-filename.

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start Of Selection

START-OF-SELECTION.

*To Upload Flat file

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = itab1

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7.

SORT itab1 BY matnr.

LOOP AT itab1.

CLEAR gv_matnr.

SELECT SINGLE matnr INTO gv_matnr

FROM mara WHERE bismt = itab1-matnr.

IF itab1-text NE ' '.

itab-matnr = gv_matnr.

itab-text = itab1-text.

APPEND itab.

ENDIF.

CLEAR itab.

ENDLOOP.

DELETE itab WHERE matnr EQ ' '.

  • Upload the Texts

SORT itab BY matnr.

LOOP AT itab.

dt_lines-tdformat = 'ST'.

dt_lines-tdline = itab-text.

APPEND dt_lines.

dl_lan = sy-langu.

dl_name = itab-matnr.

  • Call the Function Module to Create Text

CALL FUNCTION 'CREATE_TEXT'

EXPORTING

fid = c_best

flanguage = dl_lan

fname = dl_name

fobject = c_material

save_direct = 'X'

fformat = '*'

TABLES

flines = dt_lines

EXCEPTIONS

no_init = 1

no_save = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE:/ 'Long Text Creation failed for Material'(001),

itab-matnr.

ELSE.

WRITE:/ 'Long Text Created Successfully for Material'(002),

itab-matnr.

ENDIF.

AT END OF matnr.

REFRESH dt_lines.

ENDAT.

ENDLOOP.

with regards,

Hema SUndara.

pls give points if found helpful.