Description: Hard coding Tracker Program
When?
Hard-coding has been very much an integral part of ABAP coding right through the black and white versions of SAP to the newer and more colorful versions of SAP. Many a times lot of text is hard coded in programs right from select statements to selection screen parameters to more complicated case statements and other conditional statements. The more deadlier hard coding is found in user exits or BTE's. Typically during roll-outs the existing programs may have to be modified to include the new company code etc. However it might take lot of debugging to figure out what went wrong if we missed a small exit where very important code was written.
How?
The below mentioned program can be run before roll-outs to determine if any hard coding is present. The hard coding can be from company code to plant to form names or report names. The output of this report will help you to estimate roughly in which programs or exits changes might have to be done. This report will be also useful for production support issues arising after go-live.
Selection Screen:
Selection Texts:
P_CHK Programs starting with : For example Z* for custom Reports
P_HARD Hard coded string For example we are searching for company code IN01 enter IN01
P_FULL Full details All the details including Line number are displayed
P_NAM Only program names Only the Program names are displayed
For hard coding in Z Reports P_CHK should be: Z*
For hard coding in Z Function Modules P_CHK should be: LZ*
SOURCE CODE:
*---------------------------------------------------------------------*
* Report Name: Z_TEST_HARD_CODING
* Desc : Detecting hard coding in Programs
* Author : Arun Nair
*---------------------------------------------------------------------*
REPORT z_test_hard_coding NO STANDARD PAGE HEADING
LINE-SIZE 180
LINE-COUNT 45.
*---------------------------------------------------------------------*
* DATA DECLARATION *
*---------------------------------------------------------------------*
TYPES: BEGIN OF ty_ztab,
prog TYPE programm,
END OF ty_ztab.
TYPES: BEGIN OF ty_zprog,
line TYPE char72,
END OF ty_zprog.
TYPES: BEGIN OF ty_zprogdet,
prog TYPE programm,
linenr TYPE i,
line TYPE char72,
END OF ty_zprogdet.
DATA: i_prog TYPE STANDARD TABLE OF ty_ztab,
wa_prog TYPE ty_ztab.
DATA: i_zprog TYPE STANDARD TABLE OF ty_zprog,
wa_zprog TYPE ty_zprog.
DATA: i_zprogdet TYPE STANDARD TABLE OF ty_zprogdet,
wa_zprogdet TYPE ty_zprogdet.
PARAMETERS: p_hard TYPE char25 OBLIGATORY.
PARAMETERS: p_chk TYPE char25 OBLIGATORY DEFAULT 'Z*'.
PARAMETERS: p_full RADIOBUTTON GROUP g1,
p_nam RADIOBUTTON GROUP g1.
*---------------------------------------------------------------------*
* START OF SELECTION *
*---------------------------------------------------------------------*
START-OF-SELECTION.
*-- Replace * by %
REPLACE ALL OCCURRENCES OF '*' IN p_chk WITH '%'.
*--get the list of programs
SELECT prog FROM d010sinf
INTO TABLE i_prog
WHERE prog LIKE p_chk.
IF sy-subrc = 0.
LOOP AT i_prog INTO wa_prog.
READ REPORT wa_prog-prog INTO i_zprog.
IF sy-subrc = 0.
LOOP AT i_zprog INTO wa_zprog.
IF wa_zprog-line CS p_hard.
wa_zprogdet-prog = wa_prog-prog.
wa_zprogdet-line = wa_zprog-line.
wa_zprogdet-linenr = sy-tabix.
APPEND wa_zprogdet TO i_zprogdet.
CLEAR wa_zprogdet.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ELSE.
*-- Message - No entries found
ENDIF.
IF i_zprogdet IS INITIAL.
*-- Message - No entries found
ENDIF.
*---------------------------------------------------------------------*
* END OF SELECTION *
*---------------------------------------------------------------------*
END-OF-SELECTION.
*-- Display report
LOOP AT i_zprogdet INTO wa_zprogdet.
AT NEW prog.
IF p_full EQ 'X'.
SKIP.
WRITE: / wa_zprogdet-prog COLOR 4.
SKIP.
ELSE.
WRITE: / wa_zprogdet-prog COLOR 4.
ENDIF.
ENDAT.
IF p_full EQ 'X'.
WRITE: / wa_zprogdet-prog,
'LINE Nr:',
wa_zprogdet-linenr,
wa_zprogdet-line COLOR 2.
ENDIF.
ENDLOOP.
No comments:
Post a Comment