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 cast any variable to char?

0 Kudos

I just have this simple line

gwa_list-key = sy-tabix. (the index here were set to last character hence i need to delete leading space)

SHIFT gwa_list-key LEFT DELETING LEADING space.

is it possible to do this in a one liner? i have tried doing CAST but returned - Unexpected operator "CAST".

gwa_list-key = cast #( sy-tabix )

1 ACCEPTED SOLUTION

pfefferf
Active Contributor

Converting to a string should to the trick as your result field is a string/character typed field.

gwa_list-key = conv string( sy-tabix ).
5 REPLIES 5

venkateswaran_k
Active Contributor
0 Kudos

Hi

You can use as below

 gwa_list-key = sy-tabix.
 
  key2 =  conv int2( gwa_list-key ).

This will give result as you expect.

pfefferf
Active Contributor

Converting to a string should to the trick as your result field is a string/character typed field.

gwa_list-key = conv string( sy-tabix ).

0 Kudos

or even

gwa_list-key = |{ sy-tabix }|.

(maybe slower?)

0 Kudos

thank you! i had the incorrect syntax

conv num2( var ) do the trick

Sandra_Rossi
Active Contributor
0 Kudos

Moreover, the ABAP documentation uses the term "cast" to cast the type of a variable without changing its value, while the term "conversion" is used to transfer the value of a variable to another variable of a different type by using a conversion.

Hopefully, it's not possible to cast ANY variable to CHAR, for instance internal tables and reference variables cannot be cast.