Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reg: hard coding..

Former Member
0 Likes
513

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

4 REPLIES 4
Read only

Former Member
0 Likes
488

Hi Akshita,

Here's an example of hard coding while displaying error message:

MESSAGE e048 WITH 'Error Text'.

('Error Text' is hard coding in code)

You can remove hard coding by creating Text Symbols. Example

MESSAGE e048 WITH text-004.

(Where text-004 is equivalent to Error Text)

Regards,

George

    • reward points if you find this hint useful

Read only

Former Member
0 Likes
488

Hi ,

U can avoid hard coding by using local constants,

as if u use a value which is required more than once then it is advisable to use constants as in near future if you would like to change that value you only need to change the value once where you have defined the constant hence it reduces effort.

For ex: you want to put a flag after some if conditions

IF <variable > IS NOT INITIAL.

flag = 'X'.

ELSE.

falg = ' '. " space

ENDIF.

so instead of using 'X' u can use a constant

DATA: gc_x TYPE c value 'x'.

U can also reduce hard coding by using text symbols.

Read only

Former Member
0 Likes
488

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'.

Reward points if you find useful.

Read only

Former Member
0 Likes
488

HI Akshita,

Assume that you are writing a report which writes the name of a company at a number of locations. Say the name is 'XYZ'.

A few days later the company name gets cahnged to 'ABC'.

If you have hard code it like

write:/ 'XYZ'.

.

.

.

.

.

write:/ 'XYZ'.

then you msut replace wherever you have written the statement.

but if you have done like this:

data: v_company(3) value 'XYZ'.

write:/ v_company.

.

.

.

write:/ v_company.

You can just change at one place i.e

data: v_company(3) value 'ABC'.

this is the advantage of avoiding hard coding.

Regards

Ravi