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

Creating TYPES structure without nesting

pnamin77
Explorer
0 Likes
3,476

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

pnamin77
Explorer
0 Likes
3,314

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

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

this one works ? (not tested)

Read only

pnamin77
Explorer
0 Likes
3,314

Thanks frdric.girod

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

The INCLUDE (Flat structure) is still there.

Read only

pnamin77
Explorer
0 Likes
3,315

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

Read only

0 Likes
3,314

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

Read only

0 Likes
3,314

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

Read only

3,314

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

0 Likes
3,314

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.

Read only

Sandra_Rossi
Active Contributor
3,314

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

FredericGirod
Active Contributor
0 Likes
3,314

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

Read only

nomssi
Active Contributor
3,314

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

pnamin77
Explorer
0 Likes
3,314

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.