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

String Manipulation

Former Member
0 Likes
1,172

I need help with concatenating a string. I need to pad a field (material #) to 18 characters.

Here is the code:

No matter what I try, I lose the full length of matnr when I do the concatenation. It drops the trailing spaces.

data: v_tabkey like cdpos-tabkey.

data: v_matnr(18) type c.

move i_ekpo-matnr to v_matnr.

concatenate '010' v_matnr i_ekpo-werks into v_tabkey.

If i_ekpo-matnr = 'PET'. I get '010PET0010'. I need '010PET 0010'.

Thanks for any help.

Janet

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,141
concatenate '010' v_matnr into v_matnr.
concatenate v_matnr i_ekpo-werks into v_tabkey separated by space.
14 REPLIES 14
Read only

Former Member
0 Likes
1,142
concatenate '010' v_matnr into v_matnr.
concatenate v_matnr i_ekpo-werks into v_tabkey separated by space.
Read only

0 Likes
1,141

I need the full 15 spaces after PET to have the material number the full 18 characters.

Read only

0 Likes
1,141

You might want to try using a place holder. Like so.......



move i_ekpo-matnr to v_matnr.
translate v_matnr using ' %'.

concatenate '010' v_matnr i_ekpo-werks into v_tabkey.

translate v_tabkey using '% '.

Regards,

Rich Heilman

Read only

0 Likes
1,141

Hi :

Use :

v_tabkey(3) = '010'

v_tabkey+3(18) = v_matnr.

v_tabkey+21(4) = v_werks.

In this situation you should have the 15 spaces !

Hope this helps,

Erwan

Read only

0 Likes
1,141

Rich,

Thank you, again.

But I am confused. How does this command find the trailing spaces when the string length command doesn't?

Read only

0 Likes
1,141

The TRANSLATE statement is simply translating the string, character by character, so where there is a SPACE is it replacing with a '%', this fills the rest of the V_MATNR with a character, then when concatenting, it uses all 18 characters, then you are simply transalating it back afterwards.

Regards,

Rich Heilman

Read only

0 Likes
1,141

Yep, I understood that. It is just strange that that appears to be the only command that is aware of the spaces.

Thanks again.

Read only

0 Likes
1,141

The REPLACE statement will do it too.

Regards,

Rich Heilman

Read only

0 Likes
1,141

Good to know.

Thanks.

Read only

Former Member
0 Likes
1,141

Hi,

data: v_tabkey like cdpos-tabkey.

data: v_matnr(18) type c.

move i_ekpo-matnr to v_matnr.

<b>

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

Here you need to conver the material no conversion from External to Internal.use the Function module CONVERT_FIELD_TO_INTERN_FORMAT for that matrial field

************************************</b>

concatenate '010' v_matnr i_ekpo-werks into v_tabkey.

If i_ekpo-matnr = 'PET'. I get '010PET0010'. I need '010PET 0010'.

Read only

0 Likes
1,141

This didn't help. I still got a field back with a length of 3.

Read only

0 Likes
1,141

If you have tried using the placeholder and it doesn't work. Please post the code there so that I can take a look.

Regards,

Rich Heilman

Read only

0 Likes
1,141

Hi Janet,

Please give the result needed ( v_tabkey ) with the actual example plz, because I don't understand...

Read only

Former Member
0 Likes
1,141

Hi,

Use this,

concatenate '010' v_matnr space i_ekpo-werks into v_tabkey.

Regards,

Aman