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

Nested Type consisting another table type!

gadde_shrinivas
Explorer
0 Likes
3,795

Hi,

How can I achieve below type declarations?


TYPES:BEGIN OF ty_scarr,

        carrid    TYPE scarr-carrid,

        carrname  TYPE scarr-carrname,

        currcode  TYPE scarr-currcode,

      END OF ty_scarr,

      BEGIN OF ty_sflight,

        carrid TYPE sflight-carrid,

        connid TYPE sflight-connid,

        fldate TYPE sflight-fldate,

        price  TYPE sflight-price,

      END OF ty_sflight,

      tt_sflight TYPE STANDARD TABLE OF ty_sflight.

TYPES:BEGIN OF ty_result.

        INCLUDE TYPE ty_scarr.

        TYPES: sflight_tab TYPE tt_sflight,

      END OF ty_result.

The above results in syntax error however below one works:


TYPES:BEGIN OF ty_scarr,

        carrid    TYPE scarr-carrid,

        carrname  TYPE scarr-carrname,

        currcode  TYPE scarr-currcode,

      END OF ty_scarr,

      BEGIN OF ty_sflight,

        carrid TYPE sflight-carrid,

        connid TYPE sflight-connid,

        fldate TYPE sflight-fldate,

        price  TYPE sflight-price,

      END OF ty_sflight,

      tt_sflight TYPE ty_sflight OCCURS 0.

TYPES:BEGIN OF ty_result.

        INCLUDE TYPE ty_scarr.

        TYPES: sflight_tab TYPE tt_sflight,

      END OF ty_result.

Is there a way to achieve above without using "OCCURS 0" keyword as "OCCURS" keyword is not supported withing OO context?

Thanks!

1 ACCEPTED SOLUTION
Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
2,094

Hello Shrinivas,

Please use the below syntax

Data :       tt_sflight TYPE STANDARD TABLE OF ty_sflight.

Thanks

4 REPLIES 4
Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
2,095

Hello Shrinivas,

Please use the below syntax

Data :       tt_sflight TYPE STANDARD TABLE OF ty_sflight.

Thanks

Read only

0 Likes
2,094

I tried that too however with below code now I get syntax error "The type 'TT_SFLIGHT' is unknown, but there is a type with the similar name 'TY_SFLIGHT'." on line "TYPES: sflight_tab TYPE tt_sflight"


TYPES:BEGIN OF ty_scarr,

        carrid    TYPE scarr-carrid,

        carrname  TYPE scarr-carrname,

        currcode  TYPE scarr-currcode,

      END OF ty_scarr,

      tt_scarr TYPE STANDARD TABLE OF ty_scarr,

      BEGIN OF ty_sflight,

        carrid TYPE sflight-carrid,

        connid TYPE sflight-connid,

        fldate TYPE sflight-fldate,

        price  TYPE sflight-price,

      END OF ty_sflight.

DATA: tt_sflight TYPE STANDARD TABLE OF ty_sflight.

TYPES:BEGIN OF ty_result.

        INCLUDE TYPE ty_scarr.

TYPES: sflight_tab TYPE tt_sflight,

END OF ty_result,

tt_result TYPE STANDARD TABLE OF ty_result.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,094

Hello,

Which ABAP release are you working on?

When i use your code (on an ABAP 740 kernel) i get the following error message -

This is because the type is generic w.r.t the key. If you intend to use it in other types, you have to explicitly define the key for the table type.

Since I'm on ABAP release 740 so i can use the addition EMPTY KEY -

  1.       tt_sflight TYPE STANDARD TABLE OF ty_sflight
  2.                  WITH NON-UNIQUE EMPTY KEY.

If you are on previous releases i think you can use the addition DEFAULT KEY.

BR,

Suhas

PS - Further read:

Read only

0 Likes
2,094

Thanks. Adding "DEFAULT KEY" helped.