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

Reverse- Re Engineering Structers or Tables to SQL

Former Member
0 Likes
1,289

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

6 REPLIES 6
Read only

Former Member
0 Likes
1,004

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

Read only

0 Likes
1,004

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

Read only

JanStallkamp
Advisor
Advisor
0 Likes
1,004

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

Read only

0 Likes
1,004

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

Read only

0 Likes
1,004

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

Read only

P281512
Participant
0 Likes
1,004

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