Application Development and Automation 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: 
Read only

Convert Numeric to string (4)

Former Member
0 Likes
1,963

Hello

How can I convert numeric to string (4 characters)

n type i.

st (4) type c.

n= 1 , st = '0001'

n = 10 , st = '0010'

n = 20, st = '0020'

etc

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,526

Hi,

try this -

DAta:n type i value 1,

st(4) type n.

st = n.

Write:st.

or

DAta:n(4) type n value 10,

st(4) type c.

move n to st.

Write:st.

6 REPLIES 6
Read only

Former Member
0 Likes
1,527

Hi,

try this -

DAta:n type i value 1,

st(4) type n.

st = n.

Write:st.

or

DAta:n(4) type n value 10,

st(4) type c.

move n to st.

Write:st.

Read only

Former Member
0 Likes
1,526

Hi Ignacio,

Try this:

REPORT  ychandra_test3.

data:

    num(4) type n value 10,
    str(4) type c.

    str = num.

    write: str.

Regards,

Chandra Sekhar

Edited by: Chandrasekhar Gandla on Sep 22, 2008 1:01 PM

Read only

Former Member
0 Likes
1,526

Hi Ignacio,

You can do this by using field-symbols:

field-symbols: <fs> type any.

st(4) type c,

n type i.

assign st to <fs>

move <fs> to n.

Hope this will help.

Regards,

Nitin.

Read only

Former Member
0 Likes
1,526

data: n type i,
      st(4) type c.

n  = 20.
move n to st.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = st
 IMPORTING
   OUTPUT        = st.
Read only

Former Member
0 Likes
1,526

If you can use a character variable (type C) instead of an I, like in the following example, execute the code below and check if it works for you. You would set the size of your string changing the number within the parenthesis. Later you can assign this character variable to a string variable.

DATA x(4) TYPE c value '1'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = x
 IMPORTING
   OUTPUT        = x.

WRITE: / 'RESULT:', x.

x = 20.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = x
 IMPORTING
   OUTPUT        = x.

WRITE: / 'RESULT:', x.

DATA z type string.
z = x.

WRITE: /, z.

Read only

Vijay
Active Contributor
0 Likes
1,526

hi,

try like this.....

data: v_abc type numc4,

v_xyz type char4.

v_abc = 10 ( assigned value as example).

v_xyz = v_abc.

regards

vijay.