Focal Point
storing and incrementing sequence number in a file

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7791000991

November 30, 2006, 04:56 PM
leo13
storing and incrementing sequence number in a file
Hi,
I am trying to create a file with a single field -- a sequence number. I would like to then be able to retrieve that sequence number, increment it by 1 and then write the new sequence number back to my file. I've tried using filedef in conjunction with -READ and -WRITE but I can't seem to get it to work. And, for some reason, when I create an & variable and set it equal to the value I've -READ from my file, it stores the name of my & variable, not the value of it. Does anyone have code that will do what I want? Thanks in advance for any help you can offer.


WebFOCUS 7.7.05
Windows 2008
November 30, 2006, 06:47 PM
Francis Mariani
This works:

FILEDEF D001 DISK C:\TEMP\D001.txt
-RUN

-READ D001 &SEQ.I4.

-TYPE AFTER READ: &SEQ

-SET &SEQ = &SEQ + 10001;

-SET &SEQ = EDIT(&SEQ,'$9999');

-TYPE BEFORE WRITE: &SEQ

-WRITE D001 &SEQ

-READ D001 &SEQ.I4.

-TYPE AFTER READ: &SEQ


Adding 10001 instead of 1 preserves the leading zeros. If you just add 1 then the leading zeros get truncated and written to the file. If you do a subsequent READ, it may not work, because the sequence number may not be the length as specified in the -READ statement.

I created a text file containing one row with the value 0055. I ran the code repeatedly and it successfully updated the text file.

The number being added has to be one digit bigger than the value you're reading in: I assume my largest sequence number will be four digits, hence I add 10001.

Tell me how this goes.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 01, 2006, 08:57 AM
leo13
Hi, Francis
This was exactly what I was looking for. Not sure why I couldn't make this work. Thanks so much for your help.


WebFOCUS 7.7.05
Windows 2008