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: 

How to check if the parameter of a method is "SUPPLIED" dynamically

Hi,

I will have to say that I have a peculiar requirement. I wanted to know dynamically whether a particular parameter is "SUPPLIED" or not. The current code that I have written does not work.

Ex. I have a method METHOD1 in class ZCL_CLASS1 with the following parameters:

IV_P1  TYPE IMPORTING

IV_P2 TYPE IMPORTING

EV_P1 TYPE EXPORTING

EV_P2 TYPE EXPORTNG

Now I have a report which calls this method:


ZCL_CLASS1=>METHOD1(

EXPORTING

     iv_p1 = lv_p1

     iv_p2 = lv_p2

IMPORTING

     ev_p1 = lv_p3 ).


Within the method METHOD1 I have the following code:

DATA: lo_obj_ref TYPE REF TO cl_abap_classdescr,

           lt_meth    TYPE abap_methdescr_tab,

           lt_params  TYPE abap_parmdescr_tab,

           ls_param   TYPE LINE OF abap_parmdescr_tab.

     FIELD-SYMBOLS <ls_meth> TYPE LINE OF abap_methdescr_tab.

     lo_obj_ref ?= cl_abap_classdescr=>describe_by_name( p_name = 'ZCL_CLASS1' ).

     lt_meth = lo_obj_ref->methods.

     READ TABLE lt_meth ASSIGNING <ls_meth> WITH TABLE KEY name = 'METHOD1'.

     ASSERT CONDITION sy-subrc = 0.

     lt_params = <ls_meth>-parameters.

    

     LOOP AT lt_params INTO ls_param.

       IF ( ls_param-name ) IS SUPPLIED.

         " Do something

       ENDIF.

     ENDLOOP.


In the above code piece the dynamic check " IF ( ls_param-name ) IS SUPPLIED" gives a syntax check. I guess you can only use the static definition to check if the parameter is SUPPLIED.


Wanted to know if anyone has done this before and if yes then how this an be achieved. I tried a lot with RTTI classes and methods and nowhere I can know whether the parameter has been formally bound in the caller.


Best regards,

Sudhi

10 REPLIES 10

Former Member
0 Kudos

Hi,

Before calling static method of your Z-Class you can check whether all exporting parameters are supplied are not.


I will have to say that I have a peculiar requirement. I wanted to know dynamically whether a particular parameter is "SUPPLIED" or not. The current code that I have written does not work.

IF LV_P1 IS NOT INITIAL AND LV_P2 IS NOT INITIAL.

ZCL_CLASS1=>METHOD1(

EXPORTING

     iv_p1 = lv_p1

     iv_p2 = lv_p2

IMPORTING

     ev_p1 = lv_p3 ).

ENDIF.

Thanks

KH

0 Kudos

Hi KH,

There will be no changes to the caller. We need to see how the caller has called the method and then adjust the logic...

Best regards,

Sudhi

former_member200338
Active Contributor
0 Kudos

are IV_P1 and IV_P2 optional parameters in the method call?

0 Kudos

The more important part is to check for the bound importing parameters in the caller ( which is exporting parameters in the method). Based on which parameters are needed in the caller then there is a change in the logic.

Best regards,

Sudhi

SharathYaralkattimath
Contributor
0 Kudos

Hi Sudhi,

I have an idea to include a optional exporting parameter in method:

e_para_name type C length 30.

    LOOP AT lt_params INTO ls_param.

     e_para_name = ls_param-name.          "Exporting parameter of class method

       IF ( e_para_name ) IS SUPPLIED.

         " Do something

       ENDIF.

     ENDLOOP.

Please let me know if this works..

Thanks,

Sharath

0 Kudos

Hi Sharath,

Thanks for the pointer but this will check if the e_para_name is supplied and not the value in it.

Best regards,

Sudhi

0 Kudos

Hi Sudhi,

I tested at my end & didn't work as you said,

Another idea is to GENERATE SUBROUTINE POOL.

Thanks,

Sharath

0 Kudos

The generate subroutine pool will be an independent executable program by itself. The moment we change the context of the method to call any other method the context of the exporting parameters and its property of whether it is "SUPPLIED" will be lost. Even the subroutine pool will not be able to access the parameter property at that time... Looks like we would have to go the static way of what has been requested and process the method call...

Best regards,

Sudhi

0 Kudos

Hi,

Does not throw any syntax errors. But doesn't work as expected.

Rds

Siva

Former Member
0 Kudos

Hi Sudhindra,

You have to write below code to check whether the parameter had been supplied or not.

IF iv_p1 IS SUPPLIED.

"" Do Something

ENDIF.


Make the importing parameter as 'OPTIONAL'.

Thanks & Regards

Richa