0% found this document useful (0 votes)
238 views32 pages

Using BAdI BNK BADI FILE ERROR ALRT EN V 1.0

The document describes how to customize alert notifications for file errors in Bank Communication Management. It provides steps to define additional fields to include in generated emails, and to override the default SAP implementation with a custom BAdI implementation. The steps create an enhancement for an existing BAdI method to add more data from payment batches, such as totals, counts, and spool requests, to the alert notifications.

Uploaded by

ashwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views32 pages

Using BAdI BNK BADI FILE ERROR ALRT EN V 1.0

The document describes how to customize alert notifications for file errors in Bank Communication Management. It provides steps to define additional fields to include in generated emails, and to override the default SAP implementation with a custom BAdI implementation. The steps create an enhancement for an existing BAdI method to add more data from payment batches, such as totals, counts, and spool requests, to the alert notifications.

Uploaded by

ashwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Using BAdI BNK_BADI_FILE_ERROR_ALRT

You want to use alerting mechanism in Bank Communication Management with BAdI
BNK_BADI_FILE_ERROR_ALRT. In this document is described how to define additional fields to be
included into generated e-mail.

Switching-Off predefined BAdI BNK_BADI_PAYM_ALRT_DEFAULT


Please, follow the steps:

- Start transaction SE24 and enter in field Object Type CL_BNK_BADI_FIL_ERR_ALRT_IMPL

- Press button Display (F7)

- Double-click on method name IF_EX_BNK_FILE_ALRT~CREATE_ALERT


- Click on button Enhance (Ctrl+F5)

- Editor will be change mode with enhancements

- From menu choose option Edit → Enhancement Operations → Show Implicit Enhancement
Options
- Select the very first implicit enhancement at the beginning of method
IF_EX_BNK_FILE_ALRT~CREATE_ALERT and click on button Create Enhancement
Implementation ... (Ctrl+Shift+F8)

- Choose a type for the enhancement as "Code"


- Fill in values and press OK button, for example:
o Enhancement Implementation: ZBNK_BADI_FIL_ERR_ALRT_IMPL
o Short Text: Implicit Enhancement: Method CREATE_ALERT

- Use package valid for your local transports in layer HOME, which could be transported within
your landscape, in our example we are using local package $TMP, as we are not going to
transport Customer BAdI Enhancement. Press Save button (Enter)

- Type in code RETURN. and activate your changes by pressing button Activate Enhancements
(Ctrl+F3)
- SAP default implementation in BAdI BNK_BADI_FILE_ERROR_ALERT will not be executed
Customer BAdI Implantation BNK_BADI_FILE_ERROR_ALRT

Customer BAdI Implementation

Please, follow the steps:

- Start transaction SE18 and enter in field Enhancement Spot BNK_BADI_FILE_ERROR_ALRT


- Press button Display (F6)

- Click on button Create BAdI Implementation


- We will be creating new BAdI implementation, so click on button Create Enhancement
Implementation

- Fill in required values, for example:


o Enhancement Implementation: ZBNK_BADI_FILE_ERROR_ALRT
o Short Text: Customer Enhancement ZBNK_BADI_FILE_ERROR_ALRT
- Press button Creation of Enhancement (Enter)
- Use package valid for your local transports in layer HOME, which could be transported within
your landscape, in our example we are using local package $TMP, as we are not going to
transport Customer BAdI Enhancement
- Press Save button (Enter)

- Press button Select Specified Enhancement Implementation (Enter)

- Create BAdI Implementation, fill in for example values:


o BAdI Implementation: ZBNK_BADI_FILE_ERROR_ALRT
o Description: Customer BAdI Implementation: ZBNK_BADI_FILE_ERROR_ALRT
o Implementing Class: ZCL_BNK_BADI_FILE_ERROR_ALRT
- Press button Continue (Enter)

- Use the same package as before, in our example local package $TMP
- Press Save button (Enter)

Implementing Class

Now you have the Customer BAdI implementation and you can create the class to enable processing
of pain.002.001.02 in CPON Service incoming files
- Double-click in button Implementing Class

- Double-click on method IF_EX_BNK_FILE_ALRT~CREATE_ALERT


- Answer Yes on question

- Copy the code from the example

METHOD if_ex_bnk_file_alrt~create_alert.
* "nte1389302 Populate Container for File Error
CONSTANTS: con_file_cr_error TYPE j_vorgang VALUE 'BFE'.
DATA: l_alert_id TYPE salrtextid,
li_container TYPE REF TO if_swf_cnt_container,
l_str_pay_alrt TYPE bnk_str_pay_stat,
l_laufd TYPE laufd, "nte1389302
l_laufi TYPE laufi,
l_srtf3 TYPE srtf1_fpm,
l_str_reguhm TYPE reguhm,
l_rest(28).

CHECK i_batch_no IS NOT INITIAL.

* SAP Support: Dec-20-2021 --------------------------------------------

* Add some other fileds of BNK_BATCH_HEADER ===========================


CONSTANTS:
con_field_paym_sum TYPE string VALUE 'PAYM_SUM',
con_field_maxpayamt TYPE string VALUE 'MAXPAYAMT_RULECU',
con_field_item_cnt TYPE string VALUE 'ITEM_CNT',
con_field_paym_curr TYPE string VALUE 'PAYM_CURR'.
DATA:
l_rule_curr TYPE bnk_com_rule_curr,
l_paym_sum TYPE rwbtr,
l_paym_sum_conv TYPE rwbtr,
l_maxpayamt_rulecu TYPE bnk_com_max_pymntamt_in_rulcur,
l_maxpayamt_rulecu_conv TYPE bnk_com_max_pymntamt_in_rulcur,
l_str_bnk_batch_header TYPE bnk_batch_header,
l_str_bnk_batch_item TYPE bnk_batch_item.
FIELD-SYMBOLS:
<fs_paym_sum> TYPE any,
<fs_maxpayamt> TYPE any,
<fs_item_cnt> TYPE any,
<fs_paym_curr> TYPE any.

CALL FUNCTION 'BNK_API_GET_RULE_CURR'


IMPORTING
e_rule_curr = l_rule_curr.

SELECT SINGLE *
FROM bnk_batch_header
INTO l_str_bnk_batch_header
WHERE batch_no EQ i_batch_no. "#EC CI_NOFIELD
IF sy-subrc EQ 0.
MOVE-CORRESPONDING l_str_bnk_batch_header TO l_str_pay_alrt.

ASSIGN COMPONENT:
con_field_paym_sum OF STRUCTURE l_str_pay_alrt TO <fs_paym_sum>,
con_field_maxpayamt OF STRUCTURE l_str_pay_alrt TO <fs_maxpayamt>,
con_field_item_cnt OF STRUCTURE l_str_pay_alrt TO <fs_item_cnt>,
con_field_paym_curr OF STRUCTURE l_str_pay_alrt TO <fs_paym_curr>.

IF <fs_paym_sum> IS ASSIGNED OR <fs_maxpayamt> IS ASSIGNED OR


<fs_item_cnt> IS ASSIGNED OR <fs_paym_curr> IS ASSIGNED.

SELECT *
FROM bnk_batch_item
INTO l_str_bnk_batch_item
WHERE batch_no EQ i_batch_no.

* Number of Payments
IF <fs_item_cnt> IS ASSIGNED.
ADD 1 TO <fs_item_cnt>.
ENDIF.

* Amount Paid in the Payment Currency - Calculation


IF <fs_paym_sum> IS ASSIGNED.
l_paym_sum = l_paym_sum + abs( l_str_bnk_batch_item-amt_rulecu ).
ENDIF.

* Maximum Payment Amount in Rule Currency - Calculation


IF <fs_maxpayamt> IS ASSIGNED.
IF abs( l_str_bnk_batch_item-amt_rulecu ) GT l_maxpayamt_rulecu.
l_maxpayamt_rulecu = abs( l_str_bnk_batch_item-amt_rulecu ).
ENDIF.
ENDIF.

ENDSELECT.

* Amount Paid in the Payment Currency


IF <fs_paym_sum> IS ASSIGNED AND <fs_paym_curr> IS ASSIGNED.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
date = sy-datum
foreign_currency = <fs_paym_curr>
local_amount = abs( l_paym_sum )
local_currency = l_rule_curr
IMPORTING
foreign_amount = l_paym_sum_conv
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
IF sy-subrc EQ 0.
WRITE abs( l_paym_sum_conv ) TO <fs_paym_sum>
CURRENCY <fs_paym_curr>.
ENDIF.
ELSEIF <fs_paym_sum> IS ASSIGNED.
WRITE abs( l_paym_sum ) TO <fs_paym_sum>.
ENDIF.

* Maximum Payment Amount in Rule Currency


IF <fs_maxpayamt> IS ASSIGNED AND <fs_paym_curr> IS ASSIGNED.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
date = sy-datum
foreign_currency = <fs_paym_curr>
local_amount = abs( l_maxpayamt_rulecu )
local_currency = l_rule_curr
IMPORTING
foreign_amount = l_maxpayamt_rulecu_conv
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
IF sy-subrc EQ 0.
WRITE abs( l_maxpayamt_rulecu_conv ) TO <fs_maxpayamt>
CURRENCY <fs_paym_curr>.
ENDIF.
ELSEIF <fs_maxpayamt> IS ASSIGNED.
WRITE abs( l_maxpayamt_rulecu ) TO <fs_maxpayamt>.
ENDIF.

ENDIF. "IF <*> IS ASSIGNED

ENDIF. "IF sy-subrc EQ 0.

* Add spool request from JOB PAYM:LAUFD_F/LAUFI_F/* ===================


CONSTANTS:
con_field_spool_ln01 TYPE string VALUE 'SPOOL_LN01',
con_field_spool TYPE string VALUE 'SPOOL_LN'.
DATA:
l_job_name TYPE string,
l_rqident TYPE tsp01-rqident,
l_str_tbtcp TYPE tbtcp,
l_tab_list_str TYPE list_string_table,
l_line_string TYPE string,
l_index TYPE n LENGTH 2,
l_field_name TYPE string.

FIELD-SYMBOLS:
<fs_spool> TYPE any.

ASSIGN COMPONENT con_field_spool_ln01 OF STRUCTURE l_str_pay_alrt


TO <fs_spool>.
IF <fs_spool> IS ASSIGNED.

CONCATENATE 'PAYM:' l_str_bnk_batch_header-laufd_f '/'


l_str_bnk_batch_header-laufi_f '/%'
INTO l_job_name.

* Select SPOOL Job by Job Name


SELECT *
FROM tbtcp
INTO l_str_tbtcp
WHERE jobname LIKE l_job_name.

FREE: l_tab_list_str.
l_rqident = l_str_tbtcp-listident.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB_DAT'
EXPORTING
rqident = l_rqident
IMPORTING
buffer_dat = l_tab_list_str[]
EXCEPTIONS
no_such_job = 1
not_abap_list = 2
job_contains_no_data = 3
selection_empty = 4
no_permission = 5
can_not_access = 6
read_error = 7
OTHERS = 8.
IF sy-subrc EQ 0.
LOOP AT l_tab_list_str INTO l_line_string.
IF l_index EQ 99.
* Only first 99 lines are displayed
EXIT.
ENDIF.

ADD 1 TO l_index.
CONCATENATE con_field_spool l_index INTO l_field_name.

ASSIGN COMPONENT l_field_name OF STRUCTURE l_str_pay_alrt


TO <fs_spool>.
IF sy-subrc EQ 0.
<fs_spool> = l_line_string.
ENDIF.
ENDLOOP. "LOOP AT l_tab_list_str INTO l_line_string.

ENDIF. "IF sy-subrc EQ 0.


ENDSELECT. "SELECT * FROM tbtcp INTO l_str_tbtcp WHERE jobname LIKE l_j
ob_name.

ENDIF. "IF <fs_spool> IS ASSIGNED.

* SAP Support: Dec-20-2021 --------------------------------------------

SELECT SINGLE * FROM reguhm INTO l_str_reguhm WHERE batchno = i_batch_no.


"#EC CI_NOFIELD

l_str_pay_alrt-batch_no = i_batch_no.
l_str_pay_alrt-zbukr = l_str_reguhm-zbukr.
l_str_pay_alrt-hbkid = l_str_reguhm-hbkid.
l_str_pay_alrt-sys_stat = con_file_cr_error.

CALL FUNCTION 'BSV_GET_TEXT_VRGNG'


EXPORTING
langu = sy-langu
vrgng = con_file_cr_error
IMPORTING
txt = l_str_pay_alrt-sys_stat_text.

* Rule Id "nte1389302
IF l_str_reguhm-laufi+5(1) = 'B'.
l_laufi = l_str_reguhm-laufi.
l_laufd = l_str_reguhm-laufd.
ELSE.
l_laufi = l_str_reguhm-laufi_m.
l_laufd = l_str_reguhm-laufd_m.
ENDIF.
SELECT SINGLE srtf3 FROM reguh INTO l_srtf3
WHERE laufd = l_laufd
AND laufi = l_laufi
AND xvorl = space
AND zbukr = l_str_reguhm-zbukr
AND lifnr = l_str_reguhm-lifnr
AND kunnr = l_str_reguhm-kunnr
AND empfg = l_str_reguhm-empfg
AND vblnr = l_str_reguhm-vblnr.

IF l_srtf3 CS cl_bnk_constants=>con_seperator.
SPLIT l_srtf3 AT cl_bnk_constants=>con_seperator INTO
l_str_pay_alrt-rule_id l_rest.
ELSE.
l_str_pay_alrt-rule_id = l_srtf3.
ENDIF.

* Declaration of the alert-container including application data


TRY.
li_container = cl_swf_cnt_factory=>create( ).
CATCH cx_swf_utl_no_instance_found
cx_swf_utl_obj_create_failed .
c_alert_rc = 98.
ENDTRY.

TRY.
li_container->element_set(
name = 'BNK_STR_PAY_STAT'
value = l_str_pay_alrt ).

CATCH cx_swf_cnt_cont_access_denied
cx_swf_cnt_elem_not_found
cx_swf_cnt_elem_access_denied
cx_swf_cnt_elem_type_conflict
cx_swf_cnt_unit_type_conflict
cx_swf_cnt_elem_def_invalid
cx_swf_cnt_invalid_qname
cx_swf_cnt_container .
c_alert_rc = 99.
ENDTRY.

CALL FUNCTION 'SALRT_CREATE_API'


EXPORTING
ip_category = 'PAYALRT'
ii_container = li_container
ip_wait_on_commit = ' '
IMPORTING
ep_alert_id = l_alert_id
EXCEPTIONS
alert_category_unknown = 1
alert_no_recipients = 2
alert_error_unknown = 3
destination_undefined = 4
communication_failure = 5
system_failure = 6
OTHERS = 7.

c_alert_rc = sy-subrc.
c_alert_id = l_alert_id.

ENDMETHOD.
- Activate all objects related to the Customer BAdI Implementation
- Press button Activate (Ctrl+F3)

- Select all objects by pressing button Select All (F9)


- And press button Continue (Enter)

Check the Implementation is called

At this moment you should be able to influence alerting mechanism in case of status Payment
Medium Creation Error. To be sure navigate back to Customer BAdI Implementation:

- Press button Back (F3)


- Double-click on BAdI name:

- You can see, that the Implementation is Active and will be called
(Optional) Disabling the feature

If you want to disable this feature, please, in change mode uncheck the option "Implementation is
active" and activate the Customer BAdI Implementation, please keep in mind, that with implicit
enhancement in class CL_BNK_BADI_FIL_ERR_ALRT_IMPL, nothing might be called:

As a result will be:


Repeat the same to activate the feature again.

Append Structure to BNK_STR_PAY_STAT


Once new BAdI implementation is active, we need to append new fields to the structure
BNK_STR_PAY_STAT.

Please, follow the steps:

- Start transaction SE11, select radio button next to Data type and field BNK_STR_PAY_STAT
- Press button Display (F7)

- From menu choose Goto → Append Structure (F5)


- Enter any name, for example ZMAIL_ALERT and press Continue (Enter) button

- Enter description: Append Structure to BNK_STR_PAY_STAT


- Add any fields from DB table BNK_BATCH_HEADER
- Because you can enhance structure BNK_STR_PAY_STAT with characters only, use for fields
PAYM_SUM and MAXPAYAMT_RULECU Data Element CHAR20

- For adding values from spool list, we will add Built-In Types fields
- You can add fields from SPOOL_LN01 to SPOOL_LN99

- Activate append structure ZMAIL_ALERT by pressing button Activate (Ctrl+F3)


- Use package valid for your local transports in layer HOME, which could be transported within
your landscape, in our example we are using local package $TMP, as we are not going to
transport Customer BAdI Enhancement
- Press Save button (Enter)

- You can ignore warnings


- When you return back to the structure BNK_STR_PAY_STAT, you will see:

Editing Alert Category in transaction ALRTCATDEF

Once new BAdI implementation is active, we need to append new fields to the structure
BNK_STR_PAY_STAT.

Please, follow the steps:

- Start transaction ALTRCATDEF


- Under Treasury Alerts add new Alert Category PAYALRT with values like this setup:

- With detail

- Under Container add structure BNK_STR_PAY_STAT


- And Properties
- Binding could be on Properties Tab
- Long and short text could be:

- Short Text
Bank file Alert Company &BNK_STR_PAY_STAT.ZBUKR& Bank &BNK_STR_PAY_STAT.HBKID& Doc
&BNK_STR_PAY_STAT.GRP_FIELD1_VALUE&
- Long Text
Error in Payment Bank File with following Details:
Company &BNK_STR_PAY_STAT.ZBUKR&
House bank &BNK_STR_PAY_STAT.HBKID&
Batch Number &BNK_STR_PAY_STAT.BATCH_NO&
----------------------------------------------------------------------
Amount Paid &BNK_STR_PAY_STAT.PAYM_SUM& &BNK_STR_PAY_STAT.PAYM_CURR&
Maximum &BNK_STR_PAY_STAT.MAXPAYAMT_RULECU&
&BNK_STR_PAY_STAT.PAYM_CURR&
Payment Items &BNK_STR_PAY_STAT.ITEM_CNT&
----------------------------------------------------------------------
Create User &BNK_STR_PAY_STAT.CRUSR&
Change Date &BNK_STR_PAY_STAT.CHDATE&
KZ Payment DOC &BNK_STR_PAY_STAT.GRP_FIELD1_VALUE&
----------------------------------------------------------------------
Message & Message Text
&BNK_STR_PAY_STAT.SPOOL_LN01&
&BNK_STR_PAY_STAT.SPOOL_LN02&
&BNK_STR_PAY_STAT.SPOOL_LN03&
- Save your changes by pressing button Save (Ctrl+S)

You might also like