BDC (Batch Data Communication) - SAP ABAP

BDC (Batch Data Communication)




Batch input is a standard technique used to transfer large volumes of data into an SAP system.
The advantage of batch input is that all the transaction-level checks can be performed on the data and then the data is updated through the transactions (Via Screens).
Data transfer project involves the following steps: 
1. Identifying the data that needs to be transferred to the SAP.
2.Record the screen fields using transaction: SHDB & generate a program from it.
3. Write the BDC program separately by making use of Recoding code (Step no:2)
4. If required, Convert the data while passing from Non-SAP to SAP (External to Internal).
5. Handle various errors/messages in program as per requirement.
6.Validate the data while processing.
7.Process the program and verify the transferred data in SAP.
8. Set the data transfer frequency as per business requirement.
Note:
Batch input programs allow us to capture all the manual steps involved in processing data of a transaction to automate the process.

Data transfer Processes:
There are 2 Processes are available for transferring the data.
  1. Outbound Process
  2. Inbound Process
1.Outbound Process:
Transferring the data from SAP to NON-SAP or SAP to SAP server is called 'Outbound Process'.
2.Inbound Process:
 Receiving the data from NON-SAP to SAP or SAP to SAP is called as 'Inbound Process'.

BDC Methods:
A.Call transaction
B.Session method
C.Direct Input method
A. Call Transaction
 is a process of transferring the data from flat file / Application server file into SAP by calling a transaction through a series of sequence of steps.
Advantages:
  •  Call Transaction is very fast compared to session method & Updates database immediately.
  • This method is used for transferring less amount (< 10000 rows/records) of data.
  • Data update can be done Synchronous and Asynchronous.
 We need to handle the errors exclusively by capturing it into one internal table which is of type structure: BDCMESGCOLL.
Syntax:
CALL TRANSACTION <TCODE> 
        USING <BDCDATA>     " (BDCDATA-> is a structure of BDC)
       UPDATE <S/A>              " S->Synchronous, A->Asynchronous
          MODE <A/E/N>          " A-> All Screens, E-Error, N-No screens (Background Job)
MESSAGES INTO <IT_BDCMSGCOLL>. 

" Success / Failure messages have captured in <IT_BDCMSGCOLL>.
 Example:
CALL TRANSACTION 'MM01'
                 USING IT_BDCDATA                       
              UPDATE 'S'                       
                  MODE 'A'
     MESSAGES INTO IT_BDCMSGCOLL. 
Details of Call Transaction Syntax:
 BDCDATA:
to capture the screen and field information into an internal table with a special structure known as BDCDATA.
The BDCDATA structure:
 The BDCDATA structure consists of 5 components, as detailed in below table:

 Field name and Its Meaning in an understandable format:
Field Name
Meaning
PROGRAM
Program Name of the screen to which the data is transferred
DYNPRO
Screen number of the program(specified in the PROGRAM field above)
DYNBEGIN
Flag to indicate new screen
FNAM
Field name of screen
FVAL
Value to be transferred to the field
The data in IT_BDCDATA looks as below:
Note:
Capturing all the fields data by using F1 (input help) is very difficult so, we could use one a technique called as 'RECORDING METHOD' (Tcode for recording: SHDB).
UPDATE
 Data can be updated
 synchronously or
 asynchronously.
With synchronous updates, the system waits for the previous transaction to commit.
With asynchronous updates, the system will start processing the next transaction without waiting for the previous transaction to commit.
For example:
 if you’re updating a sales order header and item data,
synchronous updates can ensure that the sales order item data is updated only after the header data is committed to the database.
If you use asynchronous updates, the sales order item data may commit to the database without waiting for the header data to commit first.  For this reason, an asynchronous update is faster than a synchronous update.
The CALL TRANSACTION method doesn’t support an automated error log or resuming on error.
Error handling should be performed in the program. You can call one transaction at a time, and the data is processed synchronously.
MODE:
The transaction can be executed in
  • foreground mode,
  • background mode,
  • foreground on error mode.
 When a transaction is executed in foreground mode, the transaction runs in the foreground, displaying all the screens.
Running a transaction in foreground mode is useful when doing a test run, because it helps verify that the fields are mapped correctly with the right data.
When a transaction is executed in background mode, the transaction completely runs in the background and no screens are displayed. Any messages raised by the transaction during the execution will be transferred to the batch input program at the end.
Running a transaction in background mode is the preferred method for production runs.
If foreground on error mode is used, the transaction runs in the background unless any error messages are raised by the transaction.
If an error message is raised, the transaction screen that has caused the error is displayed to the user.
Messages in Call Transaction:
we need to handle the messages by declaring an internal table of type BDCMSGCOLL in our program.
Every record status (Messages) will be stored in the internal table which we declared.
BDCMSGCOLL Structure:
Field Name
Meaning
MSGTY
Message Type
MSGID
Message ID
MSGNR
Message Number
MSGV1
Variable1 of a message
MSGV2
Variable2 of a message
MSGV3
Variable3 of a message
MSGV4
Variable4 of a message
FORMAT_MESSAGE is the function module which is used to handle the errors in call transaction
method.

we should pass below inputs to the above function module which are captured from

BDCMESSAGECOLL
1. Message id
2. Message number
3. Message1
4. Message2
5. Message3
6. Message4
7. language

Then, FM will give output ‘Proper message’ from sap.

Structure of a BDC Program:


As part of BDC Program, we need to capture below information from SAP screen to pass data automatically,
  • program name
  • screen number
  • screen field name
  • Field Value
using the above 4 fields information, we can map BDCDATA structure using above fields.


Sample Program by making use of all the above information:

PROGRAM ZSAMPLE_BDC_PROGRAM.

Data:
it_bdcdata TYPE STANDARD TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.

START-OF-SELECTION.

PERFORM   bdc_dynpro USING
PROGRAM NAME          'SCREEN NUMBER'.


PERFORM   bdc_field    USING  'SCREEN FIELD NAME'   'FIELD VALUE'.


PERFORM   bdc_field    USING  'SCREEN FIELD NAME'   ' FIELD VALUE '.

CALL Transaction 'TRANSACTION NAME' using IT_BDCDATA.

FORM bdc_dynpro USING  program 
                                                 dynpro.
CLEAR wa_bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro    = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.

FORM bdc_field USING fnam  
                                           fval.
CLEAR wa_bdcdata.
wa_bdcdata-fnam  = fnam.
wa_bdcdata-fval     = fval.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.

Steps to generating a batch input program via Transaction:


Note: Check the given transaction manually before doing Recording of it.


Then, proceed for Recording of Transaction as follows:


Steps to be done:

1. Record the data flow
2. Process (re-check the recording)
3. Create a program from recording
Step1:
1. On the initial screen of Transaction SHDB (Transaction Recorder: Recording Overview), as shown in below screen, click the New Recording button.


2. In the Create Recording dialog box, as shown in below screen,




provide a name for the recording,


enter the transaction code for which the recording should be performed.
We can also set the Update Mode to update the data. (update modes: A/S).
CATT mode: No CATT
Select the Default Size checkbox to avoid screen resolution issues.
After providing all the above information click on "START RECORDING".
  Enter,  Industry sector : M
               Material Type   : ROH
Click on Select Views

      Select the Basic Data




Click On Continue...


 
Enter,
Material Description  : TestMaterial
Unit Of Measurement   : KG
And click on SAVE
 ...Material No will be generated

Note:
  1. Enter the values on to the screen fields only one time during recording of a transaction.
    (Do not enter values for multiple times in a single field).
  2. Once you done with recording of a transaction, validate it.
Step2: Recording - Re-Check by processing                 
To ensure every field input has entered only one time for smooth execution.
Execute: SHDB

Select specific recording ->

Click on Process Button->
and just press ENTER button continuously to observe how you have recorded your screen fields.

Step3: Generate a Program from recording:
To generate the Program from recording, do the following steps:
Select the specific recording

Click On Program button on Application Toolbar.
Then below screen opens,
Click on Continue...

Provide, Title and Click on Source Code

Save the program.
It will generate code in ABAP Editor as shown below:
we will add data uploading logic to the above BDC program to satisfy the requirement.

Program Using Call Transaction:




Call Transaction Program Processing logic steps:
1.Copy the subroutines definitions by double clicking on BDC_DYNPRO & BDC_FIELD:  PERFORM BDC_DYNPRO
PERFORM BDC_FIELD 
from include bdcrecx1 and keeptkeep that logic afterthe last statement of your program. after the declarations replace Internal table BDCDATA with IT_BDCDATA.

Comment out IF CONDITION inside BDC_FIELD definition.

2.Comment out below 4 statements in your program,
      include bdcrecx1.        " (you can find this before Start-of-selection)
      perform open_group.
      perform bdc_transaction using <TRANSACTION>.  " -> <Transaction -> Recorded Transaction>
      perform close_group.        

3.Declare a local structure as per required fields and field types can be taken from generated code.
4.Declare an internal table & work area as per the input file structure.
5.Declare mandatory internal tables for BDC those are BDCDATA & BDCMSGCOLL as follows:


*& BDC Structure
    DATA: IT_BDCDATA TYPE TABLE OF BDCDATA,
                WA_BDCDATA TYPE BDCDATA         .

*& Message collection during processing of data

  DATA: IT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL,
              WA_BDCMSGCOLL TYPE BDCMSGCOLL    .
Note : All the declarations should before START-OF-SELECTION event.

6. After Start-of-Selection event,  
Use Function Module: 'GUI_UPLOAD' to upload(Transfer) the data from input file into
   declared Internal table (Ex: DATA IT_DATA type table of TY_DATA).

7.Write the Processing logic using LOOP...Endloop.
Note:
 -> Use the generated code (from recording) between Loop and endloop.
-> Replace the Hard coded values of generated code with workarea fields.


8.Use Call Transaction SYNTAX to pass the IT_BDCDATA to the respective Transaction.
Note:
Clear the used variables, workareas   
Refresh: IT_BDCDATA & IT_BDCMSGCOLL .... before endloop.




Example 1:
Call Transaction Program for standard transaction MM01:

REPORT ztemp_rec_mm01
       
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPES:BEGIN OF ty_data,      

           mbrsh   TYPE rmmg1-mbrsh,      
           mtart   TYPE rmmg1-mtart,       
           maktx1  TYPE sktext-maktx,       
           maktx2  TYPE sktext-maktx,       
           meins   TYPE mara-meins,       
           END OF ty_data.












DATA:it_data TYPE TABLE OF ty_data,      
          wa_data TYPE ty_data.



*& BDC Structure
DATAit_bdcdata TYPE TABLE OF bdcdata,       

           wa_bdcdata TYPE bdcdata         .



*& Message collection during processing of data
DATAit_bdcmsgcoll TYPE TABLE OF bdcmsgcoll,       

           wa_bdcmsgcoll TYPE bdcmsgcoll    .









START-OF-SELECTION.   






CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING       

    filename            'C:\Users\nagaraju.adhikari\Desktop\MM01_FILE.txt'
      filetype            
'ASC'
      has_field_separator 
'X'
    TABLES       

    data_tab            it_data.   






 IF sy-subrc 0.     
  DELETE it_data INDEX 1.   
 ENDIF.
*& Processing Logic
  LOOP AT it_data INTO wa_data.
    
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-MBRSH'
                                                          wa_data
-mbrsh .    "'M'.                     " 1
    PERFORM bdc_field       USING 
'RMMG1-MTART'
                                                         wa_data
-mtart.      " 'ROH'. " 2 input Field

    
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' '3005'.
    PERFORM bdc_field       USING 
'BDC_OKCODE'
                                                             
'=BU'.

    
PERFORM bdc_field       USING 
'SKTEXT-MAKTX(01)'
                                                               wa_data
-maktx1.    "Test Mat2'.  3 Input field
    PERFORM bdc_field       USING 
'SKTEXT-MAKTX(02)'
                                                              wa_data
-maktx2   "'Test Mat2'. 4 Input field
    PERFORM bdc_field       USING 
'BDC_CURSOR'
                                                             
'MARA-MEINS'.
    PERFORM bdc_field       USING 
'MARA-MEINS'
                                                             wa_data
-meins " 'KG'.      5 Input field

    
CALL TRANSACTION 
'MM01'
               USING it_bdcdata
              
UPDATE 
'S'
                MODE 
'A'          " A-> Foreground
       MESSAGES INTO it_bdcmsgcoll.
    
CLEAR:wa_data.    

 REFRESH:it_bdcdata,it_bdcmsgcoll.   
ENDLOOP.
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.   CLEAR WA_bdcdata.   wa_bdcdata
-program  program.
  wa_bdcdata
-dynpro   dynpro.
  wa_bdcdata
-dynbegin 'X'.
  APPEND wa_bdcdata TO it_bdcdata. ENDFORM.                    
"BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.   CLEAR wa_bdcdata.   wa_bdcdata
-fnam fnam.   wa_bdcdata-fval fval.   APPEND wa_bdcdata TO it_bdcdata. ENDFORM.                    "BDC_FIELD

 *& We have completed Call Transaction program


Now SAVE-CHECK-ACTIVATE and Execute and check whether the values are flowing properly into the respective input fields or not...


To validate Material Master data after executing BDC:

Go to MM03 Transaction -> Enter Material No and verify data and
Check tables in SE11:
MARA -> Material Master Data
MAKT -> Material Texts




Example 2:


Call Transaction program for Custom Transaction:


Custom Transaction Screen:







Call Transaction Program:


Record a transaction: Use transaction : SHDB


1.Click on New recording




2.Enter recording details







3.Enter screen inputs







4.SAVE




5. BACK






6.









7.SAVE




Generate a Program from recording:


1.





 


2.







Code will be generated.


4.BDC Call Transaction Program Using Upload functionality + above recording code (Step3)


REPORT ZBANK_BDC_PROGRAM
       
NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPESBEGIN OF TY_DATA,
         ACCNO 
TYPE ZACC_DATA-ACCNO,
         ACHOL 
TYPE ZACC_DATA-ACHOL,
         BNKNM 
TYPE ZACC_DATA-BNKNM,
         BNLOC 
TYPE ZACC_DATA-BNLOC,
       
END OF TY_DATA.

DATAIT_DATA TYPE TABLE OF TY_DATA,
      WA_DATA 
TYPE TY_DATA.

DATAIT_BDCDATA TYPE TABLE OF BDCDATA,
      WA_BDCDATA 
TYPE BDCDATA.

DATAIT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL,
      WA_BDCMSGCOLL 
TYPE BDCMSGCOLL.

DATA :W_PROPER_MESSAGE TYPE STRING.

START-OF-SELECTION.

  
CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      FILENAME            
'C:\Users\nagaraju.adhikari\Desktop\BANK_FILE.TXT'
      FILETYPE            
'ASC'
      HAS_FIELD_SEPARATOR 
'X'
    
TABLES
      DATA_TAB            
IT_DATA.
  
IF SY-SUBRC 0.
    
DELETE IT_DATA INDEX 1.
  
ENDIF.

  
LOOP AT IT_DATA INTO WA_DATA.

    
PERFORM BDC_DYNPRO      USING 'ZBANK_DATA_INSERT' '9000'.
    
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  
'=SAVE'.
    
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  
'WA_DATA-BNLOC'.
    
PERFORM BDC_FIELD       USING 'WA_DATA-ACCNO'
                                  WA_DATA
-ACCNO.   "'107'.             " 1
    
PERFORM BDC_FIELD       USING 'WA_DATA-ACHOL'
                                  WA_DATA
-ACHOL.   "'JHANVI'.          " 2
    
PERFORM BDC_FIELD       USING 'WA_DATA-BNKNM'
                                  WA_DATA
-BNKNM.   " 'ICICI'.           " 3
    
PERFORM BDC_FIELD       USING 'WA_DATA-BNLOC'
                                  WA_DATA
-BNLOC.   "'SECUNDERABAD'.    " 4

    
PERFORM BDC_DYNPRO      USING 'ZBANK_DATA_INSERT' '9000'.
    
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  
'=BACK'.

    
CALL TRANSACTION 'ZBANK_DATA'
          
USING IT_BDCDATA
          
UPDATE 'S'
          
MODE   'A'
   MESSAGES 
INTO IT_BDCMSGCOLL.

*& You can use FORMAT_MESSAGE FM here
    
IF SY-SUBRC 0.
*& Success Records
      
READ TABLE  IT_BDCMSGCOLL INTO WA_BDCMSGCOLL
                            
WITH KEY MSGTYP 'S' .
      
IF SY-SUBRC 0.
        
WRITE 'Accountis created with number:' ,  WA_BDCMSGCOLL-MSGV1 COLOR 3.
      
ENDIF.
    
ELSE.
*& Error Records
      
LOOP AT IT_BDCMSGCOLL INTO WA_BDCMSGCOLL
                          
WHERE MSGTYP 'E' .
        
CALL FUNCTION 'FORMAT_MESSAGE'
          
EXPORTING
            
ID   WA_BDCMSGCOLL-MSGID
            LANG 
'E'
            
NO   WA_BDCMSGCOLL-MSGNR
            V1   
WA_BDCMSGCOLL-MSGV1
            V2   
WA_BDCMSGCOLL-MSGV2
            V3   
WA_BDCMSGCOLL-MSGV3
            V4   
WA_BDCMSGCOLL-MSGV4
          
IMPORTING
            MSG  
W_PROPER_MESSAGE.

        
IF SY-SUBRC 0.
          
WRITE / W_PROPER_MESSAGE  COLOR .
        
ENDIF.

        
CLEAR:WA_BDCMSGCOLL,W_PROPER_MESSAGE.
      
ENDLOOP.
    
ENDIF.

    
CLEAR:WA_DATA.
    
REFRESH:IT_BDCDATAIT_BDCMSGCOLL.

  
ENDLOOP.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  
CLEAR WA_BDCDATA.
  WA_BDCDATA
-PROGRAM  PROGRAM.
  WA_BDCDATA
-DYNPRO   DYNPRO.
  WA_BDCDATA
-DYNBEGIN 'X'.
  
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  
CLEAR WA_BDCDATA.
  WA_BDCDATA
-FNAM FNAM.
  WA_BDCDATA
-FVAL FVAL.
  
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.


*& Output:





 


 


Session Method:


is a 2 step process.


1. Create a session using ABAP program


2. Process the session using Transaction -> SM35


1. Program Structure for Session Method:


Step 1:


Declarations to be done for


IT_DATA (For Input)


IT_BDCDATA (For BDC Structure)


IT_BDCMSGCOLL (For BDC messages collections)


Step 2:


Upload file using FM: GUI_UPLOAD-> IT_DATA


Step 3:


use FM: BDC_OPEN_GROUP -> to Create a Session


Step 4:


Process the IT_DATA Using Loop---Endloop.


loop IT_DATA into WA_DATA.


Use generated code from recording -> to fill IT_BDCDATA


Use FM: BDC_INSERT before endloop,


Insert Transaction code & IT_BDCDATA into session method


endloop.


Step 5:


Use FM: BDC_CLOSE_GROUP -> to close the session.


 


Note:


Data will not go & store directly into the transactions rather it creates a session with the data.


To view & process the created session use Transaction: SM35




2.Steps to process Session Method


Use Transaction: SM35






Select te session which you have created using ABAP Program.






Click on Process or (use Function Key F8)







Select radio button for Processing Mode (Foreground/background/error screen) .






Click on process to Continue.


Note:


1.If you choose Foreground mode: Process the data by clicking on enter button continuously.


2.If you choose Background mode: System will take care of the data processing.


After Processing,


Check the status of recording it will be marked as processed.


Then click on log







Do the analysis of session by clicking on analysis button.





 


Select tab to see the log creation details of session.






If you find any error records then fix those errors and re-run those records in another session.


Example1:


Example Program on Session Method:


REPORT ztemp_rec_mm01
       
NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES:BEGIN OF ty_data,
      mbrsh   
TYPE rmmg1-mbrsh,
      mtart   
TYPE rmmg1-mtart,
      maktx1  
TYPE sktext-maktx,
      maktx2  
TYPE sktext-maktx,
      meins   
TYPE mara-meins,
      
END OF ty_data.

DATA:it_data TYPE TABLE OF ty_data,
     wa_data 
TYPE ty_data.

*& BDC Structure
DATAit_bdcdata TYPE TABLE OF bdcdata,
      wa_bdcdata 
TYPE bdcdata         .

*& Message collection during processing of data
DATAit_bdcmsgcoll TYPE TABLE OF bdcmsgcoll,
      wa_bdcmsgcoll 
TYPE bdcmsgcoll    .

START-OF-SELECTION.
  
CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      filename            
'C:\Users\nagaraju.adhikari\Desktop\Classes-Online\MM01_FILE.txt'
      filetype            
'ASC'
      has_field_separator 
'X'
    
TABLES
      data_tab            
it_data.
  
IF sy-subrc 0.
    
DELETE it_data INDEX 1.
  
ENDIF.

*&---------------------------------------------------------
*& 1st FM :   BDC_OPEN_GROUP
*&---------------------------------------------------------

  
CALL FUNCTION 'BDC_OPEN_GROUP'
    
EXPORTING
      
client sy-mandt
      
group  'SESSION1'
      keep   
'X'          "FILLER1
      user   
sy-uname.    "FILLER12

  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.

*& Processing Logic
  
LOOP AT it_data INTO wa_data.

    
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-MBRSH'
                                   wa_data
-mbrsh .        "'M'.                     " 1
    
PERFORM bdc_field       USING 'RMMG1-MTART'
                                  wa_data
-mtart.          " 'ROH'.                   " 2

    
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' '3005'.
    
PERFORM bdc_field       USING 'BDC_OKCODE'
                                  
'=BU'.

    
PERFORM bdc_field       USING 'SKTEXT-MAKTX(01)'
                                  wa_data
-maktx1.         "'Test Mat2'.           " 3
    
PERFORM bdc_field       USING 'SKTEXT-MAKTX(02)'
                                  wa_data
-maktx2.         "'Test Mat2'.           " 4
    
PERFORM bdc_field       USING 'BDC_CURSOR'
                                  
'MARA-MEINS'.
    
PERFORM bdc_field       USING 'MARA-MEINS'
                                  wa_data
-meins.          " 'KG'.                  " 5

*& 2ND FM
    
CALL FUNCTION 'BDC_INSERT'
      
EXPORTING
        tcode     
'MM01'
      
TABLES
        dynprotab 
it_bdcdata.

    
IF sy-subrc <> 0.
* Implement suitable error handling here
    
ENDIF.

    
CLEAR:wa_data.
    
REFRESH:it_bdcdata,it_bdcmsgcoll.
  
ENDLOOP.

*& 3rd FM
  
CALL FUNCTION 'BDC_CLOSE_GROUP'.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  
CLEAR wa_bdcdata.
  wa_bdcdata
-program  program.
  wa_bdcdata
-dynpro   dynpro.
  wa_bdcdata
-dynbegin 'X'.
  
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  
CLEAR wa_bdcdata.
  wa_bdcdata
-fnam fnam.
  wa_bdcdata
-fval fval.
  
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.                    "BDC_FIELD


Example2:


REPORT ZBANK_BDC_PROGRAM
       
NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPESBEGIN OF TY_DATA,
         ACCNO 
TYPE ZACC_DATA-ACCNO,
         ACHOL 
TYPE ZACC_DATA-ACHOL,
         BNKNM 
TYPE ZACC_DATA-BNKNM,
         BNLOC 
TYPE ZACC_DATA-BNLOC,
       
END OF TY_DATA.

DATAIT_DATA TYPE TABLE OF TY_DATA,
      WA_DATA 
TYPE TY_DATA.

DATAIT_BDCDATA TYPE TABLE OF BDCDATA,
      WA_BDCDATA 
TYPE BDCDATA.

DATAIT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL,
      WA_BDCMSGCOLL 
TYPE BDCMSGCOLL.

DATA :W_PROPER_MESSAGE TYPE STRING.

START-OF-SELECTION.

  
CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      FILENAME            
'C:\Users\nagaraju.adhikari\Desktop\BANK_FILE.TXT'
      FILETYPE            
'ASC'
      HAS_FIELD_SEPARATOR 
'X'
    
TABLES
      DATA_TAB            
IT_DATA.
  
IF SY-SUBRC 0.
    
DELETE IT_DATA INDEX 1.
  
ENDIF.



*&---------------------------------------------------------
*& 1st FM :   BDC_OPEN_GROUP
*&---------------------------------------------------------
  
CALL FUNCTION 'BDC_OPEN_GROUP'
    
EXPORTING
      
client sy-mandt
      
group  'BANKDATA'
      keep   
'X'          
      user   
sy-uname.    


  LOOP AT IT_DATA INTO WA_DATA.

    
PERFORM BDC_DYNPRO      USING 'ZBANK_DATA_INSERT' '9000'.
    
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  
'=SAVE'.
    
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  
'WA_DATA-BNLOC'.
    
PERFORM BDC_FIELD       USING 'WA_DATA-ACCNO'
                                  WA_DATA
-ACCNO.   "'107'.             " 1
    
PERFORM BDC_FIELD       USING 'WA_DATA-ACHOL'
                                  WA_DATA
-ACHOL.   "'JHANVI'.          " 2
    
PERFORM BDC_FIELD       USING 'WA_DATA-BNKNM'
                                  WA_DATA
-BNKNM.   " 'ICICI'.           " 3
    
PERFORM BDC_FIELD       USING 'WA_DATA-BNLOC'
                                  WA_DATA
-BNLOC.   "'SECUNDERABAD'.    " 4

    
PERFORM BDC_DYNPRO      USING 'ZBANK_DATA_INSERT' '9000'.
    
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  
'=BACK'.

*& 2ND FM
    
CALL FUNCTION 'BDC_INSERT'
      
EXPORTING
        tcode     
'MM01'
      
TABLES
        dynprotab 
it_bdcdata.

    
CLEAR:WA_DATA.
    
REFRESH:IT_BDCDATAIT_BDCMSGCOLL.

  
ENDLOOP.

*& 3rd FM
  
CALL FUNCTION 'BDC_CLOSE_GROUP'.


*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  
CLEAR WA_BDCDATA.
  WA_BDCDATA
-PROGRAM  PROGRAM.
  WA_BDCDATA
-DYNPRO   DYNPRO.
  WA_BDCDATA
-DYNBEGIN 'X'.
  
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  
CLEAR WA_BDCDATA.
  WA_BDCDATA
-FNAM FNAM.
  WA_BDCDATA
-FVAL FVAL.
  
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.


Differences Between Call Transaction and Session Method:


Call Transaction
Session Method
Synchronous/Asynchronous updates
Only Synchronous Updates
Can transfer small amount of data
Can transfer large amount of data
Processing is faster
Processing is slower
Errors needs to be handled Explicitly
Error log is created in SM35
Data is updated immediately
Data is not updated until session is processed

Comments

Popular posts from this blog

SAP ABAP-Internal Table Operations and Example Program

HR ABAP Interview Questions and Answers