Application Development 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: 

Declaring deep types in ABAP code

Former Member
0 Kudos

I am struggling with the declaration of local types in an ABAP program. When I declare a structure that contains a component which I reference to a previously declared table type, the system gives a compile error.

The following code gives an error on the highlighted line:

    types: begin of ts_docprop,

             key type string,

             value type string,

           end of ts_docprop.

    types: tt_docprop type standard table of ts_docprop.

    types: begin of ts_document,

             document_id type string,

             document_type type string,

             properties type tt_docprop, "<<<<< Error here

           end of ts_document.    

This results in the following error:

"TT_DOCPROP" has a generic type. Use of this type is only possible for typing field symbols and formal parameters

However, I am sure it must be possible to declare a deep type this way.

Instead, I have to resort to proxying declarations via data, which seems totally unnecessary:

types: begin of ts_docprop,

          key type string,

          value type string,

        end of ts_docprop.

data: ls_docprop type ts_docprop.

types: tt_docprop like standard table of ls_docprop.

data: lt_docprop type tt_docprop.

types: begin of ts_document,

          document_id type string,

          document_type type string,

          properties like lt_docprop,

        end of ts_document.


The first method above would be analogous to declaring structures and table types in the DDIC and should work. What have I missed?

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor

Hi,

Try:


TYPES: BEGIN OF ts_docprop,

             key TYPE string,

             value TYPE string,

           END OF ts_docprop.



  TYPES: tt_docprop TYPE STANDARD TABLE OF ts_docprop WITH NON-UNIQUE DEFAULT KEY .



  TYPES: BEGIN OF ts_document,



           document_id TYPE string,



           document_type TYPE string,



           properties TYPE tt_docprop, "<<<<< Error here



         END OF ts_document.

8 REPLIES 8

rosenberg_eitan
Active Contributor

Hi,

Try:


TYPES: BEGIN OF ts_docprop,

             key TYPE string,

             value TYPE string,

           END OF ts_docprop.



  TYPES: tt_docprop TYPE STANDARD TABLE OF ts_docprop WITH NON-UNIQUE DEFAULT KEY .



  TYPES: BEGIN OF ts_document,



           document_id TYPE string,



           document_type TYPE string,



           properties TYPE tt_docprop, "<<<<< Error here



         END OF ts_document.

0 Kudos

Perfect, thanks!

0 Kudos

You are wellcome.

Have a look here

if you have the time.....

Regards.

0 Kudos

Be careful with DEFAULT KEY. It will construct the standard key which comprises character-like and byte-like (covered by the XSEQUENCE generic typ) data types - that is types c, string, x and xstring.

If you have something like "DELETE ADJACENT DUPLICATES", only the fields of the key will be considered. So if you have other types in your table, their value won't be checked. For this reason, I tend to use NON-UNIQUE KEY table_line.

0 Kudos


First of all Thanks for the warning.

It is good to have extra eyes around.

- Usually I perform a sort before the "DELETE ADJACENT DUPLICATES" would this fix the problem ?

- What is the benefit "table_line"  ? Am I correct to asume this will create a big key made up from the whole record ?

Regards.

0 Kudos

The sort is always necessary for D.A.D., but it won't fix the problem. You could use DELETE ADJACENT DUPLICATES COMPARING ALL FIELDS. I got bitten by this just a few days ago.

table_line is indeed a big key of all fields.

There's a blog somewhere quite recently that talks about issues with DEFAULT KEY, but I've not been able to find it.

0 Kudos

Here is the blog

0 Kudos

Thanks.

As I said It is good to have extra eyes around.

So when we will see automatic mail alert to all SAP programmers about this problem ?

Regards.