READ DATA |
Read Data from Program |
1. Read Data: |
READ DATA varlist,...[,ERR=stmtref] |
READ DATA FROM data$ [,fileopt] TO varlist |
data$ |
Data to be parsed into the varlist. String expression. | ||||||||
fileopt |
Supported file options (see File Options):
| ||||||||
stmtref |
Program line number or statement label to which to transfer control. | ||||||||
varlist |
List of variables to receive the values from the DATA statements. Comma-separated numeric and string variables are allowed. |
Use the READ DATA directive to read data embedded in a program.
READ DATA varlist,...[,ERR=stmtref]
Use this format to transfer the values/expressions from data statements in a program to the variables identified in varlist. When READ DATA is executed, PxPlus evaluates each expression in the data statements in order and places the values into the corresponding variables defined in your READ DATA directive.
PxPlus increments an internal pointer to the next data expression during the reading of data$. When the end of a data statement is reached, the next data statement in the program is used. Use a RESTORE directive to reset the pointer to the start of the first data statement.
Include the END= or ERR= option to avoid an Error #2 when the pointer is at end of file:
0010 data "Dog","Cat","Pig"
0020 data "Pig","Cat","Dog"
0030 read data X$, end=1000
0040 print X$," | ",
0050 goto 0030
1000 restore
1010 print "DONE"; stop
->begin
->run
Dog | Cat | Pig | Pig | Cat | Dog | DONE
READ DATA FROM data$[,REC=string$][SEP=char$] TO varlist[,ERR=stmtref]
You can READ DATA FROM a string to initialize a list of variables or to parse a record into different IOLists.
Example 2 - Initialize Variables:
You can READ DATA to an IOList to initialize all variables:
0010 ! Clear all variables in an IOLIST
0100 read data from "" to iol=8000
8000 iolist ID$,NAME$,AMT
0010 read data from "",rec=WORK$ to iol=iol(WORK)
You can use READ DATA to parse a record into different IOLists:
0100 read record (1)R$
0200 if R$(1,1)="T" then read data from R$ to iol=8000
0200: else read data from R$ to iol=8010
8000 iolist TYPE$,TRN_DATE$,TRN_AMOUNT
8010 iolist TYPE$,PAY_DATE$,PAY_AMOUNT
DATA Define Data Elements
RESTORE Reset Program Data Position
BEGIN Reset Files and Variables
LOAD Read Program into Memory