SAP Note 3047487 BAdI Examples
SAP Note 3047487 BAdI Examples
SAP Note 3047487 BAdI Examples
2
This document has the purpose of centralizing useful information for BAdI development of Electronic
Remuneration Book (RPC_PAYCL_LRE_DRIVER) report.
To know more about general functions of BAdI development, see the following SAP documentation:
• What is a BAdI?
The main goal is to provide real examples of BAdI implementations as to assist on customer development.
IMPORTANT REMARKS
• The following source code snippets are just examples and provide very basic examples on how to
address common scenarios within the available BAdIs. Only basic error-handling is defined in the
snippets, so the same must be adjusted by customers upon using, according to their business needs.
• The information provided below provides examples that are intended to be self-explanatory. Questions
regarding the use of these examples are deemed consultancy and should not be addressed through SAP
Support Portal.
• The use of the information below is entirely optional and SAP is not responsible for issues that may arise
from it. User discretion is advised.
1.4.1 HRPAYCL_B_LRE_FILL_PRE_TOTAL
The HRPAYCL_B_LRE_FILL_PRE_TOTAL BAdI is executed for each run of the report for an employee
before calculating the totals for all previous fields. This means that at the point that this BAdI is executed, all
the non-total fields should be filled with the employee information and can be modified or used in the BAdI.
1.4.1.1 Creating a specific field using Master Data information
The example below shows how to use the BAdI to create a new field for the employee.
METHOD if_hrpaycl_b_lre_pre_total~fill_pre_total.
DATA lo_new_field TYPE REF TO if_hrpaycl_lre_field. "This is the necessary
type to create a field
DATA lo_p0185 TYPE REF TO if_hrpadcl_infotype.
DATA ls_p0185 TYPE p0185.
DATA lv_begda TYPE begda.
DATA lv_endda TYPE endda.
* First, we can acquire the information that was selected at the report
screen utilizing the
* ms_config_date attribute from the io_run_configuration object.
lv_begda = io_run_configuration->ms_config-date_range-begda.
lv_endda = io_run_configuration->ms_config-date_range-endda.
* Next, we can use the io_master_date object, which contains the master data
information for
* the current employee to acquire the infotype 0185 in the selected time-
frame
* In this example, we will use the subtype 02 ( Passport) of the 0185
infotype to use as RUT.
TRY.
lo_p0185 = io_master_data->get_last( iv_infty = '0185'
iv_subty = '02'
iv_begda = lv_begda
iv_endda = lv_endda ).
lo_p0185->get_infotype( IMPORTING es_infty = ls_p0185 ).
CATCH cx_hrpadcl_infty_not_found.
RETURN.
ENDTRY.
METHOD if_hrpaycl_b_lre_pre_total~fill_pre_total.
DATA lo_new_field TYPE REF TO if_hrpaycl_lre_field.
DATA lv_endda TYPE endda.
DATA lv_amount TYPE betrg.
DATA lr_data_reference TYPE REF TO data. "Necessary type in order to
access a table
DATA lt_rt TYPE hrpay99_rt.
DATA ls_wage_type TYPE pc207.
* We start by cetting the end date information from the ms_config attribute
of the run configuration of the report
lv_endda = io_run_configuration->ms_config-date_range-endda.
* Now we will use the io_payroll_result object, which you can use to acess
all the payroll information from the employee
* In this example we are acquiring the reference to a table using the
get_table method so we can access the employee's RT
lr_data_reference = io_payroll_result->get_table( 'RT' ).
* As we have fetched the reference to the RT, we must copy it to an
internal table in order to use it
lt_rt = lr_data_reference->*.
* Next we will loop at the RT and we will seek for the /103 wage-type
LOOP AT lt_rt INTO ls_wage_type
WHERE lgart = '/103'.
lv_amount = ls_wage_type-betrg * '0.15'.
ENDLOOP.
* After that, we must create the new field in order to insert it
lo_new_field = cl_hrpaycl_lre_field_assembler=>make(
iv_code = '2331'
iv_value = lv_amount ).
* But as we are modifying an existant field, we first must delete the old
entry, using the remove method of the io_field_collection object.
io_field_collection->remove( '2331' ).
* After that, we can sucessfuly add the field created in this BAdI in the
field_collection.
io_field_collection->add( lo_new_field ).
* With this done, the field created in this BAdI is effectivly created for
to the employee
ENDMETHOD.
rv_result = lv_value.
ENDMETHOD.
ENDCLASS.
Table 3: Example code for if_hrpaycl_b_lre_pre_total implementation
The example below shows how to use your custom formatter in the BAdI implementation:
METHOD if_hrpaycl_b_lre_pre_total~fill_pre_total.
DATA lo_new_field TYPE REF TO if_hrpaycl_lre_field.
DATA lv_endda TYPE endda.
DATA lv_amount TYPE betrg.
DATA lr_data_reference TYPE REF TO data.
DATA lt_rt TYPE hrpay99_rt.
DATA ls_wage_type TYPE pc207.
DATA lo_formatter TYPE if_hrpaycl_lre_field_formatter. "Necessary
type to create a formatter
* In this example we are once again using an information from the employee's
RT, but in this case we
* want to calculate a field that must contain the decimals value.
lv_endda = io_run_configuration->ms_config-date_range-endda.
lr_data_reference = io_payroll_result->get_table( 'RT' ).
lt_rt = lr_data_reference->*.
LOOP AT lt_rt INTO ls_wage_type
WHERE lgart = '/103'.
* We are using an arbitrary value only to generate a value with decmilas
lv_amount = ls_wage_type-betrg * '0.0738'.
ENDLOOP.
* Now we must instantiate the formatter using the custom formatter class we
created
CREATE OBJECT lo_formatter TYPE lcl_no_rounding_formatter.
* After that, we must use the make_with_custom_format method from the
assembler so we can use the custom
* formatter.
lo_new_field = cl_hrpaycl_lre_field_assembler=>make_with_custom_format(
iv_code = '1132'
iv_value = lv_amount
io_formatter = lo_formatter ).
io_field_collection->add( lo_new_field ).
* With this done, the field created will have the custom field formatter.
ENDMETHOD.
Table 4: Example code for if_hrpaycl_b_lre_pre_total implementation
The expected result for the “Tasa indemnización a todo evento” is as below:
1.4.2 HRPAYCL_B_LRE_FILL_FINAL
The HRPAYCL_B_LRE_FILL_FINAL BAdI is executed for each run of the report for an employee after
calculating the totals for all fields. This means that at the point that this BAdI is executed, you have access to
all generated fields and all of them can be modified or used in the BAdI. Its functionality is the same as the
HRPAYCL_B_LRE_FILL_PRE_TOTAL BAdI, and the examples provided above will also work in this BAdI.
www.sap.com/contactsap
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or plat form directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation
to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are
cautioned not to place undue reliance on these forward-looking statements, and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other
countries. All other product and service names mentioned are the trademarks of their respective companies. See www.sap.com/trademark for additional trademark information and notices.