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: 

Method that returns a table?

Former Member
0 Kudos

I am creating a Class and in the this class I want a method that returns a table.

Class: ZTEST_CLASS

Method: GET_PATCHES

Parameters: DATA Returning TYPE /SDF/CHAR300


method.
  CALL FUNCTION '/SDF/OCS_GET_INFO'
    TABLES
      TT_PATCH = DATA.
endmethod.

I get nothing but errors about how DATA is not an internal table.

If I change it to make an internal table:


method.
  DATA: itab TYPE TABLE OF /SDF/CHAR300.

  CALL FUNCTION '/SDF/OCS_GET_INFO' DESTINATION rfcdest
    TABLES
      TT_PATCH = ITAB.


endmethod.

This works, or at least it doesn't give any errors however I'm still not clear on how I can get that ot hte DATA returning parameter?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

If you define your attribute table in the Public Section of your class, you can reference to it as you wrote.

13 REPLIES 13

Former Member
0 Kudos

Hi,

You can define a table type which has /SDF/CHAR300 as its line type and define your returning parameter using this definition.

Regards,

Sükrü

0 Kudos

Sorry, but where do I define the table type in order for my returning parameter to get it?

Former Member
0 Kudos

Hi,

If your class is a local class, then you can define it in your in top include of your report of function group. But if it is global class that you are creating with the transaction SE24, then you define it in the DDIC. For example(for local class case)

Report XYZ.

types: gtyt_sdf_300 type standard table of /SDF/CHAR300.

.....

class lcl_test_class definition.

public section.

methods : get_patches

returning value(rt_patches) type gtyt_sdf_300.

endclass.

.....

Regards,

Sükrü

0 Kudos

I am making a global class so I will need to create a new Dictionary Table?

I will try that now and see what happens.

0 Kudos

Yes, you can create a <b>Table Type</b> using SE11.

0 Kudos

I must be doing something completely wrong.

I defined a new table and defined my DATA parameter to the type of the new table. But still no luck I get ""DATA" is not an internal table - the "OCCURS n" specification is missing"

Thanks for the help but I will do this another way.

I get my table inside the method but when I try to give it to the method parameter it just complains

Thanks again.

Former Member
0 Kudos

Hi Craig,

You had to create a Table type not a new DB table. Table types are also created using transaction SE11(Using radiobutton Data type and then selectiong table type as the data type to be created).

0 Kudos

I have options for

Database table

View

Data tyoe

Tyoe Group

Domain

Search help

Lock object

However, I think I might have got it now - just one question.

In the class I have a attribute defined for DATA (the table but not as a returning parameter on the method) is it possible that the method could update this table? If so how would I then access this attribute of the class?

I think I have it...


   DATA: itab TYPE ZSC_PATCHES.

   DATA: obj TYPE REF TO ZSC_GENERAL_METHODS.
   CREATE OBJECT obj.
   obj->GET_SYSTEM_PATCHES( rfcdest = 'TT1' ).
   itab = obj->DATA.

The method runs the CALL FUNCTION and then moves the table info from itab to DATA then I have the data from DATA available

Sound about right?

Message was edited by: Craig Cmehil

0 Kudos

In 620 there isn't a separate option for Table type anymore. You choose Data Type. You then get another popup asking you if you want to create a Data element, Structure, or a Table Type.

0 Kudos

Thanks for the tip Thomas!

0 Kudos

For a full sample of the code I finally got to work thanks to you guys look

Former Member
0 Kudos

If you define your attribute table in the Public Section of your class, you can reference to it as you wrote.

0 Kudos

Thanks for all your help!!!!