SAP Business Partner-BAPI_BUPA_BANKDETAIL_ADD-Bank Details Upload Tool.
BAPI_BUPA_BANKDETAIL_ADD BAPI is used to create bank details for a business partner.
Any errors that may occur are returned as check results in the RETURN table. If an error occurs, the bank details are not created.
You can also state a bank details ID in the BANKDETAILID field. If you state an ID, the system checks whether this ID has already been assigned. If it has been assigned, a corresponding error message is returned by the RETURN table parameter. If you do not state a bank details ID when you create the bank details, the next free bank details ID is determined by the system and assigned to the record that you are currently creating.
In the BANKDETAILDATA-EXTERNALBANKID field you have the option to enter an external bank details ID. If you state an ID, the system checks whether this ID already exists. If it does exist, an error message is issued by the RETURN table parameter.
Entering a valid bank country in the BANKDETAILDATA structure is mandatory. The system checks that the bank country was entered.
The validity of the bank key entry in the BANKDETAILDATA-BANK_KEY field is also checked.
The combination of bank country, bank key, and account number must not exist already.
In the case of Japanese banks, the system checks that the BANKDETAILDATA-ACCOUNTHOLDER field is maintained. Information on the name of the account holder is mandatory for Japanese banks.
If no validity data is entered, then these newly created bank details are valid from the current date till 31.12.9999.
Any errors that may occur are returned as check results in the RETURN table. If an error occurs, the bank details are not created.
You can also state a bank details ID in the BANKDETAILID field. If you state an ID, the system checks whether this ID has already been assigned. If it has been assigned, a corresponding error message is returned by the RETURN table parameter. If you do not state a bank details ID when you create the bank details, the next free bank details ID is determined by the system and assigned to the record that you are currently creating.
In the BANKDETAILDATA-EXTERNALBANKID field you have the option to enter an external bank details ID. If you state an ID, the system checks whether this ID already exists. If it does exist, an error message is issued by the RETURN table parameter.
Entering a valid bank country in the BANKDETAILDATA structure is mandatory. The system checks that the bank country was entered.
The validity of the bank key entry in the BANKDETAILDATA-BANK_KEY field is also checked.
The combination of bank country, bank key, and account number must not exist already.
In the case of Japanese banks, the system checks that the BANKDETAILDATA-ACCOUNTHOLDER field is maintained. Information on the name of the account holder is mandatory for Japanese banks.
If no validity data is entered, then these newly created bank details are valid from the current date till 31.12.9999.
SAMPLE CODE:
*&---------------------------------------------------------------------*
*& Report ZMM_VENDOR_BANK_UPLOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm_vendor_bank_upload.
TYPES: BEGIN OF gty_final,
partner TYPE bu_partner, " Business Partner
bank_ctry TYPE banks, " Country Key
bank_key TYPE bankk, " Bank Key
bank_acct TYPE bankn, " Bank account number
ctrl_key TYPE bkont, " Bank Control Key
bank_ref TYPE bkref, " Reference specifications for bank details
accountholder TYPE bu_koinh, " Account Holder Name
bankaccountname TYPE bu_bankaccname, " Name of Bank Account
bankdetailvalidfrom TYPE bu_datfrom, " Valid From
bankdetailvalidto TYPE bu_datto, " Valid To
bank_account_type TYPE bu_account_type, " Bank Account Type
END OF gty_final,
BEGIN OF gty_log,
partner TYPE bu_partner, " Business Partner
bank_ctry TYPE banks, " Country Key
bank_key TYPE bankk, " Bank Key
bank_acct TYPE bankn, " Bank account number
ctrl_key TYPE bkont, " Bank Control Key
bank_ref TYPE bkref, " Reference specifications for bank details
accountholder TYPE bu_koinh, " Account Holder Name
bankaccountname TYPE bu_bankaccname, " Name of Bank Account
bankdetailvalidfrom TYPE bu_datfrom, " Valid From
bankdetailvalidto TYPE bu_datto, " Valid To
bank_account_type TYPE bu_account_type, " Bank Account Type
type TYPE bapiret2-type,
id TYPE bapiret2-id,
number TYPE bapiret2-number,
message TYPE bapiret2-message,
END OF gty_log.
DATA: gt_final TYPE TABLE OF gty_final,
gwa_final TYPE gty_final,
gt_log TYPE TABLE OF gty_log,
gwa_log TYPE gty_log.
DATA: gv_ucomm TYPE sy-ucomm,
gv_string TYPE xstring,
gwa_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat.
DATA: gv_validto TYPE datum VALUE '99991231',
gv_begincol TYPE i VALUE '1',
gv_beginrow TYPE i VALUE '2',
gv_endcol TYPE i VALUE '150',
gv_endrow TYPE i VALUE '65000',
gv_flag TYPE flag VALUE 'X',
gv_user TYPE ad_flgmob VALUE '3',
gv_user1 TYPE ad_flgmob VALUE '1',
gv_cons_001 TYPE ad_consnum VALUE '001',
gv_cons_002 TYPE ad_consnum VALUE '002',
gv_cons_003 TYPE ad_consnum VALUE '003'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_fname TYPE rlgrap-filename.
SELECTION-SCREEN: SKIP 1.
SELECTION-SCREEN PUSHBUTTON /1(20) TEXT-002 USER-COMMAND dwld MODIF ID upd.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN.
gv_ucomm = sy-ucomm.
AT SELECTION-SCREEN OUTPUT.
IF gv_ucomm = 'DWLD'.
PERFORM download_format.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM f4_filepath.
START-OF-SELECTION.
PERFORM upload_file.
PERFORM add_bank.
PERFORM display_log.
*&---------------------------------------------------------------------*
*& Form download_format
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM download_format .
CLEAR: gv_string, gt_fcat, gwa_fcat.
PERFORM fill_catalog USING 'PARTNER' 'Business Partner'.
PERFORM fill_catalog USING 'BANK_CTRY' 'Country Key'.
PERFORM fill_catalog USING 'BANK_KEY' 'Bank Key'.
PERFORM fill_catalog USING 'BANK_ACCT' 'Bank Account No.'.
PERFORM fill_catalog USING 'CTRL_KEY' 'Bank Control Key'.
PERFORM fill_catalog USING 'BANK_REF' 'Reference'.
PERFORM fill_catalog USING 'ACCOUNTHOLDER' 'Account Holder Name'.
PERFORM fill_catalog USING 'BANKACCOUNTNAME' 'Name Of Bank Account'.
PERFORM fill_catalog USING 'BANKDETAILVALIDFROM' 'Valid From'.
PERFORM fill_catalog USING 'BANKDETAILVALIDTO' 'Valid To'.
PERFORM fill_catalog USING 'BANK_ACCOUNT_TYPE' 'Bank Account Type'.
CALL FUNCTION 'ZDOWNLOAD_FILE'
EXPORTING
i_fieldcat = gt_fcat
i_xlsx = gv_flag
IMPORTING
e_xstring = gv_string
CHANGING
c_data = gt_final.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f4_filepath
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f4_filepath .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-cprog
IMPORTING
file_name = p_fname.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form fill_catalog
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
FORM fill_catalog USING p_fname p_text.
CLEAR: gwa_fcat.
gwa_fcat-fieldname = p_fname.
gwa_fcat-seltext = p_text.
APPEND gwa_fcat TO gt_fcat.
CLEAR gwa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM upload_file .
FIELD-SYMBOLS : <col> TYPE any.
DATA: BEGIN OF gt_intern OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF gt_intern.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = gv_begincol
i_begin_row = gv_beginrow
i_end_col = gv_endcol
i_end_row = gv_endrow
TABLES
intern = gt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
RAISE read_failed.
ENDIF.
LOOP AT gt_intern.
ASSIGN COMPONENT gt_intern-col OF STRUCTURE gwa_final TO <col>.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
<col> = gt_intern-value.
ENDCATCH.
IF sy-subrc = 1.
WRITE: / 'Conversion error:',gt_intern-value.
EXIT.
ENDIF.
AT END OF row.
APPEND gwa_final TO gt_final.
CLEAR gwa_final.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form add_bank
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM add_bank .
DATA: lwa_bankdetail TYPE bapibus1006_bankdetail,
lv_out TYPE bapibus1006_head-bankdetailid,
lt_return TYPE TABLE OF bapiret2,
lwa_return TYPE bapiret2.
LOOP AT gt_final INTO gwa_final.
gwa_final-partner = |{ gwa_final-partner ALPHA = IN }|.
MOVE-CORRESPONDING gwa_final TO lwa_bankdetail.
CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
EXPORTING
businesspartner = gwa_final-partner
bankdetaildata = lwa_bankdetail
IMPORTING
bankdetailidout = lv_out
TABLES
return = lt_return.
READ TABLE lt_return INTO lwa_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
MOVE-CORRESPONDING gwa_final TO gwa_log.
gwa_log-type = 'S'.
gwa_log-id = '00'.
gwa_log-number = '000'.
gwa_log-message = 'Bank Details Added Successfully.'.
APPEND gwa_log TO gt_log.
CLEAR: gwa_log.
ELSE.
MOVE-CORRESPONDING gwa_final TO gwa_log.
gwa_log-type = lwa_return-type.
gwa_log-id = lwa_return-id.
gwa_log-number = lwa_return-number.
gwa_log-message = lwa_return-message.
APPEND gwa_log TO gt_log.
CLEAR: gwa_log.
ENDIF.
CLEAR: lwa_bankdetail, lv_out, lt_return, lwa_return.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display_log
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_log .
CALL FUNCTION 'ZDISPLAY_ALV'
EXPORTING
i_title = 'Upload Log Details'
i_program = sy-repid
TABLES
t_alv = gt_log.
ENDFORM.
*& Report ZMM_VENDOR_BANK_UPLOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm_vendor_bank_upload.
TYPES: BEGIN OF gty_final,
partner TYPE bu_partner, " Business Partner
bank_ctry TYPE banks, " Country Key
bank_key TYPE bankk, " Bank Key
bank_acct TYPE bankn, " Bank account number
ctrl_key TYPE bkont, " Bank Control Key
bank_ref TYPE bkref, " Reference specifications for bank details
accountholder TYPE bu_koinh, " Account Holder Name
bankaccountname TYPE bu_bankaccname, " Name of Bank Account
bankdetailvalidfrom TYPE bu_datfrom, " Valid From
bankdetailvalidto TYPE bu_datto, " Valid To
bank_account_type TYPE bu_account_type, " Bank Account Type
END OF gty_final,
BEGIN OF gty_log,
partner TYPE bu_partner, " Business Partner
bank_ctry TYPE banks, " Country Key
bank_key TYPE bankk, " Bank Key
bank_acct TYPE bankn, " Bank account number
ctrl_key TYPE bkont, " Bank Control Key
bank_ref TYPE bkref, " Reference specifications for bank details
accountholder TYPE bu_koinh, " Account Holder Name
bankaccountname TYPE bu_bankaccname, " Name of Bank Account
bankdetailvalidfrom TYPE bu_datfrom, " Valid From
bankdetailvalidto TYPE bu_datto, " Valid To
bank_account_type TYPE bu_account_type, " Bank Account Type
type TYPE bapiret2-type,
id TYPE bapiret2-id,
number TYPE bapiret2-number,
message TYPE bapiret2-message,
END OF gty_log.
DATA: gt_final TYPE TABLE OF gty_final,
gwa_final TYPE gty_final,
gt_log TYPE TABLE OF gty_log,
gwa_log TYPE gty_log.
DATA: gv_ucomm TYPE sy-ucomm,
gv_string TYPE xstring,
gwa_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat.
DATA: gv_validto TYPE datum VALUE '99991231',
gv_begincol TYPE i VALUE '1',
gv_beginrow TYPE i VALUE '2',
gv_endcol TYPE i VALUE '150',
gv_endrow TYPE i VALUE '65000',
gv_flag TYPE flag VALUE 'X',
gv_user TYPE ad_flgmob VALUE '3',
gv_user1 TYPE ad_flgmob VALUE '1',
gv_cons_001 TYPE ad_consnum VALUE '001',
gv_cons_002 TYPE ad_consnum VALUE '002',
gv_cons_003 TYPE ad_consnum VALUE '003'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_fname TYPE rlgrap-filename.
SELECTION-SCREEN: SKIP 1.
SELECTION-SCREEN PUSHBUTTON /1(20) TEXT-002 USER-COMMAND dwld MODIF ID upd.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN.
gv_ucomm = sy-ucomm.
AT SELECTION-SCREEN OUTPUT.
IF gv_ucomm = 'DWLD'.
PERFORM download_format.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM f4_filepath.
START-OF-SELECTION.
PERFORM upload_file.
PERFORM add_bank.
PERFORM display_log.
*&---------------------------------------------------------------------*
*& Form download_format
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM download_format .
CLEAR: gv_string, gt_fcat, gwa_fcat.
PERFORM fill_catalog USING 'PARTNER' 'Business Partner'.
PERFORM fill_catalog USING 'BANK_CTRY' 'Country Key'.
PERFORM fill_catalog USING 'BANK_KEY' 'Bank Key'.
PERFORM fill_catalog USING 'BANK_ACCT' 'Bank Account No.'.
PERFORM fill_catalog USING 'CTRL_KEY' 'Bank Control Key'.
PERFORM fill_catalog USING 'BANK_REF' 'Reference'.
PERFORM fill_catalog USING 'ACCOUNTHOLDER' 'Account Holder Name'.
PERFORM fill_catalog USING 'BANKACCOUNTNAME' 'Name Of Bank Account'.
PERFORM fill_catalog USING 'BANKDETAILVALIDFROM' 'Valid From'.
PERFORM fill_catalog USING 'BANKDETAILVALIDTO' 'Valid To'.
PERFORM fill_catalog USING 'BANK_ACCOUNT_TYPE' 'Bank Account Type'.
CALL FUNCTION 'ZDOWNLOAD_FILE'
EXPORTING
i_fieldcat = gt_fcat
i_xlsx = gv_flag
IMPORTING
e_xstring = gv_string
CHANGING
c_data = gt_final.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f4_filepath
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f4_filepath .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-cprog
IMPORTING
file_name = p_fname.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form fill_catalog
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
FORM fill_catalog USING p_fname p_text.
CLEAR: gwa_fcat.
gwa_fcat-fieldname = p_fname.
gwa_fcat-seltext = p_text.
APPEND gwa_fcat TO gt_fcat.
CLEAR gwa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM upload_file .
FIELD-SYMBOLS : <col> TYPE any.
DATA: BEGIN OF gt_intern OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF gt_intern.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = gv_begincol
i_begin_row = gv_beginrow
i_end_col = gv_endcol
i_end_row = gv_endrow
TABLES
intern = gt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
RAISE read_failed.
ENDIF.
LOOP AT gt_intern.
ASSIGN COMPONENT gt_intern-col OF STRUCTURE gwa_final TO <col>.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
<col> = gt_intern-value.
ENDCATCH.
IF sy-subrc = 1.
WRITE: / 'Conversion error:',gt_intern-value.
EXIT.
ENDIF.
AT END OF row.
APPEND gwa_final TO gt_final.
CLEAR gwa_final.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form add_bank
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM add_bank .
DATA: lwa_bankdetail TYPE bapibus1006_bankdetail,
lv_out TYPE bapibus1006_head-bankdetailid,
lt_return TYPE TABLE OF bapiret2,
lwa_return TYPE bapiret2.
LOOP AT gt_final INTO gwa_final.
gwa_final-partner = |{ gwa_final-partner ALPHA = IN }|.
MOVE-CORRESPONDING gwa_final TO lwa_bankdetail.
CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
EXPORTING
businesspartner = gwa_final-partner
bankdetaildata = lwa_bankdetail
IMPORTING
bankdetailidout = lv_out
TABLES
return = lt_return.
READ TABLE lt_return INTO lwa_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
MOVE-CORRESPONDING gwa_final TO gwa_log.
gwa_log-type = 'S'.
gwa_log-id = '00'.
gwa_log-number = '000'.
gwa_log-message = 'Bank Details Added Successfully.'.
APPEND gwa_log TO gt_log.
CLEAR: gwa_log.
ELSE.
MOVE-CORRESPONDING gwa_final TO gwa_log.
gwa_log-type = lwa_return-type.
gwa_log-id = lwa_return-id.
gwa_log-number = lwa_return-number.
gwa_log-message = lwa_return-message.
APPEND gwa_log TO gt_log.
CLEAR: gwa_log.
ENDIF.
CLEAR: lwa_bankdetail, lv_out, lt_return, lwa_return.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display_log
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_log .
CALL FUNCTION 'ZDISPLAY_ALV'
EXPORTING
i_title = 'Upload Log Details'
i_program = sy-repid
TABLES
t_alv = gt_log.
ENDFORM.
Download the below FM's from the links given below.
2. ZDISPLAY_ALV