2019 Mar 12 2:49 PM
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.
2019 Mar 12 4:18 PM
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.
2019 Mar 12 3:02 PM
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).
2019 Mar 12 4:14 PM
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
2019 Mar 13 7:29 AM
2019 Mar 12 4:12 PM
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.
2019 Mar 12 4:18 PM
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.
2019 Mar 12 4:45 PM
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