Home > Blockchain >  How to expose the return type of a global class method?
How to expose the return type of a global class method?

Time:02-04

I've written an ABAP Method, which returns me some analyses in a custom table. Now I want to call this Method from an RFC module.

So far so good - the method works fine, but I'm curious of how to return this table? Do I have to create a table / structure ... in SE11 to make it work because otherwise I can't refer to this table type or is there an easier way? I'm quite new to ABAP so I don't know the best practices.

m_analyses = new zcl_manalyses(  ).
data(lt_m_analyses) = m_analyses->analyse_m_data(
    budat_from  = budat_from
    budat_to    = budat_to
).

enter image description here

CodePudding user response:

The TYPES statement can not only occur inside a method's body, but also inside the class definition, in which case it can be accessed from other places with class_name=>type_name (if it's public):

CLASS cl_user_registry DEFINITION PUBLIC.
  PUBLIC SECTION.
   TYPES:
     BEGIN OF user,
       firstname TYPE string,
       lastname  TYPE string,
     END OF user,
     users TYPE STANDARD TABLE OF user.

   METHODS:
     get_current_users
       RETURNING users.
ENDCLASS.

DATA current_users TYPE cl_user_registry=>users.
current_users = cl_user_registry=>get_current_users( ).

CodePudding user response:

You first have to create a structure in ABAP Dictionary (SE11), then you create a table type in SE11 as well.

You then reference the structure in the line type of the table type.

Try using the new global table type, it should work. (with typing 'TYPE')

  •  Tags:  
  • Related