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 trim

Former Member
0 Likes
1,319

Hi,

Im displaying 2 string variables using write statement. The variables are var1 & var2 .var1 is of length 40 while var2 is of length 10.

The write statement is of form . write:/ var1 , var2.

However if var1 contains smaller data lets say 'abc' the output is displayed as

'abc ' var2.

It leaves 37 blank characters and then displays var2 contents. Is there any way to trim var1 while displaying ?

Kindly suggest any direct method, i dont want to use a third dummy variable .

Counting on your expertise frnds .

Thanks

11 REPLIES 11
Read only

GauthamV
Active Contributor
0 Likes
1,267

Use UNPACK statement.

Read only

Former Member
0 Likes
1,267

CONDENSE <Variable> NO-GAPS.

hope this helps.

Read only

Former Member
0 Likes
1,267

Hi Mak,

Unpack works only in case of numeric values it will give dump if the value is character

For this u have to

Delete leading spaces from var1.(syntax)

and then print.

or

SHIFT var1 RIGHT DELETING TRAILING space.(change right to left and trailing to leading as desired)

Thanks & regards,

Ruchi Tiwari

Edited by: Ruchi Tiwari on Mar 10, 2009 10:08 AM

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,267

Hello,

You can try using the key word addition NO-GAP with the WRITE stmt.

I tried but did not find any keyword which fits your requirement.

You need to declare a 3rd variable & try:

DATA:
v_var1 TYPE char10 VALUE 'No',
v_var2 TYPE char10 VALUE 'Gaps',
v_var3 TYPE string.

CONCATENATE v_var1 v_var2 INTO v_var3 SEPARATED BY space.

WRITE: v_var3.

May be someone else has a better answer.

BR,

Suhas

Edited by: Suhas Saha on Mar 10, 2009 10:16 AM

Read only

Former Member
0 Likes
1,267

Hi,

Use strings instead, whatever may be the value,it will take only the space required.

data : var1 type string value 'asd',

var2(10) type c value 'sdf'.

write 😕 var1,var2.

Read only

Former Member
0 Likes
1,267

Write: Var1 no-gap, var2.

I dont have sap access, can you check

Read only

0 Likes
1,267

no-gap doesnt work ! Thanks for your replies guys...but still im struggling

Read only

0 Likes
1,267

have u tried delete and shift syntax ?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,267

Hello Mac,

Did you check my solution? Or you DONOT want to use a new variable.

BR,

Suhas

Read only

0 Likes
1,267

thanks for your inputs guys , I dont want to use third variable because there are more than 20 variables for which i want to trim the variables . So is there any way i can do it in write statement itself ?

Read only

Former Member
0 Likes
1,267

use Concatenate var1 ,var2 into var1 sperated by ','.

condense var1 with no gaps.

write 😕 var1.