Saturday, 4 January 2014

Table Events

Scenario: Creating a table with TMG and then creating  table events.

Step 1. Go to Tcode- SE11.









Step2. Provide the below table name and click on create button.

















Step3. Provide delivery class and other details and click on Technical settings.














Step4. Provide the details, Save it and click on the Back button.



















Step5. Under the fields tab, provide some fields and activate the table.















Step6. Navigate along the menu path to create the TMG.

















Step7. Provide the details and click on the Create button to create the TMG.




















Step8. After the TGM is created, navigate along the highlighted path.




















Step9. Select the screen and click on Continue button.















Step10. Click on the Layout button as highlighted.






























Step11. We will make the field 'ADD_YEAR' in display mode which will be automatically filled by the table events. Double click on the field 'ADD_YEAR'.















Step12. The below screen appears.

































Step13. Deselect the Input and output field and select output only.

































Step14. Now the field ADD_YEAR appears in Display mode. Click on Flow Logic button to go Back.

































Step15. Activate it and go back.

































Step16. Navigate along the highlighted path to create the table Event.




















Step17. Click on New Entries button.












Step18. Press F4 key from the keyboard to select one of the predefined event number.
















Step19. Below screen appears displaying all available table events.

































Step20. Select event 05 and Under the FORM Routine tab, provide a subroutine name and press Enter from key board. After that One Editor Icon will appear Under Editor tab. Click on the Editor Icon.
















Step21. Select the First Include program and click on continue button.















Step22. The selected include program will be inserted in the main program 'SAPLZSTUD_EVENT' and click on Continue button
















Step23. Provide the below code and activate it and go back.












Step24. Now go to SE38.









Step25. Provide the main program name 'SAPLZSTUD_EVENT' and click on change button.
















Step26. The Program status is inactive as the include containing the event is inserted in the program. Click on Activate button.






















Step27. The main program status is active.























Step28. Now in SE11, navigate along the high lighted path to create the record.

















Step29.  Click on New Entries button.















Step30. The screen appears in editable mode except the field 'ADD_YEAR'.















Step31. Provide the ID, name and mark and then hit Enter key from keyboard.














Step32. The table Event is triggered and the ADD_YEAR is filled with current Year vale.















Step33. Now lets create another event. So navigate along the highlighted path.



















Step34. Click on New Entries.













Step35.  Select the Event as '01', provide a subroutine name and hit Enter key from key board. Click on the Appearing Editor Icon under  Editor tab.
















Step36. Select the proposed Include and click on the continue button.















Step37. Click on Continue button.



















Step38. Provide the below code. Here the field symbol: <table2> carries the current record to be inserted in the table. For details refer to step number :. Activate it and go back.















Step39. So upto this we created two table  events.















Step40. In SE38, Provide teh main program name 'SAPLZSTUD_EVENT' and click on change button.



















Step41. The status is inactive as another include is inserted into it. Click on Activate button to activate it.


























Step42.  The status is active now.























Step43. Now navigate along the highlighted path to create table entries.


















Step44. Click on New Entries.















Step45. Provide the below values and hit Enter.
























Step46. The ADD_YEAR is filled by one of the table event. Now select the row and save it.























Step47. Now provide another vales for the record and hit Enter key from keyboard.























Step48. Select the particular row and click on Save button.






















Step49. The error message is thrown by the table event as the TOT_MARK is grater than 750.




















Step50.  To check the details, Go to SE38.









Step51. Provide the main program name and click on change button.


















Step52. Double click on the include.
























Step53. Put a break point.















Step54. In the table again create a new record, select the row and click on the Save button














Step55. The global variable <table2> contains the vale of the current record.










________________________________________________________________________________

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.




























_______________________________________________________________________________

Comments system

Disqus Shortname