creating strings

Rozamunda used Ask the Experts™
i need to pass a string with combined fields from a trigger buffer

str1        S    50

str1 =  %trim(str1) +  'fld1   ' + fld2 '+...etc;

I am adding those fields in a loop, but when I trim each field the string is
compacted : str1 ='fld1fld2'. I would like to preserve the spaces
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
apply trim to individual fields instead of str1, append ' ' to str1 to separate next field in your loop


I can't because fields  need to have their original padding

  fld1 = %subst( buffer:pos,fldlength) ...etc
i am extrancting them from a buffer (trigger buffer)
i don't understand, if u want to keep those padding and str1 is just a concatenation of all those fields, why u need trimming anything at all?
how about
str1 = %trim(str1) + ' ' +fld
VP Technology / Senior Consultant
OK, if you do this:
Original = '1           '
B = '2  '
C= '3  '

You want to end up with '1     2 3 ', right?

I assume that the code above is not really what you are doing  something more like this:

d string s    50a

exsr prepareDataToAppend;
dow not DONE;
   string = %trim(string) + dataToAppend;
   exsr prepareDatatoAppend;

Of course, the problem with this is that on each pass, the trailing spaces from the last pass will be trimmed off.

The secret here is to use a variable length field for the STRING variable instead of a fixed-length field, and to do no trimming.

d string s    50a         VARYING

exsr prepareDataToAppend;
dow not DONE;
   string = string + dataToAppend;
   exsr prepareDatatoAppend;

- Gary Patterson;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial