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

passing an Internal Table as parameter to a method

Former Member
0 Likes
24,796

Hi,

Can we pass an internal table as a parameter to a method.if so how can we do that?i am new to abap objects..

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
9,327

Easy. You define the parameter as a table type. Table types are defined in the data dictionary, in type pools and within classes.

You should read the documentation about table types, table types in the dictionary and types in classes. Also have a look at some standard classes suppleid by SAP.

Hi,

Can we pass an internal table as a parameter to a method.if so how can we do that?i am new to abap objects..

5 REPLIES 5
Read only

matt
Active Contributor
9,328

Easy. You define the parameter as a table type. Table types are defined in the data dictionary, in type pools and within classes.

You should read the documentation about table types, table types in the dictionary and types in classes. Also have a look at some standard classes suppleid by SAP.

Read only

Former Member
0 Likes
9,327

Hi Matt,

Here is the code that i am trying to execute.I am extracting the data in the method "Extract" and passing it to the method "Display" to produce a report output.When i execute this it is giving me an error saying that t_mara is not an internal table since i just refered it with x_mara in the class definition.So how can i modify this code to pass t_mara as an internal table from the method "Extract".Please help me.

&----


*& Report ZOBJ_PRAC *

*& *

&----


*& *

*& *

&----


REPORT zobj_prac .

----


  • CLASS example DEFINITION

----


*

----


CLASS example DEFINITION.

PUBLIC SECTION.

TYPES : BEGIN OF x_mara,

matnr TYPE matnr,

ersda TYPE ersda,

END OF x_mara.

METHODS : extract EXPORTING t_mara TYPE x_mara,

display IMPORTING it_mara TYPE x_mara.

ENDCLASS. "example DEFINITION

"example IMPLEMENTATION

----


  • CLASS example IMPLEMENTATION

----


*

----


CLASS example IMPLEMENTATION.

METHOD extract.

DATA :lt_mara TYPE STANDARD TABLE OF x_mara INITIAL SIZE 0,

lw_mara TYPE x_mara.

SELECT matnr ersda FROM mara INTO TABLE lt_mara UP TO 10 ROWS.

t_mara[] = lt_mara[].

ENDMETHOD. "extract

METHOD display.

DATA :lt_mara TYPE STANDARD TABLE OF x_mara INITIAL SIZE 0,

lw_mara TYPE x_mara.

lt_mara[] = it_mara[].

LOOP AT lt_mara INTO lw_mara.

WRITE:/ lw_mara-matnr,

20 lw_mara-ersda.

ENDLOOP.

ENDCLASS. "example IMPLEMENTATION

START-OF-SELECTION.

DATA : b1 TYPE REF TO example.

CREATE OBJECT b1 TYPE example.

TYPES : BEGIN OF x_mara,

matnr TYPE matnr,

ersda TYPE ersda,

END OF x_mara.

data : t_mara type standard table of x_mara initial size 0,

it_mara type standard table of x_mara initial size 0.

call method b1->extract

importing

t_mara = t_mara.

it_mara[] = t_mara[].

call method b1->display

exporting

it_mara = it_mara.

Edited by: Sai Chaitanya on Dec 2, 2008 5:30 AM

Read only

Former Member
9,327

Hi Chaitanya,

Declare a table type ( here tt_mara ) and use it.....

*----------------------------------------------------------------------*
*       CLASS example DEFINITION                                       *
*----------------------------------------------------------------------*
CLASS example DEFINITION.

  PUBLIC SECTION.

    TYPES : BEGIN OF x_mara,
            matnr TYPE matnr,
            ersda TYPE ersda,
            END   OF x_mara.

    TYPES   tt_mara TYPE STANDARD TABLE OF x_mara.  " TABLE TYPE

    METHODS : extract EXPORTING t_mara  TYPE tt_mara,
              display IMPORTING it_mara TYPE tt_mara.
ENDCLASS. "example DEFINITION

*----------------------------------------------------------------------*
*       CLASS example IMPLEMENTATION                                   *
*----------------------------------------------------------------------*
CLASS example IMPLEMENTATION.
  METHOD extract.

  ENDMETHOD.                    "extract
  METHOD display.

  ENDMETHOD.                    "display
ENDCLASS.                    "example IMPLEMENTATION

Cheers,

Jose.

Read only

uwe_schieferstein
Active Contributor
0 Likes
9,327

Hello Sai

Below you find my recommendation how to code your class:


*&---------------------------------------------------------------------*
*& Report  ZUS_DUMMY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_dummy.



*----------------------------------------------------------------------*
*       CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.

  PUBLIC SECTION.
    TYPES: ty_t_mara    TYPE STANDARD TABLE OF mara.

    METHODS:
      extract
        RETURNING value(rt_mara)  TYPE mara_tt,

      extract_by_export
        EXPORTING
          et_mara   type ty_t_mara.

ENDCLASS.                    "lcl_myclass DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_myclass IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass IMPLEMENTATION.

  METHOD extract.
    SELECT * FROM mara INTO TABLE rt_mara UP TO 10 ROWS.
  ENDMETHOD.                    "extract

  METHOD extract_by_export.
    SELECT * FROM mara INTO TABLE et_mara UP TO 10 ROWS.
  ENDMETHOD.                    "extract

ENDCLASS.                    "lcl_myclass IMPLEMENTATION


DATA: go_myclass   TYPE REF TO lcl_myclass,
      gt_mara      TYPE STANDARD TABLE OF mara.

START-OF-SELECTION.

  CREATE OBJECT go_myclass.
  gt_mara = go_myclass->extract( ).

  call method go_myclass->extract_by_export
    importing
      et_mara = gt_mara.

END-OF-SELECTION.

Regards

Uwe

Read only

Former Member
0 Likes
9,327

Thank You all..