Custom Logic and BADI

You use this instruction to call any custom ABAP programming you have written.

Activities

Run the following instruction to call custom ABAP programs:

*CALL_CUSTOM_LOGIC <filter_value_of_the_BADI>

where filter_value_of_the_BADI is the name of the filter you provided during the BADI implementation of UJ_CUSTOM_LOGIC BADI.

Custom logic example

*CALL_CUSTOM_LOGIC COMPLEX_ALLOCATION

BADI examples

*START_BADI / *END_BADI call any custom ABAP programming written using UJ_CUSTOM_LOGIC BADI (Transaction SE19) and allow you to export parameters to ABAP codes in the BADI.

Syntax

*START_BADI <filter_value_of_your_BADI_implementation>

<key1> = <value1>

<key2> = <value2>

*END_BADI

where filter_value_of_your_BADI_implementation is the name of the filter you provided during the BADI implementation of UJ_CUSTOM_LOGIC BADI.

Syntax example

The following example shows how to call an implemented BADI, with CALC_ACCT as the filter value, for adding two accounts to a destination account:

*START_BADI ROUND

DECIMAL = 2

*END_BADI

The DECIMAL parameter is visible in the IT_PARAM internal table inside the EXECUTE method. In the EXECUTE method, you can write custom code to change the incoming transactional data of CT_DATA.

Optional Parameters

You can use the following optional parameters within a *START_BADI / *END_BADI instruction:

  • Query - Performs the default query. Valid values are On, the default, and Off. Set Query to Off if you want to perform your own query.

  • Write - Automatically writes back the data. Valid values are On, the default, and Off.

Example

Implementing code (in EXECUTE method of the implemented class) for declining depreciation

Note

Before you can use a BADI in script logic, implement UJ_CUSTOM_LOGIC BADI from transaction SE19. See the ABAP online help at http://help.sap.com/saphelp_nw70/helpdata/en/32/a83942424dac04e10000000a1550b0/content.htmInformation published on SAP site. for information on how to implement a BADI.

METHOD if_uj_custom_logic~execute.

DATA: ls_param TYPE ujk_s_script_logic_hashentry,

l_log TYPE string,

l_ast_acct(16) TYPE c,

l_year(3) TYPE n,

l_percentage(3) TYPE p,

lo_model TYPE REF TO if_uj_model,

lo_dim TYPE REF TO if_uja_dim_data,

ls_dim TYPE uja_s_dim,

time_dim(16) TYPE c,

lr_rec TYPE REF TO data,

lr_result_rec TYPE REF TO data,

l_intermediate_value TYPE uj_sdata,

lt_final TYPE REF TO data.

FIELD-SYMBOLS: <ls_rec> TYPE ANY,

<ls_result_rec> TYPE ANY,

<ls_time> TYPE ANY,

<ls_signed.data> TYPE ANY,

<lt_final> TYPE STANDARD TABLE

* Make sure all the parameters are passed.

CLEAR ls_param.

READ TABLE it_param WITH KEY hashkey = 'YEAR' INTO ls_param.

IF sy-subrc NE 0.

l_log = 'You have not specified the parameter ''YEAR'' which is required.'.

cl_ujk_logger=>log( i_object = l_log ).

RAISE EXCEPTION TYPE cx_uj_custom_logic.

EXIT.

ENDIF.

l_year = ls_param-hashvalue.

CLEAR ls_param.

READ TABLE it_param WITH KEY hashkey = 'PERCENTAGE' INTO ls_param.

IF sy-subrc NE 0.

l_log = 'You have not specified the parameter ''PERCENTAGE'' which is required.'.

cl_ujk_logger=>log( i_object = l_log ).

RAISE EXCEPTION TYPE cx_uj_custom_logic.

EXIT.

ENDIF.

l_percentage = ls_param-hashvalue.

* Get name of the account dim

cl_uj_model=>get_model( EXPORTING i_appset_id = i_appset_id

RECEIVING ro_model = lo_model ).

CALL METHOD lo_model->get_dim_data_by_type

EXPORTING

i_dim_type = uj00_cs_dim_type-time

i_appl_id

= i_appl_id

RECEIVING

ro_dim_data = lo_dim.

TRY.

CALL METHOD lo_dim->get_info

IMPORTING

es_dim_info = ls_dim.

ENDTRY.

time_dim = ls_dim-dimension. TRANSLATE time_dim TO UPPER CASE.

CREATE DATA lt_final LIKE ct_data.

ASSIGN lt_final->* TO <lt_final>. CREATE DATA lr_result_rec LIKE LINE OF ct_data. ASSIGN lr_result_rec->* TO <ls_result_rec>. CREATE DATA lr_rec LIKE LINE OF ct_data. ASSIGN lr_rec->* TO <ls_rec>.

* Loop through incoming data and create a result set

LOOP AT ct_data ASSIGNING <ls_rec>.

<ls_result_rec> = <ls_rec>.

ASSIGN COMPONENT time_dim OF STRUCTURE <ls_result_rec> TO <ls_time>.

<ls_time>+0(4) = is <ls_time>+0(4) + l_year.

ASSIGN COMPONENT 'SIGNEDDATA' OF STRUCTURE <ls_result_rec> TO <ls_signeddata>.

DO l_year TIMES.

l_intermediate_value = l_intermediate_value + ( <ls_signeddata> - l_intermediate_value ) * l_percentage / 100.

ENDDO.

<ls_signeddata> = <ls_signeddata> - l_intermediate_value.

APPEND <ls_result_rec> TO <lt_final>.

ENDLOOP.

* Send the result data back.

Note

Business Planning and Consolidation always overwrites existing values.

ct_data = <lt_final>.

ENDMETHOD.

Script logic file content to call the BADI:

*START_BADI DECD

QUERY = ON

WRITE = ON

YEAR = 1

PERCENTAGE = 10 *END_BADI

Note

ET_MESSAGE in the BADI logs the messages to the Data Manager.

If you want to stop the execution, raise the cx_uj_custom_logic exception within a BADI implementation.

Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended to better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or by its gross negligence.

More Information

For instructions about creating an SAP Business Add-In, see the ABAP model help in the SAP NetWeaver Library.