‎2007 Feb 17 5:33 AM
HI,
could any one tel me what exactly mean by hard coding, and how to avoid that in program, if you give me one or two exampls that would be great.
Thanx in advance.
Akshitha
‎2007 Feb 17 6:30 AM
Hi,
please close this thread i have answered the same in other group
Thanks
Shiva
‎2007 Feb 19 12:58 PM
Hi Akshitha,
Hard coding is like passing a value directly and by not using a variable or constant. It is very important to restrict from hard coding, because it hampers the reusablity of a code. For Example :-
Case: data : lv_age1 type i.
lv_age = 10.
Now, if you are using the number 10 at many places in the code, say about 50
places, and suddenly you want the number to be changed to 20 rather than 10.
In that case you would have to go to 50 places and delete and change.
Solution: data: lv_age type i.
constant: c_no type i value 10.
lv_age = c_no.
Now, if you are using the number 10 at many places in the code, say about 50
places, and suddenly you want the number to be changed to 20 rather than 10.
Now you just need to change the statement:-
constant: c_no type i value 20.
Thus you save the time to change at 49 places.
Hope you understood, what i wished to convey here.
NOTE: Please reward points if you are satisfied :).
Thanks and regards,
Ravi .
‎2007 Feb 22 5:26 PM
Hi,
hard coding is nothing using values directly with any constants/text elements.
for eg: if you are assinging value 40 to variable. you need to declare it as a constant and then assign.
gv_var = '40'. -
wrong
gv_var = gc_40. -
Correct.
Br,
Laxmi
‎2007 Mar 11 5:47 AM
Please reply with your status - whether you have understood or need further explanation.
Hard coding is the assignment of values directly in our program instead of using Variables or Text-elements.
ex:
1.
tables: spfli.
parameters: p_carrid type spfli-carrid.
data: wa type spfli.
data: itab like table of wa.
select connid from spfli into table itab where carrid eq <b>'AA'</b>. - Hard coding of values
( Instead write: select connid from spfli into table itab where carrid eq <b>p_carrid</b>. )
2.
write 'This is an example'. - Hard coding ( this is called a Text literal, which cannot be translated to other languages )
make it generalised by declaring a text-element for it in the text-elements section of your program.
to do this, simply press 'F2' on the text - 'This is an example', then declare the text element and activate it.
Now, you can translate this to other languages.
Hope I am clear with my examples.
Reward points if I was helpful to you.
Regards.
‎2007 Mar 13 6:26 AM
hii akshita,
hardcoding means when you use the values in quotes ie for example
IF MATNR = '1000001'.
this is hard coding you are giving a value to compare,you can avoid this by using either constants or any variable which have same values ie
if say ITAB-MATNR is having the value you want to check then use
IF MATNR = ITAB-MATNR.
.......
ENDIF.
Thanks
‎2008 Jun 02 9:31 AM
Hello,
what is so bad about hard coding ?
- Translation - ok
but what more ? Where lies the risk ?
Does someone have a link for a good explanation ?
I have to explain it to our developpers and they like hard coding and dont understand why not - so I thought aböut it - and did not too much reasons.
Best regards
Simone
‎2008 Jun 02 10:21 AM
Hi,
When you assign a hard coded value to a variable,then type of that does not match with hard coded value.
eg.
data: name type char3.
if you assign a hard coded value to variable name
name = 'WYXZ'.
As hardcoded value does not have a type so a type mismatch is there.
Reawrd points if helpful.
‎2008 Jun 03 12:48 PM
>
> Hello,
>
> what is so bad about hard coding ?
Hard coding will give you a lot of headaches once the organizational structure changes. Stuff like IF BUKRS = '0200' or IF BSEG-HKONT(1) = '5' is very painful to track down and correct.
Use select options, global constants or bespoke customizing tables to avoid hardcoding as much as possible. I'm speaking from bitter experience...
Cheers
Thomas
‎2008 Jun 03 7:33 AM
hard coding is basically when u dnt use variables bt u directly fill in values to those fields.
it can be also when while naming the text box u name it as the tablename-fieldname where that is wat value u want fr that field..
in this case u need nt do any coding. all data ull enter into dat field will get automatically into table..
u just need to type a statement modify table..
this is easier bt this highly degrades performance specially in case of when dere is lot of data.. so it is not preffered in production..
reward pts if found useful..
thanks n regards..
palak
‎2009 Feb 16 9:54 AM
Hi Akshita,
Hard coding has got some disdvantages:
1) First one we know in case of TRANSLATION: when we log in some other language then alse we ould see the same language as text on old language in which it is created.
so it is advisable to use text elemtns and maintain there translation in SE63.
2) In case of UPGRADES you will have issues if your texts are HARD coded and you wont have elements for there conversion.
3) Also from good practice point of view it is not considered good if you arent making full use of functionalities provided by SAP like transalation in SE63 and SAP text elements.
Thanks.
Vishal
‎2009 Apr 22 7:27 AM
hi,
hard coding means passing direct value to the varaiables or function modules from performance point of view it is not recommended 2 pass hard coded values for eg while using alv if v need 2 hv a hotspot v need 2 use 'X' instead of that v declare a variable check as char type an initialize that as check = 'X'.
and then pass check where ever required.
data: check(1).
check = 'X'.
wa_fieldcat-fieldname = 'LIFNR'.
wa_fieldcat-tabname = 'IT_EKKO'.
WA_FIELDCAT-OUTPUTLEN = 10.
WA_FIELDCAT-HOTSPOT = CHECK. -
> passing check and not hard coded value
WA_FIELDCAT-SELTEXT_L = 'VEN ACC NO'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
i hope it solves ur prob
thanks
shivraj
‎2009 Apr 22 8:47 AM
I have to explain it to our developpers and they like hard coding and dont understand why not - so I
thought aböut it - and did not too much reasons.
Hard coded is poor coding in terms of flexibility.