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

deleting spaces for charcter variable

Former Member
0 Likes
1,273

Hi Experts,

i have a variable like name1(40) type c.

So the value for name1 is: ravi.

So in the out put it will disply along with 36 spaces in the right side of data.

So iwant to delete the right side spaces if exists,

Can nay body tell me how can i do this?

regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,254

SHIFT NAME1 LEFT DELETING TRAILING SPACE.

Hi Experts,

i have a variable like name1(40) type c.

So the value for name1 is: ravi.

So in the out put it will disply along with 36 spaces in the right side of data.

So iwant to delete the right side spaces if exists,

Can nay body tell me how can i do this?

regards

11 REPLIES 11
Read only

Former Member
0 Likes
1,254

U can use TRANSLATE Command.

DATA: T(10) VALUE 'A;C:E,G.',

TRANSLATE T USING '; : , . '.

CONDENSE T NO-GAPS.

WRITE : T.

Regards,

rewards point.

Read only

Former Member
0 Likes
1,254

Use this piece of logic to remove all the special characters from the character value input by the user..

this program wil ensure that only A-Z,a-z and 0-9 wil come in the value..rest wil be deleted

reward if helpfull.

parameters: str(100) type c default ' #ABc D%12*3) ' lower case.

data: len1 type i.

data: ofst1 type i.

data len type i value '1'.

Constants c_abcde(26) type c value 'abcdefghijklmnopqrstuvwxyz'.

str = '#ABcD%123)'.

len1 = strlen( str ).

write:/ str.

do.

if ofst1 = len1.

exit.

endif.

if str+ofst1(1) CN sy-abcde

and str+ofst1(1) CN c_abcde

and str+ofst1(1) NE SPACE

and str+ofst1(1) CN '0123456789'.

replace section offset ofst1 length len of str

with SPACE.

ofst1 = ofst1 - 1.

endif.

ofst1 = ofst1 + 1.

if str+ofst1 eq SPACE.

exit.

endif.

enddo.

write:/ str.

CONDENSE str NO-GAPS.

SHIFT str LEFT DELETING LEADING SPACE.

write:/ str.

U can also use translate command if u r sure that which all special characters u want to remove..

so its better to use my above code instead of TRANSLATE command

regards,

rewards point.

Read only

Former Member
0 Likes
1,254

just use simple logic :

data : v_data(10) type c '0123456789'.

data v_final(62) type c.

start-of-selection.

concatenate v_data sy-abcde into v_final.

now compare field with v_final

if v_final co field.

here use concatenate field for specila charcter with space.

use search command.

endif.

rewards point.

Read only

Former Member
0 Likes
1,254

DATA : v_str type String,

V_len type i,

v_num type i.

start-of-selection.

v_str = 'ABCD123456'.

v_len = strlen( v_str ).

do .

v_num = v_num + 1.

if v_len eq v_num.

exit.

else.

if v_str+0(v_num) ca sy-abcde.

REPLACE v_str+0(v_num) WITH space INTO v_str.

v_num = v_num - 1 .

v_len = v_len - 1.

endif.

endif.

enddo.

By using this code and logic check the fields which are containing special chars

and replace them.

Note : in one variable take all possible special charectors and check the incoming variable with this special char variable if found replace.

regards,

rewards point.

Read only

Former Member
0 Likes
1,255

SHIFT NAME1 LEFT DELETING TRAILING SPACE.

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
1,254

Hi,

Use 'condense' statement.

Hope it solves ur problem...

Cheers,

Simha.

Read only

Former Member
0 Likes
1,254

Hi

Try this code.

data name1 type name1.

name1 = 'anees'.

write: name1 right-justified.

Reward if helpfull.

Anees

9886358645

Read only

Former Member
0 Likes
1,254

Hi

Try this code.

data name1 type name1.

name1 = 'anees'.

write: name1 right-justified.

Reward if helpfull.

Anees

9886358645

Read only

Former Member
0 Likes
1,254

Try this code.

DATA: BEGIN OF sentence,

word1 TYPE c LENGTH 30 VALUE 'She',

word2 TYPE c LENGTH 30 VALUE 'feeds',

word3 TYPE c LENGTH 30 VALUE 'you',

word4 TYPE c LENGTH 30 VALUE 'tea',

word5 TYPE c LENGTH 30 VALUE 'and',

word6 TYPE c LENGTH 30 VALUE 'oranges',

END OF sentence,

text TYPE string.

text = sentence.

CONDENSE text.

write : text.

Read only

Former Member
0 Likes
1,254

Hi,

Try This

DATA : name(40) TYPE c VALUE 'Dhwani',

s_name(5) TYPE c VALUE 'Shah'.

CONCATENATE text name INTO text.

CONDENSE text NO-GAPS.

CONCATENATE text s_name INTO text.

WRITE : text.

Read only

Former Member
0 Likes
1,254

Hi,

sorry made some change...

DATA : name(40) TYPE c VALUE 'Dhwani',

s_name(5) TYPE c VALUE 'Shah',

<b> text TYPE string.</b>

CONCATENATE text name INTO text.

CONDENSE text NO-GAPS.

CONCATENATE text s_name INTO text.

WRITE : text.