Page 1 of 1

Stock table file format

Posted: Sat May 15, 2004 10:28 pm
by Dale Harris
This is the code for accessing the stock table in POS, it is written in Qbasic:

First you have to know how many records are in the stock table. Accessing the .POS file tells you how many are supposed to be there, accessing the .TBL file tell you how many really are there. If the numbers do not match then use the lower value.

FL$= “FILENAME”
OPEN “R”,1,FL$+”.POS”,80:FIELD 1,70 AS A$,1 AS B$:GET 1,1
RCC = ASC(B$): CLOSE 1
IF RCC = 32 THEN RCC = 15
RCC = (RCC - 10) * 1000
OPEN “R”,1,FL$+”.TBL”,120:FIELD 1,7 AS A$,1 AS B$,1 AS C$:GET 1,1
RC = (ASC(C$) - 10) * 1000
IF A$ <> "VERSION" OR B$ <> CHR$(6) THEN
PRINT “Not stock table version 6”: END
END IF
CLOSE 1
IF RCC < RC THEN RC = RCC

NOTE: Since the first record in the file is now used for a description of the file the actual stock table begins with the second record. Therefore stock table lines 1 to 1000 will be in records 2 to 1001 of the stock table file.

Whenever the POS program goes the stock table feature (where new items may be added) the stock table index (the .IDX file) will be restored so any errors in the .IDX file will be repaired.

The last 14 bytes of each record are reserved for future use and should be filled with CHR$(0) until then.

REM FL$ = NAME OF REGISTER DATA FILES
DIM TB$(14)
AA: DATA 24,7,1,1,4,4,1,4,18,4,4,4,30,4
OPEN 'R', 2, FL$ + '.TBL', 120
RESTORE AA: B = 0
FOR A = 1 TO 14
READ C
FIELD #2, B AS NULL$, C AS TB$(A)
B=B+A
NEXT A

Each record is comprised of 14 fields in this order.

1. A 24 byte description.
$=LSET(DESCRIPTION$)

2. 7 bytes for the regular price X 100 stored as a string. For example if the if the price is
12345.67 then the stored string is 1234567.
$=RSET(STR$(REGULARPRICE*100))

3. 1 byte is the value of the 'category' stored as an ASCII character. For example if the
item is in category 38 then the character '$' ( = ASCII 38 ) will be stored there.
$=LSET(CHR$(CATEGORY))

4. 1 byte as the tax rate chart stored as a string of the rate chart. If the rate is 1 then the
character '1' ( = ASCII 49 ) is stored.
$=LSET CHR$(RATECHART+48))

5. 4 bytes as the compressed long integer string of the pieces sold x 1000.
$=MKL$(PIECES*1000)

6. 4 bytes as the compressed long integer string of the value sold x 1000.
$=MKL$(VALUE*1000)

7. 1 byte is the value of the 'vendor' stored as an ASCII character. For example if the item
is from vendor 38 then the character '$' ( = ASCII 38 ) will be stored there.
$=LSET(CHR$(VENDOR))

8. 4 bytes as the compressed long integer string of the inventory pieces x 1000.
$=MKL$(INVENTORY*1000)

9. 18 bytes as the string of the stock number.
$=RSET(LTRIM$(RTRIM$(STR$(STOCKNUMBER#))))

10. 4 bytes as the compressed long integer string of the cost x 100.
$=MKL$(COST*1000)

11. 4 bytes as the compressed long integer string of the model stock.
$=MKL$(MODEL)

12. 4 bytes as the compressed long integer string of the pack.
$=MKL$(PACK)

13. The 30 byte vendor stock number.
$=LSET(VENDOR$)

14. 4 bytes as the compressed long integer string of the sale price..
$=MKL$(SALEPRICE*100)

Posted: Mon May 31, 2004 4:09 am
by JF Mous
Hi Dale,

I have just two more small questions about the file format.

1/ You say each record ends with 14 unused bytes for future use. The total record length is 120 bytes. So there should be (120-14) 106 bytes of actual data. But this was the old recordlength. With the 4-byte sale price added in the new format I count 110 bytes of actual data, so there is no room for 14 unused bytes.

2/ Field 10 is Cost. In the description is written Cost*100, The code below says Cost*1000.

Grtz,

J Mous