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

BDC

Former Member
0 Likes
662

hi

i have a requirement on a bdc for MM01 transaction. please provide the sample program for the same.

regards

1 ACCEPTED SOLUTION
Read only

Former Member
6 REPLIES 6
Read only

Former Member
Read only

Former Member
0 Likes
617

Hi Sanju,

These are the steps for BDC of MM01:

Goto transaction SHDB. Click on new recording from application toolbar.

Give recording name and trabnsaction code(MM01)and click on start recording. You will be taken to MM01 screen. Fill the input fields (Material, Industry sector and material type and press enter). Select the views (eg: basic data1, basic data2) and click on continue.Fill the fields you want to transfer value (eg: like material description, basic unit of measure,material group,gross weight and weight unit say). and click on save.you will reach to screen indocatiog recordin you have done. and save here. Click on back button. Select the recording name and click on program button. Fill the program name for your program starting with "Z". Select transfer from recordig radio button and click on contuinue. Give title and click on source code button from dialog box and save it.

So your source code is filled.

create a internal table itab containing all the recorded fields.

data : begin of itab occurs 0,

matnr type rmmg1-matnr,

mbrsh type rmmg1-mbrsh,

mtart type rmmg1-mtart,

maktx type makt-maktx,

meins type mara-meins,

matkl type mara-matkl,

end of itab.

After start-of-selection : call function module GUI_UPLOAD in which give the path of flat file as

fileneme = 'D:\file.txt'

Specify file type = 'ASC '

and specify tables

data_tab = itab[]

Give statement :Loop at itab "(after perform Open_group)

Replace the fields you have given with itab-field . For eg:

Repalce

perform bdc_field using 'rmmg1-matnr ' 'ZAmit_steel'.

with

<b>perform bdc_field using 'rmmg1-matnr ' itab-matnr.</b>

Applied to all other fields also.

Give endloop befor: PERFORM close_group.

Activate the program and execute it. In selection screen choose "generate session " radiobutton. give a session name. Check keep sesion checkbox. Remoce "/" from "no data indicator field" and execute.

Now goto SM35 and select the session name you have given and click on analysis. And select the appropriate execution method (foreground,background,error analysis). if background is selected entire processing is done at once. if foreground is selected you have to manually press enter to continue processing. After this process is complete press on "Process button" in SM35 which will indicate log of whole process.

Give me your mail id I can forward you lot more docs on BDC.

award points if found useful

Regards,

Amit.

Message was edited by: amit bhadauria

Read only

0 Likes
617

Hi Amit,

How r u hope,

Plz send me the BDC documents.

my mail id is justin.jayaraj@lunarismail.info

Read only

0 Likes
617

just check for sample code..

Read only

Former Member
0 Likes
617

Hi sanju,

&----


*& Report ZMM01_BDC *

*& *

&----


*& *

*& *

&----


REPORT ZMM01_BDC .

  • INTERNAL TABLE DECLARATIONS

data: begin of itab occurs 0,

mbrsh(1), " INDUSTRY TYPE

mtart(4), " MATERIAL TYPE

maktx(40), " MATERIAL DESCRIPTION

meins(4), " UNIT

matkl(10) type n, " MATERIAL GROUP

brgew(21), " GROSS WEIGHT

gewei(4), " UNIT

ntgew(21), " NET WEIGHT

wrkst(18), " OLD MATERIAL

kzumw(1), " ENV.

end of itab.

  • TEXT INTERNAL TABLE

data: begin of itxt occurs 0,

line(255),

end of itxt.

  • BDCDATA INTERNAL TABLE

data: btab like bdcdata occurs 0 with header line.

  • START OF SELECTION

start-of-selection.

perform uploads.

perform bdc_transfer.

&----


*& Form UPLOADS

&----


form uploads.

call function 'UPLOAD'

exporting

  • CODEPAGE = ' '

filename = 'C:\'

filetype = 'ASC'

tables

data_tab = itxt

.

if sy-subrc <> 0.

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

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

endif.

loop at itxt.

if sy-tabix > 1.

split itxt-line at ',' into itab-mbrsh

itab-mtart

itab-maktx

itab-meins

itab-matkl

itab-brgew

itab-gewei

itab-ntgew

itab-wrkst

itab-kzumw.

append itab.

clear itab.

endif.

endloop.

endform. " UPLOADS

&----


*& Form BDC_TRANSFER

&----


form bdc_transfer.

data v_l type d.

v_l = sy-datum - 1.

  • OPEN GROUP

call function 'BDC_OPEN_GROUP'

exporting

group = 'CR MAT'

holddate = v_l

keep = 'X'

user = sy-uname.

loop at itab.

perform populate.

  • BDC INSERT

call function 'BDC_INSERT'

exporting

tcode = 'MM01'

tables

dynprotab = btab.

REFRESH BTAB.

endloop.

  • CLOSE GROUP

call function 'BDC_CLOSE_GROUP'.

endform. " BDC_TRANSFER

&----


*& Form POPULATE

&----


form populate.

perform generate using: 'X' 'SAPLMGMM' '0060',

' ' 'BDC_OKCODE' '/00',

' ' 'RMMG1-MBRSH' ITAB-MBRSH,

' ' 'RMMG1-MTART' ITAB-MTART,

'X' 'SAPLMGMM' '0070',

' ' 'BDC_OKCODE' '=ENTR',

' ' 'MSICHTAUSW-KZSEL(01)' 'X',

' ' 'MSICHTAUSW-KZSEL(02)' 'X',

'X' 'SAPLMGMM' '4004',

' ' 'BDC_OKCODE' '/00',

' ' 'MAKT-MAKTX' ITAB-MAKTX,

' ' 'MARA-MEINS' ITAB-MEINS,

' ' 'MARA-MATKL' ITAB-MATKL,

' ' 'MARA-BRGEW' ITAB-BRGEW,

' ' 'MARA-GEWEI' ITAB-GEWEI,

' ' 'MARA-NTGEW' ITAB-NTGEW,

'X' 'SAPLMGMM' '4004',

' ' 'BDC_OKCODE' '/00',

' ' 'MARA-WRKST' ITAB-WRKST,

' ' 'MARA-KZUMW' ITAB-KZUMW,

'X' 'SAPLSPO1' '0300',

' ' 'BDC_OKCODE' '=YES'.

endform. " POPULATE

&----


*& Form GENERATE

&----


form generate using value(p_1) value(p_2) value(p_3).

if p_1 eq 'X'.

btab-program = p_2.

btab-dynpro = p_3.

btab-dynbegin = p_1.

else.

btab-fnam = p_2.

btab-fval = p_3.

endif.

append btab.

clear btab.

endform. " GENERATE

reward if helpful,

keerthi.

Read only

Former Member
0 Likes
617

Hi,

chk the below code tht is session method for MM01 Transaction.Befor tht io have mentioned the steps.

Steps to be followed:

1. Work out the transaction you would use to create the data manually.

2. Use transaction SHDB to record the creation of one material master data.

Click the New recording button or the Menu - Recording - Create

3. Save the recording, and then go back a screen and go to the overview.

4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer from recording.

5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to make the following changes:

5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB separated).

5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data, then modify the perform bdc_field commands to use the file data.

5.3. After perform bdc_transaction, add the endloop.

Execute the program. It will have options to create a batch session or to process directly.

Also chk the link for detail description.

http://www.sap-img.com/bdc.htm

Program:

report ZHARINI_BDC_SESSION no standard page heading line-size 255.

TABLES: MARA,MAKT.

DATA: BEGIN OF ITAB OCCURS 10,

MATNR LIKE MARA-MATNR,

MBRSH LIKE MARA-MBRSH,

MTART LIKE MARA-MTART,

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF ITAB.

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

*include bdcrecx1.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = 'C:/HAR.TXT'

FILETYPE = 'DAT'

TABLES

data_tab = ITAB

.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

GROUP = 'SESHR'

  • HOLDDATE = SY-DATUM

KEEP = 'X'

USER = SY-UNAME.

LOOP AT ITAB.

PERFORM FILL_BDCDATA.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

TABLES

dynprotab = BDCDATA.

REFRESH BDCDATA.

ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

&----


*& Form FILL_BDCDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form FILL_BDCDATA.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

ITAB-MATNR.

perform bdc_field using 'RMMG1-MBRSH'

ITAB-MBRSH.

perform bdc_field using 'RMMG1-MTART'

ITAB-MTART.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=DEF_SAVE'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

*perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

  • 'X'.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'USRM1-AAUSW'.

perform bdc_field using 'BDC_OKCODE'

'=DEF_SKIP'.

perform bdc_field using 'USRM1-AAUSW'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'USRM1-SISEL'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'USRM1-AAUSW'

'X'.

perform bdc_field using 'USRM1-SISEL'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BABA'.

perform bdc_field using 'MAKT-MAKTX'

ITAB-MAKTX.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

ITAB-MEINS.

perform bdc_field using 'MARA-MTPOS_MARA'

'NORM'.

endform. " FILL_BDCDATA

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> SPACE.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDIF.

ENDFORM.

----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM.

Reward Points if helpful.

Regards,

Harini.S