03-01-2022 6:38 AM
I am having a requirement to create an internal table which should have a structure containing all fields of one internal table (like BSEG, AUSP) and few fields from another table like (MARC-WERKS).
When I use something like
TYPES: BEGIN OF ty_custom_tab,
include TYPE tab1,
field1 TYPE tab2-field1,
END OF ty_custom_tab.
The above code creates a nested structure in the internal table with two columns:
1. The INCLUDE structure
2. the field
Reading this data table is quite cumbersome.
Is there anyway this can be simplified. Tab1 contains a lot of fields. So listing them all in the TYPES declaration is not a good idea.
I want he include structure in the exploded view (tab1-fld1, tab1-fld2....................tab1-fldn, tab2-fld1).
03-01-2022 7:12 AM
I figured it out.
Did some fiddling around and this is the code that works
TYPES: BEGIN OF ty_custom_tab.
INCLUDE STRUCTURE tab1,
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.
The above code works.
Reference link: here
03-01-2022 6:48 AM
TYPES: BEGIN OF ty_custom_tab.
include TYPE tab1,
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.
this one works ? (not tested)
03-01-2022 7:02 AM
Thanks frdric.girod
I tried this but it doesn't make any difference.
The INCLUDE (Flat structure) is still there.
03-01-2022 7:12 AM
I figured it out.
Did some fiddling around and this is the code that works
TYPES: BEGIN OF ty_custom_tab.
INCLUDE STRUCTURE tab1,
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.
The above code works.
Reference link: here
03-01-2022 8:53 AM
You are using "INCLUDE STRUCTURE tab1" which means that tab1 is a data object. You should prefer (not mandatory) referring to a data type as far as possible e.g. "INCLUDE TYPE type_of_tab1".
03-01-2022 9:52 AM
sandra.rossi
What would be a data type for a transparent table like MARA?
If I need to replace STRUCTURE with TYPE
03-01-2022 12:38 PM
A transparent table corresponds in ABAP to a structured data type of same name.
TYPES BEGIN OF structured_type.
INCLUDE TYPE mara AS mara. " AS mara to do as Jacques said
TYPES END OF structured_type.
03-01-2022 1:16 PM
This does work, I tried frdric.girod's suggestion and the only difference I made was putting that 'AS mara' statement.
I suspected the AS addition would be for Aliasing, though it made a big difference.
03-01-2022 8:55 AM
If tab1 is a structured data type, this code works (same as Frederic but comma after tab1 replaced with dot):
TYPES: BEGIN OF ty_custom_tab.
include TYPE tab1.
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.
If tab1 is a structured data object, you should use:
TYPES: BEGIN OF ty_custom_tab.
include STRUCTURE tab1.
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.
03-01-2022 9:11 AM
03-01-2022 9:24 AM
To be able to easily access both the fields and the structure, I prefer
TYPES: BEGIN OF ty_custom_tab,
INCLUDE TYPE tab1 AS tab1.
TYPES: field1 TYPE tab2-field1,
END OF ty_custom_tab.
03-01-2022 9:50 AM
Thanks sandrarossi frdric.girod ,
The ITAB1 in context for me is the table AUSP which is a transparent table (data object). So STRUCTURE worked here instead of TYPE.
If it would have been a STRUCTURE for eg. AUSPDATA, then TYPES would have worked instead.