‎2007 Aug 20 6:37 PM
Let's say I have the following code:
DATA idx TYPE i.
DATA msg TYPE string.
msg = "You are on index #".
CONCATENATE msg idx INTO msg.
WRITE msg.
This obviously won't work because idx isn't the right data type so my question is, how do I cast idx into a string-type? In C# you just did something like this:
(string)idx or idx.ToString()
‎2007 Aug 20 8:46 PM
Hi,
May be this way.
DATA idx TYPE i.
DATA msg TYPE string.
DATA v_idxt(50) type c.
msg = 'You are on index #'.
write : idx to v_idxt.
CONCATENATE msg v_idxt INTO msg.
WRITE msg.
aRs
‎2007 Aug 20 8:51 PM
I'm not a big fan of moving something to another variable field simply because CONCATENATE can't handle it. I find it quite annoying so I would suggest doing the same like this instead.
DATA idx TYPE i.
DATA msg TYPE string.
* Simple move the value to the string field
msg = idx.
condense idx no-gaps.
* Now add the literal text on the front.
CONCATENATE 'You are on index #' msg INTO msg.
WRITE msg.Regards,
RIch Heilman
‎2007 Aug 20 9:37 PM
Hello Steve
It may look like overkill but this static method is quite useful to convert pieces of data into a C-container (string or character field).
TYPES: BEGIN OF ty_s_msg.
TYPES: idx TYPE i.
TYPES: blank(1) TYPE c.
TYPES: msg TYPE bapi_msg. " or TYPE string
TYPES: END OF ty_s_msg.
DATA:
ls_msg TYPE ty_s_msg.
ls_msg-idx = '<index>'.
ls_msg-blank = space.
ls_msg-msg = 'You are on index #'.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
ex_value = ls_msg
IMPORTING
ex_container = ls_msg-msg. " concatenated valuesRegards
Uwe
‎2007 Aug 20 9:43 PM