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

Global Object Attribute local type

FelixOrtiz
Explorer
0 Likes
3,606

I created a local type in the class.

Loc. Definitions/Implementations

types:

   BEGIN OF ty_escal,

       level    TYPE i,

       urg(4)   TYPE n,

       high(4TYPE n,

       med(4)   TYPE n,

       low(4)   TYPE n,

   END OF ty_escal.

Now I want to create a private attribute of the class using this type.

I also would like to define a table type and create an private table of the same type.

What am I missing?

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
2,161

Make sure you have defined the type TY_ESCAL in the one the section of the class, not within the method. Types defined within the method implementation can only be used within the method itself, not an attribute to the calss.

If you are working with Global class in Class Editor SE24, Navigate to Attributes tab. Here you can simply use a name for your desired variable and use TY_ESCAL as the Type.

For Internal table attribute, you should create a table type from your Type. So, in the same section where you have TY_ESCAL defined, define another type. Use this type to declare you ITAB.

TYPES: TT_ESCAL TYPE STANDARD TABLE OF TY_ESCAL.

Regards,
Naimesh Patel

6 REPLIES 6
Read only

Former Member
0 Likes
2,161

Hi Felix,

please check the bewlo link.It will help u.

http://help.sap.com/saphelp_40b/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm

CLASS C_COUNTER DEFINITION.

  PUBLIC SECTION.
    METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,
             INCREMENT_COUNTER,
             GET_COUNTER EXPORTING VALUE(GET_VALUE) TYPE I.

  PRIVATE SECTION.
    DATA COUNT TYPE I.

ENDCLASS.


Thanks

Tarak

Moderator Message - How is your response relevant to the OP's query?

Message was edited by: Suhas Saha

Read only

Former Member
0 Likes
2,161

Dear Felix,

Please check the below code:

   CLASS LCL_MONTH DEFINITION.
PRIVATE SECTION.
    TYPES: BEGIN OF TY_VBRK,
      VBELN TYPE VBELN_VF,
      FKDAT TYPE FKDAT,
      BELNR TYPE BELNR_D,
      KUNAG TYPE KUNAG,
      POSNR TYPE POSNR_VF,
      FKIMG TYPE FKIMG,
      VRKME TYPE VRKME,
      MATNR TYPE MATNR,
    END OF TY_VBRK.

     CLASS-DATA: IT_VBRK TYPE STANDARD TABLE OF TY_VBRK,
                WA_VBRK TYPE TY_VBRK.
ENDCLASS.                    "LCL_MONTH DEFINITION

Read only

naimesh_patel
Active Contributor
0 Likes
2,162

Make sure you have defined the type TY_ESCAL in the one the section of the class, not within the method. Types defined within the method implementation can only be used within the method itself, not an attribute to the calss.

If you are working with Global class in Class Editor SE24, Navigate to Attributes tab. Here you can simply use a name for your desired variable and use TY_ESCAL as the Type.

For Internal table attribute, you should create a table type from your Type. So, in the same section where you have TY_ESCAL defined, define another type. Use this type to declare you ITAB.

TYPES: TT_ESCAL TYPE STANDARD TABLE OF TY_ESCAL.

Regards,
Naimesh Patel

Read only

0 Likes
2,161

Thank you, I have attempted your described steps, however I recieve an error that ty_escal is not known.

Please see attached screenshots

Read only

0 Likes
2,161

You have defined your TYPE in wrong section. It should be defined in Type Tab rather than "Loc. Definitions/Implementations" section. If you open your class in SE24, you would find a tab called, Types. You need to create your type in this tab.

You can also directly create the TYPE by, menu Go To > Section > Private Section in SE24. Cut and paste your Type from section "Loc. Definitions/Implementations" to this Private Section. After that you should be able to use it for declaring an attribute.

Loc. Definitions/Implementations should be used for Local helper classes within the Global Class itself. They are hidden even from the Inheritance tree as well. You can read one of my article When to use Local Class and when not to! | ABAP Help Blog on when to really use Local Helper class.

Thanks,
Naimesh Patel

Read only

0 Likes
2,161

Thank you, you are exactly correct.  I moved my types definition to the private section of the class in the source code based editor (7.02), just above my data statements for defining private attributes. Worked perfectly!  I was experimenting with exactly that when your post confirmed it.

Thanks again.

Felix