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: 

MM01

Former Member
0 Kudos

Dear sir,

i m ABAP Programmer..

i need step by step procedure create material using MM01.

With Regards,

Shankar

4 REPLIES 4

Former Member
0 Kudos

hi dear..

its better if you open a material in MM03..and create new using same values..

if u still not able to find any value open table MARA, MARC MVKE etc to see the value to put in screen.

hope this idea ll helpful..

Former Member
0 Kudos

Hi Maria,

check this sample code.

TABLES : IBIPPARMS.

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

*& Types

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

TYPES : BEGIN OF TY_ITAB,

MATNR TYPE MATNR, "MATERIAL NO

WERKS TYPE WERKS, "PLANT

STLAN TYPE STLAN, "BOM USAGE

DATUV TYPE DATUV, "VALID DATE

BMENG TYPE BMENG, "BASE QUANTITY

IDNRK TYPE IDNRK, "COMPONENT

MENGE TYPE RC29P-MENGE, "QUANTITY

MEINS TYPE MEINS, "UNIT

POSTP TYPE POSTP, "ITEM CATEGORY

END OF TY_ITAB.

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

*& DATA Declaration

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

DATA : IT_ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE.

DATA : IT_BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.

DATA : IT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.

DATA : P_FILE1 TYPE STRING ,"FILE NAME

V_LINES TYPE I.

DATA : IT1_ITAB like IT_ITAB occurs 0 with header line.

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

*& SELECTION-SCREEN DECLARATION

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

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

PARAMETERS : P_FILE TYPE LOCALFILE OBLIGATORY."FILE NAME

SELECTION-SCREEN END OF BLOCK B1 .

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

  • AT-SELECTION-SCREEN DECALRATION *

  • *

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

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

----


clear : P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

IMPORTING

FILE_NAME = P_FILE.

IF P_FILE IS NOT INITIAL.

  • VALIDATE FILE TYPE

PERFORM SUB_VALIDATE_txt_TYPE.

ENDIF.

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

  • START-OF-SELECTION

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

start-of-selection.

perform upload.

perform bdc.

&----


*& Form upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload .

clear : P_FILE1.

P_FILE1 = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = P_FILE1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_ITAB

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.

endif.

ENDFORM. " upload

form bdc.

*COPY DATA FROM IT_ITAB INTO IT_ITAB1

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

IT1_ITAB[] = IT_ITAB[].

*IF SY-SUBRC <> 0 OR IT_ITAB IS INITIAL.

    • UNABLE TO UPLOAD DATA FROM FLAT FILE

*MESSAGE I003(ZMSG).

*ENDIF.

&----


*& Form bdc

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


*FORM BDC.

LOOP AT IT_ITAB.

REFRESH IT_BDCDATA .

*FIRST SCREEN

perform bdc_dynpro using 'SAPLCSDI' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RC29N-DATUV'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29N-MATNR'

IT_ITAB-MATNR.

perform bdc_field using 'RC29N-WERKS'

IT_ITAB-WERKS.

perform bdc_field using 'RC29N-STLAN'

IT_ITAB-STLAN.

perform bdc_field using 'RC29N-DATUV'

IT_ITAB-DATUV.

*SECOND SCREEN

perform bdc_dynpro using 'SAPLCSDI' '0110'.

perform bdc_field using 'BDC_CURSOR'

'RC29K-BMENG'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29K-BMENG'

IT_ITAB-BMENG.

perform bdc_field using 'RC29K-STLST'

'1'.

*THIRD SCREEN

LOOP AT IT1_ITAB WHERE MATNR = IT_ITAB-MATNR.

perform bdc_dynpro using 'SAPLCSDI' '0111'.

perform bdc_field using 'BDC_CURSOR'

'RC29K-LABOR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPLCSDI' '0140'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSTP(02)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*perform bdc_field using 'RC29P-IDNRK(01)'

  • IT_ITAB-IDNRK.

perform bdc_field using 'RC29P-IDNRK(SY-TABIX)'

IT_ITAB-IDNRK.

perform bdc_field using 'RC29P-IDNRK(02)'

'100017'.

perform bdc_field using 'RC29P-MENGE(SY-TABIX)'

IT_ITAB-MENGE.

perform bdc_field using 'RC29P-MENGE(02)'

'200'.

perform bdc_field using 'RC29P-MEINS(SY-TABIX)'

IT_ITAB-MEINS.

perform bdc_field using 'RC29P-MEINS(02)'

'kg'.

perform bdc_field using 'RC29P-POSTP(SY-TABIX)'

IT_ITAB-POSTP.

perform bdc_field using 'RC29P-POSTP(02)'

'l'.

ENDLOOP.

perform bdc_dynpro using 'SAPLCSDI' '0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR'.

perform bdc_field using 'RC29P-POSNR'

'0010'.

perform bdc_field using 'RC29P-IDNRK'

'100012'.

perform bdc_field using 'RC29P-MENGE'

'150'.

perform bdc_field using 'RC29P-MEINS'

'KG'.

perform bdc_dynpro using 'SAPLCSDI' '0131'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POTX1'.

perform bdc_field using 'RC29P-SANKA'

'X'.

perform bdc_dynpro using 'SAPLCSDI' '0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR'.

perform bdc_field using 'RC29P-POSNR'

'0020'.

perform bdc_field using 'RC29P-IDNRK'

'100017'.

perform bdc_field using 'RC29P-MENGE'

'200'.

perform bdc_field using 'RC29P-MEINS'

'KG'.

perform bdc_dynpro using 'SAPLCSDI' '0131'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POTX1'.

perform bdc_field using 'RC29P-SANKA'

'X'.

perform bdc_dynpro using 'SAPLCSDI' '0140'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'=FCBU'.

*perform bdc_transaction using 'CS01'.

*perform close_group.

CALL TRANSACTION 'CS01' USING IT_BDCDATA MODE 'N'

UPDATE 'S'

MESSAGES INTO IT_BDCMSGCOLL.

CLEAR IT_ITAB.

ENDLOOP.

endform.

**GET THE NUMBER OF LINES

*DESCRIBE TABLE IT_BDCMSGCOLL LINES V_LINES.

**ENDFORM.

&----


*& Form SUB_VALIDATE_TXT_TYPE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SUB_VALIDATE_txt_TYPE .

DATA : STR1 TYPE LOCALFILE,

STR2 TYPE CHAR3.

SPLIT P_FILE AT '.' INTO STR1 STR2.

TRANSLATE STR2 TO LOWER CASE.

IF STR2 NE 'txt'.

  • please enter '.txt' file format

MESSAGE I001(ZMSG).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " SUB_VALIDATE_TXT_TYPE

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0160 text

  • -->P_0161 text

----


FORM bdc_dynpro USING PROGRAM DYNPRO.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0160 text

  • -->P_ENDLOOP text

----


FORM bdc_field USING FNAM FVAL.

CLEAR IT_BDCDATA. .

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDFORM. " bdc_field

or this link is helpfull for u..

http://allaboutsap.blogspot.com/2007/03/bdc-explained-part-2-sample-program-for.html

reward is usefull.

Thank's.

Patil

Former Member
0 Kudos

This step-by-step code sample helps you upload data using BDC.

Procedure

Give the t-code shdb in the command field.

Click the new recording button.

Give a name to the recording and the t-code you want to record.

E.g.:

Recording : ZMAT_UPLOAD

Transaction code : MM01

When you click save, it takes you to t-code (MM01) you would like to do recording for upload.

Record carefully. Fill in the details you want to upload. In this case I have entered the material no, industry sector, material type, material description and basic unit of measure.

Then the Transaction recorder – edit recording ZMAT_UPLOAD screen is displayed. You can edit your recording or just save it and click back button.

Select your recording and click create program button.

Enter the program name say ZMAT_UPLOAD.Select the transfer from recording option. Save it.Give the program title, type as executable program and click source code button at the bottom.

The following piece of code is generated automatically.

report ZMAT_UPLOAD

no standard page heading line-size 255.

include bdcrecx1.

start-of-selection.

perform open_group.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

'MYMATERIAL10'.

perform bdc_field using 'RMMG1-MBRSH'

'P'.

perform bdc_field using 'RMMG1-MTART'

'ZOH'.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'MAKT-MAKTX'

'MY MATERIAL10'.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

'G'.

perform bdc_field using 'MARA-MTPOS_MARA'

'NORM'.

perform bdc_transaction using 'MM01'.

Perform close_group.

From the above code it is clear that recording has been created using matnr = mymaterial10 , industry sector = p , material type = zoh , description = my material10 , basic unit of measure = g. For our case I have assumed industry sector and material type to be constant and have not included in flat file.

The bold lines in the below code are the changes made to the sap generated program , to upload our data.

report ZMAT_UPLOAD

no standard page heading line-size 255.

types declaration..........................................................................

<b>types : begin of t_mat,

matnr(20),

desc(50),

uom(5),

end of t_mat.</b>

internal table and workarea declaration.......................................

<b>data : i_mat type table of t_mat.

data : wa_mat type t_mat.</b>

include bdcrecx1.

start-of-selection.

moving the flat file content to internal table................................

<b>CALL FUNCTION 'UPLOAD'

EXPORTING

FILETYPE = 'DAT'

TABLES

data_tab = i_mat

.

IF sy-subrc <> 0.

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

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

ENDIF.</b>

perform open_group.

<b>loop at i_mat into wa_mat.</b>

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

<b> wa_mat-matnr.</b>

perform bdc_field using 'RMMG1-MBRSH'

'P'.

perform bdc_field using 'RMMG1-MTART'

'ZOH'.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'MAKT-MAKTX'

<b> wa_mat-desc.</b>

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

<b> wa_mat-uom.</b>

perform bdc_field using 'MARA-MTPOS_MARA'

'NORM'.

perform bdc_transaction using 'MM01'.

endloop.

Perform close_group.

<b>Hope this is helpful, Do reward points</b>

former_member189629
Active Contributor
0 Kudos

Check these links,

Program to create Material Master data using BAPIs

http://allaboutsap.blogspot.com/2007/09/program-to-create-material-master-data.html

BDC explained (Basics, Thumb rules, Tips & Tricks, Sample program for MM01 upload)

http://allaboutsap.blogspot.com/2007/03/bdc-explained-part-2-sample-program-for.html

Reward if helpful,

Karthik