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

Sample code for itab in method

Former Member
0 Likes
541

Hi All,

Can anyone provide me some inputs/sample code for passing an internal table

as importing parameter of a method in a class.

thanks

Ricky

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
464

Yes, you need to type it as a table type.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
464

Here is a short example.



report zrich_0001.


*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.

    types: tt001 type table of t001.

    class-data: itab type table of t001.

    class-methods: fill_itab importing im_itab type tt001.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.

  method fill_itab.
    itab = im_itab.
  endmethod.

endclass.

data: it001 type table of t001.

start-of-selection.

  select * into table it001 from t001.

  call method lcl_app=>fill_itab( it001 ).


Regards,

Rich Heilman

Read only

Former Member
0 Likes
464

hi,

for method definition.

types : ty_mara type table of mara.

data : itab type ty_mara.

methods : get_data importing itab type ty_mara

for method implementation

method get_data.

" you can acess itab here.

endmethod.

for calling method.

ob->get_data exporting it_mara.

A better way to do this is to pass all the user data from selection screen to the method and define table in the class that selects the data as per the selection crieteria. So you have the data in the form of table which is protected. Here is the sample code.

REPORT zfgli003.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

*-- Ledger

PARAMETERS: p_rldnr LIKE zzprodnt-rldnr DEFAULT 'NP'.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

DATA : o_tm1_intf TYPE REF TO lcl_tm1_intf.

CREATE OBJECT o_tm1_intf.

CALL METHOD o_tm1_intf->get_data EXPORTING e_rldnr = p_rldnr .

CLASS lcl_tm1_intf DEFINITION.

PUBLIC SECTION.

types : BEGIN OF ty_zzprodnt, "Type-ledger summary table

company TYPE obukr, "Company

gl_acct TYPE racct, "GL Account

cst_ctr TYPE kostl, "Cost Center

prt_ctr TYPE prctr, "Profit Center

rfarea TYPE fkber, "Functional Area

wbs_ele TYPE ps_posid, "WBS Element

prd_ass TYPE rkeg_wwz01, "Product Assignment

corp_bd TYPE rkeg_wwz05, "Corporate Brand

END OF ty_zzprodnt.

data : itab type table of ty_zzprodnt.

METHODS : get_data IMPORTING e_rldnr TYPE c.

ENDCLASS. "lcl_tm1_intf DEFINITION

CLASS lcl_tm1_intf IMPLEMENTATION.

METHOD get_data.

SELECT robukrs

racct

rcntr

rprctr

rfarea

rzzwbs_el

rzzwwz01

rzzwwz05

FROM zzprodnt

INTO TABLE it_zzprodnt

WHERE rldnr = e_rldnr.

IF sy-subrc = 0.

endif.

ENDMETHOD. "get_data

ENDCLASS. "lcl_tm1_intf IMPLEMENTATION

Hope this helps.

Regards,

Richa