‎2012 Jan 10 9:42 PM
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?
‎2012 Jan 10 9:46 PM
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
‎2012 Jan 10 10:45 PM
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?
‎2012 Jan 11 12:27 PM
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.
‎2012 Jan 11 12:54 PM
Hi,
Get Year from Current date using SY-DATUM and then validate year with out hard coding.
‎2012 Jan 11 3:32 PM
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.
‎2012 Jan 13 10:00 AM
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
‎2012 Jan 13 12:21 PM
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.
‎2012 Jan 13 2:29 PM
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.