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: 

Dynamically created method call - parameter problems

Former Member
0 Kudos

Hello together

I need some help with the development of a dynamically created method call. The method I want to call dynamically needs an filter object (ZCL_FILTER) as a optional parameter and returns a material number (MATNR).

CLEAR ls_parameter.

ls_parameter-name = 'IO_FILTER'.

ls_parameter-kind = cl_abap_objectdescr=>exporting.

CREATE DATA ls_parameter-value TYPE REF TO zcl_filter.

INSERT ls_parameter INTO TABLE lt_parameters.

CLEAR ls_parameter.

DATA lv_materialnummer TYPE matnr.

ls_parameter-name = 'EV_MATERIAL_NUMBER'.

ls_parameter-kind = cl_abap_objectdescr=>receiving.

CREATE DATA ls_parameter-value TYPE matnr.

INSERT ls_parameter INTO TABLE lt_parameters.

CALL METHOD io_child->(<fs_classpath_entry_method>)

     PARAMETER-TABLE

         lt_parameters.

The method call itself works like a charm when I do not try to pass the object lo_filter (as in the code above). In the shown case an exception is thrown by the system.

When I use

CREATE DATA ls_parameter-value TYPE REF TO zcl_filter.


instead of


GET REFERENCE OF lo_filter INTO ls_parameter-value.

it technically works fine, but the object lo_object is not exported to the method which doesn't make sense at all. The same problem occurs when I try to pass a table as a parameter with this method. Only the exporting of a single string variable works.

Has someone a good idea of how to pass complex structurs (objects, tables) as a parameter in a dynamical created method call?

Thanks in advance
Peter

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

GET REFERENCE should work for any type, and it should work also with the dynamic call ("GET REFERENCE OF lo_filter INTO ls_parameter-value"). As dynamic calls are widely used by SAP, I doubt there is a kernel bug.

No issue on my 7.31 system:

REPORT.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
    CLASS-METHODS test IMPORTING io_demo TYPE REF TO demo.
    DATA attr TYPE string.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA: lt_par TYPE abap_parmbind_tab,
          ls_par TYPE abap_parmbind,
          oref   TYPE REF TO demo.

    CREATE OBJECT oref.

    REFRESH : lt_par.
    CLEAR ls_par.
    ls_par-name = 'IO_DEMO'.
    ls_par-kind = cl_abap_objectdescr=>exporting.
    GET REFERENCE OF oref INTO ls_par-value.
    INSERT ls_par INTO TABLE lt_par.

    CALL METHOD ('TEST')
      PARAMETER-TABLE
      lt_par.

    cl_demo_output=>display_data( oref->attr ).
  ENDMETHOD.
  METHOD test.
    IF io_demo IS BOUND.
      io_demo->attr = 'BB'.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).
3 REPLIES 3

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

It makes not too much sense to use CREATE DATA here, if you want to pass a reference to an existing data object. What prevents you using GET REFERENCE? See the example in the documentation.

If you want to use CREATE OBJECT, you also have to take care to assign data to or get the data from the created anonymous data objects. Above, you do nothing for that. You pass an empty parameter.

Horst

Sandra_Rossi
Active Contributor
0 Kudos

GET REFERENCE should work for any type, and it should work also with the dynamic call ("GET REFERENCE OF lo_filter INTO ls_parameter-value"). As dynamic calls are widely used by SAP, I doubt there is a kernel bug.

No issue on my 7.31 system:

REPORT.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
    CLASS-METHODS test IMPORTING io_demo TYPE REF TO demo.
    DATA attr TYPE string.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA: lt_par TYPE abap_parmbind_tab,
          ls_par TYPE abap_parmbind,
          oref   TYPE REF TO demo.

    CREATE OBJECT oref.

    REFRESH : lt_par.
    CLEAR ls_par.
    ls_par-name = 'IO_DEMO'.
    ls_par-kind = cl_abap_objectdescr=>exporting.
    GET REFERENCE OF oref INTO ls_par-value.
    INSERT ls_par INTO TABLE lt_par.

    CALL METHOD ('TEST')
      PARAMETER-TABLE
      lt_par.

    cl_demo_output=>display_data( oref->attr ).
  ENDMETHOD.
  METHOD test.
    IF io_demo IS BOUND.
      io_demo->attr = 'BB'.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Former Member
0 Kudos

I got this working now, the problem I originally had was caused by the method I called itself. Thanks a lot