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: 

Return internal table from class method

former_member215563
Active Participant
0 Kudos

Hi All,

im trying to  return an internal table f but it is giving me an error,specification gt_mara is not expected.

CLASS z_model DEFINITION.

  PUBLIC SECTION.

    METHODS get_data RETURNING VALUE (gt_mara) type t_mara.

  PRIVATE SECTION.

    DATA:gt_mara TYPE STANDARD TABLE OF mara-matnr.

    TYPES:t_mara TYPE TABLE OF mara-matnr.

ENDCLASS.

CLASS z_model IMPLEMENTATION.

  METHOD get_data.

    SELECT matnr from mara into table gt_mara

      where matnr eq 'dlsadla''.

  ENDMETHOD.

ENDCLASS.

t_view = o_model->get_data( ).

Regards,

Faiz

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

try like this:


*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

CLASS z_model DEFINITION.







  PUBLIC SECTION.



    TYPES: BEGIN OF tp_mara .

    TYPES: matnr TYPE mara-matnr .

    TYPES: END OF tp_mara .



    TYPES: tp_mara_tab TYPE STANDARD TABLE OF tp_mara WITH NON-UNIQUE KEY matnr .



    METHODS get_data

      RETURNING value(it_mara) TYPE tp_mara_tab .



  PRIVATE SECTION.



ENDCLASS.                    "z_model DEFINITION

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

CLASS z_model IMPLEMENTATION.



  METHOD get_data.





  ENDMETHOD.                    "get_data



ENDCLASS.                    "z_model IMPLEMENTATION

7 REPLIES 7

Former Member
0 Kudos

Please refer this link: http://scn.sap.com/thread/1084946

0 Kudos

I did the same thing

FredericGirod
Active Contributor
0 Kudos

Hi,

why did you declare gt_mara in private section ?

regards

Fred

0 Kudos

Hi Fred,

Even if I remove it from private section and declare globally, still im getting the same error.

rosenberg_eitan
Active Contributor
0 Kudos

try like this:


*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

CLASS z_model DEFINITION.







  PUBLIC SECTION.



    TYPES: BEGIN OF tp_mara .

    TYPES: matnr TYPE mara-matnr .

    TYPES: END OF tp_mara .



    TYPES: tp_mara_tab TYPE STANDARD TABLE OF tp_mara WITH NON-UNIQUE KEY matnr .



    METHODS get_data

      RETURNING value(it_mara) TYPE tp_mara_tab .



  PRIVATE SECTION.



ENDCLASS.                    "z_model DEFINITION

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

CLASS z_model IMPLEMENTATION.



  METHOD get_data.





  ENDMETHOD.                    "get_data



ENDCLASS.                    "z_model IMPLEMENTATION

rosenberg_eitan
Active Contributor
0 Kudos

Forgot to add:


INITIALIZATION .



  DATA: it_mara TYPE z_model=>tp_mara_tab .



  DATA: z_model_obj TYPE REF TO z_model .



  CREATE OBJECT z_model_obj .



  it_mara = z_model_obj->get_data( ) .

Regards.

0 Kudos

Thanks Eitan..it works like a charm