SAP Tutorials Blog




 Step by Step tutorial on BDC Session Method Program in SAP ABAP

BDC Session Method is used to upload data from Non-SAP to SAP System. Using Session method,

we can transfer data through more than one Transaction, Unlike BDC Call Transaction Method Program.


We are Processing Batch input Session From SM35 Transaction Code.


Session method.

1) synchronous processing.

2) can transfer a large amount of data.

3) processing is slower.

4) error log is created

5) data is not updated until the session is processed.


Call transaction Method.

1) asynchronous processing

2) can transfer a small amount of data

3) processing is faster.

4) errors need to be handled explicitly

5) data is updated automatically


Go to SHDB and Press Enter

Step by Step tutorial on BDC Session Method Program in SAP ABAP


 

Click on New Recording Button and Give the zrecord1 name and enter transaction code MM01 and click on the Start recording button.

Step by Step tutorial on BDC Session Method Program in SAP ABAP


The system goes to the Create material screen, there give the industry sector and material type and selects basic data 1.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


Now it will come to the second screen where give the below details and click on save button and go back.

Step by Step tutorial on BDC Session Method Program in SAP ABAP


Now save the recording and go back.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


Now, select the created record, click on the program button.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


The system will ask you the program name, give it, and continue.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


Now give the program title and continue.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


Now double click on BDCRECX1 main program


Step by Step tutorial on BDC Session Method Program in SAP ABAP


Copy the below code.


Step by Step tutorial on BDC Session Method Program in SAP ABAP


BDC Session Method Program

report ZSESSION_PROGRAM

       no standard page heading line-size 255.


TYPES : BEGIN OF ty_mat,

          mbrsh TYPE mbrsh,

          mtart TYPE mtart,

          maktx TYPE maktx,

          matkl TYPE matkl,

          meins TYPE meins,

        END OF ty_mat.



DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.


DATA:

        f_name   TYPE rlgrap-filename,

        it_mat   TYPE STANDARD TABLE OF ty_mat,

        wa_mat   TYPE ty_mat.



*Input Path

PARAMETERS:

  p_file   TYPE rlgrap-filename.                  " File Path


* Data decleration

DATA:

  wa_path TYPE string ,

  wa_error TYPE string,

  wa_cnt   TYPE i,

  w_mode    TYPE c,

  wa_cnt1(2) TYPE n.



* Opening window for path selection


at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      program_name  = syst-cprog

      dynpro_number = syst-dynnr

      field_name    = ' '

    IMPORTING

      file_name     = p_file.


  TYPES:

    fs_struct(4096) TYPE c OCCURS 0 .


  DATA:

    w_struct TYPE fs_struct.


* Uploading excel file.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

    EXPORTING

      i_field_seperator          = 'X'

*   I_LINE_HEADER              =

      i_tab_raw_data             = w_struct

      i_filename                 = p_file

    TABLES

      i_tab_converted_data       = it_mat

    EXCEPTIONS

      conversion_failed          = 1

      OTHERS                     = 2

            .

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.


start-of-selection.



  CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

      CLIENT              = SY-MANDT

      GROUP               = 'AKS'

      KEEP                = 'X'

      USER                = SY-UNAME

    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.


START-OF-SELECTION.

  LOOP AT it_mat INTO wa_mat.


    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_mat-mbrsh."record-MBRSH_001.

    perform bdc_field       using 'RMMG1-MTART'

                                  wa_mat-mtart."record-MTART_002.

    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'."record-KZSEL_01_003.

    perform bdc_dynpro      using 'SAPLMGMM' '4004'.

    perform bdc_field       using 'BDC_OKCODE'

                                  '/00'.

    perform bdc_field       using 'MAKT-MAKTX'

                                  wa_mat-maktx."record-MAKTX_004.

    perform bdc_field       using 'BDC_CURSOR'

                                  'MARA-MATKL'.

    perform bdc_field       using 'MARA-MEINS'

                                  wa_mat-meins."record-MEINS_005.

    perform bdc_field       using 'MARA-MATKL'

                                  wa_mat-matkl."record-MATKL_006.

    perform bdc_dynpro      using 'SAPLSPO1' '0300'.

    perform bdc_field       using 'BDC_OKCODE'

                                  '=YES'.



    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

              .

    REFRESH BDCDATA.

  ENDLOOP.




  CALL FUNCTION 'BDC_CLOSE_GROUP'

    EXCEPTIONS

      NOT_OPEN    = 1

      QUEUE_ERROR = 2

      OTHERS      = 3.

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

*----------------------------------------------------------------------*

*        Start new screen                                              *

*----------------------------------------------------------------------*

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.   


Serkan AKKAVAK

Computer Engineer BSc

SAP Department Deputy Manager

Contact : serkurumsal@yandex.com