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

variable type question

Former Member
0 Likes
1,334

Hi,

my requirements are the following :

I must have variable with f.e a fixed length of 10.

In this variable a value will be put with a variable length.

If this length is smaller then 10, the remaining characters must be filled up with spaces, so that the actual length is always 10.

Is there a variable type that supports this ? How must i achieve this ?

with regards

Erik Dierinck

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,300

declare as type n.

data: v_num(10) type n value '10'.

write: v_num.

Regards,

ravi

12 REPLIES 12
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,300

You can define your length in the data statement. Doing so makes this field always a length of 10.

data: variable(10) type c.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,300

u can declare the variable as below

data text(10) type n.

but text will always have leading zeroes and not spaces.

Sample code

PARAMETER: ckb1(10) TYPE n.

DATA: len1 TYPE i.

len1 = STRLEN( ckb1 ).

MESSAGE i000(vz) WITH len1.

-Kiran

Read only

Former Member
0 Likes
1,301

declare as type n.

data: v_num(10) type n value '10'.

write: v_num.

Regards,

ravi

Read only

0 Likes
1,300

Hi,

Declare as type n.


data: num(10) type n .
num = '1'.
write: num.

Regards

vijay

Read only

0 Likes
1,300

Okay,

But will this also work with a concatenation :

suppose i have three variables

var1(10) = 'test'

var1 ='test1'

var2 ='test2'

the result of the concatenation must be

"test test1 test2"

with regards

Read only

0 Likes
1,300

What exactly is the requirement. Do you need to have some space in your result field?

Regards,

Rich Heilman

Read only

0 Likes
1,300

Yes

Read only

0 Likes
1,300

Hi,

you can do this way...

REPORT  ZZSDSDF                                 .

data: v1(10),v2(10),v3(10),v(30).

v1(10) = 'test'.
v2 = 'test1'.
v3 = 'test2'.
v = v1.
v+10(10) = v2.
v+20(10) = v3.

write v.

Regards

vijay

Read only

0 Likes
1,300

You will need to give a placeholder during concatenation, then you can get rid of it.



report zrich_0001.

data: var1(10) type c,
      var2(10) type c,
      var3(30) type c,
      result(30) type c.

var1 = 'Tst1'.
var2 = 'Tst2'.
var3 = 'Tst3'.

translate var1 using ' %'.
translate var2 using ' %'.
translate var3 using ' %'.

concatenate var1 var2 var3 into result.

translate result using '% '.

write:/ result.

Regards,

Rich heilman

Read only

Former Member
0 Likes
1,300

hi

good

good

you can declare the variable as

data: variablename(10) type c.

then down check that variable in a loop whenever the data from the database will be less than 10 than use tha APPEND command to append 0 before that.

thansk

mrutyun

Read only

Former Member
0 Likes
1,300

Hi Erik,

Use Character type for your requirement.

Declare it as

DATA : var(10) TYPE C.

Consider this program,


REPORT zarun_2.

DATA : char(10) TYPE c,
       len TYPE i.

char = 'TEST'.
len = STRLEN( char ).
WRITE : / char, 13 'Length:', len.

CLEAR char.
char = 'TESTSDN'.
len = STRLEN( char ).
WRITE : / char, 13 'Length:', len.

CLEAR char.
char = 'TESTSDNSAP'.
len = STRLEN( char ).
WRITE : / char, 13 'Length:', len.


Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi

Read only

Former Member
0 Likes
1,300

Hi Erik,

You can do it in this way.


REPORT zarun_2.

DATA :  char1(10) TYPE c,
        char2(10) TYPE c,
        char3(10) TYPE c,
       result(30) TYPE c. " Or can use type <b>STRING</b>

char1 = 'test'.
char2 = 'test1'.
char3 = 'test2'.

CONCATENATE char1 char2 char3 INTO result <b>SEPARATED BY space.</b>

WRITE result.

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi