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

Best Way to Replace Hardcoded Values in Source

ChadRichardson
Participant
0 Likes
6,151

Good morning, Experts

We are debating the best method to replace hardcoded values in source. Starting out we hardcoded company codes, customer codes, shipping points, ... and as we've grown we've had to go back in to these source objects and add more values to the hardcoded list. Now we're taking a step back and wanting to replace these values within "something" so that an addition or subtraction from the list could be "configured" instead of requiring a programming change.

We have built a Z-table with program name as part of the key that does appear to be functional. Any change to the hardcoded list would then be changed using SM30 against this table. But we're wondering if this is the best way...

What are you using to avoid hardcoding or what ideas might you have???

Thanks in advance...

Chad

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
4,289

I would try to use selection options first, if not possible introduce custom config tables, if not possible introduce global constants (can be centralised in reusable includes, so just one place must to be updated in the future).

For the config tables, I would not choose program name as key, usually there is some relation between organizational criteria (e.g. find controlling area for a company code via TKA02).

You could quote an example case here for better understanding.

Thomas

13 REPLIES 13
Read only

Former Member
0 Likes
4,289

Hi,

I prapose you can make a CLUSTER TABLE for it...Pass the KEYS...like PROGRAM NAME in 1st layer then COMpany code in 2nd layer and in that you can maintain values....and write a FM to fetch the valus from that cluster table....values fetched can be used to replace hardcoding.

Hope i am able to explain

Amresh.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,289

Hello Chad,

Is this a report which you are concerned with? If so, then may be you can have the company codes, customer codes, shipping points in the selection-screen.

So that the user can i/p the values for which he wants to display the report.

BR,

Suhas

Read only

0 Likes
4,289

Some are reports but others are user exits, includes and other objects that we would not have access to screen selection variables.

Hidden screen selection variables do work for reports, but a lot of our changes are in other types of objects.

Thanks,

Chad

Read only

ThomasZloch
Active Contributor
0 Likes
4,290

I would try to use selection options first, if not possible introduce custom config tables, if not possible introduce global constants (can be centralised in reusable includes, so just one place must to be updated in the future).

For the config tables, I would not choose program name as key, usually there is some relation between organizational criteria (e.g. find controlling area for a company code via TKA02).

You could quote an example case here for better understanding.

Thomas

Read only

0 Likes
4,289

For example...

One of our main shipping label programs needs to ONLY do a specific subroutine for a set of customers. Something like the following:

IF kunnr = '0000000001' OR

kunnr = '0000000002' OR

kunnr = '0000000003' OR

kunnr = '0000000004' OR

kunnr = '0000000005'.

PERFORM Process_UPC.

ENDIF.

Is a "config" table a specific type of table within SAP or is it just a Z-table used for a specific purpose???

Read only

0 Likes
4,289

For this example I would consider an extension to the customer master (KNA1 if based only on customer number). You can append fields and also add them to the maintenance screens without modifying the standard. How about a new flag "specific <whatever> on shipping label" that can be set for the relevant customers? There is also a few existing attribute fields (KNA1-KATRx) that could be used.

Yes, I was referring to Z-tables created as "sort of customizing" tables with table maintenance dialogs, and depending on the case with or without transport request handling. You could also solve the example problem with such a table. However, you will have more and more tables to maintain with this approach if you also apply it other cases. Of course you could maybe combine all settings relevant to customer master in one table. It's an extensive topic.

Thomas

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,289

>

> Is a "config" table a specific type of table within SAP or is it just a Z-table used for a specific purpose???

Hello Chad,

"Config" tables are ideally Std. SAP tables which can be maintained through customizing.(e.g., TCURR, T042Z). But in your case i feel you have to create a Z-table which has the values of the Vendors for which you need to trigger some code.

Hope this helps.

BR,

Suhas

Read only

0 Likes
4,289

Hi Chad,

I think the best option for you to maintain a custom table with constant values, where you can keep Program name / Field name / Index as primary key. You can write a FM through which you will copy all the data related to that program, at the very beginning of execution. We are working in this way, to avoid hardcoded value.

Kuntal

Read only

0 Likes
4,289

I can only stress again that I would make this independent of program or other technical names. The same functional logic might appear in many different programs, multiplying the maintenance effort.

Thomas

Read only

0 Likes
4,289

Yes Thomas - I agree maintenance effort is much in this case.

Kuntal

Read only

0 Likes
4,289

I would agree. By program name does have some limitations. For example, a single program that has multiple conditions to be configured. In that case we've configured the program name + "-1", "-2", "-3".

As far as not using the actual program name is concerned. I supposed we could use some generic descriptor like "UPC Label Customers" instead of the program name.

Still even if we used the program name the config tied to that program name could be used in other programs.

Read only

naimesh_patel
Active Contributor
4,289

We also had a long debate on the same issue.

We decided to try the Soft-Code values instead of the Hard Code.

1. Create some custom tables which can hold the constant values. Like: We have some special processing for the normal sales Order ZOR1 and different logic for the Returns order ZRE1.

So, we have created

One table for the Group - NORM, RETN

One table for the Sales Order & Group relation.

NORM - ZOR1

NORM - ZOR2...

RETN - ZRE1

RETN - ZRE2

Create a View Cluster to maintain these tables easily.

2. Create a Classes which can fatch this data

Like: VALID_SALES_ORDER_TYPE


Definition-
Importing : 
  Sales Order type
  Group
Exporting
  Valid

Implementation-
  Get the value from the table Sales Order & group relation

This class contains some other methods also, like VALID_GROUPS_4_SO, VALID_SO_4_GROUP etc.

Advantage: You can easily maitain a new Hardcoded value in the SM30

Disadvantage: Lots of coding

Another Approch:

You can create one Global class for Constants. You can maintain all your constants in that global class and use them in your coding. One main advantage would be, you can easily do the where used list on each individual constant.

Regards,

Naimesh Patel

Read only

0 Likes
4,289

Hi, we have one req very similar to this. can you please give an example of how to do this? so I could understand it better?

I already gave 1 constant (has multiple values) in the z table from sm30. now I want to use it in my program instead of hardcoding the values.