Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

What Is BDC in SAP ? Types of BDC ?

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

What is BDC in SAP ? Types of BDC ?

Batch Data Conversion, this can be called even as Batch Data Communication.

BDC can transfer data from non-sap to sap system and even across sap system.

Using Mapping logic validations can be done in BDC. Mapping logic can transfer data from Internal Table
through application to do validations.

Steps in BDC are:

1. Transferring data from flat file to Internal Table


2. Transferring data from Internal table through application to do validations
3. After validation completed, transferring data to Database.

In BDC out bound system (sender) is Flat file and Inbound system (receiver) is SAP

 BDCMSGCOLL is a predefined structure to design log file to store error records.

BDCDATA is a structure defined with below fields in data dictionary, it holds the information
related to each screen field .

 Program - Name of the program.


 Dynpro - Screen Number.
 Dynbegin - Start the process.
 Fnam - Field name on the SAP screen.
 Fval - Field value of SAP screen.

Use of BDCDATA

It is a structure which holds the information related to each screen i.e. program name, screen no,
field name, field values, information of that particular screen to be transferred into the SAP.
In simple words, it holds all the screen related information and field information to be transferred into
corresponding SAP transaction. Program Dynpro Dynbegin Fnam Fval

SAPLGMM 0060
RMMG1-MATNR "1011"
RMMG1-MBRSH "FOOD"
RMMG1-MTART "FERT"

To find the above information for each field, press F1 on particular field It will display help
information.
Click on the button "technical information".
It will show the entire technical information of a screen.
Please note down the program name, screen number, screen field name.
This procedure has to be repeated for each field on a SAP screen. Since, it is very difficult to
note down the technical information for each field, we have an alternate and easy method called
as "RECORDING METHOD”

 BDCDATA is a predefined structure for validations in BDC. Fields for this structure are:
PROGRAM
DYNPRO
DYNBEGIN
FNAM
FVAL
Program: Program means module pool program of application using for validations
Dynpro: provides screen number where data transferring currently
Dynbegin: Means first screen number from application.
Fnam: Means fields from application to do validations
Fval: Means data having in Internal table

BDC(Batch Data Communication) is a batch interfacing technique which is used to insert mass data
into SAP R/3 system, in BDC the data will be loaded into R/3 using SAP Screen which we use to
create a record (Example: Material in MM01).In simple BDC is a technique in SAP, which is used to
upload mass data into R/3 server from a flat file( .txt, Excel etc).
In BDC the data will be flowing in SAP R/3 through screens (Ex: MM01), BDC is a inbound process.

The BDC can be performed in two methods:

 Session Method / Batch Input Method.


 Call Transaction Method.

Recording is a part of above two methods.

Features of Session / Batch Input method:

i. This method is compatible to transfer small amount of data and even large amount of
data.
ii. This method is compatible to process data in fore ground and even back ground.
iii. Through this method sap provided log file to store error records.
iv. This method is compatible to handle multiple applications for validations. (for example:
MM01,XK01,XD01 etc..)
v. This method can process data asynchronously and update Database Synchronously.

Note: Asynchronous is faster than synchronous. Process means Transferring the data from Internal
table to Application.

SYNTAX for Session Method:

Predefined function modules for session method are:

BDC_OPEN_GROUP
BDC_CLOSE_GROUP

BDC_INSERT

BDC_OPEN_GROUP: It maintain sap information to transfer data from Flat file to SAP

Parameters are:

CLIENT - means production client id

USER - means user id from production client

GROUP - it maintains an identity to monitor data uploading. (we can pass our own name and it will
display at sm35 while process)

BDC_CLOSE_GROUP: This is mandatory whenever we call BDC_OPEN_GROUP

BDC_INSERT: This provides validations logic based on structure BDCDATA. Parameters are:

TCODE - means application tcode

DYNPROTAB - means internal table design based on BDC table

In BDC Validation Logic means Mapping logic.

Requirement: Upload the flat file data into sap through MM01

MM01.txt

REPORT  ZBDC_SESSION_FRG2. Or ZBDC_SESSION_FRG1.
TYPES : BEGIN OF BDC,
MBRSH TYPE RMMG1-MBRSH,
MTART TYPE RMMG1-MTART,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF BDC.

DATA : BDCDATA type TABLE OF BDCDATA WITH HEADER LINE.

Or DATA: BDCDATA type TABLE OF BDCDATA,
       WA1 like LINE OF BDCDATA.

DATA :IT_BDC type table of BDC,
      WA type BDC.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME ='C:\Users\ARSUSER\Desktop\MM01.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_BDC.

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'ADIL'
* KEEP = 'X'
USER = SY-UNAME.

LOOP AT IT_BDC INTO WA.

CLEAR BDCDATA.
REFRESH BDCDATA[].

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MBRSH'
    wa-MBRSH.
perform bdc_field using 'RMMG1-MTART'
    wa-MTART.

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'

'/00'.

perform bdc_field using 'MAKT-MAKTX'
      wa-MAKTX.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
     wa-MEINS.

perform bdc_field using 'MARA-MTPOS_MARA'

'NORM'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
TABLES
DYNPROTAB = BDCDATA.

ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA. “CLEAR WA1.
BDCDATA-PROGRAM = PROGRAM. “WA1-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO. “WA1-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'. “WA1-DYNBEGIN = 'X'.
APPEND BDCDATA. “APPEND WA1 to BDCDATA.
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.
IF FVAL IS NOT INITIAL.
CLEAR BDCDATA. “CLEAR WA1.
BDCDATA-FNAM = FNAM. “WA1-FNAM = FNAM.
BDCDATA-FVAL = FVAL. “WA1-FVAL = FVAL.
APPEND BDCDATA. “APPEND WA1 to BDCDATA.
ENDIF.
ENDFORM.

Execute the program, and check it in SM35 Transaction.

If we run in Back ground, then check in SM37 transaction

Finally go to SE11 and check in MARA table.


CALL TRANSACTION METHOD:
It is the process of transferring the data from flat file into SAP by calling a transaction through a
series of sequence of steps.

Features of Call transaction Method:

i. This method is compatible to transfer small amount of data Only.


ii. This method is compatible to process data in fore ground. to process in back ground
logic should customize explicitly.
iii. Through this method sap NOT customized log file to store error records. Means in this
method user should customize log file. To customize log file predefined database
structure is BDCMSGCOLL
iv. This method can support one application at a time for validations.
v. This method can process data synchronously and update Database asynchronously.
vi. This method is very fast.

SYNTAX :
CALL TRANSACTION 'TCODE'
USING bdcdata
UPDATE 'A/S'
MODE 'A/E/N'
MESSAGES INTO BDCMSGCOLL .
*T CODE, is a transaction to which we are loading data ex:MM01
*bdcdata is a table which contains data related to each screen
*A/S asynchronous or synchronous method.
*A/E/N Append mode or error screen mode or NO screen mode.
*MESSTAB is a message table to store messages (success, error, warning etc)

Update: There are two types of updates are available.


Asynchronous update (COMMIT).
Synchronous update (COMMIT & WAIT).

UPDATE WORK PROCESS: This work process is responsible for updating the data into the
database.
ASYNCHRONOUS UPDATE (COMMIT):

 In this type the call transaction screens will communicate with the update work process to
update the data into database.
 It doesn’t wait for the update to be finished.
 It immediately starts to process the next record without waiting for the update to be finished.
 That’s why this process is very fast.
 It is generally not recommended for the large amount of data, because the called transaction
does not return any success or error messages.

SYNCHRONOUS UPDATE (COMMIT & WAIT):

 In this mode, the called transaction communicates with the update work process to update the
data into database.
 It will wait for the update to be finished.
 Once the update is finished, then it continues to process the next record.
 It is generally recommended for large amount of data because it returns success and error
messages.

MODE:

It specifies the type of the mode to execute the transaction.


There are 3 options for mode

 A All screen mode/Append mode(Foreground).


 E Error screen mode (only error screens will be displayed).
 N No screen mode (Background).

KNA1.txt

REPORT  ZBDC_CALL_TRANSACTION.
Types : BEGIN OF TY_ITAB,
kunnr TYPE KUNNR,
ktokd TYPE KTOKD,
bukrs TYPE BUKRS,
vkorg TYPE VKORG,
vtweg TYPE VTWEG,
spart TYPE SPART,
name1 TYPE NAME1,
land1 TYPE LAND1_gp,
spras TYPE SPRAS,
SORTL type SORTL,
ort01 type ort01,
PSTLZ type PSTLZ,
END OF TY_ITAB.

data: ITAB type TABLE OF ty_itab,
      wa type ty_itab.
DATA : BDCDATA TYPE TABLE OF BDCDATA,
       wa1 LIKE LINE OF bdcdata.
data: ktab type TABLE OF bdcmsgcoll,
      wa_ktab type bdcmsgcoll.
*to download successfull and error records
data: wa_stab type ty_itab,
      I_stab type TABLE OF ty_itab,
      wa_etab type ty_itab,
      i_etab type TABLE OF ty_itab.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Users\ARSUSER\Desktop\KNA1.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB.

LOOP AT ITAB INTO wa.

REFRESH BDCDATA.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF02D-REF_KUNNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.

PERFORM BDC_FIELD USING 'RF02D-KUNNR' wa-kunnr.

***PERFORM BDC_DYNPRO USING 'SAPMF02D' '7100'.
PERFORM BDC_FIELD USING 'RF02D-KTOKD' wa-ktokd.
*PERFORM BDC_FIELD USING 'RF02D-KUNNR' ''.

PERFORM BDC_FIELD USING 'RF02D-BUKRS' wa-bukrs.
PERFORM BDC_FIELD USING 'RF02D-VKORG' wa-vkorg.
PERFORM BDC_FIELD USING 'RF02D-VTWEG' wa-vtweg.
PERFORM BDC_FIELD USING 'RF02D-SPART' wa-spart.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'KNA1-SPRAS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=UPDA'.

PERFORM BDC_FIELD USING 'KNA1-NAME1' wa-name1.
PERFORM BDC_FIELD USING 'KNA1-LAND1' wa-land1.
PERFORM BDC_FIELD USING 'KNA1-SPRAS' wa-spras.
PERFORM BDC_FIELD USING 'KNA1-SORTL' wa-sortl.
PERFORM BDC_FIELD USING 'KNA1-ORT01' wa-ort01.
PERFORM BDC_FIELD USING 'KNA1-PSTLZ' wa-pstlz.

CALL TRANSACTION 'XD01' USING BDCDATA MODE 'A' MESSAGES INTO KTAB.

loop at ktab into wa_ktab.
  if wa_ktab-msgtyp = 'I' or wa_ktab-msgnr = '000'.
    MOVE-CORRESPONDING wa to wa_stab.
    append wa_stab to I_stab. " success records
    elseif wa_ktab-msgtyp = 'E' or wa_ktab-msgnr = '001'.
   MOVE-CORRESPONDING wa to wa_etab.
   append wa_etab to I_etab. " error records
   endif.
  endloop.
ENDLOOP.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR wa1.
wa1-PROGRAM = PROGRAM.
wa1-DYNPRO = DYNPRO.
wa1-DYNBEGIN = 'X'.
APPEND wa1 to BDCDATA.

ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> SPACE.

CLEAR wa1.
wa1-FNAM = FNAM.
wa1-FVAL = FVAL.
APPEND wa1 to BDCDATA.
ENDIF.

ENDFORM.

RECORDING METHOD:

Since, it is very difficult to find technical information of each field on the screen; we go for a
method called as "Recording method".
The recording method is going to record all the fields in the transaction and it generated the
technical information such as program name, screen no, field name, field value for each field on
the SAP screen.
By using the recording method, it is very easy to create a BDC program.

Steps for recording a transaction.


SHDB is the T-code for recording method, go to SHDB, list of recordings will be displayed ( if any),
click on New Recording to create new recording.

A pop up will open, provide a recording name ZSAPN_MM01, provide transaction code as MM01
and click recording.
It will go to material creation screen, provide values for material creation.
A pop up will open, select basic data1 and enter

Enter below details.


Click Save( Ctrl S), it will go to a screen with recording code.

Click Save, go back, you will go to recording overview screen and click on program button to create
a program for this.
Provide a program name and enter.

Provide title, type and click on source code.


Save it in a local object, you will find the below code in the program

report ZSAPN_MM01
no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.


*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: MATNR
MATNR_001(018),
* data element: MBRSH
MBRSH_002(001),
* data element: MTART
MTART_003(004),
* data element: XFELD
KZSEL_01_004(001),
* data element: MATNR
MATNR_005(018),
* data element: MBRSH
MBRSH_006(001),
* data element: MTART
MTART_007(004),
* data element: XFELD
KZSEL_01_008(001),
* data element: MAKTX
MAKTX_009(040),
* data element: MEINS
MEINS_010(003),
end of record.
*** End generated data section ***

start-of-selection.

perform open_dataset using dataset.


perform open_group.

do.

read dataset dataset into record.


if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPLMGMM' '0060'.


perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_001.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002.
perform bdc_field using 'RMMG1-MTART'
record-MTART_003.
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)'
record-KZSEL_01_004.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_005.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_006.
perform bdc_field using 'RMMG1-MTART'
record-MTART_007.
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)'
record-KZSEL_01_008.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_009.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_010.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.
enddo.

perform close_group.
perform close_dataset using dataset.
Requirement: Create a BDC program with Call Transaction method to migrate (create) material master
basic data using a flat file (.txt with tab delimited).

Requirement analysis: To fulfil the above requirement we need to create recording for MM01 t-
code using SHDB transaction, upload flat file data to a internal table, process using BDC.
Flat file format.
Note:For better understanding, create a material in MM01 with basic data(basic view1 only),
refer Creating material in SAP
Follow the below steps to create a BDC form Material

Create recording for MM01 transaction


Create recording for material master MM01 with material basic data i:e basic view1, copy the code to
create a new program, the below code will be generated. Try to understand the below code.

perform bdc_dynpro using 'SAPLMGMM' '0060'.


perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'ENTR'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_001. "pass material no
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002. "pass industry sector
perform bdc_field using 'RMMG1-MTART'
record-MTART_003. "pass material type
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE' "enter
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004. "basic view1 pass 'X'
perform bdc_dynpro using 'SAPLMGMM' '4004'. "calling second screen (basic view1)
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_005. "material description
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'. "base unit of meassure
perform bdc_field using 'MARA-MEINS'
record-MEINS_006.
perform bdc_transaction using 'MM01'. "finally calling transaction

Add data declarations


Add required data declarations for material data as per flat file

TYPES: BEGIN OF TY_MARA, "user defined types as per flat file


MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message table
DATA:FILE TYPE STRING. "file name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "input parameter for file upload

Upload data from flat file


Upload data into a internal table from a flat file using GUI_UPLOAD, all BDC performs are available
in standard programs, simpley double click on each perform and copy from standard program, paste
at the bottom.

FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = FILE "file name
FILETYPE = 'ASC' "file type
HAS_FIELD_SEPARATOR = 'X' "is tab delimited
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Process records one by one to BDC


Loop through internal table and pass records to BDC call transaction.

LOOP AT IT_MARA INTO WA_MARA. "loop all records and pass one by one to BDC
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR'
WA_MARA-MATNR. "pass material no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass indistry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass material type
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)' "select basic view1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass material description
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unit oe meassure

CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction


MODE 'N' "N-no screen mode, A-all screen mode, E-error
screen mode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EQ 0.
WRITE :/ WA_MARA-MATNR, 'submitted to BDC'.
ENDIF.

ENDLOOP.

The filnal BDC for migrating Material Master basic data is below

REPORT ZSAPN_BDC
NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES: BEGIN OF TY_MARA, "user defined types as per flat file


MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message table
DATA:FILE TYPE STRING. "file name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "input parameter for file upload

START-OF-SELECTION.
IF P_FILE IS NOT INITIAL.
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = FILE "file name
FILETYPE = 'ASC' "file type
HAS_FIELD_SEPARATOR = 'X' "is tab delimited
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDIF.
LOOP AT IT_MARA INTO WA_MARA. "loop all records and pass one by one to BDC
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR'
WA_MARA-MATNR. "pass material no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass indistry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass material type
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)' "select basic view1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass material description
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unit oe meassure

CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction


MODE 'N' "N-no screen mode, A-all screen mode, E-error
screen mode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EQ 0.
WRITE :/ WA_MARA-MATNR, 'submitted to BDC'.
ENDIF.

ENDLOOP.

DATA : WA_BDCMSG LIKE LINE OF BDCMSG.


IF BDCMSG IS NOT INITIAL. "display messages
LOOP AT BDCMSG INTO WA_BDCMSG.
WRITE:/ WA_BDCMSG-TCODE, WA_BDCMSG-MSGTYP, WA_BDCMSG-MSGV1, WA_BDCMSG-FLDNAME .
CLEAR WA_BDCMSG.
ENDLOOP.
ENDIF.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM. "program
WA_BDCDATA-DYNPRO = DYNPRO. "screen
WA_BDCDATA-DYNBEGIN = 'X'. "begin
APPEND WA_BDCDATA TO IT_BDCDATA..
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.


* IF FVAL <> NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM. "field name ex: matnr
WA_BDCDATA-FVAL = FVAL. "field value ex: testmat001
APPEND WA_BDCDATA TO IT_BDCDATA.
* ENDIF.
ENDFORM.

report ZSAP_MM01
       no standard page heading line-size 255.

include bdcrecx1.

TYPES: BEGIN OF TY_MARA, "user defined types as per flat file
       MATNR TYPE MARA-MATNR,
       MBRSH TYPE MARA-MBRSH,
       MTART TYPE MARA-MTART,
       MEINS TYPE MARA-MEINS,
       MAKTX TYPE MAKT-MAKTX,
       END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message table
DATA:FILE TYPE STRING. "file name

PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***
data: begin of record,
** data element: MATNR
*        MATNR_001(018),
** data element: MBRSH
*        MBRSH_002(001),
** data element: MTART
*        MTART_003(004),
* data element: XFELD
        KZSEL_01_004(001),
** data element: MAKTX
*        MAKTX_005(040),
** data element: MEINS
*        MEINS_006(003),
** data element: MTPOS_MARA
        MTPOS_MARA_007(004),
      end of record.

*** End generated data section ***

AT SELECTION-SCREEN on VALUE-REQUEST FOR P_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      FIELD_NAME = 'P_FILE'
    IMPORTING
      FILE_NAME  = P_FILE.

start-of-selection.

IF P_FILE IS NOT INITIAL.
    FILE = P_FILE.
    CALL FUNCTION 'GUI_UPLOAD' "upload flat file
      EXPORTING
        FILENAME            = FILE "file name
        FILETYPE            = 'ASC' "file type
        HAS_FIELD_SEPARATOR = 'X' "is tab delimited
      TABLES
        DATA_TAB            = IT_MARA.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

  ENDIF.

*perform open_dataset using dataset.
*perform open_group.

*do.

*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
LOOP AT IT_MARA INTO WA_MARA. "loop all records and pass one by one to BDC

perform bdc_dynpro      using 'SAPLMGMM' '0060'.
perform bdc_field       using 'BDC_CURSOR'
                              'RMMG1-MTART'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
perform bdc_field       using 'RMMG1-MATNR'
                              wa_mara-matnr.
perform bdc_field       using 'RMMG1-MBRSH'
                              wa_mara-MBRSH.
perform bdc_field       using 'RMMG1-MTART'
                              wa_mara-MTART.
perform bdc_dynpro      using 'SAPLMGMM' '0070'.
perform bdc_field       using 'BDC_CURSOR'
                              'MSICHTAUSW-DYTXT(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'
                              record-KZSEL_01_004.
perform bdc_dynpro      using 'SAPLMGMM' '4004'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'MAKT-MAKTX'
                              wa_mara-MAKTX.
perform bdc_field       using 'BDC_CURSOR'
                              'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'
                              wa_mara-MEINS.
perform bdc_field       using 'MARA-MTPOS_MARA'
                              record-MTPOS_MARA_007.
perform bdc_dynpro      using 'SAPLSPO1' '0300'.
perform bdc_field       using 'BDC_OKCODE'
                              '=YES'.
perform bdc_transaction using 'MM01'.

*enddo.
    CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction
                          MODE 'N' "N-no screen mode, A-all screen mode, E-
error screen mode
                          UPDATE 'A' "A-assynchronous, S-synchronous
                          MESSAGES INTO  BDCMSG. "messages
    IF SY-SUBRC EQ 0.
      WRITE :/  WA_MARA-MATNR, 'submitted to BDC'.
    ENDIF.

endloop.
*perform close_group.
*perform close_dataset using dataset.
DATA : WA_BDCMSG LIKE LINE OF BDCMSG.
  IF BDCMSG IS NOT INITIAL. "display messages
    LOOP AT BDCMSG INTO WA_BDCMSG.
      WRITE:/ WA_BDCMSG-TCODE, WA_BDCMSG-MSGTYP, WA_BDCMSG-MSGV1, WA_BDCMSG-
FLDNAME .
      CLEAR WA_BDCMSG.
    ENDLOOP.
  ENDIF.

Save and Activate then Execute the Program.


Select radio button for Session / Call Transaction Methods.
Provide File name by using F4.
Execute.

Normally flat files will be kept on the presentation servers.


For more security, flat files will be kept on the application server. When we want to do some
operations on the files present in the application server like READING,WRITING or OVERWRITING
we use OPEN DATASET
To open a file on the application server, OPEN DATASET statement is used.
it has three options FOR INPUT,FOR OUTPUT,FOR UPDATE.
Syntax for open dataset statement is OPEN DATASET <filename>.

To read data from a file on the application server, use the READ DATASET statement:
Syntax
READ DATASET <dsn> INTO <f> [LENGTH <len>].

Screen resolution in BDC


Example: If u write table control bdc program in 14'' monitor screen, then if the same program u run at
different monitor size, then the screen resolution problem comes in to the picture.

like, u get 5 records in table control in one screen, and some other records in other screen, to avoid
this screen resolution problem we use CTU-PARAMS Structure.
In our program we have to set CTU_PARAMS-defsize = 'X' (‘X’ is a Standard size, ‘ ‘ space is
current size)
Then we will be free of screen resolution problem.
Data: wa_opt type CTU_PARAMS. ( work area is defined to screen resolution)
----
Wa_opt-DEFSIZE = ‘X’
Call transaction 'MM01' using t_bdcdata option from wa_opt.

In case of Session Method, need to tick the check box ‘Dynpro Standard size’ in Recording

LSMW : stands for Legacy System Migration Workbench. Legacy system means Non-sap system.
This is data migration tool, designed by sap for Functional consultants.

You might also like