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: 

ITAB key components order at runtime is different than at the time of definition

ivan_shadrin
Participant
0 Kudos

Hi, Gurus!

I've faced an issue with internal tables.

1. I created a dictionary structure. It contains include structure and two additional fields (see picture 1).

Picture 1. Table line definition.

2. I wrote a simple test program. Its logic is very straightforward (see picture 2).

I declared a standard table with line type based on the structure I've just created and custom primary key.

Please note that the order of the key componens is different than in the structure definition in ABAP Dictionary (see picture 1). The first key field is from the include structure. The next two fields - are additional fields I've manally added into the structure definition. The last key field belongs to the include structure again (see picture 2-1).

3. I added a record into the table in order to be able to see the key definition in the debugger.

4. Then I tried to open the table key definition in the debugger (see picture 2-2, 2-3 and 2-4).

5. As you can see, Primary key definition in debugger is different than the PK definition in the program. At runtime the fields from the include structure go first and other fields go after them.

Picture 2. The test program

I've also tried to define internal table in the ABAP dictionary and got same resutl. The fields from the include structure go before other fields no matter if I defined another order in the key definition.

I've tried that in two systems: 7.3.1 SP 7 and 7.3.1 SP 11. In both cases result was the same.

Is this behaviour a feauture or it is just a bug?

Is it documented? Of course, I've tried to search on SCN, integrated ABAP help and even in the Official ABAP reference but found nothing.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

I think it should be considered as a bug, but the solution is not trivial as the issue comes from the limitation of the TPD_CONTROL C/kernel program. You may see the limitation in method IF_TPDA_CONTROL~GET_SYMB_ITAB of class CL_TPDA_CONTROL; there is call 'TPD_CONTROL' id 'COMPTYPETAB' field comptypetab, which is used later to display the key. Unfortunately, the information is insufficient in COMPTYPETAB because the order of key fields is absent. Value of COMPTYPETAB while debugging the debugger:

METATYPE  COMPNAME      ISKEY ... 
1         CREATE_TIME   X
1         CHANGE_TIME
1         CLOSING_TIME  X
1         CASE_GUID     X
1         CASE_TYPE     X

Consequently, you have the same problem with any kind of structure, even if they don't contain nested structures, and even if it's a local structure.

8 REPLIES 8

Former Member
0 Kudos

Add the Keyword COMPONENTS to your definition

DATA: lt_tab TYPE Sorted TABLE of ...

               WITH NON-UNIQUE KEY primary_key

                    COMPONENTS ... ... ... ...

edit: if this has no effect (at least it should have no effect) I think the best thing you can do is to define the structure first and include a variable of that structure into your table.

Message was edited by: Markus V ... Typo

0 Kudos

Hi, Markus!

As it was expected, I've got the same result when using the COMPONENTS clause.

In fact, I'm not looking for a workaround (it is obvious). I just want to find the reason of this behaviour. Is is a bug in the Debugger? Or, may be, it is a bug in the ABAP AS?

Or is it just a feature, not described in the official reference?

Former Member
0 Kudos

I  don't know which one of both it is but you could try it by creating a test scenario and see if the sorting is according to your definition or according to the ABAP debugger

Sandra_Rossi
Active Contributor
0 Kudos

I think it should be considered as a bug, but the solution is not trivial as the issue comes from the limitation of the TPD_CONTROL C/kernel program. You may see the limitation in method IF_TPDA_CONTROL~GET_SYMB_ITAB of class CL_TPDA_CONTROL; there is call 'TPD_CONTROL' id 'COMPTYPETAB' field comptypetab, which is used later to display the key. Unfortunately, the information is insufficient in COMPTYPETAB because the order of key fields is absent. Value of COMPTYPETAB while debugging the debugger:

METATYPE  COMPNAME      ISKEY ... 
1         CREATE_TIME   X
1         CHANGE_TIME
1         CLOSING_TIME  X
1         CASE_GUID     X
1         CASE_TYPE     X

Consequently, you have the same problem with any kind of structure, even if they don't contain nested structures, and even if it's a local structure.

0 Kudos

Hi, Sandra!

I've rewritten my program (see picture 1).

- Nested structure is replaced by the local type without any includes,

- I created an instance of CL_ABAP_TABLEDESCR in order to see the actual definition of the table key.

Picture 1. Modified program

The results are the following:

DEFINITION:

create_time

case_type

case_guid

change_time

RUNTIME (CL_ABAP_TABLEDESCR):

CREATE_TIME

CASE_TYPE

CASE_GUID

CHANGE_TIME

DEBUGGER (IF_TPDA_CONTROL~GET_SYMB_ITAB):

CREATE_TIME

CHANGE_TIME

CASE_GUID

CASE_TYPE

Hence, you are right. It seems to be a bug in the debugger.

And it exists in 7.40 sp 0014 too.

So, I've satisfied my curiosity.

Thanks all for the help and feedback!

I don't have an access to the SAP support, so I'm not going to open a ticket :-).

0 Kudos

@sandra.rossi I've been trying to debug CL_TPDA_CONTROL or call TPD_CONTROL but to no avail. Could you share a way to call it when it is not bound to a debugger session?

0 Kudos

williangruber It's not related to the OP question, please ask a new one.

0 Kudos

OK, I just couldn't find a way to send you a direct message, and thought it wouldn't be of interest to SCN this topic.

Thank you