BDC with Call Transaction with Messge Handling


 Business Scenario: Uploading the customer master records to SAP system by BDC call transaction methods message handling.

 Step0. The Recording of the XD01 transaction is given below.

Step1. Create a BDC report in SE38 to upload Customer MAster Data.

Step2. Provide a Program name and click on the create button.

 Step3. Provide the below program code and activate the program.

 

 

REPORT  zbdc_call_trans_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,

              lt_msg TYPE TABLE OF bdcmsgcoll,
ls_msg TYPE bdcmsgcoll,
msg_text(255).

PARAMETERS : path TYPE rlgrap-filename OBLIGATORY DEFAULT ‘C:\Users\ratn\Desktop\bdc with call transaction\LEAGCT 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.

  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’.

******************************MODE *********************

      ” A(ALL SCREEN)

      ” E(ERROR SCREEN ONLY)

      ” N(WITHOUT SCREEN & PROCESSING TREMINATED WITH BREACKPOINT)

      ” P(WITHOUT SCREEN & PROCESSING NOT TREMINATED WITH BREACKPOINT )

******************************UPDATE *********************

      “A(ASYNCHRONOUS UPDATE)

      “S(SYNCHRONOUNE UPDATE)

      “L(LOCAL UPDATES)

***********************************************************

      CALL TRANSACTION ‘XD01’ USING lt_bdc

                              MODE ‘N’

                              UPDATE ‘A’

                              MESSAGES INTO lt_msg.

      REFRESH lt_bdc.

    ENDLOOP.

  ELSE.

    MESSAGE ‘No record to Upload’ TYPE ‘I’.

  ENDIF.

  LOOP AT  lt_msg INTO ls_msg.
CALL FUNCTION ‘FORMAT_MESSAGE’
EXPORTING
id        = ls_msg-msgid
lang      = ‘E’
no        = ls_msg-msgnr
v1        = ls_msg-msgv1
v2        = ls_msg-msgv2
v3        = ls_msg-msgv3
v4        = ls_msg-msgv4
IMPORTING
msg       = msg_text
EXCEPTIONS
not_found = 1
OTHERS    = 2.
IF sy-subrc = 0.
WRITE :/ msg_text.
ENDIF.

ENDLOOP.

*&———————————————————————*

*&      Form  CALL_SCREEN

*&———————————————————————*

 

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

*&———————————————————————*

 

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


Step4. Maintain a excel file with the below file format.

 Step5. Execute the program and select the path of the excel file from our local machine and execute it.

 Step6. The below customers are created with the BDC upload.

 Step7. Now go to Tcode- XD03 to view the above created customers.

 Step8. Provide the customer name and click on the continue button.

 Step9. The details of the customer is displayed as follows.

Step10.  Provide the customer name and click on the continue button.

 Step11. The details of the customer is displayed as follows.

Step12.  Provide the customer name and click on the continue button.

 Step13. The details of the customer is displayed as follows.


 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s