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

Adding Spaces in the variable.

Former Member
0 Likes
7,503

Hi All,

the problem scenario is :

I have a varaible of type c and length 10, and its filled with only 6 characters. Further there is another Variable of type c and size 4 , both need to concatenated .

The problem is when I concatenate both variables they come up joined. I need to have the 4 characters space between both variables.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,947

Hello,

CONCATENATE is not going to be of any help.

Try like this:

DATA:
V_STR1 TYPE CHAR10 VALUE '123456',
V_STR2 TYPE CHAR4 VALUE '1234',
V_STR TYPE STRING.

MOVE V_STR1 TO V_STR.

V_STR+10 = V_STR2.

WRITE: V_STR.

Hope this helps.

BR,

Suhas

13 REPLIES 13
Read only

Former Member
0 Likes
3,947

Hi,

If the variable has spaces at the end, these spaces are generally ignored.

So, when you concatenate both the variables, you would not get spaces in between.

If the variable is sure to have only 6 digits,

you can use the concatenate statement to separate it by 4 spaces:

concatenate varA varB separated by ' '.

Read only

former_member242255
Active Contributor
0 Likes
3,947

DATA: w_num1(10) TYPE c VALUE '123456',

w_num2(4) TYPE c VALUE '1234',

w_space(4) TYPE c,

w_num(20) TYPE c.

CONCATENATE w_num1 w_num2 INTO w_num SEPARATED BY w_space.

WRITE w_num.

Read only

Former Member
0 Likes
3,947

Hi,

please check the code below. give d as 4spaces in quotes.

data: a type string value 'sudarsan',

b TYPE string value 'dande',

c type string,

d(4) type c value ' '.

CONCATENATE a b INTO c SEPARATED BY d.

WRITE c.

Read only

dev_parbutteea
Active Contributor
0 Likes
3,947

Hi,

Try using offset.

e.g data: v1 type char10 value '666666',

v2 type char4 value '4444',

v3 type char30.

v3(10) = v1.

v3+10(4) = v2.

Read only

Former Member
0 Likes
3,947

USE Below.


DATA: a(10) type c.
a = 'sixsix'.

DATA: b(4) type c.
b = 'four'.

DATA c(12) type c.
CONCATENATE a b INTO c SEPERATED BY SPACE.

Read only

Former Member
0 Likes
3,947

Hi;

data: lv_var4 type char4,

lv_var10 type char10,

lv_var14 type char14.

concatenate lv_var10

space(4)

lv_var4 into lv_var14 seperated by space(1).

Regards

Shashi

Read only

Former Member
0 Likes
3,947

data: a type string value 'sudarsan',

b TYPE string value 'dande',

c type string,

d(4) type c value ' '.

CONCATENATE a b INTO c SEPARATED BY d.

WRITE c.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,948

Hello,

CONCATENATE is not going to be of any help.

Try like this:

DATA:
V_STR1 TYPE CHAR10 VALUE '123456',
V_STR2 TYPE CHAR4 VALUE '1234',
V_STR TYPE STRING.

MOVE V_STR1 TO V_STR.

V_STR+10 = V_STR2.

WRITE: V_STR.

Hope this helps.

BR,

Suhas

Read only

former_member222860
Active Contributor
0 Likes
3,947

Try this:

DATA: var1(10) type c value 'MAHESH'.
DATA: var2(4) type c value 'ABAP'.
DATA: var3(14) type c.
data: var4(4) type c .

var4 = SPACE.

concatenate var1(10) var2(4) into var3 SEPARATED BY var4.

write:/ var3.

Read only

Former Member
0 Likes
3,947

hi,

if my understanding is correct

you can use the below method for this:

data: ct(10) TYPE c VALUE '123456',

gt(4) TYPE c VALUE '7890'.

CONCATENATE ct GT INTO result RESPECTING BLANKS.

ouput will be :

123456 7890

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,947

Hello,

Your code does not even SYNTAX check !!! Plz verify before posting.

AFAIK the OP's req. cannot be met using CONCATENATE stmt.

BR,

Suhas

Read only

Former Member
0 Likes
3,947

Thanks for your replies...

BUT in case when the length first variable keeps on changing as its being returned by a function ex it becomes 7 or 8 then how can i insert 2 or 3 spaces ...

Read only

0 Likes
3,947

find the lenght of the first_variable and then use OFFSET accordingly.

apart from the above replies, u can also try like, put some speacial characters like $, in the place where do u want see the space, then REPLACE these $ with SPACES.

thanq