2006 Nov 01 4:43 AM
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
2006 Nov 01 5:17 AM
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
2006 Nov 01 5:35 AM
Hi Uwe ,
Thanks for your help I will try it out .
Thanks
Anita
2006 Nov 01 6:07 AM
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.