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