Introduction: -
In modern ABAP development, one of the key goals is to avoid reinventing the wheel and instead leverage the rich set of standard functionalities already available in SAP. Many standard SAP programs encapsulate complex business logic, validations, and data retrieval mechanisms that are both reliable and performance-optimized. However, in real-time project scenarios, developers often face requirements to build custom reports or screens while still utilizing this existing standard logic.
A common challenge arises when developers tend to replicate standard program logic into custom code, leading to increased maintenance effort, redundancy, and potential inconsistencies. This approach not only violates best practices but also makes future enhancements difficult.
This blog focuses on a practical and efficient approach to reuse standard SAP program logic dynamically within a custom ABAP program that includes a custom screen (Dynpro). By doing so, we can:
Requirement: - Assume there is a standard SAP screen that contains dynamically generated fields at runtime. The requirement is to dynamically capture the required data from this standard screen and consume it in a custom screen by creating a custom ABAP program, without modifying the standard object.
Note: - This is the Standard screen which contains the dynamic filed.
Create the custom screen which contains the only the required field , and get data from the standard screen.
** Fetched the data from the stnadard report RFDOPR12.
DATA: lt_range TYPE rsds_trange,
lt_dynamic_fields TYPE rsds_texpr.
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_false
data = abap_true ).
APPEND INITIAL LINE TO lt_range ASSIGNING FIELD-SYMBOL(<lfs_range>).
IF <lfs_range> IS ASSIGNED.
<lfs_range>-tablename = 'KNA1'.
APPEND INITIAL LINE TO <lfs_range>-frange_t ASSIGNING FIELDSYMBOL(<lfs_field>).
IF <lfs_field> IS ASSIGNED.
<lfs_field>-fieldname = 'KTOKD'.
<lfs_field>-selopt_t = CORRESPONDING #( so_ktokd[] ).
ENDIF.
ENDIF.
IF lt_range IS NOT INITIAL.
CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_EX'
EXPORTING
field_ranges = lt_range
IMPORTING
expressions = lt_dynamic_fields.
ENDIF.
SUBMIT RFDOPR12 WITH
xnurford = xnurford WITH
monat = monat WITH
dd_stida = dd_stida WITH
n_belege = n_belege WITH
stat_blg = stat_blg WITH
sortart = sortart WITH
verdicht = verdicht WITH
rastverd = rastverd WITH
konzvers = konzvers WITH
xbukrdat = xbukrdat WITH
rart-net = rart-net WITH
rart-skt = rart-skt WITH
rart-zhl = rart-zhl WITH
rart-ueb = rart-ueb WITH
rastbis1 = rastbis1 WITH
p_lvar = p_lvar WITH
rastbis2 = rastbis2 WITH
rastbis3 = rastbis3 WITH
rastbis4 = rastbis4 WITH
rastbis5 = rastbis5 WITH
faktor = faktor WITH
stellen = stellen WITH
pzuor = pzuor WITH
xgetausw = xgetausw WITH
umsatzkz = umsatzkz WITH
xhitlist = xhitlist WITH
title = title WITH
listsep = listsep WITH
mikfiche = mikfiche WITH
p_acc = p_acc WITH
dd_kunnr IN so_kunnr WITH
dd_bukrs IN so_bukrs WITH
akonts IN so_akont WITH
uebesal2 IN uebesal2 WITH
vertage IN vertage WITH
dd_gjahr IN dd_gjahr WITH
kksaldo2 IN kksaldo2 WITH
agoblig2 IN agoblig2 WITH
akonts IN akonts WITH
akontp IN akontp WITH
berabzu2 IN berabzu2 WITH
unbabzu2 IN unbabzu2 WITH
zinse2 IN zinse2 WITH
jhrausg2 IN jhrausg2 WITH
budat IN budat WITH
bldat IN bldat WITH
netdt IN netdt WITH
FREE SELECTIONS lt_dynamic_fields
AND RETURN.
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data =
DATA(lr_po_data) ).
ASSIGN lr_po_data->* TO <lt_po_data>.
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE 'Unable to retrieve ALV data'(006) TYPE
if_xo_const_message=>success DISPLAY LIKE
if_xo_const_message=>error.
LEAVE LIST-PROCESSING.
ENDTRY.
* Now we will get the data into lt_po_data internal table.
Reusing standard SAP program logic within custom ABAP developments is a powerful technique that helps strike the right balance between flexibility and standardization. Instead of duplicating complex logic, leveraging existing standard programs ensures that your custom solution remains robust, consistent, and aligned with SAP best practices.
By dynamically integrating standard functionality into a custom screen (Dynpro), we not only reduce development effort but also simplify long-term maintenance. Any improvements or corrections delivered by SAP in standard programs can be indirectly leveraged, minimizing the need for repeated enhancements in custom code.
Thank you..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 12 | |
| 8 | |
| 8 | |
| 8 | |
| 6 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 4 |