Sunday 5 January 2014

BDC with Session Method

Scenario: Uploading customer master records to SAP system by BDC session method.

Session Method:
  • Session method is always synchronous.
  • Message is handled automatically by the session log.
  • Mostly used for huge amount of data upload.
  • Multiple Trasactions can be processed by a single session method.

Step1. The recording of XD01 (Customer Master Creation ) from SHDB transaction is given below.

















































































Step2. Go to SE38 and create a report program for bdc session method.








Step3. Provide the below code & activate the program.
______________ __________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZBDC_SESSION_METH_CUST_MASTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zbdc_session_meth_cust_master.

TYPES : BEGIN OF ty_cust,
            comp_code TYPE bukrs,
            sales_org TYPE vkorg,
            dist_chnl TYPE vtweg,
            divi TYPE spart,
            acc_grp TYPE ktokd,
            title TYPE  anred,
            land TYPE land1,
            region TYPE regio,
            lang TYPE spras,
            ord_prob TYPE awahr,
            curr TYPE waers,
           del_prio TYPE lprio,
           shipp_cond TYPE vsbed,
           delv_plant TYPE vwerk,
        END OF ty_cust.
DATA : lt_excel TYPE TABLE OF alsmex_tabline,
              ls_excel TYPE alsmex_tabline,
              lt_cust TYPE TABLE OF ty_cust,
              ls_cust TYPE ty_cust,
              lt_bdc TYPE TABLE OF bdcdata,
              ls_bdc TYPE bdcdata,
              session_name TYPE apqi-groupid.

PARAMETERS : path TYPE rlgrap-filename OBLIGATORY DEFAULT 'C:\Users\ratn\Desktop\bdc with call transaction\LEAGCY CUST RECORD'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR path .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'PATH'
    IMPORTING
      file_name     = path.

START-OF-SELECTION.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = path
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 50
      i_end_row               = 50
    TABLES
      intern                  = lt_excel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  LOOP AT lt_excel INTO ls_excel.
    CASE ls_excel-col.
      WHEN '001'.
        ls_cust-comp_code = ls_excel-value.
      WHEN '002'.
        ls_cust-sales_org  = ls_excel-value.
      WHEN '003'.
        ls_cust-dist_chnl  = ls_excel-value.
      WHEN '004'.
        ls_cust-divi  = ls_excel-value.
      WHEN '005'.
        ls_cust-acc_grp  = ls_excel-value.
      WHEN '006'.
        ls_cust-title  = ls_excel-value.
      WHEN '007'.
        ls_cust-land  = ls_excel-value.
      WHEN '008'.
        ls_cust-region  = ls_excel-value.
      WHEN '009'.
        ls_cust-lang  = ls_excel-value.
      WHEN '010'.
        ls_cust-ord_prob  = ls_excel-value.
      WHEN '011'.
        ls_cust-curr  = ls_excel-value.
      WHEN '012'.
        ls_cust-del_prio  = ls_excel-value.
      WHEN '013'.
        ls_cust-shipp_cond  = ls_excel-value.
      WHEN '014'.
        ls_cust-delv_plant  = ls_excel-value.
      WHEN OTHERS.
    ENDCASE.
    AT END OF row.
      APPEND ls_cust TO lt_cust.
      CLEAR : ls_cust, ls_excel.
    ENDAT.
  ENDLOOP.
  PERFORM bdc_open_group.
  PERFORM bdc_create_group.
  PERFORM bdc_close_group.



*&---------------------------------------------------------------------*
*&      Form  BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM bdc_open_group .

  CONCATENATE sy-datum sy-uzeit INTO session_name .

  CALL FUNCTION 'BDC_OPEN_GROUP'
 EXPORTING
   client                    = sy-mandt
*   DEST                      = FILLER8
   group                     = session_name
*   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.

ENDFORM.                    " BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
*&      Form  BDC_CREATE_GROUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM bdc_create_group .
  IF lt_cust IS NOT INITIAL.
    LOOP AT lt_cust INTO ls_cust.
      PERFORM : call_screen USING 'SAPMF02D' '0100' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'RF02D-KTOKD'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
      PERFORM : fill_screen USING 'RF02D-BUKRS' ls_cust-comp_code.
      PERFORM : fill_screen USING 'RF02D-VKORG' ls_cust-sales_org.
      PERFORM : fill_screen USING 'RF02D-VTWEG' ls_cust-dist_chnl.
      PERFORM : fill_screen USING 'RF02D-SPART' ls_cust-divi.
      PERFORM : fill_screen USING 'RF02D-KTOKD' ls_cust-acc_grp.

      PERFORM : call_screen USING 'SAPMF02D' '0110' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-SPRAS'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
      PERFORM : fill_screen USING 'KNA1-ANRED' ls_cust-title.
      PERFORM : fill_screen USING 'KNA1-LAND1' ls_cust-land.
      PERFORM : fill_screen USING 'KNA1-REGIO' ls_cust-region.
      PERFORM : fill_screen USING 'KNA1-SPRAS' ls_cust-lang.

      PERFORM : call_screen USING 'SAPMF02D' '0120' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-LIFNR'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0125' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-NIELS'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0130' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNBK-BANKS(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

      PERFORM : call_screen USING 'SAPMF02D' '0340' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVA-ABLAD(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

      PERFORM : call_screen USING 'SAPMF02D' '0370' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNEX-LNDEX(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.
      PERFORM : fill_screen USING 'KNA1-CIVVE' 'X'.

      PERFORM : call_screen USING 'SAPMF02D' '0360' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVK-NAMEV(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

      PERFORM : call_screen USING 'SAPMF02D' '0210' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-AKONT'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0215' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-ZTERM'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0220' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB5-MAHNA'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0230' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-VRSNR'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.

      PERFORM : call_screen USING 'SAPMF02D' '0310' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-BZIRK'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
      PERFORM : fill_screen USING 'KNVV-AWAHR' ls_cust-ord_prob.
      PERFORM : fill_screen USING 'KNVV-WAERS' ls_cust-curr.


      PERFORM : call_screen USING 'SAPMF02D' '0315' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-VWERK'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
      PERFORM : fill_screen USING 'KNVV-LPRIO' ls_cust-del_prio.
      PERFORM : fill_screen USING 'KNVV-KZAZU' 'X'.
      PERFORM : fill_screen USING 'KNVV-VSBED' ls_cust-shipp_cond.
      PERFORM : fill_screen USING 'KNVV-VWERK' ls_cust-delv_plant.
      PERFORM : fill_screen USING 'KNVV-ANTLF' '9'.

      PERFORM : call_screen USING 'SAPMF02D' '0320' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-PERFK'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTS'.

      PERFORM : call_screen USING 'SAPMF02D' '1350' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVI-TAXKD(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

      PERFORM : call_screen USING 'SAPMF02D' '0324' 'X'.
      PERFORM : fill_screen USING 'BDC_CURSOR' '*TPART-VTEXT(01)'.
      PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

      CALL FUNCTION 'BDC_INSERT'
        EXPORTING
          tcode            = 'XD01'
*         POST_LOCAL       = NOVBLOCAL
*         PRINTING         = NOPRINT
*         SIMUBATCH        = ' '
*         CTUPARAMS        = ' '
        TABLES
          dynprotab        = lt_bdc
        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.
      ENDIF.
    ENDLOOP.
    WRITE:/ 'Please check tcode- SM35 for the session: ', session_name.
  ELSE.
    MESSAGE 'No record to Upload' TYPE 'I'.
  ENDIF.
ENDFORM.                    " BDC_CREATE_GROUP
*&---------------------------------------------------------------------*
*&      Form  BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM bdc_close_group .
  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.

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

ENDFORM.                    " BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*&      Form  CALL_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0273   text
*      -->P_0274   text
*      -->P_0275   text
*----------------------------------------------------------------------*
FORM call_screen  USING pgm
                                        dyn
                                        dyn_bgn.

  ls_bdc-program = pgm.
  ls_bdc-dynpro = dyn.
  ls_bdc-dynbegin = dyn_bgn.
  APPEND ls_bdc TO lt_bdc.
  CLEAR ls_bdc.
ENDFORM.                    " CALL_SCREEN
*&---------------------------------------------------------------------*
*&      Form  FILL_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0625   text
*      -->P_0626   text
*----------------------------------------------------------------------*
FORM fill_screen  USING nam
                                       val.
  ls_bdc-fnam = nam.
  ls_bdc-fval = val.
  APPEND ls_bdc TO lt_bdc.
  CLEAR ls_bdc.
ENDFORM.                    " FILL_SCREEN


_________________________________________________________________________________

Step 3.1. The excel file format should be as follows.





Step4.  Run the report and select the excel file and execute it.










Step5. The output of teh report is as follows.











Step6. Go to SM35 tcode.











Step7. Select the Session and clcik on the process button.















Step8. Select the radio button as per necessary and click on Process button.






















Step9. Hit Enter key from key board to continue.





























Step10. Hit Enter key from key board to continue.































Step11.Hit Enter key from key board to continue.

























Step12.Hit Enter key from key board to continue.


















 Step13.Hit Enter key from key board to continue.


















Step14.Hit Enter key from key board to continue.



















Step15. Hit Enter key from key board to continue.




















Step16. Hit Enter key from key board to continue.
















 Step17. Hit Enter key from key board to continue.




















Step18. Hit Enter key from key board to continue.































Step19. Hit Enter key from key board to continue.




























Step20. Hit Enter key from key board to continue.






















Step21. Hit Enter key from key board to continue.



























Step22.Hit Enter key from key board to continue.




























Step23.Hit Enter key from key board to continue.

























Step24.Hit Enter key from key board to continue.



















Step25.Hit Enter key from key board to continue.
























Step26.Hit Enter key from key board to continue. After processing all the reocrd the below screen will apprear. Now to see the message log select the line and click on Analysis button.














Step27. The The transaction XD01 is called thrice as our excel contained 3 records of customer master.
































Step28. Click on the third tab and it displays what are the customer numbers are created.
 ________________________________________________________________________________

No comments:

Comments system

Disqus Shortname