‎2008 Aug 05 12:37 PM
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?
‎2008 Aug 05 12:45 PM
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
‎2008 Aug 05 12:39 PM
‎2008 Aug 05 12:45 PM
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
‎2008 Aug 05 1:23 PM
‎2008 Aug 05 1:46 PM
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_matnretc.
Get into the habit now!
‎2008 Aug 05 2:40 PM
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.
‎2008 Aug 05 1:42 PM
hi,
Create a Work Area inside the class and use it as the Header for the internal table.
Regards
Sumit Agarwal
‎2008 Aug 05 3:02 PM
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
‎2008 Aug 06 12:47 PM
Hi Pavan
can u describe me more in details plz?
im very new to OOP