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

How to avoid using constants ?

Former Member
0 Likes
3,429

Hello,

I am starting a new project and I am thinking of a way to avoid using constants.

For example, in a report, it selects all the order with types ZLN and ZLB.

I know that I have several possibilities :

- hard code it in the program (using constants which I want to avoid)

- create a specific table with all the types that I want to select (this may be the best solution but it can be very long -> too much table to create)

- put the parameter in the selection screen (but then we have to put default values which come back to the same problem)

...

So, I didn't found any perfect solution, Do you know what is the method recommended by SAP ?

What kind of technics did you use in you projects ?

Thank you for your help !

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
2,875

You can always use table TVARVC and the associated transaction to store parameter data. For a report though - I use constants, having first challenged the business about whether they're like to change or not.

matt

16 REPLIES 16
Read only

matt
Active Contributor
0 Likes
2,876

You can always use table TVARVC and the associated transaction to store parameter data. For a report though - I use constants, having first challenged the business about whether they're like to change or not.

matt

Read only

Former Member
0 Likes
2,875

I did think of TVARVC but I don't really see how to use it as it was not really build for this utilization !

-> It supposed that you always call the variant (the TVARVC only define which values will be used in the variant).

Of course you can also select directly in the table with for example a variable name = program name + parameter.

But this is not the real utilization of TVARVC and this take time to code.

Challenging the business and see if I can hard code the value or not is what I always do. But I have order to stop hard coding anything !

Read only

matt
Active Contributor
0 Likes
2,875

I'd have thought TVARVC was exactly suited to this task. But I'd go with Rob on this one. Variant. Why don't you want to use constants anyway?

Read only

Former Member
0 Likes
2,875

Thank you all for your answers,

I don't want to use constants (except for particular cases) because it is not maintainable without a developer.

I think I am going with this solution :

- if there is a lot of entries or the data is very suceptible to be modify -> I create a specific table

- if there are few entries or the data will probably not change -> I'll add the value in TVARVC and call the transaction with a default variant that contains all the parameters defined in TVARVC.

What do you think ?

Read only

Former Member
0 Likes
2,875

the best way is to create a ztable with the below fileds and maintain it..

MANDT MANDT

PROGNAME----- PROGNAME

FIELDNAME----- RVARI_VNAM

NUM---- TVARV_NUMB

TYPE---- RSSCR_KIND

SIGN---- TVARV_SIGN

OPTI----- TVARV_OPTI

LOW----- TVARV_VAL

HIGH---- TVARV_VAL

we use it in our project to maintain the constants.. even programs constant can also be maintained as there is the filed program name..

Read only

matt
Active Contributor
0 Likes
2,875

>

> What do you think ?

I think your approach is reasonable. I don't agree with imran khan, as you'll get the same results using TVARVC, which has its own transaction, by simply concatenating Program and Variable into the NAME field.

matt

Read only

Former Member
0 Likes
2,875

Hi,

yeah u can use the table tvarvc but the problem is its tough to maintain the table..

its a better thing to make a z_const table it will be very helpfull through out the project as we can even maintain the program specific constants in it..

just for an example if u have a requirement that only specif users can run this transaction jus maintain the users list for the program..

and in program we can check the values from the z_const for the authorised users.. etc there are soo many uses

i

work for one of the largest client in world with huge cycles of immplementations, suports, rollouts but we never come across any complications..

Read only

matt
Active Contributor
0 Likes
2,875

work for one of the largest client in world with huge cycles of immplementations, suports, rollouts but we never come across any complications..

I could say the same for TVARVC which has the added advantage that it is SAP standard.

matt

Read only

Former Member
0 Likes
2,875

I think you mean "hardcoding values" rather than "constants".

In any event, I would put it on the selection screen and create a variant. If there are a lot of values, you can cut and paste or upload them from a text file.

Rob

Read only

0 Likes
2,875

Yes constants is the way to declare hard coded values.

I can't put all of them in a selection screen as the user is not always able to find what is the value he is supposed to write. It would be ok if the selection screen is filled automatically, even without selected a variant.

Edited by: Louis-Arnaud Bouquin on Nov 3, 2009 6:38 PM

Read only

0 Likes
2,875

Hi Louis,

If you are making it as a selection screen field, then you should make the input select-options as non-editable.

In this way user will have no confusion whether he is supposed to enter/alter value in that field.

If there are few entries then normally we will go for TVARVC.

If there are large number of constant values, then its better to go for custom database tables

Thanks,

Nisha Vengal.

Read only

0 Likes
2,875

Hi Friend ,

As you taught , there are multiple ways to handle the constants in the program.

But finally time & efficency matters alot .

so my idea would be i will list all the constant & get the quick understanding of the constant type's.

For example : Order type is Customizing data which will maintained by Fun.Consultant , so i will give work for him to maitain the Varient against Order type in the TVARC table .so that in the program i will declare one order type vraible under atselection-screen event i will write select Query to get the vaule from the TVARC table which will be maintaine . we can write the execption also with sy-subrc <> o.if it is not maintianed .so far all customizing data fields this would be the best way for constants maintaining outside your program .

Similarly if any system constants then we can get it in runtime with SYST table parameters .

if there are any ABAP Program Constants ( Titles,labels ,case condition parameters,ect) maintain in the tprogram ext elements , or you can generically maintain a Utility class where you can create an attribute so that whereeven you want you can reuse the same .

Regards,

Read only

Former Member
0 Likes
2,875

What you can also take a look into to avoid the global impact of using a CONSTANT, is a little STATIC.

Check the ABAPDOCU keyword documentation for it's uses.

Regarding GET/SET parameters, I would also like to point out that you should not use these to control security in the program. It is only a preference, which the user themselves can also influence via several transactions, not least of which is SU3 (own data) in the SESSION_MANAGER menu...

When you might instead want to look into are Personalization Keys. These can be set by an administrator, or even transported together with the role to use the application.

Cheers,

Julius

Read only

Clemenss
Active Contributor
0 Likes
2,875

Hi Louis-Arnaud,

if you start a new project you may be able to spare some time to think about the business process. Identify the objects where you might have used constants: Some of them are required for the design of the process. Those have to go to customizing tables which have to be changed by IT personell for new process designs and then transported to QA and production.

Others have to be changed by business people from time to time, put them into master data table with maintenance view.

Customizing tables should be integrated in the implementation guide (-> img extension), master data maintenance integrated in user menu.

Regards,

Clemens

Read only

venkat_o
Active Contributor
0 Likes
2,875

Hi Louis, <li>I would go with SELECT-OPTIONS for order types. Create Variant on selection-screen and ask them to use the variant before run the program. Thanks Venkat.O

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,875

What i do is create a class in se24

and declare the constants,Hardcoded values in Attributes of class statically.

and then use it in program.