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.
Hey Alex,
I use 11.3, and the following statement displays the expected 41:
display num-entries(fill("|",40),"|")
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
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.
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. "
This might have been fixed in 11.5. I get the expected count even without the carriage return after the last line.