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 find if is constant or variable in perform using

0 Kudos
818

Hi,

i need to check in a perform if the value is coming from constants or variable.

How can i check this?

Example:



data: variable(5).
start-of-selection.
perform test1 using variable.
perform test1 using space.

form test1 using p_to_change.
"only when it is called with variable
"how can I do this?
  p_to_change = 'X'.
endform. 
 


1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
360

If the variable is modifiable in the calling procedure and the parameter is passed by reference (fits your case), then you may differentiate the two cases by checking the read-only flag of the parameter via RTTI:

IF abap_true = CL_ABAP_DATADESCR=>IS_READ_ONLY( p_data = ref #( p_to_change ) ).
  " constant (or read-only variable)
ENDIF.
6 REPLIES 6

matt
Active Contributor
0 Kudos
360

You can't. But why do you need to? (Incidentally, your DATA statement is using an obsolete form, and FORMs are also obsolete and shouldn't be used in new programs).

0 Kudos
360

I've semplified that, but it's a standard code that use this type of statement.

I'm trying to catch that because i need to change the value if it's from the constant.

Maybe is there a chance to check the properties of the passed field?

thanks

matt
Active Contributor
0 Kudos
360

So apparently you can! 🙂

Sandra_Rossi
Active Contributor
0 Kudos
360

Please use the COMMENT button to reply to someone's answer. ANSWER is only to propose a solution. You also have an option to convert your answer into a comment.

Sandra_Rossi
Active Contributor
361

If the variable is modifiable in the calling procedure and the parameter is passed by reference (fits your case), then you may differentiate the two cases by checking the read-only flag of the parameter via RTTI:

IF abap_true = CL_ABAP_DATADESCR=>IS_READ_ONLY( p_data = ref #( p_to_change ) ).
  " constant (or read-only variable)
ENDIF.

360

Solved. It works, thanks Sandra.

Results:

1

2.

Example:

DATA: variable(5),
      var2.
START-OF-SELECTION.
  PERFORM test1 USING variable.
  PERFORM test1 USING space.
*&---------------------------------------------------------------------*
*&      Form  test1
*&---------------------------------------------------------------------*

FORM test1 USING p_to_change.
  IF abap_true = cl_abap_datadescr=>is_read_only( p_data = REF #( p_to_change ) ).
    " constant (or read-only variable)
    WRITE:/ '2'.
  ELSE.
    WRITE:/ '1'.
  ENDIF.
ENDFORM.                    "test1