Register Login

ABAP Code Sample to Upload Data Using BDC Recording

Updated Jul 09, 2018

How to Upload Data to ABAP Code Sample to using BDC Recording?

Code samples are intended for educational use only, not deployment. They are untested and unsupported by SAP. SAP disclaims all liability to any person in respect to any damage that is incurred, whether wholly or partially, from use of the code.

Applies To:
ABAP

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

By: Kavitha Bhuvaneswaran, Wipro Technologies
Date: 18 Jan 2005

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 = my material 10 , 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 colored lines in the below code are the changes made to the sap generated program , to upload our data.

*Programmed by : Kavitha Bhuvaneswaran..................................*

*Description : program to upload new materials...........................*

*Technique used : BDC recording.................................................*

report ZMAT_UPLOAD
no standard page heading line-size 255.

*types declaration..........................................................................*

types : begin of t_mat,
matnr(20),
desc(50),
uom(5),
end of t_mat.

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

data : i_mat type table of t_mat.
data : wa_mat type t_mat.

include bdcrecx1.

start-of-selection.

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

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.

perform open_group.

loop at i_mat into wa_mat.

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'
wa_mat-matnr.
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'
wa_mat-desc.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
wa_mat-uom.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
perform bdc_transaction using 'MM01'.

endloop.

Perform close_group.

Test the above modified program. We get a selection screen as below.

ABAP-BDC-1

We can choose either the session or call transaction method. In our case we continue with session method. Give a name to session say ZMAT_UPLOAD and execute. Then we get the prompt as below.

ABAP-BDC-2

Enter your flat file name and click transfer.

We get the below list.

ABAP-BDC-3

Then go to SM35 and select your session and click process.

ABAP-BDC-4

You can process it in any of the 3 modes as shown below.

ABAP-BDC--5

  • If you are using the call transaction method you can select the run mode in the initial screen itself. (see page 5).Then we must browse for the flat file.(see page 6).
  • Data gets uploaded.

Disclaimer & Liability Notice

This document may discuss sample coding, which does not include official interfaces and therefore is not supported. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing of the code and methods suggested here, and anyone using these methods, is doing it under his/her own responsibility.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of the technical article, including any liability resulting from incompatibility between the content of the technical article and the materials and services offered by SAP. You agree that you will not hold SAP responsible or liable with respect to the content of the Technical Article or seek to do so.


 Download attached file.

You must be Logged in to download this file

×