Bug in Num-entries?

Posted by Alex Hart on 04-Nov-2015 09:17

Has anyone experienced something like this:

My input has 40 delimiters | but if there is no value behind the last delimiter NUM-ENTRIES returns 40 and not 41. If I add a space after the last delimiter or if I add a carriage return then it works correctly.

The document says: "NUM-ENTRIES returns the number of delimiters plus 1, and it returns 0 if list equals the empty string"

(Using OE 11.3)

Sorry I should have stated I am reading input from a file, after adding a carriage return at end of file it imports and delimits correctly. So not sure if the issue is with the IMPORT or the NUM-ENTRIES, but I assuemd num-entries as the error message was put out (Run ErrorMsg just outputs the error message)

REPEAT:
  IMPORT STREAM sIn UNFORMATTED cLine.
  IF NUM-ENTRIES(cLine, "|") < 41
  THEN DO:
    RUN ErrorMsg("Not enough entries:" + ".", iLine).
    NEXT.
  END.

Ok I think it is related to import. 

http://knowledgebase.progress.com/articles/Article/P124970?q=num-entries+last+entry+empty+line+feed+carriage+return&l=en_US&c=Product_Group%3AOpenEdge&fs=Search&pn=2

All Replies

Posted by smat-consulting on 04-Nov-2015 09:32

Hey Alex,

 I use 11.3, and the following statement displays the expected 41:

display num-entries(fill("|",40),"|")

Posted by Simon L. Prinsloo on 04-Nov-2015 09:35

I tested the following code and got the expected result on these versions:

DEFINE VARIABLE cList AS CHARACTER NO-UNDO.

cList  = FILL("|",40).

MESSAGE NUM-ENTRIES(cList ,"|") SKIP LENGTH(cList)
  VIEW-AS ALERT-BOX.

11.3.2 Windows 32-bit 

11.4.0 Windows 32-bit

11.5.1.003 Windows 64-bit

11.6.0 Windows 64-bit

Posted by Marco Aurelio on 04-Nov-2015 09:49

hi,

  i've tested  in 11.4 and it worked fine, never knew a problem with num-entries since v6.

this returns 41.

def var x as c.

assign x = "1|1|1|1|1|1|1|1|1| 10 |1|1|1|1|1|1|1|1|1| 20 |1|1|1|1|1|1|1|1|1| 30 |1|1|1|1|1|1|1|1|1| 40 |".

message num-entries(x,"|") view-as alert-box.

this retuns each entry in its place, even empty 41th

def var i as i.

def var i2 as i.

do i = 1 to num-entries(x,"|"):

  assign i2 = i2 + 1.

  display i2 entry(i,x,"|") with frame a 18 down.

  down with frame a.

end.

Posted by Brian K. Maher on 04-Nov-2015 14:41

Alex,
 
Code fragment please.  A quick test using 11.6 returned the correct value ... display num-entries("a|b|c|d|e|","|").
 
Brian

Posted by Alex Hart on 05-Nov-2015 02:43

I updated my post. I wonder if it is related to this comment in documentation " The UNFORMATTED option forces IMPORT to read one physical line at a time. A physical line ends with a newline or linefeed character. "

Posted by jquerijero on 06-Nov-2015 16:02

This might have been fixed in 11.5. I get the expected count even without the carriage return after the last line.

This thread is closed