Temp-table blank record

whwar9739

Member
I tend to use temp-tables frequently when using a external file for input. I always seem to get an extra record that is blank. Here is some sample code that I use to do this.

Code:
DEF TEMP-TABLE l-example
   FIELD field1
   FIELD field2...
 
INPUT FROM example.csv.
 
REPEAT:
   CREATE l-example.
   IMPORT DELIMITER "," l-example.
END.
 
FOR EACH l-example:
   DISPLAY l-example.
END.
 
Most probably This is because of a control character in the CSV input file at the end . U can see this, if you open that external file in any dos editor. Easy way to avoid this by skipping the loop if the input line is blank
Regards
Philip P Oommen
 
Discard the last posting. This is because you are creating a blank record even though the last line is blank. Put a Do transaction as shown below.

DEF TEMP-TABLE l-example
FIELD field1
FIELD field2...

INPUT FROM example.csv.
Do Transaction:
REPEAT:
CREATE l-example.
IMPORT DELIMITER "," l-example.
END.
END.
FOR EACH l-example:
DISPLAY l-example.
END.
Regards
Philip P Oommen
 

whwar9739

Member
Thanks, philippoommen1 that did the trick. So can anyone expain to me why that worked? Or why I was getting the extra blank record in the first place??
 

TomBascom

Curmudgeon
This should make what is happening a bit clearer:

Code:
define temp-table tt /* no-undo */
  field ttLine as character format "x(30)"
.

define variable i as integer no-undo.
define variable inLine as character no-undo format "x(30)".

input from "text.txt".

repeat /* transaction */:

  message transaction "".

  /**/ import unformatted inLine. /**/

  create tt.
  /* import unformatted tt.ttLine. */
  /**/ tt.ttLine = inLine. /**/

end.

input close.

for each tt:
  i = i + 1.
  display i tt.ttLine.
end.

The loop only ever ends because the IMPORT fails at EOF. If the IMPORT is before the CREATE then there is no blank record. But if the IMPORT is after the CREATE you end up with a blank. Why? Because temp-tables don't start transactions all by themselves.

Mess arround with the comments to see what the various permutations result in ;)
 

ss_kiran

Member
The attached document gives more information on why a blank record was created.

- Kiran
 

Attachments

  • tmptbl101.doc
    52 KB · Views: 22

whwar9739

Member
The attached document gives more information on why a blank record was created.

Kiran, thanks that was extremely informational and definately helped me understand what was going on.

Again Thanks to all who answered my question.
 
Top