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: 

Creating TYPES structure without nesting

pnamin
Explorer
0 Kudos

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).

1 ACCEPTED SOLUTION

pnamin
Explorer
0 Kudos

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

11 REPLIES 11

FredericGirod
Active Contributor
TYPES: BEGIN OF ty_custom_tab.
include TYPE tab1,
TYPES : field1 TYPE tab2-field1,
END OF ty_custom_tab.

this one works ? (not tested)

pnamin
Explorer
0 Kudos

Thanks frdric.girod

I tried this but it doesn't make any difference.

The INCLUDE (Flat structure) is still there.

pnamin
Explorer
0 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

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".

0 Kudos

sandra.rossi
What would be a data type for a transparent table like MARA?
If I need to replace STRUCTURE with TYPE

Sandra_Rossi
Active Contributor

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.

0 Kudos

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.

Sandra_Rossi
Active Contributor

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.

FredericGirod
Active Contributor
0 Kudos

Sandra is also known as Maitre Capello (french joke) 😉

nomssi
Active Contributor

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.

pnamin
Explorer
0 Kudos

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.