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

Better way to manage Hardcoded values in program?

Former Member
0 Likes
4,625

Hi All,

What would be the better way to manage hard code values in the program .

One option will be create a custom table and store the constant values in it , and retrieve based on the program id.

If such case what would be the best optimum table design for this case?

table structure :

Program ID
constant field name 
constant value

But the above design doesn't have the uniqueness .

Any new ideas on this ?

Thanks,

Raghavendra

Hi All,

What would be the better way to manage hard code values in the program .

One option will be create a custom table and store the constant values in it , and retrieve based on the program id.

If such case what would be the best optimum table design for this case?

table structure :

Program ID
constant field name 
constant value

But the above design doesn't have the uniqueness .

Any new ideas on this ?

Thanks,

Raghavendra

10 REPLIES 10
Read only

former_member404244
Active Contributor
0 Likes
2,405

Hi,

I don't think it will be a good option as each and evry program will have thier own hardcoded values....and also custom table takes some space in the database as well.The custom table can be helpful if multiple programs use same hardcoded value...

I feel use constants in the indiviudal programs or if you don't want to change the code then specify them in the selection screen and try to use them in ur code.

Regards,

Nagaraj

Read only

Former Member
0 Likes
2,405

Hi Raghavendra,

I think declaring constant values in program will better option rather than using table for constant values.

this is the suggestion of standard sap .

when you go for extended check, if you have used any constant then it shows error.

E.g.

Declare your constant with some suitable char which will indicate it is constant and for particular field.

Thanks and Regards,

Vijay

Read only

Former Member
0 Likes
2,405

I thought this process because of this:

there will be few requirements just to change the value of constants , at that time Maintainability of hard code values in program is cumbersome process.. You need to comment the existing code and then rewrite the same code new constant value. But instead of that if you have a custom table where you do maintain such kind of frequent hard code values change, just changing the table entry will solve the problem .In this case we do can save a lot of effort and time . No need to create a TR , no transport, USER can also do this.

Read only

0 Likes
2,405

Hi,

I understand what u said..But for custom table also some one needs to maiantain when there is change in the constant values.... also this needs to be maintained in all the servers... also authorization needs to be given for maintainence of the custom table.

if you are not using SM30 or some tcode to maintain the values then u need to do another program to update the values...once any change comes then once again u need to modify the program.

so my suggestion is use constants or else specify a separate block in the selection screen and then specify the values and use them in ur program, when u do this u don't need to change the program...

Regards,

Nagaraj

Read only

0 Likes
2,405

Hi,

In this case i would go for the following fields;

Key Fields

Program

Field

Sequence

No-Key fields

ActiveFlag

Value

Description

Created on

Created by

Last change on

Last Chang by

Regards

Karthik D

Read only

0 Likes
2,405

Hi Karthik,

Do you have any example on this? looks like the sequence indicator will do better things

Read only

0 Likes
2,405

>

> Hi Karthik,

> Do you have any example on this? looks like the sequence indicator will do better things

Hi,

I hope all fields are self explanatory, so you have to maintain the entry with the program name , field name and sequence 1 for the first time, check the active flag if you want to have this record as active.

In program use a select query to fetch the data value, checking the active flag is set.

Using sequence you can maintain multiple values for a field.

Regards

Karthik D

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,405

what about maintaining the constants in attributes of a class ?

Read only

Former Member
0 Likes
2,405

Always reinventing the wheel......

There's a standard way to deal with constants without repeating coding. Also multi value constants with all features of Selecti-options (Ranges) are applicable there.

Table TVARV (TVARVC on > 4.6C)

Transaction STVARV

These Variables are also useful within Report-Variants.

The only poor is that SAp does not provide a way to compare variables with tose ranges.

We developed a public static method do so and we deal with TVARV variables in the same manner as the IN statement in ABAP

Cheers

carsten

Read only

Former Member
0 Likes
2,405

Hi Raghavendra,

Herewith, I am giving you a small idea. Please use this if it helps you.

Please create a COM PARAM database table with the following structure.

Pgmid - Program name

para1 - Parameter name (Constant name) Data element - PARAM_D

para2 - Parameter name (Variant of constant 1) Data element should be same as para1

Use of this is that, for example PARA1 = Module PARA2 = SD

PARA1 = Module PARA2 = FI

PARA1 = Module PARA2 = MM (Like this variations could be handled)

sign - Data element = DDSIGN (Value can be Included in range / Excluded in Range)

opt - Data element = DDOPTION (Value can be EQ/NE/GE/GT/LT/etc)

low - Data element = SETVAL (Value for the constant)

high - Data element = SETVAL (Value for the constant can be SPACE if the constant is not a range of values)

description - Description for the constant (CHAR255)

This is the way which most of the experts would prefer, instead of hardcoding the values

After creating the table, you can maintain the constants in this table as records.

Thanks and Best Regards,

Suresh