Data Migration Techniques:BDC Using Session Method

 

BDC (Batch Data Communication):

  • It is one of the data migration technique to transfer the data from legacy system(Non SAP System) to SAP system. 
  • Transaction code to work with BDC is 'SHDB'.

There are 3 methods for BDC

  1. CALL Transaction Method
  2. Session Method
  3. Direct Input Method
Note: Do not use F4 or F1 while recording and make sure passing correct data

Session Method:

  • Goto T-code 'SHDB'.
  • Click on 'new recording'.

  • Enter Recording name and T-code you want recording (Eg:MM01).
  • Click on 'Start Recording'.

 
  • MM01 screen will appear 
  • Enter the required data
  • Click on 'Select Views'
  • Select 'Basic Data1' and continue.
 
  •  Enter data and click on 'Save'.

  • Click on 'Save' and 'Back'.
  • Select the Recording and click on 'Program'

  • Enter Program Name and select radio button 'Transfer from recording'
  • Click on 'Continue'
  • System will generate the program. Go to se38 and edit the program like below.

 

REPORT zvb_test_mat
       NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES:BEGIN OF ty_data,
        matnr TYPE mara-matnr,
        mbrsh TYPE mara-mbrsh,
        mtart TYPE mara-mtart,
        maktx TYPE makt-maktx,
        meins TYPE mara-meins,
      END OF ty_data.

DATA:ls_data TYPE ty_data,
     lt_data TYPE TABLE OF ty_data.
DATA:lv_file TYPE string,
     lv_msg  TYPE string.

*Copied from Include bdcrecx1_s
DATA:ls_bdcdata TYPE bdcdata,
     lt_bdcdata TYPE TABLE OF bdcdata.

PARAMETERS:p_file TYPE localfile.

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.

START-OF-SELECTION.
  lv_file = p_file.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lv_file
      has_field_separator     = 'X'
    TABLES
      data_tab                = lt_data
    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.

* Include bdcrecx1_s:
* The call transaction using is called WITH AUTHORITY-CHECK!
* If you have own auth.-checks you can use include bdcrecx1 instead.
*include bdcrecx1_s.

  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      client              = sy-mandt
*     DEST                = FILLER8
      group               = 'MM01_GROUP'
*     HOLDDATE            = FILLER8
      keep                = 'X'
      user                = sy-uname
*     RECORD              = FILLER1
*     PROG                = SY-CPROG
*     DCPFM               = '%'
*     DATFM               = '%'
*     APP_AREA            = FILLER12
*     LANGU               = SY-LANGU
* 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.


*start-of-selection.
  LOOP AT lt_data INTO ls_data.
*perform open_group.

    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'
                                   ls_data-matnr.
*                              'PMAT'.
    PERFORM bdc_field       USING 'RMMG1-MBRSH'
                                   ls_data-mbrsh.
*                              'P'.
    PERFORM bdc_field       USING 'RMMG1-MTART'
                                   ls_data-mtart.
*                              'NLAG'.
    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'
                                  ls_data-maktx.
*                              'Test material'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'MARA-MEINS'.
    PERFORM bdc_field       USING 'MARA-MEINS'
                                  ls_data-meins.
*                              'EA'.
    PERFORM bdc_field       USING 'MARA-MTPOS_MARA'
                                  'NLAG'.

    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode            = 'MM01'
*       POST_LOCAL       = NOVBLOCAL
*       PRINTING         = NOPRINT
*       SIMUBATCH        = ' '
*       CTUPARAMS        = ' '
      TABLES
        dynprotab        = lt_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.

    REFRESH:lt_bdcdata.
*perform bdc_transaction using 'MM01'.

*perform close_group.
  ENDLOOP.

  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

*Copied from Include bdcrecx1_s
FORM bdc_dynpro USING program dynpro.
  CLEAR ls_bdcdata.
  ls_bdcdata-program  = program.
  ls_bdcdata-dynpro   = dynpro.
  ls_bdcdata-dynbegin = 'X'.
  APPEND ls_bdcdata TO lt_bdcdata.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
*  IF FVAL <> NODATA.
  CLEAR ls_bdcdata.
  ls_bdcdata-fnam = fnam.
  ls_bdcdata-fval = fval.
  APPEND ls_bdcdata TO lt_bdcdata.
*  ENDIF.
ENDFORM.
*Copied from Include bdcrecx1_s

  • Execute the program. 
  • Go to T-code 'SM35'. 
  • Select the session and click on 'Reprocess'.

 

 

Comments

Popular posts from this blog

CDS Views: Table Functions with Example

ABAP-Managed Database Procedures (AMDP) with Example

Passing Dynamic Variables to SO10 TEXT