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: 

How to create a structure in a method

Former Member
0 Kudos
173

Hi

Would any please tell me how to delcare a structure in a method which contains a SAP defined structre in it . I have done it in normal ABAP but it not taking that syntax in ABAP objects method . Please tell me syntax for a method .

Thanks

Anita

3 REPLIES 3

uwe_schieferstein
Active Contributor
0 Kudos
97

Hello Anita

I assume you tried the statement

DATA: begin of <struct>.
...

In methods we have to use the following approach:

TYPES: begin of ty_s_struc.
TYPES:   field1   TYPE <fieldname>.
TYPES:   field2   TYPE <struct-fieldname>.
TYPES:   ...
TYPES: end of ty_s_struc.
DATA:
  ls_struc     TYPE ty_s_struc,
  lt_itab      TYPE STANDARD TABLE OF ty_s_struc
               WITH DEFAULT KEY.

I prefer to place my type definition in the "TYPES section" (see push button "Types" in SE24). However, all types defined within your class are <b>private</b> meaning you cannot use them in the interface of public methods.

Regards

Uwe

0 Kudos
97

Hi Uwe ,

Thanks for your help I will try it out .

Thanks

Anita

0 Kudos
97

Hello Anita

You may have wondered why I used the option

... WITH DEFAULT KEY.

The reason for that is that I sometimes got an syntax error saying "...generic type cannot be used..." when I defined my data variables. This syntax error never occurs with the added option.

Regards

Uwe

PS: There is no need to use TYPES: ... for each single field in your structure. However, I am sometimes old-fashioned in the sense: single line -> single statement.