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

internal table when creating a class

Former Member
0 Likes
3,014

Hi everybody

im defining parameters when defining a class

one of the parameters is IT_MARA, of type MARA

Ive declared a method - SELECT_DATA, where the code is

SELECT * FROM MARA

INTO TABLE IT_MARA....

When activating it

Im getting the error - IT_MARA is not an internal table 'OCCURS n ' specification is missing

anybody knows how to solve that issue?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,630

Hi,

The declaration for internal table has to be like

IT_MARA TYPE TABLE OF MARA.

For classes, this much wont be sufficient. You need to declare the key for the table as well.

IT_MARA TYPE TABLE OF MARA WITH { DEFAULT KEY | key of your choice }.

Moreover it is not possible in OOABAP to declare internal tables with header line.

~Piyush Patil

Edited by: Piyush Patil on Aug 5, 2008 5:16 PM

8 REPLIES 8
Read only

Former Member
0 Likes
1,630

data: IT_MARA type TABLE OF mara WITH HEADER LINE.

Read only

Former Member
0 Likes
1,631

Hi,

The declaration for internal table has to be like

IT_MARA TYPE TABLE OF MARA.

For classes, this much wont be sufficient. You need to declare the key for the table as well.

IT_MARA TYPE TABLE OF MARA WITH { DEFAULT KEY | key of your choice }.

Moreover it is not possible in OOABAP to declare internal tables with header line.

~Piyush Patil

Edited by: Piyush Patil on Aug 5, 2008 5:16 PM

Read only

0 Likes
1,630

hmm ok, so how should I write it then?

anybody has any idea?

Read only

matt
Active Contributor
0 Likes
1,630

Never use tables with header lines. It's bad programming.

In ABAP Objects and in non-ABAP Objects programs you should use the form:

DATA: mytab TYPE table_defn.

DATA: my_wa TYPE line_type.

E.g.

DATA: my_mara_tab TYPE HASHED TABLE OF mara WITH UNIQUE KEY matnr.
DATA: ls_mara TYPE mara.
FIELD-SYMBOLS: <ls_mara> TYPE mara.

LOOP AT my_mara_tab INTO ls_mara.
...
LOOP AT my_mara_tab ASSIGNING <ls_mara>,
...
READ TABLE my_mara_tab INTO ls_mara WITH TABLE KEY matnr = l_matnr

etc.

Get into the habit now!

Read only

0 Likes
1,630

Hi Anjali,

I figure out you are having trouble passing an internal table out of a method of a class.

The error you get is because the parameter you have declared using TYPE MARA actually creates a line type and not an internal table in the signature of the method.

You have to declare the parameter with a 'table type' rather, and it will create an internal table.

You could use either a global table type or a local one.

Please have a look at the code below using a local table type for this problem:


CLASS a DEFINITION.
  PUBLIC SECTION.
    TYPES ty_mara TYPE TABLE OF mara.     "Local Table Type
    METHODS meth EXPORTING et_mara TYPE ty_mara.   "This makes an internal table
ENDCLASS. 


CLASS a IMPLEMENTATION.
  METHOD meth.
    SELECT * FROM mara INTO TABLE et_mara UP TO 10 ROWS.
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION.

  DATA lt_mara TYPE TABLE OF mara.
  DATA lr_a    TYPE REF TO a.

  CREATE OBJECT lr_a.
  CALL METHOD lr_a->meth
    IMPORTING
      et_mara = lt_mara.
  BREAK-POINT.

Read only

Former Member
0 Likes
1,630

hi,

Create a Work Area inside the class and use it as the Header for the internal table.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
1,630

Hi Anjali,

If you are working with global class

Using the push button Local Types

define the local type as

types : ty_mara type standard table of mara.

use the ty_mara in defining the parameter it will take as the table type

Define local work area for processing

Regards

Pavan

Read only

0 Likes
1,630

Hi Pavan

can u describe me more in details plz?

im very new to OOP