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

field conversion.

Former Member
0 Likes
584

Hi,

im using an integer to increment a counter and i need to move it in to a char. what if i need a zero '0' before the count if the number is less than 10 in my char field.

Regards,

ravi.

6 REPLIES 6
Read only

Former Member
0 Likes
556

Try:


DATA: f1(10) VALUE '123'.

WRITE: /001 f1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = f1
  IMPORTING
    output = f1.

WRITE: /001 f1.

Rob

Read only

0 Likes
556

use this demo code -

data: d_integer type i ,

d_char(2) type N.

d_integer = 4.

d_char = d_integer.

write: d_char.

amit

Read only

Former Member
0 Likes
556

Hi Ravi,

DATA V_INT TYPE I VALUE '5'.

DATA V_CHAR(16).

DATA V_NUMBER(2).

IF V_INT < '10'.

V_CHAR = V_INT.

CONDENSE V_CHAR NO-GAPS.

CONCATNATE '0' V_CHAR INTO V_NUMBER.

ELSE.

V_CHAR = V_INT.

CONDENSE V_CHAR NO-GAPS.

V_NUMBER = V_CHAR.

ENDIF.

Thanks,

Vinay

Read only

Former Member
0 Likes
556

Hi Ravi

We can do the same by declaring a variable of type N with required length.

We can perform airthematic operations as long as only numericals exist.

The advantage with data type N is by default we will be having LEADING ZEROES for numbers.

data: l_int type i value '2',
        l_num(2) type N.

l_num = l_int.
write:/ 'Type I:', l_int,
     / 'Type N:', l_num.

Kind Regards

Eswar

Read only

Former Member
0 Likes
556

Dear Ravi,

Go through the following chunk of code:

DATA: GV_IDX1 TYPE I,

GV_IDX2(2) TYPE N.

DO.

GV_IDX1 = GV_IDX1 + 1.

GV_IDX2 = GV_IDX1.

WRITE: / GV_IDX1,

GV_IDX2.

IF GV_IDX1 GT 10.

EXIT.

ENDIF.

ENDDO.

The O/P will be:

1 01

2 02

3 03

. .

. .

9 09

10 10

Use Data Type NUMC inorder to carry out this type of operation.

Regards,

Abir

************************************

  • Don't forget to award Points *

Read only

Former Member
0 Likes
556

i dont know whether your counter is less than 100 or not if it is so then

you can use type n which will place 0 before your variable

data : v_data(2) type n.

otherwise

you can check the counter whether it is lt 10 or not

if counter lt 100.

v_data = counter.

<now char field > = v_data.

else.

directly take char fied = counter.

regards

shiba dutta