2008 Dec 01 11:08 AM
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..
2008 Dec 01 3:14 PM
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..
2008 Dec 01 3:14 PM
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.
2008 Dec 02 4:29 AM
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
2008 Dec 02 5:29 AM
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 IMPLEMENTATIONCheers,
Jose.
2008 Dec 02 5:32 AM
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
2008 Dec 02 6:25 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |