Skip to Content
0
Jun 09, 2009 at 01:01 PM

How to get data back from a method - a newbie question

92 Views

Hi,

I'm working on my first object and I am able to create an instance and it runs, but I am struggling with how to pass the data back to my calling program. Here is my code:

Public Section looks like this:

CLASS yandy_zcl_zvd047i DEFINITION

PUBLIC

CREATE PUBLIC .

PUBLIC SECTION.

TYPES:

BEGIN OF t_cust_hier,

hityp TYPE hityp,

kunnr TYPE kunnr,

datab TYPE datab,

datbi TYPE datbi,

hkunnr TYPE hkunnr_kh,

END OF t_cust_hier.

DATA: i_cust_hier TYPE TABLE OF t_cust_hier.

METHODS constructor.

METHODS get_data

EXPORTING

!p_ch TYPE t_cust_hier.

The Constructor is empty:

method CONSTRUCTOR.

endmethod.

Get_data is as follows:

METHOD get_data.

TYPES: BEGIN OF t_ch,

hityp TYPE hityp_kh,

kunnr TYPE kunnr_kh,

datab TYPE datab_kh,

datbi TYPE datbi_kh,

hkunnr TYPE hkunnr_kh,

END OF t_ch.

DATA: i_ch TYPE TABLE OF t_ch.

SELECT

hhityp hkunnr hdatab hdatbi h~hkunnr

INTO TABLE i_ch

FROM knvh AS h.

SORT i_ch[] BY kunnr.

  • p_ch = i_ch.

I have an EXPORTING parameter called P_CH with an associated tpye of T_CUST_HIER.

I'm struggling with that last line of code. when uncommented, I get a compile error saying:

The type of "I_CH" cannot be converted to the type of "P_CH".

Then my calling program looks like this (and I'm struggling with the importing parameter on the get_data method call):

REPORT yandy_zvd047i.

TYPES: BEGIN OF t_ch,

hityp TYPE hityp_kh,

kunnr TYPE kunnr_kh,

datab TYPE datab_kh,

datbi TYPE datbi_kh,

hkunnr TYPE hkunnr_kh,

END OF t_ch.

DATA: o_zvd047i TYPE REF TO yandy_zcl_zvd047i.

DATA: i_ch type table of t_ch.

START-OF-SELECTION.

create object o_zvd047i.

o_zvd047i->get_data( importing p_ch = i_ch ).

END-OF-SELECTION.

<<text removed>>

Thanks,

Andy

Edited by: Matt on Jun 9, 2009 8:02 PM