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

Declaring a sorted table from a dbtab

Former Member
0 Likes
10,314

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
Read only

Former Member
9,829

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
Read only

Former Member
9,830

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.

Read only

0 Likes
9,829
...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)

Read only

9,829

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.

Read only

0 Likes
9,829

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

Read only

0 Likes
9,829

aveekbaruah

Yes. Refer to the documentation.

Read only

ThangaPrakash
Active Contributor
0 Likes
9,829

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.