11-21-2019 11:26 AM
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?
11-21-2019 11:32 AM
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.
11-21-2019 11:32 AM
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.
11-21-2019 12:52 PM
...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)
11-21-2019 1:32 PM
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.
11-21-2019 1:38 PM
gabmarian Will the insert statement take care of duplicate entries too?
11-21-2019 1:47 PM
11-21-2019 1:09 PM
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.