on 2025 Feb 27 3:02 AM
I have a class in which I have defined various Text elements.
For eg.
H01=Title1
H02=Title2
H03=Title3
H04=Title4
etc.
I am trying to print all the titles in my class. I have a loop in my class and I am building the text element name dynamically.
lv_title = `TEXT-H` && conv ty_n2( sy-tabix ).
Now, I use this variable to dynamically access the text element in the program
assign (lv_title) to <title>.
Class is syntactically correct and executes fine with expected results.
But, I get a warning saying: "The old variant of "<dynamic-object>" should not be used in the current ABAP language version."
If this is considered the "old" variant, what is the equivalent "new" variant to access variables by name?
I am on ABAP Cloud version, so that limits the commands available to me (for eg. READ TEXTPOOL isn't available to me)
Request clarification before answering.
No pragma exists to remove the warning but you may rewrite your code to avoid field symbols.
As per the ABAP Cloud - ABAP Keyword Documentation: "This syntax is only supported temporarily in the current ABAP language version and must be replaced with valid syntax for that version [...] This variant should not be used any more. Especially for accessing structure components, other variants are preferable."
If you have a structure, use ASSIGN COMPONENT ... OF STRUCTURE ...
That's not possible for the pseudo structure TEXT of Symbol Texts, but you may rewrite this way which is more clean code (of course, I don't know what your real case is, so I use a dummy example):
CLASS zcl_test DEFINITION
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zcl_test IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TYPES:
BEGIN OF ty_month,
astrological_sign TYPE string,
END OF ty_month.
TYPES ty_n2 TYPE n LENGTH 2.
DATA months TYPE TABLE OF ty_month.
DATA lv_title TYPE string.
" Original code
DATA(month) = months[ astrological_sign = 'Lion' ].
lv_title = `TEXT-H` && CONV ty_n2( sy-tabix ).
ASSIGN (lv_title) TO FIELD-SYMBOL(<title>).
" Suggested clean code
DATA(month_number) = line_index( months[ astrological_sign = 'Lion' ] ).
DATA(month_name) = SWITCH string( month_number
WHEN 1 THEN 'January'(H01)
WHEN 2 THEN 'February'(H02)
" Etc.
).
ENDMETHOD.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Why don't you use RS_TEXTPOOL_READ
lv_classn = iv_class.
lv_classn+30(2) = 'CP'.
TRANSLATE lv_classn USING ' ='.
lv_programm = lv_classn.
CALL FUNCTION 'RS_TEXTPOOL_READ'
EXPORTING
objectname = lv_programm
action = 'SHOW'
language = iv_langu
TABLES
tpool = lt_table
EXCEPTIONS
object_not_found = 1
permission_failure = 2
invalid_program_type = 3
error_occured = 4
action_cancelled = 5.
Or you could use the READ TEXTPOOL statement followed by some clean ASSIGN syntax for the type 'I' (text symbols)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ciao Juwin.
The problem is that TEXT is not a structure so these suggested variants cannot be used.
... { struc-(comp) }
| { dref->(comp_name) }
| { COMPONENT comp OF STRUCTURE struc } ...
I suggest to declare a proper structure like my_text and to put or duplicate the text symbol's values there as subcomponents.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use left = right
something like this ----- <title> = lv_title.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
9 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.