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 a sorted table from a dbtab

former_member333493
Participant
0 Kudos

In the public section of my class, I have:

TYPES: ty_t_tadir_detail TYPE SORTED TABLE OF dbtab.

In the private section, I have:

DATA: gt_tadir_detail TYPE ty_t_tadir_detail.

When I try to activate, I get the error:

"TY_T_TADIR_DETAIL" is a generic type. Use this type only for typing field symbols and formal parameters.

How do I make a sorted table gt_tadir_detail from my dbtab, to be used as a class attribute?

1 ACCEPTED SOLUTION

gabmarian
Active Contributor

You have to explicitly specify the keys for the table type, otherwise it will be considered generic:

... TYPE SORTED TABLE OF dbtab [ WITH UNIQUE | NON-UNIQUE ] KEY components. 

It's irrelevant that the line type is a structure defined by a database table.

6 REPLIES 6

gabmarian
Active Contributor

You have to explicitly specify the keys for the table type, otherwise it will be considered generic:

... TYPE SORTED TABLE OF dbtab [ WITH UNIQUE | NON-UNIQUE ] KEY components. 

It's irrelevant that the line type is a structure defined by a database table.

0 Kudos
...TYPE SORTED TABLE OF dbtab WITH UNIQUE KEY f1 f2 f3.

This works perfectly.
I have a follow-up question: what would be the correct way to add new records into GT_TADIR_DETAIL table, while keeping the table sorted? (I've read in places that APPEND statements break the sorting/result in a dump)

gabmarian
Active Contributor

aveekbaruah

Forget about APPEND in case of non-standard tables (more so, I recommend to never use it), use INSERT instead. It will insert the new entry in the appropriate position respecting the keys.

0 Kudos

gabmarian Will the insert statement take care of duplicate entries too?

gabmarian
Active Contributor
0 Kudos

aveekbaruah

Yes. Refer to the documentation.

thanga_prakash
Active Contributor
0 Kudos

aveekbaruah I have considered it as MARA table and tried below.

DATA: ty_t_tadir_detail TYPE SORTED TABLE OF mara WITH NON-UNIQUE KEY matnr.
DATA: gt_tadir_detail LIKE ty_t_tadir_detail.