‎2011 Feb 21 10:39 AM
Hi,
I am looking for some ABAP code sniplets
to reverse engineer ABAP structure, tables or datatypes
to a SQL Create table statement.
Thank You
Martin
‎2011 Feb 21 12:42 PM
Do you insist on ABAP?
I would use database tools.
The main drawback though: There is no generic answer; it will depend on the database.
Another drawback: Transparent tables only.
In case of Oracle, I'm using the dbms_metadata package. It works well for tables and indexes.
regards
‎2011 Feb 21 1:02 PM
Hi Joe,
the major point behind this post is:
- the Code Sniplet should be in ABAP to transform SAP structers
The reason is:
- get a basic SQL ( Create Table) of an SAP/BI Extractstructure
- build SQL Tables according to the definition of this structure
- the SQL dialect can be Database ystem independent or does not matter
ThanXs
Martin
‎2011 Feb 23 9:24 PM
Hi.
The SQL to create an SAP table on the DB is highly DB-specific. Some DBs offer a SQL command "CREATE TABLE ... LIKE ...". If this available for you, this would be the easiest way.
There are function modules written in ABAP available to create SQL commands to create tables (including primary keys), views and indexes. But as far as I know they are all not intended to be used in customer programs.
/Jan
‎2011 Feb 24 8:10 AM
Hi Jan,
the basic idea is to get rid of laboursome keypad hitting work:
my plan is:
to get a basic ANSI SQL compatible Create table,
to throw it into a database,
reeingeneer the physical model with an ER Modeller,
and than refine it.
Function Modules would help.
You have a glue which they are ?
Thanks
Best wishes
Martin
‎2011 Feb 24 8:59 AM
Hi.
I'm not sure if I fully understand your issue. And I would like to mention once again that the CREATE TABLE statements that are created from the DDIC are very different for different DBs.
What you can use is the class CL_SQL_METADATA. There are implementations for all DBs supported by SAP and with methods like GET_COLUMNS you can get a list of all columns of a table, their order and their datatype on the database. Then you can get information about indexes, primary keys... But keep in mind that there are some special cases. Special indexes only available on some databases, pool tables, cluster tables... This class is getting the information from the DB, not from the DDIC. Please keep in mind that the DB-view might be different from the DDIC view.
Another approach:
Use the following function modules.
DD_GET_NAMETAB -> DD_MAP_NAMETAB_TO_DDFIELDS -> DB_CREATE_TABLE_S
The last one (use no_exec = 'X'!) will create a table with the SQL statements to create a table. unfortunately in this simple combination you don't get handling of all special cases (I think information about 'nullable' is lost, no use of DDSTORAGE...)
Please keep in mind that you are dealing with DDIC-internal functionality that is not intended to be used directly by customers. Inproper use may destroy your system.
/Jan
‎2022 Apr 15 12:03 PM
Please visit https://github.com/ojnc/abapcode
Download and try ymultabflds.abap
SAP table names are famously cryptic; SE11 shows you 1 at a time
Run with input ymtinp.txt
Save Output as ymtout.txt
Not very pretty but very useful!
ymultabflds helped me between 2004 to 2014
I use it for quick reference and also for my native SQL utility in https://github.com/ojnc/yes4sql
YES4SQL being "module pool" can only be installed with abapgit
Back to SAP after 8 year gap and S4/HANA aspirant