Saturday, 28 December 2013

BDC with table control for Customer Master

Scenario: Uploading the customer master through BDC technique where multiple bank information of a particular customer needs to be maintained in the screen table control.


Step1. Go to Tcode- SHDB for recording.









Step2. Click on New Recording button.








Step3. Provide a Recording name and the transaction 'XD01' and click on continue button.



































Step4. Provide the company code, sales org, distribution channel, division and account group and hit ENTER key from keyboard.






















Step5. Provide title, country and language and hit ENTER key from keyboard.

























Step6. Hit ENTER key from keyboard to continue.


























Step7. Hit ENTER key from keyboard to continue.





















Step8. The screen appears where we have to provide multiple bank account details as a table control.


























Step9. Provide the bank country, bank key and the bank account number and hit ENTER key from keyboard.























Step10. Save the recording


























Step11. The recorded session is given as below.






















Step12. The BANK key in the sap system can be cretaed in tcode- FI01/FI02/FI03.
In teh recording we have used bank key- 5001, 5002 and 5003. These bank keys are defined in the system before creating the customer.
























Step13. Now go to tcode- SE38 to create the BDC program for table control for the customer master.












Step14. Provide a program name and click on create button and provide the below code.












*&---------------------------------------------------------------------*
*& Report  ZBDC_TABLE_CONTROL_CUST_MASTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zbdc_table_control_cust_master.

DATA : p_banks TYPE char15,
             p_bankl TYPE char15,
             p_bankn TYPE char15,
             idx TYPE num2 .

TYPES : BEGIN OF ty_cust,
             slno TYPE char2,
             cust_id TYPE char2,
             com_code TYPE bukrs,
             sales_org TYPE vkorg,
             dist_ch TYPE vtweg,
             division TYPE spart,
             acct_gr TYPE ktokd,
             title TYPE anred,
             land TYPE land1,
             lang TYPE spras,
        END OF ty_cust,

        BEGIN OF ty_bank,
            slno TYPE char2,
            cust_id TYPE char2,
            land TYPE banks,
            bank_key TYPE bankl,
            acct TYPE bankn,
        END OF ty_bank.

PARAMETERS : cust_fil TYPE ibipparms-path OBLIGATORY DEFAULT        
                                     'C:\Users\Desktop\bdc with table contorl\CUST DATA.xlsx',
                          bank_fil TYPE ibipparms-path OBLIGATORY DEFAULT  
                                    'C:\Users\Desktop\bdc with table contorl\BANK DATA.xlsx'.

DATA : lt_cust_ex TYPE TABLE OF alsmex_tabline,
             lt_bank_ex TYPE TABLE OF alsmex_tabline,
             ls_excel TYPE alsmex_tabline .

DATA : lt_cust TYPE TABLE OF ty_cust,
             ls_cust TYPE ty_cust,
             lt_bank TYPE TABLE OF ty_bank,
             ls_bank TYPE ty_bank,
             lt_bdc TYPE TABLE OF bdcdata,
             ls_bdc TYPE bdcdata.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR cust_fil .

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = space
    IMPORTING
      file_name     = cust_fil.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR bank_fil .

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = space
    IMPORTING
      file_name     = bank_fil.

START-OF-SELECTION .

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = cust_fil
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 100
      i_end_row               = 100
    TABLES
      intern                  = lt_cust_ex
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 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.


  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = bank_fil
      i_begin_col             = 1
      i_begin_row             = 2
      i_end_col               = 100
      i_end_row               = 100
    TABLES
      intern                  = lt_bank_ex
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 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.

  LOOP AT lt_cust_ex INTO ls_excel.
    CASE ls_excel-col.
      WHEN '0001'.
        ls_cust-slno = ls_excel-value.
      WHEN '0002'.
        ls_cust-cust_id = ls_excel-value.
      WHEN '0003'.
        ls_cust-com_code = ls_excel-value.
      WHEN '0004'.
        ls_cust-sales_org = ls_excel-value.
      WHEN '0005'.
        ls_cust-dist_ch = ls_excel-value.
      WHEN '0006'.
        ls_cust-division = ls_excel-value.
      WHEN '0007'.
        ls_cust-acct_gr = ls_excel-value.
      WHEN '0008'.
        ls_cust-title = ls_excel-value.
      WHEN '0009'.
        ls_cust-land = ls_excel-value.
      WHEN '0010'.
        ls_cust-lang = ls_excel-value.
    ENDCASE.
    CLEAR ls_excel.
    AT END OF row.
      APPEND ls_cust TO lt_cust.
      CLEAR : ls_cust.
    ENDAT.
  ENDLOOP.

  CLEAR : ls_excel.

  LOOP AT lt_bank_ex INTO ls_excel.
    CASE ls_excel-col.
      WHEN '0001'.
        ls_bank-slno = ls_excel-value.
      WHEN '0002'.
        ls_bank-cust_id = ls_excel-value.
      WHEN '0003'.
        ls_bank-land = ls_excel-value.
      WHEN '0004'.
        ls_bank-bank_key = ls_excel-value.
      WHEN '0005'.
        ls_bank-acct = ls_excel-value.
    ENDCASE.
    CLEAR ls_excel.
    AT END OF row.
      APPEND ls_bank TO lt_bank.
      CLEAR ls_bank.
    ENDAT.
  ENDLOOP.

  LOOP AT  lt_cust INTO ls_cust.

    PERFORM call_screen USING 'SAPMF02D' '0100' 'X'.
    PERFORM : fill_screen USING 'BDC_CURSOR' 'RF02D-KTOKD',
                        fill_screen USING 'BDC_OKCODE' '/00',
                        fill_screen USING 'RF02D-BUKRS' ls_cust-com_code,
                        fill_screen USING 'RF02D-VKORG' ls_cust-sales_org,
                        fill_screen USING 'RF02D-VTWEG' ls_cust-dist_ch,
                        fill_screen USING 'RF02D-SPART' ls_cust-division,
                        fill_screen USING 'RF02D-KTOKD' ls_cust-acct_gr.

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

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

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

*** FILL TABLE FOR TABLE CONTROL ************
    PERFORM call_screen USING 'SAPMF02D' '0130' 'X'.
    PERFORM  fill_screen USING 'BDC_CURSOR' 'KNBK-KOINH(01)'.
    PERFORM  fill_screen USING 'BDC_OKCODE' '=ENTR'.
    CLEAR idx.
    LOOP AT lt_bank INTO ls_bank WHERE cust_id = ls_cust-cust_id.

      idx = idx + 1.
      CLEAR : p_banks, p_bankl, p_bankn.
      CONCATENATE 'KNBK-BANKS(' idx ')' INTO p_banks.
      CONCATENATE 'KNBK-BANKL(' idx ')' INTO p_bankl.
      CONCATENATE 'KNBK-BANKN(' idx ')' INTO p_bankn.
      PERFORM  fill_screen USING p_banks ls_bank-land.
      PERFORM  fill_screen USING p_bankl ls_bank-bank_key.
      PERFORM  fill_screen USING p_bankn ls_bank-acct.
    ENDLOOP.

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

    CALL TRANSACTION 'XD01' USING lt_bdc
                            MODE 'A'
                            UPDATE 'A'.

    REFRESH lt_bdc[].

  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  CALL_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0391   text
*      -->P_0392   text
*      -->P_0393   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_0510   text
*      -->P_0511   text
*----------------------------------------------------------------------*
FORM fill_screen  USING fnam
                                       fval .

  ls_bdc-fnam = fnam.
  ls_bdc-fval = fval.
  APPEND ls_bdc TO lt_bdc.
  CLEAR ls_bdc.

ENDFORM.                    " FILL_SCREEN

_______________________________________________________________________________

Step15. The excel file1 contains the customer header data.








Step16. The excel file2 contains the customer bank details information.




























Step17. Run the program and select the two excel files to upload.









Step18. The XD01 screen is called. Hit the ENTER key from keyboard to continue.
























Step19. Hit the ENTER key from keyboard to continue.
























Step20. Hit the ENTER key from keyboard to continue.






















Step21. Hit the ENTER key from keyboard to continue.




















Step22. The customer bank information is filled in the table control. Hit the ENTER key from keyboard to continue.

























Step23. Hit the ENTER key from keyboard to continue.
























Step24. Hit the ENTER key from keyboard to continue.




























Step25. Hit the ENTER key from keyboard to continue.






















Step26. Hit the ENTER key from keyboard to continue.
























Step27. Hit the ENTER key from keyboard to continue.




















Step28. The customer bank information is filled in the table control. Hit the ENTER key from keyboard to continue.


























Step29. Hit the ENTER key from keyboard to continue.


























Step30. Hit the ENTER key from keyboard to continue.
































Step31. Hit the ENTER key from keyboard to continue.

























Step32. Hit the ENTER key from keyboard to continue.
























Step33. Hit the ENTER key from keyboard to continue.





















Step34. The customer bank information is filled in the table control. Hit the ENTER key from keyboard to continue.


























Step35. Hit the ENTER key from keyboard to continue.


























Step36. Hit the ENTER key from keyboard to continue.
































Step37. Hit the ENTER key from keyboard to continue.

























Step38. Hit the ENTER key from keyboard to continue.
























Step39. Hit the ENTER key from keyboard to continue.





















Step40. The customer bank information is filled in the table control area. Hit the ENTER key from keyboard to continue.


























Step41. Hit the ENTER key from keyboard to continue.


























Step42. Hit the ENTER key from keyboard to continue.
































Step43. Hit the ENTER key from keyboard to continue.


























Step44. Hit the ENTER key from keyboard to continue.


























Step45. Hit the ENTER key from keyboard to continue.




















Step46. The customer bank information is filled in the table control. Hit the ENTER key from keyboard to continue.


























Step47. Hit the ENTER key from keyboard to continue.

























Step48. The program terminates with successfully uploading the customer master details with the use of table control.




























_______________________________________________________________________________

Wednesday, 4 December 2013

OO ALV By CL_SALV_TABLE factory Method.

Case 1. Go to SE38 and create a report program. Provide below code. Execute it.
_____________________________________________________________________________
REPORT zsalv_table_diaplay.

CLASS sales_order_disp DEFINITION.

  PUBLIC SECTION.
    DATA o_salv TYPE REF TO cl_salv_table.
    METHODS build_salesorder,
                        disp_salesorder.

  PRIVATE SECTION.
    DATA lt_vbak TYPE TABLE OF vbak.

ENDCLASS.

CLASS sales_order_disp IMPLEMENTATION.

  METHOD build_salesorder.
    SELECT FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
  ENDMETHOD.

  METHOD disp_salesorder.
    try.
    cl_salv_table=>factory(
      IMPORTING
        r_salv_table   o_salv    " Basis Class Simple ALV Tables
      CHANGING
        t_table        lt_vbak
    ).

     CATCH cx_salv_msg
     endtry.

     o_salv->display).

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  DATAo_salesord TYPE REF TO sales_order_disp.
  CREATE OBJECT o_salesord.
  o_salesord->build_salesorder).
  o_salesord->disp_salesorder).
_______________________________________________________________________________
O/P: The report output is as follows:















_______________________________________________________________________________
Case 2: Making Hot Spot on for a particular column(VBELN: Sales Document)

REPORT zsalv_table_diaplay.

CLASS sales_order_disp DEFINITION.
  PUBLIC SECTION.
    DATA o_salv TYPE REF TO cl_salv_table.
    METHODS build_salesorder,
                       disp_salesorder.
  PRIVATE SECTION.
    DATA lt_vbak TYPE TABLE OF vbak.

ENDCLASS.

CLASS sales_order_disp IMPLEMENTATION.
  METHOD build_salesorder.
    SELECT FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
  ENDMETHOD.

  METHOD disp_salesorder.
    DATA o_cols TYPE REF TO cl_salv_columns_table,
                o_col  TYPE REF TO cl_salv_column_table.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table   o_salv    " Basis Class Simple ALV Tables
          CHANGING
            t_table        lt_vbak
        ).
      CATCH cx_salv_msg.    
    ENDTRY.

**********START OF HOT SPOT ON ***************
    o_cols o_salv->get_columns).
    TRY.
        o_col ?= o_cols->get_column'VBELN' )" sales reder number
      CATCH cx_salv_not_found.
    ENDTRY.
    o_col->set_cell_typeif_salv_c_cell_type=>hotspot ).
*   o_col->set_cell_type( value =  5 ).
**********END OF HOT SPOT ON ****************

    o_salv->display).

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATAo_salesord TYPE REF TO sales_order_disp.
  CREATE OBJECT o_salesord.
  o_salesord->build_salesorder).
  o_salesord->disp_salesorder).

______________________________________________________________________________
O/P: The report output is as follows:





















______________________________________________________________________________

Case 3: Hiding a particular column (ERZET: Entry time

REPORT zsalv_table_diaplay.

CLASS sales_order_disp DEFINITION.
  PUBLIC SECTION.
    DATA o_salv TYPE REF TO cl_salv_table.
    METHODS build_salesorder,
                        disp_salesorder.
  PRIVATE SECTION.
    DATA lt_vbak TYPE TABLE OF vbak.

ENDCLASS.

CLASS sales_order_disp IMPLEMENTATION.
  METHOD build_salesorder.
    SELECT FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
  ENDMETHOD.

  METHOD disp_salesorder.
    DATA o_cols TYPE REF TO cl_salv_columns_table,
               o_col  TYPE REF TO cl_salv_column_table.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table   o_salv    " Basis Class Simple ALV Tables
          CHANGING
            t_table        lt_vbak
        ).
      CATCH cx_salv_msg.  
    ENDTRY.

**********START OF HOT SPOT ON ***************
    o_cols o_salv->get_columns).
    TRY.
        o_col ?= o_cols->get_column'VBELN' )" sales reder number
      CATCH cx_salv_not_found.
    ENDTRY.
    o_col->set_cell_typeif_salv_c_cell_type=>hotspot ).
*   o_col->set_cell_type( value =  5 ).
**********END OF HOT SPOT ON ****************
**********START OF HIDING A COLUMN ***************
    TRY.
        o_col ?= o_cols->get_column'ERZET' )" Entry time
      CATCH cx_salv_not_found.
    ENDTRY.
    o_col->set_visiblevalue if_salv_c_bool_sap=>false ).
**********END OF HIDING A COLUMN ****************
    o_salv->display).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATAo_salesord TYPE REF TO sales_order_disp.
  CREATE OBJECT o_salesord.
  o_salesord->build_salesorder).
  o_salesord->disp_salesorder).

___________________________________________________________________________
O/P: The report output is as follows:


















______________________________________________________________________________
Case 4: Adding top-of-page and end-of-page

REPORT zsalv_table_diaplay.

CLASS sales_order_disp DEFINITION.
  PUBLIC SECTION.
    DATA o_salv TYPE REF TO cl_salv_table.
    METHODS build_salesorder,
              disp_salesorder.
  PRIVATE SECTION.
    DATA lt_vbak TYPE TABLE OF vbak.
    METHODS build_top_of_page CHANGING obj_salv TYPE REF TO cl_salv_table,
              build_end_of_page CHANGING obj_salv TYPE REF TO cl_salv_table.

ENDCLASS.

CLASS sales_order_disp IMPLEMENTATION.
  METHOD build_salesorder.
    SELECT FROM vbak INTO TABLE lt_vbak UP TO 10 ROWS.
  ENDMETHOD.

  METHOD disp_salesorder.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table   o_salv    " Basis Class Simple ALV Tables
          CHANGING
            t_table        lt_vbak
        ).
      CATCH cx_salv_msg.
    ENDTRY.
    me->build_top_of_page(
      CHANGING
        obj_salv o_salv ).

        me->build_end_of_page(
      CHANGING
        obj_salv o_salv ).

    o_salv->display).
  ENDMETHOD.

  METHOD build_top_of_page.
    DATA o_top TYPE REF TO cl_salv_form_layout_grid,
           o_label  TYPE REF TO cl_salv_form_label,
           o_flow   TYPE REF TO cl_salv_form_layout_flow.
    CREATE OBJECT o_top.
    o_top->create_label(
      EXPORTING
        row         =  1   " Natural Number
        column      =  1   " Natural Number
      RECEIVING
        r_value     =  o_label ).
    o_label->set_textvalue 'Sales Order Details' ).

    o_top->create_flow(
      EXPORTING
        row     2    " Natural Number
        column  =  1   " Natural Number
      RECEIVING
        r_value o_flow ).
   o_flow->create_text(
     EXPORTING
       text    'For the Month of Dec-2013' ).

    obj_salv->set_top_of_listvalue =  o_top ).
  ENDMETHOD.

  METHOD build_end_of_page.
    DATA o_end TYPE REF TO cl_salv_form_layout_grid,
           o_label  TYPE REF TO cl_salv_form_label,
           o_flow   TYPE REF TO cl_salv_form_layout_flow.
    CREATE OBJECT o_end.
    o_end->create_label(
      EXPORTING
        row         =  1   " Natural Number
        column      =  1   " Natural Number
      RECEIVING
        r_value     =  o_label ).
    o_label->set_textvalue 'SAP Labs India.' ).

    o_end->create_flow(
      EXPORTING
        row     2    " Natural Number
        column  =  1   " Natural Number
      RECEIVING
        r_value o_flow ).
   o_flow->create_text(
     EXPORTING
       text    'All rights reserved.' ).

    obj_salv->set_end_of_listvalue o_end ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATAo_salesord TYPE REF TO sales_order_disp.
  CREATE OBJECT o_salesord.
  o_salesord->build_salesorder).
  o_salesord->disp_salesorder).


_______________________________________________________________________________
O/P: The report output is as follows:






















Comments system

Disqus Shortname