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

Code that doesn't require maintenance

Former Member
0 Likes
837

We have several tables and want to code ABAP, so that data would be written and updated to the correct table accordingly. Later on, there would be requirements to add more tables and data would be updated accordingly. The requirement is to code it so that it wouldn't need to be modified every time a new table is added. The table is named by the year, so there would be table 2009, 2010, 2011, 2012, etc. So when table 2013 is added, there shouldn't be a requirement to modify or change the code. Essentially the requirement is not to hard code the year. Is this possible to do?

8 REPLIES 8
Read only

Former Member
0 Likes
795

You can use SETS for to store table names and keep on adding tables whenever you want in future.

Check F.M G_SET_GET_ID_FROM_NAME

G_SET_TREE_IMPORT

This way you will get your table name read the set data based and based on logic like as you said table is named after year

you can write your program.

Bhanu

Edited by: Bhanu Malik on Jan 10, 2012 10:46 PM

Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
795

At the risk of sounding like an idiot - why don't you just have one table and use the year as one of the key fields?

Read only

Former Member
0 Likes
795

To me I could not really understand your requirement completly. However based on my understanding:

You are planning to maintain data in different tables using ABAP program.

If program selection has an option to given Table Name as input and data would be in some file format similar to table structure given on selection screen, then you have to use Dynamic decalarations of internal tables and Field Symbols to perform the maintenance task.

Read only

Former Member
0 Likes
795

Hi,

Get Year from Current date using SY-DATUM and then validate year with out hard coding.

Read only

Former Member
0 Likes
795

hi,

Better to try with Dynamic programming techniques using field symbols,

For example with select query,

select [field set dynamic] from [table name variable] into table [dynamic internal table].

if i am not wrong, you can not create a table definition from se38 program but entries you can make it.

Read only

0 Likes
795

Hi,

I am not understanding the naming conventions for tables.

Are u saying that your table names are years and how can it be possible to have names like that for custom tables??

sorry for the confusion....

thanks.

Aswath

Read only

Former Member
0 Likes
795

Hi,

If you plan to create tables 2008, 2009, 2010 etc which are having exactly having the same fields, there is no need of so much work. Simply create one Z-table which has Year as a key field.

If you really have a a need to create different tables for different years then in your program, use the value of SY-DATUM(4). Based on this value you can easily update your desired table.

Regards,

Danish.

Read only

Former Member
0 Likes
795

The way we handle this (for many custom tables that we have for bolt-on applications) is via a small customer-written program to supply the tablename and call FM VIEW_MAINTENANCE_CALL . Our tables have generated table maintenance modules, so we can simply update this way. In our case, we have radiobuttons for display or update on the selection screen for our simple utility program that sets the table name, the display or view (action). For a limited number of tables we call the FM with SHOW_SELECTION_POPUP = 'X'. You can, of course, add authorization checks if needed for whomever is allowed to update, whether for single or multiple tables, etc.