BDC - BATCH DATA CONVERSIONS

BATCH DATA CONVERSIONS

Data Migration / Data uploading techniques into SAP is called BDC.

                                                                 or
It is a Technique of transferring the data from LEGACY SYSTEM to SAP SYSTEM.

(legacy system means third party system)

The Data is always given in the form of FILES Called as FLAT FILES ( i.e NOTEPAD,EXCEL)

We have Various techniques in BDC

1. CALL TRANSACTION (Screen level processing)

2. SESSION METHOD      (Screen level processing)

3. DIRECT INPUT METHOD ( Standard sap programs)

4. LSMW  (Tool)

5. BAPI   (Advanced technique)

CALL TRANSACTION

It is the process of transferring the data from FLAT FILE into SAP by calling a TRANSACTION through a series of sequence of steps.

                                                                          or

This technique is used to call the transaction and upload the data SCREEN BY SCREEN.

To know how many screen's are there and how many screen's we need for our requirement in CALL TRANSACTION , We need RECORDING.

RECORDING

Recording is a option to copy / record the required screen's in a TRANSACTION.

Recording is created by FUNCTIONAL TEAM and The ABAPER'S will use it in the program.

TCODE is SHDB.

SYNTAX for CALL TRANSACTION

CALL TRANSACTION ' TCODE' USING BDC DATA  UPDATE 'A/S' MODE 'A/E/N' MESSAGES INTO MESSTAB.

EXAMPLE

call transaction 'MM01' using BDC DATA update 'A' mode 'A' messages into messtab.

BDC DATA:

BDC DATA is a STRUCTURE  which holds the information related to a screen.

i.e Structure is a collection of fields.

BDC DATA Structure consists of---

1. Program Name                   =  Name of the Program of our Screen

2. Dynpro / Screen no            =  Screen Number i.e 1,2,3,....

3. Dyn begin / Start Id            = Yes or NO   i.e  'x' or '     ' (space)

4. Fname                                 = Field Name on the Screen

5. Fvalue                                 = Field value on to the field name on screen

UPDATE 'A/S'

where A-> Asynchronous Update

When we call the transaction our data is given by DIALOG WP to UPDATE WP to upload the DATA into SAP.

Then immediately DIALOG WP starts processing next record without waiting for UPDATE WP whether it is finished or not .

ASYNCHRONOUS means ALL AT A TIME.

COMMIT AND UN WAIT.

This process is VERY FAST.

Generally it is not recommended for LARGE AMOUNT OF DATA TRANSFER.

DIALOG WP  ---- NOTHING BUT SCREEN'S

UPDATE WP   ----- WILL UPDATE THE DATA INTO DATABASE.

WP = WORK PROCESS.

UPDATE 'S'

Where 'S' - Synchronous

When we call the Transaction,our date is given by DIALOG WP to UPDATE WP to upload the data into sap.

Then immediately DIALOG WP does not start processing the next record ,instead it waits for UPDATE WP to be finished.

COMMIT AND WAIT.

This process is VERY SLOW.

Generally recommended for large amount of data.


MODE

It specifies how the CALL TRANSACTION should be executed.

1. MODE 'A'     =  ALL SCREEN'S ARE DISPLAYED 

2. MODE 'N'    =  NO SCREEN'S ARE DISPLAYED

3. MODE 'E'    =  ONLY ERROR SCREEN'S ARE DISPLAYED

MESSTAB

MESS TAB is an internal table which collects / store all the error messages.





RECORDING

NEED TO GO TO SHDB TCODE.

CLICK ON NEW RECORDING ICON .



PROVIDE RECORDING NAME AND TRANSACTION CODE AND CLICK ON START RECORDING AS BELOW.



ENTER THE DETAILS OF MTART ,MBRSH MTART AS BELOW. 



PRESS ENTER.

SELECT BASIC DATA 1.




CLICK ON ENTER AND PROVIDE THE DESCRIPTION AND UNITS.. 




CLICK ON SAVE BUTTON.

OUR RECORDING WILL LOOK LIKE THIS.




TO MAKE OUR RECORDING INTO PROGRAM FOLLOW THESE STEPS.

GO TO SHDB .

SELECT OUR RECORDING. AND CLICK ON CREATE PROGRAM AS BELOW.



.




PROVIDE PROGRAM NAME AND SELECT THE RADIO BUTTON

TRANSFER  FROM RECORDING.




PRESS ENTER.


PROVIDE DESCRIPTION AND CLICK ON SOURCE CODE ICON



NOW COPY THAT RECORDING SOURCE CODE AND PASTE IT IN OUR PROGRAM.



EXAMPLE PROGRAM ON CALL TRANSACTION TO UPLOAD THE MATERIAL MASTER DATA INTO MM01.

CREATE A FLAT FILE WITH SOME DATA.....


REPORT ZBDC_CALL_TRANSACTION.
INCLUDE ZBDC_CALL_TRANSACTION_TOP" DECLARATION
*&---------------------------------------------------------------------*
*&  Include           ZBDC_CALL_TRANSACTION_TOP
*&---------------------------------------------------------------------*
" STRUCTURE FOR FLAT FILE
TYPES:  BEGIN OF TY_FILE,
        MATNR 
TYPE MARA-MATNR,
        MBRSH 
TYPE MARA-MBRSH,
        MTART 
TYPE MARA-MTART,
        MAKTX 
TYPE MAKT-MAKTX,
        MEINS 
TYPE MARA-MEINS,
        
END OF TY_FILE.
" INTERNAL TABLE AND WORK AREA DECLARATION
DATAI_FILE TYPE TABLE OF TY_FILE,
      W_FILE 
TYPE TY_FILE.
"BDCDATA DECLARATION
DATA BDCDATA TYPE BDCDATA OCCURS 0  WITH HEADER LINE.
" VARAIABLE DECLARATION
DATA V_MESSAGES TYPE STRING.
"MESSTAB DECLARATION
DATA MESSTAB TYPE BDCMSGCOLL OCCURS WITH HEADER LINE.
*************************************************************************
* TO KNOW THE DATA TYPES OF BDCDATA AND MESSTAB JUST ON THE INCLUDE
 
" WHERE WE CONVERTED OUR RECORDING PROGRAM INTO SOURCE CODE
***************************************************************************

" UPLOADING THE FLAT FILE DATA INTO INTERNAL TABLE
CALL FUNCTION 'GUI_UPLOAD'
  
EXPORTING
    FILENAME                      
'D:\NEW FOLDER\MATERIAL.TXT'
   FILETYPE                      
'ASC'
   HAS_FIELD_SEPARATOR           
'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  
TABLES
    DATA_TAB                      
I_FILE* CHANGING
*   ISSCANPERFORMED               = ' '
* 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.
* Implement suitable error handling here
ENDIF.
LOOP AT I_FILE INTO W_FILE.
" HERE WE NEED TO CONVERT OUR RECORDING INTO PROGRAM
" AND NEED TO COPY ALL PERFORMS AND FORMS.
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'        W_FILE-MATNR.
perform bdc_field       using 'RMMG1-MBRSH'        W_FILE-MBRSH.               "FIELD MAPPING FROM FLAT FILE TO RECORDING SOURCE CODE
perform bdc_field       using 'RMMG1-MTART'        W_FILE-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'
                              
'=BU'.
perform bdc_field       using 'MAKT-MAKTX'            W_FILE-MAKTX.
perform bdc_field       using 'BDC_CURSOR'
                              
'MARA-MEINS'.
perform bdc_field       using 'MARA-MEINS'            W_FILE-MEINS.
perform bdc_field       using 'MARA-MTPOS_MARA'
                              
'NORM'.
CALL TRANSACTION 'MM01' USING BDCDATA UPDATE 'A' MODE 'A' MESSAGES INTO MESSTAB.
IF SY-SUBRC 0.
WRITE:'MATERIAL HAS BEEN CREATE WITH MAT NO:',W_FILE-MATNR.
ELSE.
LOOP AT MESSTAB.
CALL FUNCTION 'FORMAT_MESSAGE'
* EXPORTING
*   ID              = SY-MSGID
*   LANG            = '-D'
*   NO              = SY-MSGNO
*   V1              = SY-MSGV1
*   V2              = SY-MSGV2
*   V3              = SY-MSGV3
*   V4              = SY-MSGV4
IMPORTING
   MSG             
V_MESSAGES* EXCEPTIONS
*   NOT_FOUND       = 1
*   OTHERS          = 2
          
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
WRITE:/ V_MESSAGES COLOR 3.
ENDLOOP.
ENDIF.
CLEARBDCDATA,MESSTAB.
REFRESH BDCDATA,MESSTAB.
ENDLOOP.
*******************************************************************
" TO GET THE FORM WE NEED DOUBLE CLICK ON THE PERFORMS WHERE
" WE CONVERTED OUR RECORDING PROGRAM INTO SOURCE CODE
********************************************************************
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  
CLEAR BDCDATA.
  BDCDATA
-PROGRAM  PROGRAM.
  BDCDATA
-DYNPRO   DYNPRO.
  BDCDATA
-DYNBEGIN 'X'.
  
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.

    
CLEAR BDCDATA.
    BDCDATA
-FNAM FNAM.
    BDCDATA
-FVAL FVAL.
    
APPEND BDCDATA.
ENDFORM.

OUTPUT:
USING MODE 'A'.

HERE SCREENS WILL BE DISPLAYED ONE BY ONE.




IT CONTINUES UP TO LAST RECORD





OUTPUT USING MODE 'N' USING ONLY 2 RECORDS IN FLAT FILE AND ONE RECORD IS INCORRECT ONLY ONE RECORD WILL BE CREATED
HERE SCREEN'S WONT BE DISPLAYED 



OUTPUT USING MODE 'E' USING ONLY 2 RECORDS IN FLAT FILE AND ONE RECORD IS INCORRECT

HERE IT WILL SHOW ONLY ERROR RECORD



EXAMPLE PROGRAM ON BDC WITH TABLE CONTROL


CREATE SOME VENDORS USING TCODE XK01.

AND WE WILL ADD BANK DETAILS TO THE VENDORS.

CREATE A FLAT FILE WITH ACCOUNT NUMBER OF VENDOR , BANK COUNTRY KEY,BANK KEYS,BANK ACCOUNT NUMBER.

AS PER ABOVE EXAMPLE DO RECORDING XK02 TCODE.

1. GO TO SHDB CLICK ON NEW RECORDING





2. GIVE TCODE AS XK02



3. CLICK ON START RECORDING


PROVIDE VENDOR AND SELECT IN GENERAL DATA SELECTION SCREEN SELECT PAYMENT TRANSACTION AND PRESS ENTER





5. CREATE SOME RECORDS





6. ENTER

7. CREATE ONE MORE RECORD





8. SAVE

9. SAVE ,BACK


10. SELECT THE RECORDING

11 CLICK ON CREATE PROGRAM



12. PROVIDE PROGRAM NAME AND SELECT  BELOW RADIO BUTTON



13. CLICK ON SOURCE CODE



14. USE THAT IN OUR PROGRAM INSIDE LOOP.





REPORT ZBDC_TABLE_CONTROL.
INCLUDE ZBDC_TABLE_CONTROL_TOP" DECLARATIONS
*&---------------------------------------------------------------------*
*&  Include           ZBDC_TABLE_CONTROL_TOP
*&---------------------------------------------------------------------*
TYPES BEGIN OF TY_FILE,
 LIFNR 
TYPE LFBK-LIFNR,
 BANKS 
TYPE LFBK-BANKS,
 BANKL 
TYPE LFBK-BANKL,
 BANKN 
TYPE LFBK-BANKN,
 
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
data : wa_options type ctu_params .
DATA : V_COUNT TYPE CHAR2 .
DATA : V_FIELD_NAME TYPE STRING .
data : bdcdata type bdcdata occurs with header line .
data : messtab type bdcmsgcoll occurs with header line .
data : lv_msg type string .

******************************************************
" UPLOADING THE FLAT FILE DATA INTO INTERNAL TABLE
******************************************************
CALL FUNCTION 'GUI_UPLOAD'
 
EXPORTING
 FILENAME 
'D:\NEW FOLDER\FILE.TXT'
 HAS_FIELD_SEPARATOR 
'X'
 
TABLES
 DATA_TAB 
I_FILE.
LOOP AT I_FILE INTO WA_FILE.
 
AT NEW LIFNR. "AT NEW MEANS...BELOW LOGIC EXECUTES ONLY WHEN THERE IS A NEW VENDOR
 
perform bdc_dynpro using 'SAPMF02K' '0101'.
 
perform bdc_field using 'BDC_CURSOR' 'RF02K-D0130'.
 
perform bdc_field using 'BDC_OKCODE' '/00'.
 
perform bdc_field using 'RF02K-LIFNR' WA_FILE-LIFNR.
 
perform bdc_field using 'RF02K-D0130' 'X'.
****BANK DATA SCREEN '0130' STARTS FROM HERE
 
perform bdc_dynpro using 'SAPMF02K' '0130'.
 
perform bdc_field using 'BDC_CURSOR' 'LFBK-BANKN(05)'.
 
perform bdc_field using 'BDC_OKCODE' 'ENTR'.
 V_COUNT 
'0' .

 
LOOP AT I_FILE INTO WA_FILE WHERE LIFNR WA_FILE-LIFNR.
 V_COUNT 
V_COUNT + .
 
CONCATENATE 'LFBK-BANKS' '(' V_COUNT ')' INTO V_FIELD_NAME .
 
perform bdc_field using V_FIELD_NAME WA_FILE-BANKS.
 
CONCATENATE 'LFBK-BANKL' '(' V_COUNT ')' INTO V_FIELD_NAME .
 
perform bdc_field using V_FIELD_NAME WA_FILE-BANKL.
 
CONCATENATE 'LFBK-BANKN' '(' V_COUNT ')' INTO V_FIELD_NAME .
 
perform bdc_field using V_FIELD_NAME WA_FILE-BANKN.
 
IF V_COUNT '5' .
 V_COUNT 
'0' .
 
perform bdc_dynpro using 'SAPMF02K' '0130'.
 
perform bdc_field using 'BDC_CURSOR' 'LFBK-BANKS(01)'.
 
perform bdc_field using 'BDC_OKCODE' '=P+'.
 
perform bdc_dynpro using 'SAPMF02K' '0130'.
 
perform bdc_field using 'BDC_CURSOR' 'LFBK-BANKN(01)'.
 
ENDIF .
 
ENDLOOP.
 
perform bdc_field using 'BDC_OKCODE' '=UPDA'.

 wa_options-dismode 
'A' .
 wa_options-updmode 
'S' .
 wa_options-defsize 
'X' "SET THE DEFAULT SCREEN SIZE
 
call transaction 'XK02' using bdcdata
 options 
from wa_options
 messages 
into messtab .
 
if sy-subrc .
 
read table messtab with key msgtyp 'S' .
 
call function 'FORMAT_MESSAGE'
 
EXPORTING
 
id messtab-msgid
 lang 
sy-langu
 
no messtab-msgnr
 v1 
messtab-msgv1
 v2 
messtab-msgv2
 v3 
messtab-msgv3
 v4 
messtab-msgv4
 
IMPORTING
 msg 
lv_msg.
 
write lv_msg color .
 
else.
 
loop at messtab.

 
call function 'FORMAT_MESSAGE'
 
EXPORTING
 
id messtab-msgid
 lang 
sy-langu
 
no messtab-msgnr
 v1 
messtab-msgv1
 v2 
messtab-msgv2
 v3 
messtab-msgv3
 v4 
messtab-msgv4
 
IMPORTING
 msg 
lv_msg.
 
write lv_msg color .
 
endloop.
 
endif .
 
refresh bdcdata .
 
refresh messtab .
 
clear bdcdata .
 
clear messtab .
 
ENDAT .
ENDLOOP .
* *-----------------------------------------------
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
 
clear bdcdata.
 bdcdata
-program program.
 bdcdata-dynpro
 dynpro.
 bdcdata-dynbegin 
'X'.
 
append bdcdata.
endform"bdc_dynpro
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
 
clear bdcdata.
 bdcdata-fnam 
fnam.
 bdcdata-fval 
fval.
 
append bdcdata.
endform"bdc_field


OUTPUT



THESE ARE THE BANK DATA THAT WE ARE ASSIGNING TO VENDOR 3333



SESSION METHOD

Session contains a group of records that need to be transferred into SAP.

To Create a SESSION we need to use 3 FUNCTION MODULE

1. BDC_OPEN_GROUP

2. BDC_INSERT

3. BDC_CLOSE_GROUP

BDC_OPENGROUP

It is a function module which is used to create a session .

group             = 'xxxxx'  -> name of the session

client no         = sy-mandt

uname             = sy-uname

keep                = 'x'   session remains in session queue (sm35)

BDC_INSERT

To insert our flat file data/BDC DATA into group/session

data          = bdc data

tcode        = 'xxxx'   (xk01)

BDC_CLOSEGROUP

It is used to close the session which we opened.

PROCESSING THE SESSION

Once Session is Created using above '3' function modules then we need to process/execute/run the session.

So the data is uploaded into SAP.

SM35 is the Tcode to process the session.

All the messages like success/failure ..etc are automatically handled by the system.

we need to declare BDC MESSTAB internal table.

SESSION STATUS

To know the status of the session (means how many records are uploaded)

Go to SM35 Tcode

select our session name.

Click on the button ANALYSIS.

Click on the tab LOG.

It shows the complete details of success and failure records.



EXAMPLE PROGRAM ON SESSION METHOD TO UPLOAD MATERIAL MASTER DATA.

First do Recording as above example program.

Go to Tcode SHDB and click on New recording




Provide the name of the recording and Tcode as MM01 and click on Start recording




Provide the details .


 


press enter

Select basic data 





Press enter

provide the details.





Click on Save.



Click on SAVE and back.

Select our recording and click on create program.



Give program Name and Select Radio Button as Transfer From Recording




Press enter

Give Title name and clik on source code



When we click on source code our recording it will look like this



Just copy this and paste it in our program.

Create a Flat file with 8 RECORDS in that 2 RECORD are error one.

*&---------------------------------------------------------------------*
*& Report  ZBDC_SESSION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zbdc_session.
*************************************************************************
" FLAT FILE STRUCTURE
TYPESBEGIN OF ty_flat,
        matnr 
TYPE mara-matnr,
        mbrsh 
TYPE mara-mbrsh,
        mtart 
TYPE mara-mtart,
        maktx 
TYPE makt-maktx,
        meins 
TYPE mara-meins,
      
END OF ty_flat.
***************************************************************************
" DECLARATION FOR INTERNAL TABLE AND WORK ARAEA
DATAit_flat TYPE TABLE OF ty_flat,
      wa_flat 
TYPE ty_flat.
**************************************************************************
" BDCDATA DECLARATION .BDCDATA TYPE WILL GET INTHAT RECORDING SOURCE CODE
"JUST DOUBLE CLICK ON THAT INCLUDE.
DATA bdcdata TYPE bdcdata OCCURS WITH HEADER LINE.
*****************************************************************************
" UPLOADING THE DATA INTO IT_FLAT INTERNAL TABLE
CALL FUNCTION 'GUI_UPLOAD'
  
EXPORTING
    filename                      
'C:\NEW FOLDER\SESSION.TXT'
   filetype                      
'ASC'
   has_field_separator           
'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  
TABLES
    data_tab                      
it_flat* CHANGING
*   ISSCANPERFORMED               = ' '
* 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.
* Implement suitable error handling here
ENDIF.
*********************************************************************
" CREATION SESSION USING BDC_OPEN_GROUP FUNCTION MODULE
CALL FUNCTION 'BDC_OPEN_GROUP'
 
EXPORTING
   
client                    sy-mandt*   DEST                      = FILLER8
    
group                     'ZMY_SESSION'  "SESSION WILL CREATED
*   HOLDDATE                  = FILLER8
   keep                       
=  'X'
   user                      
sy-uname*   RECORD                    = FILLER1
*   PROG                      = SY-CPROG
*   DCPFM                     = '%'
*   DATFM                     = '%'
* IMPORTING
*   QID                       =
* EXCEPTIONS
*   CLIENT_INVALID            = 1
*   DESTINATION_INVALID       = 2
*   GROUP_INVALID             = 3
*   GROUP_IS_LOCKED           = 4
*   HOLDDATE_INVALID          = 5
*   INTERNAL_ERROR            = 6
*   QUEUE_ERROR               = 7
*   RUNNING                   = 8
*   SYSTEM_LOCK_ERROR         = 9
*   USER_INVALID              = 10
*   OTHERS                    = 11
          
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT it_flat INTO wa_flat.
****************************************************************************
"NEED TO PASTE THE RECORDING PERFORMS HERE
" WE NEED TO MAINTAIN FIELD MAPPING
PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
PERFORM bdc_field       USING 'BDC_CURSOR'
                              
'RMMG1-AENNR'.
PERFORM bdc_field       USING 'BDC_OKCODE'
                              
'=ENTR'.
PERFORM bdc_field       USING 'RMMG1-MATNR'          wa_flat-matnr.
PERFORM bdc_field       USING 'RMMG1-MBRSH'          wa_flat-mbrsh.    " FIELD MAPPING
PERFORM bdc_field       USING 'RMMG1-MTART'            wa_flat-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' '5004'.
PERFORM bdc_field       USING 'BDC_OKCODE'
                              
'=BU'.
PERFORM bdc_field       USING 'MAKT-MAKTX'        wa_flat-maktx.
PERFORM bdc_field       USING 'BDC_CURSOR'                                "FIELD MAPPING
                              
'MARA-MEINS'.
PERFORM bdc_field       USING 'MARA-MEINS'         wa_flat-meins.
PERFORM bdc_field       USING 'MARA-MTPOS_MARA'
                              
'NORM'.
*******************************************************************************
" INSERTING THE DATA INTO SESSION USING BDC_INSERT FUNXTION MODULE
CALL FUNCTION 'BDC_INSERT'
 
EXPORTING
   tcode                  
=  'MM01'
*   POST_LOCAL             = NOVBLOCAL
*   PRINTING               = NOPRINT
*   SIMUBATCH              = ' '
*   CTUPARAMS              = ' '
  
TABLES
    dynprotab              
bdcdata* EXCEPTIONS
*   INTERNAL_ERROR         = 1
*   NOT_OPEN               = 2
*   QUEUE_ERROR            = 3
*   TCODE_INVALID          = 4
*   PRINTING_INVALID       = 5
*   POSTING_INVALID        = 6
*   OTHERS                 = 7
          
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEARbdcdata.
REFRESH bdcdata.
ENDLOOP.
**********************************************************
" CLOSING THE SESSION USING BDC_CLOSE_GROUP FUNCTION MODULE
CALL FUNCTION 'BDC_CLOSE_GROUP'
* EXCEPTIONS
*   NOT_OPEN          = 1
*   QUEUE_ERROR       = 2
*   OTHERS            = 3
          
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
WRITE:'SESSION IS CREATED AND DATA IS INERTED' COLOR 3.
***********************************************************************
" WE WILL GET THE FORM BY DOUBLE CLIKING ON
"PERFORM THAT WE GOT BY MAKING OUR RECORDING INTO SOURCE CODE
FORM bdc_dynpro USING program dynpro.
  
CLEAR bdcdata.
  bdcdata
-program  program.
  bdcdata
-dynpro   dynpro.
  bdcdata
-dynbegin 'X'.
  
APPEND bdcdata.
ENDFORM.
*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
    
CLEAR bdcdata.
    bdcdata
-fnam fnam.
    bdcdata
-fval fval.
    
APPEND bdcdata.
ENDFORM.




OUTPUT






 Now go to TCODE SM35 and select our session.


Click on PROCESS.



SELECT either BACKGROUND OR ERROR OR FOREGROUND and click on PROCESS


Here we selected selected BACKGROUND Process , when we clicked on process it moves to IN BACKGROUND TAB and later it moves to IN PROCESS TAB and finally everything is clear Our session will be available in PROCESSED TAB if not our session will be available in IN CORRECT TAB.

As our flat fuile consist of 2 error records our session will be available in IN CORRECT TAB.

Just Select our SESSION and click on ANALYSIS Button know the Reasons



Here it shows the complete details 6 records is processed where 2 records are in correct need to be processed.


 CALL TRANSACTION VS SESSION METHOD

CALL TRANSACTION:

Asynchronous and synchronous updates.

Transfer only small amount of data.

Fast Processing

We need to handle errors.

Data is updated quickly

SESSION METHOD

Only Synchronous update.

Large amount of data can be transferred.

Slow processing

In SM35 Tcode error log will be created.

Data will not be updated until session is processed.


LSMW

Legacy system migration work bench.

LSMW is a tool which is used to transfer the data from legacy system to SAP.

It is used to transfer very less amount of data.

TCODE IS LSMW.

EXAMPLE PROGRAM ON LSMW FOR UPLOADING MATERIAL MASTER DATA

STEP 1
Go to Tcode LSMW and provide a name to it and click on CREATE icon as below
Provide some description as below

Now click on EXECUTE icon.

Now the screen will appear like this

STEP 1
Select Maintain object attribute and click on execute icon.
Click on DISPLAY <-> CHANGE option.
Select the BATCH INPUT RECORDING radio button.
Provide a name to it.
Click on RECORDINGS OVERVIEW icon.
Click on create icon
Then provide some details to it as below

Press enter.
Provide the transaction name to it .

Press enter
Now it starts RECORDING provide some data

Press enter to continue.
Select BASIC DATA 1 and click on continue.

Give some description and units .

Click on save.

Now our recording look like the below snap shot

Here we need to remove the HARD CORDED VALUE and need to give names as
RMMG1-matnr = bus100 (hard coded value) to MATNR.
Similarly to all fields what we entered in recording.
So just click on DEFAULT ALL Button.
Now the field mapping is done.

Just click on SAVE.
Back.
Back.
SAVE ,BACK.
STEP 2
Maintain source structure
Here it will automatically selects the 2nd step just click on execute icon.
Click on DISPLAY <-> CHANGE option and Click on CREATE icon.
Provide the name to it.

Press enter .
SAVE , BACK
STEP 3
Maintain Source Fields
Select the 3rd step and Click on execute.
Click on DISPLAY <-> CHANGE Option.
Place the cursor on our structur name Click on TABLE MAINTAINCE Icon.
Provide the FIELD NAMES AS BELOW.


Click on SAVE .
Back.
Now save BACK to MAIN SCREEN.
STEP 4
Maintain structure relation
Just execute this 4th step by clicking on execute icon .
Click on DISPLAY <-> CHANGE option place the cursor on our recording and click on RELATIONSHIP icon

Click on SAVE
Back
STEP 5
Maintain field mapping and conversion
When we completed the previous step, the system selects the next step.
Just we need to click on execute icon.
Click on DISPLAY <-> CHANGE option.
Go to EXTRAS Tab and select AUTO FIELD MAPPING.
Click on Continue.
Click on ACCEPT PROPOSAL.

Until we get AUTO MAPPING COMPLETE.
Press ENTER.

CLICK on SAVE.
BACK.
STEP 6
Maintain fixed values
Just execute it.
STEP 7
Specify files
Just select it and click on execute.
Click on DISPLAY <-> CHANGE and Double click on LEGACY SYSTEm.

Provide the flat file.
Select  TABULATOR radio button.
Select 2 check box of file structure
Press continue.
Click on SAVE ,Back.
STEP 8
Assign Files
Just execute this step.
Click on DISPLAY <-> CHANGE.
Save , Back
STEP 9
Read Data
Just execute this step by clicking on EXECUTE icon
Click on execute icon.
Save and Back.
STEP 10
Display read data.
Just select it and execute it.
Click on continue.
BACK
STEP 11
Convert Data just select it and execute it.
Click on execute icon.
Back.
Save.
Back.
STEP 12
Display converted data.
Just execute this step .
Click on continue.
Back.
STEP 13
Create  Batch Input  Session.
Click on execute icon.
Click on Execute Icon.
Press enter.
STEP 14
Run Batch Input Session
Select it and execute it.
We will get our session.
Just select and click on PROCESS.
IT ask for FORE GROUND
                BACK GROUND
               DISPLAY ERROR
Select as per our choice.
Click on process.
It will be available in BIN BACK GROUND TAB.
Later it shows the status in under PROCESSED TAB.
Or
Select our session and click on ANALYSIS button

We can check in TCODE MM03 by giving our Material Number.
Example
Give mat no BUS 102 (what we entered in FLAT FILE

Press Enter