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

Problem with concatenating space character. Please help!

Former Member
0 Likes
2,576

Hi experts,

I have requirement for creating fixed length data like this:

Source Material.

I am getting source value dynamically. Max size of source in 10.

But sometime it may come as 'EMS01' and sometimes 'PLTN'. That its value can be of varied length.

I need to concat Source and Material with space in between. The number of spaces in between is equal to 10 - current size.

For example: If Source = 'EMS01'

then there should be 5 spaces between source and material.

If source = 'PLTN'

then there should be 6 spaces between source and material after concatenation.

I tried like this:

data: v_source(10),

v_material(8),

v_space(9),

v_spclen type i.

v_spclen = 10 - STRLEN( v_source ).

DO v_spclen TIMES.

v_space = v_space + ' '.

ENDDO.

CONCATENATE v_source v_space v_material INTO v_string.

This does not work because it is putting number 0 in v_space value.

How to resolve this? Please help!

Thanks

Gopal

Hi experts,

I have requirement for creating fixed length data like this:

Source Material.

I am getting source value dynamically. Max size of source in 10.

But sometime it may come as 'EMS01' and sometimes 'PLTN'. That its value can be of varied length.

I need to concat Source and Material with space in between. The number of spaces in between is equal to 10 - current size.

For example: If Source = 'EMS01'

then there should be 5 spaces between source and material.

If source = 'PLTN'

then there should be 6 spaces between source and material after concatenation.

I tried like this:

data: v_source(10),

v_material(8),

v_space(9),

v_spclen type i.

v_spclen = 10 - STRLEN( v_source ).

DO v_spclen TIMES.

v_space = v_space + ' '.

ENDDO.

CONCATENATE v_source v_space v_material INTO v_string.

This does not work because it is putting number 0 in v_space value.

How to resolve this? Please help!

Thanks

Gopal

7 REPLIES 7
Read only

Former Member
0 Likes
1,299

Hi

Try this:

 data: v_source(10),
v_material(8),
v_space(9),
v_spclen type i.

move  v_source to v_string.
move v_material to v_string+10.

Max

Read only

Former Member
0 Likes
1,299

Hi,

You can try this way...Try with offset and position..

v_string = v_source.
v_string+10 = v_material.

or

data: v_source(10) value 'MANT',
v_material(8) VALUE '00001'.

data v_string type char40.

CONCATENATE v_source v_material INTO v_string RESPECTING BLANKS.
WRITE:/ v_string.

Read only

Former Member
0 Likes
1,299

Hi,

Instead of doing a code for that you can use the addition RESPECTING BLANKS with the CONCATENATE statement.

Check the link for more understanding.

Regards

Sarves

Read only

Former Member
0 Likes
1,299

Hi Try like this:


data: v_source(10),
v_material(8),
v_space(9),
v_spec value '#',
v_spclen type i.

v_spclen = 10 - STRLEN( v_source ).
DO v_spclen TIMES.
 concatenate v_space v_spec into v_space.
ENDDO.
CONCATENATE v_source  v_material INTO v_string seprated by v_space.
translate v_string using '# '.

Regards,

Himanshu

Read only

Former Member
0 Likes
1,299

Hi Gopal,

try with the following statement:

'CONCATENATE v_source v_space v_material INTO v_string respecting blanks.'

Hope this will solve your problem. Because this statement add space of the variables(if some characters are left blank not fully occupied by the respective value) used in the concatenate statement.

Regards,

Prinan Pandit

Read only

sridhar_meesala
Active Contributor
0 Likes
1,299

Hi,

Try this. It may work.

v_sep = 10 - v_source.
DATA: v_source(10),
           v_material(8),
           v_space(10) VALUE 'v_sep'.

CONCATENATE v_source v_material INTO v_string SEPARATED BY v_space.
WRITE v_string .

Thanks,

Sri.

Read only

Former Member
0 Likes
1,299

Hi,

Try This.

data: v_source(10),

v_material(8),

v_space(9),

v_string(255) type c,

v_spclen type i,

v_spclen1 type i. * Delcare one more variable. This will contain Length of field v_string after assign V_source to it.

v_spclen = 10 - STRLEN( v_source ).

v_string = V_source.

CONDENSE v_string.

v_spclen1 = STRLEN( v_string ).

v_spclen1 = v_spclen1 + v_spclen. * I have Added v_spclen1 and v_spclen to get exact position from where i will add v_material

v_string+v_spclen1 = v_material.

write v_string.

Edited by: ShreeMohan Pugalia on Jul 24, 2009 3:13 PM