cancel
Showing results for 
Search instead for 
Did you mean: 

Create DB table based on CDS's structure.

hagit
Active Participant
0 Kudos

Hello experts,

We have a CDS. The problem is that we are in a very low version of ECC, so many options are not available when creating the CDS. The solution was to

  1. Create a table in SE11. The table will have the structure of the CDS plus more fields.
  2. Write an ABAP program, which
    1. selects data from the CDS
    2. Add fields with logic that cannot be written in the CDS (in our low version).
    3. Inserts the CDS's fields and the additional fields to the table, which was created in SE11.
  3. Creates a job, which will run the ABAP program.

My question is: In SE11 – How can I create the table with the structure of the CDS? (Something like include/ append structure). I wish to tie the table's structure to the CDS's structure (For the possibility that one day the structure of the CDS will be change).

Thankyou in advanced

Hagit Samet

Accepted Solutions (1)

Accepted Solutions (1)

raymond_giuseppi
Active Contributor
0 Kudos

You cannot, But you can use an CDS entity in an Abap program TYPES definiton.

"A CDS entity (CDS view, CDS table function, CDS hierarchy, or CDS abstract entity) also represents a structured type and can be used as such in ABAP programs but not in the ABAP Dictionary."

Did you try to create such a small program, that use some RTTI tool to dynamically get the field list of a such defined structure and then update the ddic table definition.

hagit
Active Participant
0 Kudos
@Raymond thank you for your answer. Could you please detail about the RTTI tool?
raymond_giuseppi
Active Contributor
0 Kudos
RTTI: Look in forum for class such as CL_ABAP_TYPEDESCR, CL_ABAP_TABLEDESCR, CL_ABAP_STRUCTDESC.
hagit
Active Participant
0 Kudos
@Raymond thank you for your answer. From a quick glance, I see that there are methods that return a list of fields, but I have not seen a method that changes the structure of a table in the DB
raymond_giuseppi
Active Contributor
0 Kudos

The RTTI class wont update ddic objects, you use the returned infomation to update the table definition (using FM such as DD_TABL_GET and DD_TABL_PUT)

(Seems answer was truncated?)

hagit
Active Participant
0 Kudos

@Raymondthank you for your answer. 

hagit
Active Participant
0 Kudos
@Raymond thank you for your great help
hagit
Active Participant
0 Kudos
@Raymond Hello, When sending a name of table to 'tabl_name' parameter in DD_TABL_GET function (line 14) and after calling 'DD_TABL_PUT' function ,then it creates a new table as excepted. But when sending a name of CDS to 'tabl_name' parameter (line 15), it creates a view. What should I change in the parameters , which are sent to 'DD_TABL_PUT',in order to receive a table (not a view)? I tried to add ls_dd02v-tabclass = 'TRANSP'. (line 44) , but it did not help.
hagit
Active Participant
0 Kudos
@Raymond , I could not add a screenshot here. So I added it in an answer
raymond_giuseppi
Active Contributor
0 Kudos
Give the name of your own table to DD FM not the CDS view name. (The table you "Create a table in SE11")
hagit
Active Participant
0 Kudos
@Raymond Thank you for your replay. The idea was to tie the new table's structure to the CDS's structure. When I will change the fields list in the select statement in the CDS (and therefor the structure of the CDS will be changed), then the new table will be created programmatically by calling FM 'DD_TABL_GET' &'DD_TABL_PUT'. The new table will be created according to the new CDS's structure. (The table's structure in SE11 is not changed – So it will not help to send the table's name to the FM.)
hagit
Active Participant
0 Kudos
@Raymond Did you see my comment? thank you.
raymond_giuseppi
Active Contributor
0 Kudos

I read your comment, but, alas, this exact requirement fell into my initial "You cannot"
(So I suggested some programatically bypass)

hagit
Active Participant
0 Kudos
@Raymond, OK . Thank you

Answers (1)

Answers (1)

hagit
Active Participant
0 Kudos

@raymond_giuseppi 

I could not add the print shoot to a comment , so I add it here.

hagit_0-1710914530208.png

 

hagit_1-1710914530212.png