IMPORT statement

I'm trying to fix an issue in Prolint, but this is a general ABL question. Here's the code:

   handlers = "":U.
   FILE-INFO:FILE-NAME = ProfileDirectory + "/handlers.d":U.
   IF FILE-INFO:FULL-PATHNAME <> ? THEN DO:
      INPUT FROM VALUE(file-info:FULL-PATHNAME).
      REPEAT:        
         IMPORT handler.                               
         /* if handler exists and supported in this Progress session, then add to list */
         IF CAN-FIND(tt_output WHERE tt_output.progname=handler) THEN 
            handlers = handlers + ",":U + handler.
      END.
      INPUT CLOSE.                                     
   END.

What I'm finding is that if there's an extra blank line at the end of the input file, then the last value for 'handler' gets added twice.

I could work around it easy enough by making sure I don't have the same value twice in a row, but the behavior surprises me and I'd like to understand it a little bit better. Is there a better way of looping and importing so that blank lines won't result in re-processing the previous values?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

at a glance

not much info how many records in .d
ok got same behaviour from

def var jungle as char.
def var jungles as char.
input from "c:\trees.d".
repeat:
import jungle.
jungles = jungles + "," + jungle.
disp jungle.
end.
input close.
disp jungles format "x(70)"

trees.d
prog
kop
gfg
gfg
gfhfh
fg
f
fg
fg
gf
ert

got ert twice

ha used repeat import loads of times never got this . oh yeah got it

def var jungle as char.
def var jungles as char.
input from "c:\trees.d".
repeat:
import jungle.
jungles = jungles + "," + jungle.
disp jungle.
jungle = "".
end.
input close.
disp jungles format "x(70)".

reset jungle variable or in your case

REPEAT:
IMPORT handler.
/* if handler exists and supported in this Progress session, then add to list */
IF CAN-FIND(tt_output WHERE tt_output.progname=handler) THEN
handlers = handlers + ",":U + handler.
handler = ""
END.

this works :)

jango


john's picture

thanks

I like your solution better than what I was going to do, thanks.


extra comma's

jungles = (if jungle <> "" then jungles + jungle + "," else jungles + "").
otherwise the list start with , and ends in ,,
handlers = (if handler <> "" then handlers + handler + ",":U else handler + "").

to be neat, not that important unless null values mess things up

jango


alternative

To be honest, I am not sure if I would use your solution, because it looks a little bit confusing to me and it ends the list with a delimiter which might be wrong.

My suggestion would be to write it like that:

handlers = handlers + (if handlers = "" then "" else ",") + yourvalue.

Hans Werner Lhotzky
CONMAPP IT-Services GesmbH


probably

you might be right for the list , i dont think thats not important element for this code snippet problem anyway, looked at it last night didn't like the list starting with "," , but your solution looks better a glance. except your testing (if handlers would think it would be handler) but principly its right) i dont think null values are that important in this case

thanks

jango


john's picture

Re: extra comma's

That would be caught by the check for a tt_output record, so it works fine as is.


ok

ok