‎2007 Feb 17 5:29 AM
HI,
could any one tel me what exactly mean by hard coding how to avoid that, if you give use one or two exampls that would be great.
Thanx in advance.
Akshitha
‎2007 Feb 19 11:57 AM
In short:
Hardcoding means that you use preset values, instead of variables.
Example:
Select from KNA1 where kunnr = '0000012345'.Better would be to use variables.
Select from KNA1 where kunnr = z_kunnr.And then retrieve the correct value another way (via another table), or use constants in the beginning of the program. With constants, it is at least easy to find where hardcoding is used.
Hardcoding is often done in user exits. For example a certain document type. But then, everytime a document type would be added that would require a similar logic, the program needs to be changed. Or for text names. Anything.
In most case it is a lot safer to create a table to store the possible values. Then all that needs to be done is to maintain that table. No changes required to the code.
Basically, that's all.
‎2007 Feb 19 12:00 PM
<b>Hard coding....</b>
if month eq 'February'.
endif.<b>without Hard coding</b>
parameters : p_month(15) default 'February'.
if month eq p_month.
endif.
‎2007 Feb 19 12:10 PM
Hard coding is similar to giving the value directly in the code.
This should be avoided, it is the standard of coding.
Eg: Say u like to pass teh value 'X' to a field.
U have do like.
CONSTANTS: c_x value 'X'.
wa_fieldcat = c_x.Also when disaplaying error messages use text elements instead of hard coding.
Message e00 WITH text-001.
Text-001 - Enter valid code.Use the above instead of
Message e00 WITH 'Enter valid code'.Hope this helps. Reward points and close the thread if ur query got solved.