6 Columns with Active Background
6 Columns with Active Background
Active List Item Background

24OOP0509 – OOP’s BDC

OOPS BDC in SAP: A Simple Guide

 

 What is OOPS BDC?

OOPS BDC refers to using Object-Oriented Programming for performing BDC. In the procedural method, BDC is managed using transaction codes like `SM35`, or by writing standard BDC programs with function modules like `CALL TRANSACTION` or `SESSION METHOD`.

In OOPS BDC, we encapsulate the entire BDC logic in objects, making the code more modular, reusable and maintainable. OOPS BDC allows developers to manage the uploading process with more flexibility and scalability.

 Key Components of OOPS BDC

The main class used for OOPS BDC is CL_BDC_SESSION. This class helps manage BDC sessions and transactions in an object-oriented way. Below are the steps involved in OOPS BDC:

  1. CL_BDC_SESSION: This is the core class that handles the creation and execution of BDC sessions.
  2. BDCDATA Structure: This standard structure is still used for storing the transactional data that will be processed during the BDC session.
  3. Methods of CL_BDC_SESSION: Methods like `CREATE_SESSION` and `PROCESS_SESSION` are used to create and execute sessions.

 

 Steps to Create a Simple OOPS BDC Program

Let’s walk through the steps to create a basic OOPS BDC program for updating data in an SAP table using the session method.

  1. Data Declaration

First, declare the necessary variables and the internal table for the BDC data.

DATA: it_bdcdata TYPE TABLE OF bdcdata,

      wa_bdcdata TYPE bdcdata,

      bdc_session TYPE REF TO cl_bdc_session.

 

  1. Populate BDCDATA Structure

The `BDCDATA` structure holds the screen and field values for the BDC transaction. You need to fill this structure with the relevant data for each screen and field in the transaction.

CLEAR wa_bdcdata.

wa_bdcdata-program  = ‘SAPLMM03’.  “Program name

wa_bdcdata-dynpro   = ‘0101’.      “Screen number

wa_bdcdata-dynbegin = ‘X’.         “Start of the screen

APPEND wa_bdcdata TO it_bdcdata.

 

CLEAR wa_bdcdata.

wa_bdcdata-fnam = ‘MATNR’.         “Field name

wa_bdcdata-fval = ‘123456’.        “Field value (Material Number)

APPEND wa_bdcdata TO it_bdcdata.

 

  1. Create a BDC Session Using OOP

Now, create an instance of the `CL_BDC_SESSION` class and pass the BDCDATA internal table to create a new session.

bdc_session = NEW cl_bdc_session( ).

bdc_session->create_session(

  EXPORTING

    session_name = ‘MY_SESSION’  ” Name of the BDC session

  TABLES

    t_bdcdata    = it_bdcdata    ” BDC data table

).

 

  1. Process the BDC Session

Once the session is created, you can process it by calling the method to execute the session.

bdc_session->process_session( ‘MY_SESSION’ ).

 

  1. Handle Errors and Messages

You can handle errors and retrieve messages after processing the session to monitor the success or failure of the BDC process.

IF sy-subrc = 0.

  WRITE: ‘BDC Session processed successfully’.

ELSE.

  WRITE: ‘Error occurred in BDC processing’.

ENDIF.

 

 Advantages of OOPS BDC

  1. Modular and Reusable Code: By using object-oriented programming, you can encapsulate BDC logic in reusable classes and methods.
  2. Improved Error Handling: OOP allows for better error handling using exception classes and messages.
  3. Cleaner and More Readable Code: OOP structures the code into meaningful classes and methods, improving readability and maintainability.
  4. Scalability: As the complexity of the program grows, OOPS BDC makes it easier to manage and extend the code.
  5. Enhanced Flexibility: OOPS BDC provides more control over the session and transaction processing.

Author : Aniket Pawar, 9373518385                                                       

24OOP0509 – OOP’s BDC

OOPS BDC in SAP: A Simple Guide

 

 What is OOPS BDC?

OOPS BDC refers to using Object-Oriented Programming for performing BDC. In the procedural method, BDC is managed using transaction codes like `SM35`, or by writing standard BDC programs with function modules like `CALL TRANSACTION` or `SESSION METHOD`.

In OOPS BDC, we encapsulate the entire BDC logic in objects, making the code more modular, reusable and maintainable. OOPS BDC allows developers to manage the uploading process with more flexibility and scalability.

 Key Components of OOPS BDC

The main class used for OOPS BDC is CL_BDC_SESSION. This class helps manage BDC sessions and transactions in an object-oriented way. Below are the steps involved in OOPS BDC:

  1. CL_BDC_SESSION: This is the core class that handles the creation and execution of BDC sessions.
  2. BDCDATA Structure: This standard structure is still used for storing the transactional data that will be processed during the BDC session.
  3. Methods of CL_BDC_SESSION: Methods like `CREATE_SESSION` and `PROCESS_SESSION` are used to create and execute sessions.

 

 Steps to Create a Simple OOPS BDC Program

Let’s walk through the steps to create a basic OOPS BDC program for updating data in an SAP table using the session method.

  1. Data Declaration

First, declare the necessary variables and the internal table for the BDC data.

DATA: it_bdcdata TYPE TABLE OF bdcdata,

      wa_bdcdata TYPE bdcdata,

      bdc_session TYPE REF TO cl_bdc_session.

 

  1. Populate BDCDATA Structure

The `BDCDATA` structure holds the screen and field values for the BDC transaction. You need to fill this structure with the relevant data for each screen and field in the transaction.

CLEAR wa_bdcdata.

wa_bdcdata-program  = ‘SAPLMM03’.  “Program name

wa_bdcdata-dynpro   = ‘0101’.      “Screen number

wa_bdcdata-dynbegin = ‘X’.         “Start of the screen

APPEND wa_bdcdata TO it_bdcdata.

 

CLEAR wa_bdcdata.

wa_bdcdata-fnam = ‘MATNR’.         “Field name

wa_bdcdata-fval = ‘123456’.        “Field value (Material Number)

APPEND wa_bdcdata TO it_bdcdata.

 

  1. Create a BDC Session Using OOP

Now, create an instance of the `CL_BDC_SESSION` class and pass the BDCDATA internal table to create a new session.

bdc_session = NEW cl_bdc_session( ).

bdc_session->create_session(

  EXPORTING

    session_name = ‘MY_SESSION’  ” Name of the BDC session

  TABLES

    t_bdcdata    = it_bdcdata    ” BDC data table

).

 

  1. Process the BDC Session

Once the session is created, you can process it by calling the method to execute the session.

bdc_session->process_session( ‘MY_SESSION’ ).

 

  1. Handle Errors and Messages

You can handle errors and retrieve messages after processing the session to monitor the success or failure of the BDC process.

IF sy-subrc = 0.

  WRITE: ‘BDC Session processed successfully’.

ELSE.

  WRITE: ‘Error occurred in BDC processing’.

ENDIF.

 

 Advantages of OOPS BDC

  1. Modular and Reusable Code: By using object-oriented programming, you can encapsulate BDC logic in reusable classes and methods.
  2. Improved Error Handling: OOP allows for better error handling using exception classes and messages.
  3. Cleaner and More Readable Code: OOP structures the code into meaningful classes and methods, improving readability and maintainability.
  4. Scalability: As the complexity of the program grows, OOPS BDC makes it easier to manage and extend the code.
  5. Enhanced Flexibility: OOPS BDC provides more control over the session and transaction processing.

Author : Aniket Pawar, 9373518385