Sunteți pe pagina 1din 7

Dynamic Enhancement Strategy Stub

Author: Arkajeet Dasgupta


Amit Kumar
Dynamic Subtotal Text in ALV
______________________________________________________________

Table of Contents
Scope of the development ............................................................................................... 3
Our Scenario………………………...…………………………………………………………...3
The Solution.....……………………………………………………………………….………….3
The Code…………………….……………………………………………………………………4
BENEFITS OF THIS TIP ................................................................................................. 6
Credits………………………………………………………………………………………………………………….………………………6

______________________________________________________________
Page 2 of 7
Dynamic Subtotal Text in ALV
______________________________________________________________

Scope of the development


Usage of a Custom Control Function Module to allow filter specific user exit logic without
impacting the existing other enhancement logic is the general TAC strategy. The control
of the enhancement logic is handled by a custom table with an identifiers, filters and
function module names. The issue arises in most ECC user exits like MV45AFZZ. While
creating the main function module stub(the actual piece of code), there is no visibility to
all the parameters that needs to be referred. For MV45AFZZ one gap may require the
usage of XVBAP and the other may be using XVBPA. Everytime a new parameter needs
to be accessed, all the existing Function Modules need to be repaired with the new
parameters and this involves changing the stub every time. This process can break the
functionality severely if any one existing function module gets missed for the new
parameter to be added and also adds manual effort and severe tracking, increases risk
to a huge extent

The Solution

The solution implemented in one of the IBM projects as a workaround to the above issue
was making the parameters for the enhancement function modules dynamic for such
cases in conjunction with a constant table to hold the parameters(CCD in this case).
Parameters specific to one logic is maintained in CCD along with the function module
name. Before calling the function module, the parameters are retrieved from CCD and
populated dynamically for being called. The rest of the strategy remains as per the TAC
process.

The Code

DATA: lis_ptab TYPE abap_func_parmbind_tab, "PARAMETER-TABLE


lwa_ptab_line TYPE abap_func_parmbind, "PARAMETER-TABLE WA
lih_etab TYPE abap_func_excpbind_tab, "EXCEPTION-TABLE
lwa_etab_line TYPE abap_func_excpbind, "EXCEPTION-TABLE WA
lwa_funclist TYPE zus_func_list, "Structure for function
List
li_func_parametrs TYPE zc_exp_ccd_tt, "Table Typ CCD data retri
eval
lwa_ccd_fetch TYPE zcrange_ccd, "Range table for CCD WA
li_ccd_fetch TYPE zc_range_ccd_tt, "Table Type for CCD ra
nge
li_ccd_data TYPE zc_exp_ccd_tt, "T Type CCD data retriev
al
li_funclist TYPE zu_func_list_tt, "Table with function li
st
l_var TYPE string, "Name
l_fmnam TYPE rs38l_fnam, "FM Name
l_check TYPE c, "Check variable
l_exc TYPE i. "Exception
FIELD-SYMBOLS: <lfs_func_param> TYPE zcexp_ccd,

______________________________________________________________
Page 3 of 7
Dynamic Subtotal Text in ALV
______________________________________________________________

<lfs_name> TYPE any.


CONSTANTS : lc_single TYPE rsscr_kind VALUE 'S',
lc_range TYPE rsscr_kind VALUE 'R',
lc_sign TYPE rsscr_kind VALUE 'I',
lc_opti TYPE tvarv_opti VALUE 'EQ',
lc_under_score TYPE char1 VALUE '_',
lc_fm_para_exc TYPE char3 VALUE 'EXC',
lc_fm_para_imp TYPE char3 VALUE 'IMP',
lc_fm_para_exp TYPE char3 VALUE 'EXP',
lc_fm_para_chg TYPE char3 VALUE 'CHG',
lc_fm_para_tab TYPE char3 VALUE 'TAB',
lc_bracket_opn TYPE char1 VALUE '(',
lc_bracket_cls TYPE char1 VALUE ')',
lc_prog TYPE sycprog VALUE 'SAPMV45A', "Prog
lc_exit_id TYPE zzexit_id VALUE 'S_MV45AFZZ_05'.
*Start of Enhancement strategy stub
*Retrieve the list of Active Function modules related to different
*requirments
CALL FUNCTION 'Z_U_USER_EXIT_CONTROL'
EXPORTING
im_exit_id = lc_exit_id
IMPORTING
ex_t_funclist = li_funclist"List of all the FM which are active
EXCEPTIONS
no_data_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* No error handling required since no function module found, so the
* enhancement is switched off.
CLEAR li_funclist.
* Function list cleared so the below logic will not trigger in any case
* if sy-subrc return is other than 0
ENDIF. "IF sy-subrc <> 0.

**Start of changes done to call the FMs dynamically


IF li_funclist IS NOT INITIAL.
*Populate range table for CCD import paramater
CONCATENATE lc_prog lc_single INTO lwa_ccd_fetch-low SEPARATED BY
lc_under_score.
lwa_ccd_fetch-sign = lc_sign.
lwa_ccd_fetch-opti = lc_opti.
APPEND lwa_ccd_fetch TO li_ccd_fetch.
CLEAR lwa_ccd_fetch.

CONCATENATE lc_prog lc_range INTO lwa_ccd_fetch-low SEPARATED BY


lc_under_score.
lwa_ccd_fetch-sign = lc_sign.
lwa_ccd_fetch-opti = lc_opti.
APPEND lwa_ccd_fetch TO li_ccd_fetch.
CLEAR lwa_ccd_fetch.
* Fetch data from CCD

CALL METHOD zclu_ccd_fetch=>fetch_values


EXPORTING
im_t_name = li_ccd_fetch
IMPORTING
ex_t_ccd = li_ccd_data

______________________________________________________________
Page 4 of 7
Dynamic Subtotal Text in ALV
______________________________________________________________

EXCEPTIONS
no_data_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
REFRESH li_ccd_data[].
ENDIF. "IF sy-subrc NE 0.
IF li_ccd_data IS NOT INITIAL.
SORT li_ccd_data BY coop2.
*Call Object specific FMs individually
LOOP AT li_funclist INTO lwa_funclist.
CLEAR: l_check,
l_exc.
IF lwa_funclist-funcname IS NOT INITIAL.
li_func_parametrs = li_ccd_data.
DELETE li_func_parametrs WHERE coop2 NE lwa_funclist-
funcname.
*Populate parameters with which FM needs to be called
*Loop within loop is necessary to call the function dynamically and
*number of rows in these
*loops are not more than 100 so perofrmance wise it should not be an
*issue . Besides, we are
*also deleting the 2nd loop internal table keeping only relevent rows i
n
*that
LOOP AT li_func_parametrs ASSIGNING <lfs_func_param>.
IF <lfs_func_param>-coop3 = lc_fm_para_exc.
"Exception parameters
l_exc = l_exc + 1.
lwa_etab_line-name = <lfs_func_param>-coop5.
lwa_etab_line-value = l_exc."
INSERT lwa_etab_line INTO TABLE lih_etab.
ELSE.
lwa_ptab_line-name = <lfs_func_param>-coop5.
CONCATENATE lc_bracket_opn <lfs_func_param>-coop4
lc_bracket_cls <lfs_func_param>-low INTO l_var.
*Take reference of SAP Standard paramter into local variable
ASSIGN (l_var) TO <lfs_name>.
IF <lfs_name> IS ASSIGNED.
CASE <lfs_func_param>-coop3.
WHEN lc_fm_para_exp.
"Populate exporting paramters dynamically
*Exporting paramter for FM means importing paramter while calling FM
lwa_ptab_line-kind = abap_func_importing.
GET REFERENCE OF <lfs_name> INTO lwa_ptab_line-value.
WHEN lc_fm_para_imp.
""Populate Importing paramters dynamically
*Importing paramter for FM means exporting paramter while calling FM
lwa_ptab_line-kind = abap_func_exporting.
GET REFERENCE OF <lfs_name> INTO lwa_ptab_line-value.
WHEN lc_fm_para_chg.
"Populate changing paramters dynamically
lwa_ptab_line-name = <lfs_func_param>-coop5.
lwa_ptab_line-kind = abap_func_changing.
GET REFERENCE OF <lfs_name> INTO lwa_ptab_line-value.
WHEN lc_fm_para_tab.
"Populate Tables paramters dynamically
lwa_ptab_line-kind = abap_func_tables.

______________________________________________________________
Page 5 of 7
Dynamic Subtotal Text in ALV
______________________________________________________________

GET REFERENCE OF <lfs_name> INTO lwa_ptab_line-value.


WHEN OTHERS.
* Do nothing
ENDCASE. "CASE <fs_func_param>-coop3
INSERT lwa_ptab_line INTO TABLE lis_ptab.
ELSE.
l_check = abap_true. "mark Check.
ENDIF. "IF <lfs_name> IS ASSIGNED.
ENDIF. "IF <fs_func_param>-coop3 = c_fm_para_exc.
CLEAR lwa_ptab_line.
UNASSIGN <lfs_name>.
ENDLOOP. "LOOP AT i_func_parametrs ASSIGNING <fs_func_param>
*Call the function module dynamically
IF l_check IS INITIAL.
* Fill the FM name in the Variable
l_fmnam = lwa_funclist-funcname.
* Check If the FM exist
CALL FUNCTION 'FUNCTION_EXISTS'
EXPORTING
funcname = l_fmnam
EXCEPTIONS
FUNCTION_NOT_EXIST = 1
OTHERS = 2.
IF sy-subrc IS INITIAL.
CALL FUNCTION lwa_funclist-funcname
PARAMETER-TABLE
lis_ptab
"List of all Importing, exporting,changing and tables paramters
EXCEPTION-TABLE
lih_etab."List of all the exceptions
IF sy-subrc EQ 1.
* Abort exception has been raised and rest of the FMs should not be
* continued
EXIT.
ENDIF. "IF sy-subrc EQ 1.
ENDIF. "IF sy-subrc IS INITIAL.
ENDIF. "IF l_check IS INITIAL.
ENDIF. "IF wa_funclist-funcname IS NOT INITIAL
CLEAR l_fmnam.
ENDLOOP. "LOOP AT i_funclist INTO wa_funclist.
ENDIF."If some parameter is found for FM
ENDIF. "IF li_funclist IS NOT INITIAL.

______________________________________________________________
Page 6 of 7
Dynamic Subtotal Text in ALV
______________________________________________________________

BENEFITS OF THIS TIP

This solution removes any manual intervention of tracking and modifying such
enhancement strategy stub every time a new function module requires new parameters
to be accessed/changed and thereby ensures that the individual function modules uses
only those parameters which it requires and not all. Risk of a break in logic inside the
user exit owing to an addition of a new parameter is also removed.

Credits

The credits for this solution/design/code is to be shared by Arkajeet Dasgupta and Amit
Kumar.

______________________________________________________________
Page 7 of 7

S-ar putea să vă placă și