Question Substring function [length] issue

GreyGoose

New Member
Hi

I hope someone can help with this as it's driving me insane! I've spent the last three days searching for answers and trying out different ideas none of which have worked.

The following code builds up the required information for a single mail merge field that is then repeated for multiple lines. This all works as expected however once output (ultimately as a pdf) it doesn't hold to the substring length I have used. I've also tried overlay and that was the same result.

Here's the relevant piece of code...
Code:
FOR EACH tt-hdr:

        ASSIGN lv-line-no = 0.
        for each tt-dtl WHERE tt-dtl.place-ref = tt-hdr.place-ref
                        use-index idx1: 
                ASSIGN lv-line-no = lv-line-no + 1.
   
            ASSIGN lv-asb-line = "".
                                    ASSIGN substring(lv-asb-line,1,30) = trim(substring(tt-dtl.sub-loc-desc,1,30)).
                                    ASSIGN substring(lv-asb-line,32,30) = trim(substring(tt-dtl.comp-desc,1,30)).
                                    ASSIGN substring(lv-asb-line,64,30) = trim(substring(tt-dtl.type-desc,1,30)).
                                    ASSIGN substring(lv-asb-line,96,20) = trim(substring(tt-dtl.risk-desc,1,20)).
                                    ASSIGN substring(lv-asb-line,118,10) = trim(substring(tt-dtl.notes,1,10)).
                        ASSIGN tt-hdr.Asbestos-lines = IF tt-hdr.Asbestos-lines = " " THEN lv-asb-line  ELSE tt-hdr.Asbestos-lines + chr(11) + lv-asb-line.

        end.     /*dtl*/
The result I get (approximately) is:

(I've used full stops to represent spacing)

Kitchen..........Sink Pad or Coating..............Chrys..........Low.........Sink pad
Unknown Room..........Ceiling................Chrys..........Low..........Ceiling
Unknown Room..........Floor Tiles..........Chrys..........Low..........Floor
Kitchen..........Floor Tile and Adhesive........None Detected........VeryLow ..........Beige
Kitchen..........Sink Pad or Coating.......... None Detected..........Very Low...........Sink pad

...which is a mess.

If I replace the tt items with simple text then it spaces correctly, so does this mean it's there are characters that I'm retrieving that the Trim function isn't recognising as spaces so not trimming?

Any assistance will be gratefully received.

Cheers

Tony
 
Last edited by a moderator:

Stefan

Active Member
  1. please add code tags around code - also around your output
  2. can you provide sample data? I started at ABL Dojo - but since the first two lines are already fine, something else must be going on.
You will need to look at what your records really contain, there may be non-breaking white space or other gunk in there. An easy way to view 'odd' characters is to serialize the data to json:

Code:
def var lcc as longchar.

temp-table tt-dtl:write-json( "longchar", lcc ).

message string( lcc ) .
A chr(11) for example will show as \u000b
 

Cringer

ProgressTalk.com Moderator
Staff member
I would do the following anyway...

Code:
assign lv-asb-line = "&1 &2 &3 &4 &5".
assign lv-asb-line = substitute (lv-asb-line,
    trim(substring(tt-dtl.sub-loc-desc,1,30)),......).
It will be a lot cleaner. I don't know if it will fix the issue, but will make your code a lot more readable and maintainable.
 

Stefan

Active Member
I would do the following anyway...

Code:
assign lv-asb-line = "&1 &2 &3 &4 &5".
assign lv-asb-line = substitute (lv-asb-line,
    trim(substring(tt-dtl.sub-loc-desc,1,30)),......).
It will be a lot cleaner. I don't know if it will fix the issue, but will make your code a lot more readable and maintainable.
Since the goal seems to be fixed width output, you will need an additional STRING with FORMAT around that trim - which then duplicates the length.

Ultimately the simplest form of getting fixed width output is the OVERLAY statement, which then looks like:

Code:
overlay( lv-asb-line,   1,30 ) = trim( tt-dtl.sub-loc-desc ).
overlay( lv-asb-line,  32,30 ) = trim( tt-dtl.comp-desc ).
overlay( lv-asb-line,  64,30 ) = trim( tt-dtl.type-desc ).
overlay( lv-asb-line,  96,20 ) = trim( tt-dtl.risk-desc ).
overlay( lv-asb-line, 118,10 ) = trim( tt-dtl.notes ).
The only thing remaining is to figure out which extra junk characters need to be added to the trim function.
 

Cringer

ProgressTalk.com Moderator
Staff member
I didn't realise fixed width was a requirement, in which case you are certainly right.
 
Top