Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Reference
S
A O F T W A R E
P R O D U C T S
T
A
D
I
N
U
UniData
Relational Database Management System
®
for UNIX
Unidata, Inc., reserves the right to make changes to this document and the software described herein at any
time and without notice. No warranty is expressed or implied other than that contained in the terms and
conditions of sale, and in no case is Unidata, Inc., liable for more than the purchase price of the product.
Unidata, Inc.
1099 18th Street, Suite 2200
Denver, Colorado 80202
Phone: (303) 294-0800
Fax: (303) 293-8880
Unidata and UniData are registered trademarks of Unidata, Inc. UniDesktop and UniServer are trademarks of Unidata, Inc. Pick is
a registered trademark of Pick Systems. Unidata is not a licensee of Pick Systems. SYBASE is a registered trademark, and DB-
Library, Net Library, Open Client, Open Server, and SYBASE Server Library are trademarks of Sybase, Inc. UNIX is a registered
trademark of UNIX System Laboratories, Inc. VMS is a trademark of Digital Equipment Corporation. Other trademarks and regis-
tered trademarks are the property of the respective trademark holders.
Contents SOFTWARE PRODUCTS
3
Contents
BITXOR ........................................................................................46
BPIOCP ........................................................................................47
BREAK .........................................................................................49
CALCULATE ...............................................................................51
CALL ............................................................................................52
CALLC .........................................................................................56
CASE ............................................................................................57
CAT ..............................................................................................60
CATS ............................................................................................61
CHAIN ..........................................................................................62
CHANGE ......................................................................................63
CHAR ...........................................................................................64
CHARS .........................................................................................65
CHECKSUM ................................................................................66
CLEAR .........................................................................................67
CLEARCOMMON .......................................................................68
CLEARDATA ..............................................................................69
CLEARFILE .................................................................................70
CLEARINPUT ..............................................................................72
CLEARSELECT ...........................................................................73
CLEARSQL ..................................................................................75
CLOSE ..........................................................................................76
CLOSESEQ ..................................................................................78
COL1 ............................................................................................80
COL2 ............................................................................................81
Comment .......................................................................................82
COMMON ....................................................................................83
CONNECT ....................................................................................87
CONTINUE ..................................................................................89
CONVERT ....................................................................................90
CONVERT ....................................................................................92
4
Contents
COS ...............................................................................................94
COUNT .........................................................................................95
COUNTS ......................................................................................97
CRT ...............................................................................................99
DATA .........................................................................................100
DATE ..........................................................................................101
DCOUNT ....................................................................................102
DEBUG .......................................................................................104
DEFFUN .....................................................................................106
DEL .............................................................................................108
DELETE .....................................................................................110
DELETE .....................................................................................112
DELETELIST .............................................................................114
DELETEU ..................................................................................115
DIMENSION ..............................................................................117
DIR ..............................................................................................120
DISCONNECT ...........................................................................121
DOWNCASE ..............................................................................122
DQUOTE ....................................................................................123
DROUND ...................................................................................124
EBCDIC ......................................................................................125
ECHO ..........................................................................................126
END ............................................................................................127
ENTER ........................................................................................128
EQ ...............................................................................................130
EQS .............................................................................................131
EQUATE ....................................................................................132
EXECUTE ..................................................................................134
EXECUTESQL ...........................................................................135
EXIT ...........................................................................................138
EXP .............................................................................................139
5
Contents
EXTRACT ..................................................................................140
FIELD .........................................................................................142
FIELDSTORE ............................................................................144
FILEINFO ...................................................................................146
FILELOCK .................................................................................149
FILEUNLOCK ...........................................................................151
FIND ...........................................................................................153
FINDSTR ....................................................................................155
FLUSH ........................................................................................157
FMT ............................................................................................158
FOOTING ...................................................................................161
FORMLIST .................................................................................163
FOR/NEXT .................................................................................164
FUNCTION ................................................................................166
GARBAGECOLLECT ...............................................................167
GE ...............................................................................................168
GES .............................................................................................169
GET .............................................................................................170
GETCOLUMNDATA ................................................................173
GETCOLUMNNAME ................................................................175
GETENV ....................................................................................177
GETERRMSG ............................................................................178
GETLIST ....................................................................................179
GETNEXTTUPLE ......................................................................181
GETPTR .....................................................................................183
GETPU ........................................................................................185
GETREADU ...............................................................................186
GETUSERNAME .......................................................................187
GETUSERGROUP .....................................................................188
GOSUB .......................................................................................189
GOTO .........................................................................................191
6
Contents
GROUP .......................................................................................193
GROUPSTORE ..........................................................................195
GT ...............................................................................................198
GTS .............................................................................................199
HASH ..........................................................................................200
HEADING ..................................................................................201
HUSH ..........................................................................................204
ICONV ........................................................................................205
IF/THEN/ELSE ..........................................................................215
IN ................................................................................................217
INDEX ........................................................................................218
INDICES .....................................................................................220
INMAT .......................................................................................222
INPUT .........................................................................................223
INPUT @ ....................................................................................227
INPUTERR .................................................................................229
INPUTIF .....................................................................................230
INPUTNULL ..............................................................................231
INPUTTRAP ..............................................................................232
INS ..............................................................................................234
INSERT ......................................................................................236
INT ..............................................................................................238
ITYPE .........................................................................................239
LE ................................................................................................241
LES .............................................................................................242
LEN .............................................................................................243
LENS ..........................................................................................244
LN ...............................................................................................245
LOCATE .....................................................................................246
LOCK ..........................................................................................250
LOOP/REPEAT ..........................................................................253
7
Contents
LOWER ......................................................................................256
LT ................................................................................................257
LTS .............................................................................................258
MAT ............................................................................................259
MATBUILD ...............................................................................261
MATCH
MATCHES .................................................................................264
MATCHFIELD ...........................................................................266
MATPARSE ...............................................................................268
MATREAD .................................................................................271
MATREADL ..............................................................................274
MATREADU ..............................................................................277
MATWRITE ...............................................................................280
MATWRITEU ............................................................................282
MAXIMUM ................................................................................284
MDPERFORM ...........................................................................285
MINIMUM .................................................................................290
MOD or REM .............................................................................291
NE ...............................................................................................292
NES .............................................................................................293
NEG ............................................................................................294
NEXT ..........................................................................................295
NOCONVERT ............................................................................296
NOT ............................................................................................298
NOTS ..........................................................................................299
NULL ..........................................................................................300
NUM ...........................................................................................301
NUMS .........................................................................................302
OCONV ......................................................................................303
OCONV Date (D) .......................................................................305
OCONV Group (G) ....................................................................309
8
Contents
9
Contents
PRINTER ....................................................................................372
PRINTER CLOSE ......................................................................373
PRINTERR .................................................................................374
PROCREAD ...............................................................................377
PROCWRITE .............................................................................379
PROGRAM .................................................................................380
PROMPT ....................................................................................381
PWR ............................................................................................382
QUOTE .......................................................................................383
RAISE .........................................................................................384
READ ..........................................................................................385
READBCK .................................................................................388
READBCKL ...............................................................................390
READBCKU ..............................................................................392
READFWD .................................................................................394
READFWDL ..............................................................................396
READFWDU ..............................................................................398
READL .......................................................................................400
READLIST .................................................................................403
READNEXT ...............................................................................406
READNEXTTUPLE ..................................................................409
READSELECT ...........................................................................411
READSEQ ..................................................................................412
READT .......................................................................................414
READU .......................................................................................418
READV .......................................................................................421
READVL ....................................................................................424
READVU ....................................................................................427
READXFWD ..............................................................................430
READXBCK ..............................................................................432
RECORDLOCKED( ) ................................................................434
10
Contents
RECORDLOCKL .......................................................................436
RECORDLOCKU ......................................................................438
RELEASE ...................................................................................440
REMOVE ....................................................................................442
REMOVE ....................................................................................446
REPLACE ...................................................................................448
RESIZET ....................................................................................451
RETURN ....................................................................................453
REUSE ........................................................................................454
REWIND ....................................................................................455
RND ............................................................................................457
RNDSEED ..................................................................................458
SADD ..........................................................................................459
SCMP ..........................................................................................460
SDIV ...........................................................................................461
SELECT ......................................................................................462
SELECTINDEX .........................................................................465
SELECTINFO ............................................................................467
SEND ..........................................................................................468
SEQ .............................................................................................470
SEQS ...........................................................................................471
SETINDEX .................................................................................472
SETTABLE ................................................................................475
SETROW ....................................................................................477
SIN ..............................................................................................479
SLEEP .........................................................................................480
SMUL .........................................................................................482
SOUNDEX .................................................................................483
SPACE ........................................................................................485
SPACES ......................................................................................486
SPLICE .......................................................................................487
11
Contents
SQUOTE .....................................................................................488
SQRT ..........................................................................................489
SSUB ..........................................................................................490
STATUS .....................................................................................491
STOP ...........................................................................................492
STR .............................................................................................494
STRS ...........................................................................................495
SUBROUTINE ...........................................................................496
SUBSTRINGS ............................................................................498
SUM ............................................................................................499
SWAP .........................................................................................501
SYSTEM .....................................................................................503
TAN ............................................................................................506
TIME ...........................................................................................507
TIMEDATE ................................................................................508
TRANSACTION ABORT ..........................................................509
TRANSACTION COMMIT .......................................................511
TRANSACTION START ...........................................................513
TRIM ..........................................................................................515
TRIMB ........................................................................................517
TRIMF ........................................................................................518
TRIMS ........................................................................................519
UDTEXECUTE ..........................................................................520
UNASSIGNED ...........................................................................522
UNLOCK ....................................................................................523
UPCASE .....................................................................................524
USE .............................................................................................525
WAIT ..........................................................................................527
WEOF .........................................................................................529
WEOFSEQ ..................................................................................532
WRITE ........................................................................................534
12
Contents
WRITELIST ...............................................................................536
WRITESEQ ................................................................................537
WRITESEQF ..............................................................................539
WRITET .....................................................................................541
WRITEU .....................................................................................544
WRITEV .....................................................................................546
WRITEVU ..................................................................................548
XLATE .......................................................................................550
Index
13
Reference SOFTWARE PRODUCTS
This section contains a detailed alphabetic listing with descriptions and working
examples of all UniBasic commands and functions.
Functions perform specialized operations that augment and enhance commands. You
always use functions as expressions or in expressions following a command.
14
Elements of Syntax Statements
15
@
Syntax
@(col.expr [,row.expr])
@ (-num.expr)
Description
The UniBasic @ function positions the cursor on the video screen. In the first form,
the system positions the cursor at the column and row you specify.
In the second form, you may specify various terminal functions by num.expr.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
@ Parameters
16
@
Parameter Description
@ Parameters (continued)
@ Terminal Functions
The following table describes the valid @ terminal functions:
Function Description
@ Terminal Functions
17
@
Function Description
18
@
Function Description
Examples
In the following example, the statement prints the message HI in the fifth column from
the left of the screen and the tenth row down from the top:
PRINT @(5,10):"HI"
19
@
In the next example, the program segment prints two messages at different points on
the screen:
ROW = 0 ; COL = 0
PRINT @(COL,ROW):"TOP":@(COL,ROW+21):"BOTTOM"
In the next example, the program segment starts reverse video mode, prints a prompt,
then stops reverse video mode:
PRINT @(-13)
PRINT "ENTER NAME:":
PRINT @(-14)
In the next example, the program segment clears the screen and places the cursor in
the home position:
CLS = @(-1)
PRINT CLS
Related Topics
@variables
For information on @variables, refer to Appendix B @variables.
REUSE.ROW
The ECL REUSE.ROW command changes the way the cursor moves on a terminal
when the cursor positioning is controlled by the @ function. For information on
REUSE.ROW, refer to UniData Commands Reference.
20
[]
[]
Syntax
string.expr [num.expr1,num.expr2] = expr
expr = string.expr [num.expr1, num.expr2]
Description
The UniBasic [ ] “square brackets” function either extracts or replaces strings.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
[ ] Parameters
Examples
In the following example, the program segment extracts the first character of the vari-
able LAST.NAME, in this case an S:
LAST.NAME = ’Smith’
L.INITIAL = LAST.NAME[1,1]
21
[]
In the next example, the program segment changes the first letter of the word Bind in
the variable TITLE to W. The resulting string is “Gone with the Wind”.
TITLE = ’Gone with the Bind’
TITLE[15,1] = ’W’
In the next example, the program segment changes the substring 234 to nulls. In
BASICTYPE M, A will be “15.” In all other BASICTYPES, a will be “1 5.”
A = "12345"
A[2,3] = ""
Related Topics
String Manipulation and Extraction
For information on string manipulation and extraction, refer to Developing UniBasic
Applications.
22
{ } CALCULATE
{}
CALCULATE
Syntax
{dictionary.item}
CALCULATE(dictionary.item)
Description
The UniBasic { } “braces” or CALCULATE function executes and captures the
results of a virtual attribute. These functions, working with the @variables, @DICT
and @RECORD, permit this operation. The dictionary.item must be a valid virtual
attribute within the dictionary previously opened to the @DICT variable with an
OPEN statement. In the {} form, the dictionary.item must be the literal dictionary
name, with no quotes. In the CALCULATE() form, the dictionary.item may be a
quoted string or a UniBasic variable. The expression uses the data from the current
@RECORD during the evaluation process.
You must open a dictionary to @DICT and read the data record into @RECORD for
the function to work properly.
If these functions are successful, they update the values in the @CONV, @FORMAT,
and @HEADER. The dictionary virtual attribute has values for conversion, format-
ting, and column headings. These values are placed in the @CONV, @FORMAT, and
@HEADER variables after the first execution of the braces function. You may then
use them in other UniBasic functions, such as ICONV, OCONV, and FMT.
Examples
In the following example, the program segment opens the CUSTOMER file to the
variable CUSTOMER and the dictionary of the CUSTOMER file to the special
@DICT variable. After selecting the CUSTOMER file, the program reads the value of
each record ID into @ID, reads the value of the customer record into @RECORD,
then uses the { } “braces” function to evaluate the current balance (storing the total in
TOTAL.DUE). The braces function updates the @CONV, @HEADER and @FOR-
MAT variables. The system uses these variables in subsequent statements to output
the value with a heading and correct format.
OPEN ’’,’CUSTOMER’ TO CUSTOMER ELSE
STOP ’NO CUSTOMER’
END
OPEN ’DICT’,’CUSTOMER’ TO @DICT ELSE
STOP ’NO DICTIONARY FOR CUSTOMER’
END
TOTAL.DUE = 0
23
{ } CALCULATE
SELECT CUSTOMER
MORE = 1
LOOP
READNEXT @ID ELSE MORE = 0
UNTIL NOT(MORE) DO
READ @RECORD FROM CUSTOMER,@ID ELSE
@RECORD = ’’
END
TOTAL.DUE += {BALANCE}
PRINT @HEADER:’’:OCONV({BALANCE},@CONV)
REPEAT
TOTAL.DUE = OCONV(TOTAL.DUE,@CONV)
PRINT "Total Due ":FMT(TOTAL.DUE,@FORMAT)
END
Related Topics
ITYPE
The UniBasic ITYPE function allows a BASIC program to access a UniData virtual
attribute from the dictionary of a UniData file.
24
$BASICTYPE
$BASICTYPE
Syntax
$BASICTYPE “param”
Description
The UniBasic $BASICTYPE command compiles data in a specified BASICTYPE.
The $BASICTYPE statement must be the first non-comment statement.
If you do not specify a $BASICTYPE, the system compiles the program in the
BASICTYPE you specify in the ECL BASICTYPE command. The default type is U.
Parameters
The following table describes the available parameters:
Parameter Description
U UniBasic
P Pick® Basic
R R/Basic
M McDonnell Douglas
$BASICTYPE Parameters
Related Topics
BASICTYPE
For information on the ECL BASICTYPE command, refer to UniData Commands
Reference.
25
$DEFINE
$DEFINE
Syntax
$DEFINE var
Description
The UniBasic $DEFINE command defines a control variable that you can later use to
direct the compilation.
Examples
In the following example, since you define SMALL, when you compile the program
segment, the system defines array1 as a 10-element array and initialized with 0.
$DEFINE SMALL
$IFDEF SMALL
DIM array1(10)
MAT array1 = 0
$ENDIF
Related Topics
$UNDEFINE
The UniBasic $UNDEFINE command deletes the definition of var, previously
defined by $DEFINE.
EQUATE
The UniBasic EQUATE command causes all occurrences of a variable to be replaced
with a variable that you designate during the compilation of a program.
26
$IFDEF
$IFDEF
Syntax
$IFDEF var statements1 [$ELSE statements2] $ENDIF
Description
The UniBasic $IFDEF command compiles one statement or another, depending upon
whether or not the variable var currently has a definition defined by a $DEFINE.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
$IFDEF Parameters
Examples
In the following example, when you compile the program segment, the system defines
array1 as a 10-element array and initialized with 0:
$DEFINE SMALL
$IFDEF SMALL
DIM array1(10)
MAT array1 = 0
$ENDIF
In the next example, when you compile the program segment, the system defines
array1 as a 100-element array and initializes it with 1:
$UNDEFINE SMALL
$IFDEF SMALL
PRINT ’SMALL was defined’
$ELSE
DIM array1(100)
MAT array1 = 1
$ENDIF
27
$IFDEF
Related Topics
$DEFINE
The UniBasic $DEFINE command defines a control variable that you can later use to
direct the compilation.
$IFNDEF
The UniBasic $IFNDEF command checks if a variable is currently undefined. If so,
the system compiles the specified statements. If not, the system compiles other speci-
fied statements.
28
$IFNDEF
$IFNDEF
Syntax
$IFNDEF var statements1 [$ELSE statements2] $ENDIF
Description
The UniBasic $IFNDEF command compiles one statement or another, depending
upon whether or not the variable var is currently undefined by $DEFINE.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
$IFNDEF Parameters
Examples
In the following example, the program segment nests the $IFDEF and $IFNDEF state-
ments. Upon compilation of this program, the size of array A might be 1000, 10, or
100 depending on whether LARGE or SMALL is defined. If both are undefined, the
size of A is 100 elements, and the initialized value of array A might be 1 or 0, depend-
ing on whether ONE is defined. If the $DEFINE statements are kept in a separate
INCLUDE file, it is a minor task to recompile programs with different definitions.
$IFDEF LARGE
DIM A(1000)
$IFDEF ONE
MAT A = 1
$ELSE
MAT A = 0
$ENDIF
$ELSE
$IFNDEF SMALL
DIM A(100)
$ELSE
29
$IFNDEF
DIM A(10)
$ENDIF
$IFDEF ONE
MAT A = 1
$ELSE
MAT A = 0
$ENDIF
$ENDIF
Related Topics
$DEFINE
The UniBasic $DEFINE command defines a control variable that you can later use to
direct the compilation.
$IFDEF
The UniBasic $IFDEF command checks if a variable is currently defined. If so, the
system compiles the specified statements. If not, the system compiles other specified
statements.
30
$INCLUDE
$INCLUDE
Syntax
$INCLUDE record [FROM [DICT] filename]
$INSERT record [FROM [DICT] filename]
$INCLUDE filename {, | | > } record
$INSERT filename {, | > } record
$INCLUDE [pathname {, | | > }] seq.filename
$INSERT [pathname {, | | >}] seq.filename
Description
The UniBasic $INCLUDE and $INSERT commands insert UniBasic source code
from the file you specify into the program being compiled.
The fifth and sixth forms of the $INCLUDE statement insert code from a UNIX or
VMS sequential file.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
$INCLUDE Parameters
31
$INCLUDE
Parameter Description
Note The filename can identify a remote file as determined by the VOC entry. The
code to be inserted can also contain $INCLUDE or $INSERT statements.
Examples
In the following example, the program statement inserts the code contained in record
code_seg1 in file BP into the program being compiled:
$INCLUDE code_seg1 FROM BP
In the next example, the program statement inserts the code contained in sequential
file my_code in directory /usr/ud/mydir into the program being compiled:
$INCLUDE /usr/ud/mydir/my_code
32
$UNDEFINE
$UNDEFINE
Syntax
$UNDEFINE var
Description
The UniBasic $UNDEFINE command deletes the definition of var previously
defined by $DEFINE.
Related Topics
$DEFINE
The UniBasic $DEFINE command defines a control variable that you can later use to
direct the compilation.
EQUATE
The UniBasic EQUATE command causes all occurrences of a specified variable to be
replaced with a specified variable during the compilation of a program.
33
ABORT
ABORT
Syntax
ABORT [expr]
Description
The UniBasic ABORT command terminates the program or subroutine in progress,
returning the user to the UniData system level. ABORT returns the user to the Uni-
Data prompt, whether the aborted program was called by another program or executed
through a UniData menu or paragraph. ABORT may include an optional string expr to
display when the program aborts. The expression may contain variables, functions,
and arithmetic or string operators.
ABORT [message-id]
ABORT [expr,...]
In the first form, the message-id must be a variable which evaluates to a key
contained in the ERRMSG file when compiled in BASICTYPE P. In the sec-
ond form of the ABORT statement, you can specify more than one expr when
compiled in BASICTYPE P.
Tip You may use the ECL ON.ABORT command so that ABORT does not termi-
nate the process. For information on the ECL ON.ABORT command, refer to
UniData Commands Reference.
Examples
In the following example, the program segment attempts to read a record from a file.
If the record does not exist, the program aborts, clears the terminal screen, and prints
the message RECORD IS MISSING at line 10, column 10 on the terminal.
CUST.ID = 1234
OPEN ’’, ’CUSTOMER’ READONLY TO CUSTOMER ELSE STOP "Cannot Open"
READ REC FROM CUSTOMER, CUST.ID ELSE
ABORT @(10,10):’RECORD IS MISSING’
END
In the next example, the segment prints a prompt if an error flag ERR.FLAG has been
set and reads the user’s input into the variable ANS. If ANS equals “Y,” the program
aborts.
34
ABORT
ERR.FLAG = 1
IF ERR.FLAG THEN
PRINT "ABORT PROGRAM?"
INPUT ANS
IF ANS = "Y" THEN ABORT
END
In the next example, in BASICTYPE P, an error message prints and the program ter-
minates when DATAFILE_1 cannot be opened:
EID = "USER-ERROR"
ERR_MSG = "CAN’T OPEN FILE"
OPEN "", "DATAFILE_1" TO DFILE ELSE
ABORT ERR_MSG, EID
END
In the next example, in BASICTYPE P, the program segment prints and the error mes-
sage from record 10075 in the ERRMSG FILE prints if the program aborts:
If A < 0 THEN ABORT 10075
Related Topics
PRINTERR
The UniBasic PRINTERR command prints error messages stored in the system error
message file (ERRMSG).
STOP
The UniBasic STOP command stops execution of a program, but returns control to the
calling program, subroutine, menu, or paragraph, if any.
ON.ABORT
The ECL ON.ABORT command executes a user specified command if a subsequent
UniBasic program aborts. For information on ON.ABORT, refer to UniData
Commands Reference.
CLEAR.ONABORT
The ECL CLEAR.ONABORT command clears the setting of an ON.ABORT com-
mand. For information on CLEAR.ONABORT, refer to UniData Commands
Reference.
35
ABS
ABS
Syntax
ABS(expr)
Description
The UniBasic ABS function returns the positive numeric value (absolute value) of the
argument. expr may be any numeric expression, negative or positive.
Examples
In the following example, the program segment prints the absolute value of the vari-
able NUM. This results in 999 printing.
NUM = -999
PRINT ABS(NUM)
In the next example, the program statement replaces the variable NUM with its abso-
lute value:
NUM = ABS(NUM)
36
ACOS
ACOS
Syntax
ACOS(expr)
Description
The UniBasic ACOS function returns the trigonometric arc cosine (inverse cosine) of
a numeric expression in degrees. expr must be a value between -1 and +1. ACOS
returns a value expressed as the degree of the arc cosine of the input, which ranges
from 0 to 180. If expr evaluates to a value outside the range of -1 and +1, the system
displays an error message and returns 0 as the result.
Examples
In the following example, the program statement assigns 60, the value of arc cosine of
0.5, to ARCCOS:
ARCCOS = ACOS(0.5)
In the next example, the program statement prints out the arc cosine of -0.5, which is
120:
PRINT ACOS(-0.5)
37
ALPHA
ALPHA
Syntax
ALPHA(“str.expr”)
Description
The UniBasic ALPHA function tests a string to see if it is composed entirely of alpha-
betic characters. If str.expr is made entirely of alphabetic characters, spaces, punctua-
tion characters, escape sequences, etc., the function returns a one. If numeric
characters are present in str.expr, or if str.expr evaluates to a null, the function returns
a zero.
Examples
In the following example, the program statement prints a 0 since the literal string con-
tains the numeric character 2:
PRINT ALPHA("ABCDEFGHIJK2")
In the next example, the program segment prints a 1 since the string ALPHA contains
only alphabetic characters:
ALPHA.T=ALPHA("CORONA")
PRINT ALPHA.T
In the next example, the program statement prints a 0 since the string does not contain
any characters. A null value is not considered an alphabetic character.
PRINT ALPHA("")
38
ASCII
ASCII
Syntax
ASCII(expr)
Description
The UniBasic ASCII function (American Standard Code for Information Interchange)
converts a string in EBCDIC format (Extended Binary Coded Decimal Information
Code) to the corresponding ASCII values. While the ASCII function works with data
in any format, its results are only meaningful when it is applied to EBCDIC data.
For more information on ASCII character codes, refer to Appendix A ASCII Character
Codes.
Examples
In the following example, the program statement converts the EBCDIC data in the
variable E.VAR to ASCII format and assigns the value to the variable A.VAR:
A.VAR=ASCII(E.VAR)
Related Topics
EBCDIC
The UniBasic EBCDIC function converts a string in ASCII format to the correspond-
ing EBCDIC values.
39
ASIN
ASIN
Syntax
ASIN(expr)
Description
The UniBasic ASIN function returns the trigonometric arc sine (inverse sine) of a
numeric expression in degrees. expr must be a value between -1 and +1. ASIN returns
a value expressed as the degree of the arc sine of the input, which ranges from -90 to
+90. If expr evaluates to a value outside the range of -1 and +1, the system displays an
error message and returns 0 as the result.
Examples
In the following example, the program statement assigns 30, the value of arc sine of
0.5, to ARCSIN.
ARCSIN = ASIN(0.5)
In the next example, the program statement prints -30, the arc sine of -0.5.
PRINT ASIN(-0.5)
40
ASSIGN
ASSIGN
Syntax
ASSIGN expr TO SYSTEM(option)
Description
The UniBasic ASSIGN command redefines some of the system-level parameters. The
value in option changes to the value you specify with expr.
Parameters
The following table describes the valid ASSIGN parameters:
Parameter Description
2 Page width
3 Page length
5 Page number
7 Terminal type
ASSIGN Parameters
For parameters 2, 3, and 5, expr should evaluate to a numeric value; for parameter 7,
expr should evaluate to a string representing a valid terminal type and be enclosed in
quotes.
Examples
In the following example, the program resets the page width to 40, page length to 30,
and terminal type to vt100.
ASSIGN 40 TO SYSTEM(2)
ASSIGN 30 TO SYSTEM(3)
ASSIGN "vt100" TO SYSTEM(7)
Related Topics
TERM
The ECL TERM command sets your terminal type and other terminal characteristics.
For information on TERM, refer to UniData Commands Reference.
41
ATAN
ATAN
Syntax
ATAN(expr)
Description
The UniBasic ATAN function returns the trigonometric arc tangent (inverse tangent)
of a numeric expression expr in degrees.
Examples
In the following example, the program segment prints the arc tangent of the variable
VAL which is 45.
VAL = 1
PRINT ATAN(VAL)
42
BITAND
BITAND
Syntax
BITAND(num.expr1,num.expr2)
Description
The UniBasic BITAND function performs the bit-wise AND logical function on the
arguments num.expr1 and num.expr2.
The following table illustrates the resulting value of the BITAND function.
0 0 0
0 1 0
1 0 0
1 1 1
3 9 1
23 87 23
Examples
In the following example, the program statement prints a 0.
PRINT BITAND(0,1)
43
BITOR
BITOR
Syntax
BITOR(num.expr1,num.expr2)
Description
The UniBasic BITOR function performs the bit-wise OR logical function on the argu-
ments num.expr1 and num.expr2.
The following table illustrates the resulting value of the BITOR function.
0 0 0
0 1 1
1 0 1
1 1 1
3 9 11
23 87 87
Examples
In the following example, the program statement prints a 1.
PRINT BITOR(0,1)
44
BITNOT
BITNOT
Syntax
BITNOT(num.expr)
Description
The UniBasic BITNOT function performs the bit-wise NOT logical function on the
argument num.expr.
The following table illustrates the correct use and resulting value of the BITNOT
function.
num.expr Result
0 1
1 0
Examples
In the following example, the program statement prints a 1.
PRINT BITNOT(0)
45
BITXOR
BITXOR
Syntax
BITXOR(num.expr1,num.expr2)
Description
The UniBasic BITXOR function performs the bit-wise XOR logical function on the
arguments num.expr1 and num.expr2.
The following table illustrates resulting value of the BITXOR function.
0 0 0
0 1 1
1 0 1
1 1 0
3 9 10
23 87 64
Examples
In the following example, the program statement prints a 1.
PRINT BITXOR(0,1)
46
BPIOCP
BPIOCP
Syntax
BPIOCP
Description
The UniBasic BPIOCP command resets the terminal pagination. Whenever a UniBa-
sic program is printing to a terminal (without using cursor addressing), and the print
statements reach the bottom of the screen, this prompt appears:
Enter <New Line> to continue...
Parameters
There are three valid parameters for this prompt:
Parameter Description
BPIOCP Parameters
The page control process is automatically disabled if the UniBasic program uses the
@ function cursor control in any way. For example, the following disables terminal
pagination:
PRINT @(1)
CRT @(2)
VARIABLE = @(3)
Under this circumstance, UniData assumes that the program will control the paging of
data. To turn automatic pagination on from within a UniBasic program, use the BPI-
OCP statement. This enables page handling and the use of the new line prompt.
47
BPIOCP
Examples
In the following example, the program prints the first 30 records of the CUSTOMER
file without any pagination prompt. The second loop will print 22 lines and then give
you the pagination prompt “Enter <New Line> to continue...”.
JUNK = @(0,0)
OPEN ’’,’CUSTOMER’ READONLY ELSE NULL
FOR CUST.ID = 1 TO 30
READ REC FROM CUST.ID THEN
PRINT CUST.ID
END ELSE
PRINT CUST.ID: "DOES NOT EXIST."
END
NEXT
BPIOCP
FOR CUST.ID = 1 TO 30
READ REC FROM CUST.ID THEN
PRINT CUST.ID
END ELSE
PRINT CUST.ID: "DOES NOT EXIST."
END
NEXT
48
BREAK
BREAK
Syntax
BREAK [KEY] {ON | OFF | expr }
Description
The UniBasic BREAK command enables or disables the break key to exit a program
to the ‘!’ debugger prompt and display the current program line number.
The system increments a counter each time BREAK OFF executes and decrements
that same counter when BREAK ON executes. Until the system counter is less than or
equal to zero (more BREAK ON statements executed than BREAK OFF statements),
the break key will be non-operational. This status continues even if you exit a program
with the BREAK key disabled.
Parameters
The following table describes the valid BREAK parameters:
Parameter Description
BREAK Parameters
Examples
In the following example, the program statement decrements the system counter and
enables the break key if the counter is less than or equal to zero.
BREAK ON
49
BREAK
In the next example, a numeric expression decides whether to enable the break key. If
X is greater than 0, then the system enables the break key.
BREAK X > 0
Related Topics
PTERM
For information on the ECL PTERM command, refer to UniData Commands
Reference.
50
CALCULATE
CALCULATE
The UniBasic { } “braces” or CALCULATE function executes and captures the
results of a virtual attribute. Refer to the {} entry for further information.
51
CALL
CALL
Syntax
CALL *sub.name [[(argument1[,argument2][MAT matrix1 [,MAT matrix2]]...)]
[ASYNC | SYNC] [ON connection]
CALL @var [[(argument1[,argument2][MAT matrix1 [,MAT matrix2]]...)]
[ASYNC | SYNC] [ON connection]
CALL sub.name [[(argument1[,argument2][MAT matrix1 [,MAT matrix2]]...)]
[ASYNC | SYNC] [ON connection]
Description
The UniBasic CALL command transfers program control to an external subroutine,
either from the main program or from another subroutine.
• The first CALL statement calls a globally cataloged subroutine.
• The second CALL statement calls a subroutine named in a variable.
• The third CALL statement calls a subroutine directly.
Control returns to the calling program or subroutine by a RETURN statement within
the called subroutine.
Note You must catalog subroutines before using them in a UniBasic CALL state-
ment.
You must separate individual arguments by commas and surround the set of argu-
ments with parentheses. You may place arguments on multiple lines as long as each
line ends with a comma. Regardless of their placement, the number and type of argu-
ments in the CALL statement must match the number and type of arguments in the
SUBROUTINE statement at the top of the external subroutine. Matrices and singl-
evalued arguments can pass in the same CALL statement.
You may pass variables that appear in a COMMON statement to subroutines. If both
the program and subroutine have a COMMON statement, the variables are accessible
in both without being passed as arguments. A variable or matrix name in a subroutine
cannot appear in both the SUBROUTINE arguments and in the subroutine’s COM-
MON variables list. You may not call matrices that appear in a COMMON statement.
52
CALL
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CALL Parameters
Examples
In the following example, the program statement calls the subroutine VID, passing the
variables TITLE and ST.
CALL VID(TITLE,ST)
53
CALL
In the next example, the program segment calls the subroutine MONTHTOTAL by
calling the @variable @VID that holds the string “MONTHTOTAL.” Note that the
subroutine arguments follow the @variable and are not stored in the variable itself.
VID = "MONTHTOTAL"
CALL @VID(TOTAL)
In the next example, the program segment calls the contents of cell (1.12) in the
matrix cells, thus calling the subroutine RECEIPTS with the argument “MON1_12”.
In the use of @matrices, you may select the matrix element by the use of an index (a
variable within the dimensions of the matrix).
"SUBROUTINE MONTHTOTAL(TOTAL)"
SALES(1,12) = "RECEIPTS"
CALL @SALES(1,12)(MON1_12)
In the next example, the program statement calls the globally cataloged subroutine
PROMPT.ROUTINE.
CALL *PROMPT.ROUTINE
In the following example, the CALL statement is invalid since subroutine SUBS has a
different number of arguments than the CALL statement. Called routines must pass
the same number of parameters.
CALL SUBS(X,Y,Z)
Called subroutine:
SUBROUTINE SUBS(X)
Related Topics
COMMON
The UniBasic COMMON command makes the named variables available to all pro-
grams and subroutines that use the same COMMON statement.
DIMENSION
The UniBasic DIMENSION command declares the name and dimensions of matrices.
RETURN
The UniBasic RETURN command transfers program control from a subroutine back
to the calling program or subroutine.
SUBROUTINE
The UniBasic SUBROUTINE command determines the beginning of an external
subroutine.
54
CALL
CATALOG
The ECL CATALOG command copies the compiled object code of a UniBasic pro-
gram into the system catalog. For information on CATALOG, refer to UniData
Commands Reference.
55
CALLC
CALLC
Syntax
CALLC c.sub.name [(argument1[,argument2]...)]
CALLC @var [(argument1[,argument2]...)]
Description
The UniBasic CALLC command transfers program control to an external C subrou-
tine, either from the main program or from another subroutine. The second form calls
an external C subroutine stored in an @variable. The arguments are optional. The
CALLC statement is similar to the normal CALL subroutine statement, except that
matrices may not be passed as arguments. The CALLC subroutine can pass back a
value called the return value to a variable. CALLC arguments can be simple variables
or complex expressions.
CALLC may also be used as a function; it is placed on the right side of an assignment
operator and its value is then assigned to the variable on the left side of the statement.
Examples
In the following example, the C subroutine called draws a circle with its center at the
12th row and 12th column and a radius of 3.
RADIUS = 3
CENTER = "12,12"
CALLC DRAW.CIRCLE(RADIUS,CENTER)
In the next example, the subroutine name is stored in the variable @SUB.NAME.
SUB.NAME = DRAW.CIRCLE
CALLC @SUB.NAME(RADIUS,CENTER)
In the next example, CALLC is used as a function, allowing the return value of the C
subroutine PROGRAM.STATUS to be assigned to the variable RESULT.
RESULT = CALLC PROGRAM.STATUS
56
CASE
CASE
Syntax
BEGIN CASE
CASE expression1
statements1
CASE expression2
statements2
.
.
.
{CASE 1
statements}
END CASE
Description
The UniBasic CASE command creates a series of branches based on conditional
expressions. Case structures must always begin with BEGIN CASE and terminate
with END CASE.
The number of CASE commands within the BEGIN CASE and END CASE state-
ments is unlimited. The number of statements within each CASE branch is unlimited.
CASE statements may be nested.
The CASE command tests each of the expressions in sequence. If an expression eval-
uates as true, the system executes the statements that follow it. Once one of the CASE
expressions is found to be true, the system does not test any subsequent expressions. If
none of the conditions are true, the system does not execute any statements.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CASE Parameters
57
CASE
Parameter Description
Examples
In the following example, if the variable DUE.DATE is greater than the system date,
the program calls the subroutine PRINT.OVERDUE. (Notice that both dates are in
‘internal’ format.) If DUE.DATE is less than or equal to the system date, the program
prints the message “Okay” on your display terminal.
BEGIN CASE
CASE DUE.DATE > DATE()
GOSUB PRINT.OVERDUE:
CASE DUE.DATE <= DATE()
PRINT "Okay"
END CASE
The multiline indented statement layout shown in these examples is not required.
Tip However, this format is clearer and easier to read.
In the next example, the program segment transfers program control to either
“CHARGE:” or “CHECK:” based on the value of the variable VAL. If VAL is neither
one nor two, the program executes the statements after the CASE 1 clause.
PRINT "Option number?" ; INPUT VAL
BEGIN CASE
CASE VAL = 1
GOSUB CHARGE:
CASE VAL = 2
GOSUB CHECK:
CASE 1
PRINT "Answer 1 or 2 only"
END CASE
In the following example, the statement is invalid, since the evaluation expression
should not appear on the BEGIN CASE line.
BEGIN CASE VAR 1
58
CASE
In the next example, the statement is invalid, since BEGIN CASE must appear first.
CASE VAL
59
CAT
CAT
Syntax
expr1 CAT expr2
Description
The UniBasic CAT function concatenates expr1 to expr2.
Examples
In the following example, the program segment concatenates A to B and prints
123456.
A = "123"
B = "456"
C = A CAT B
PRINT C
Related Topics
String Manipulation
For information on string manipulation, refer to Developing UniBasic Applications.
60
CATS
CATS
Syntax
CATS(array1,array2)
Description
The UniBasic CATS function concatenates array1 to array2. Each element of array2
is concatenated to its corresponding element in array1.
Examples
In the following example, the program segment concatenates array A to array B and
prints 300A}400B}401C}402D}100E.
A = 300:@VM:400:@VM:401:@VM:402:@VM:100
B = "A":@VM:"B":@VM:"C":@VM:"D":@VM:"E"
C = CATS(A,B)
PRINT C
Related Topics
String Manipulation
For information on string manipulation, refer to Developing UniBasic Applications.
61
CHAIN
CHAIN
Syntax
CHAIN “str.expr”
Description
The UniBasic CHAIN command terminates the current UniBasic program and exe-
cutes the ECL command str.expr. CHAIN performs a function similar to the EXE-
CUTE statement, except that control is not returned to the original program. The
system treats str.expr as a command you type at the ECL colon ( : ) prompt, and there-
fore the system references the VOC file for the meaning of str.expr.
Examples
In the following example, the current program terminates and the system executes the
ECL command “RUN BP FORMLET”, where FORMLET is a compiled UniBasic
program. Control will not return to the original program when FORMLET terminates.
CHAIN "RUN BP FORMLET"
In the next example, the current program terminates and the paragraph
RUN.ACCOUNTS executes.
CHAIN "RUN.ACCOUNTS"
62
CHANGE
CHANGE
Syntax
CHANGE(string, old.substring, new.substring)
Description
The UniBasic CHANGE function replaces all occurrences of old.substring in string
with new.substring. If old.substring is null, the system does not change string.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CHANGE Parameters
Examples
In the following example, the program segment will print “UniBasic Release 3.1.0”
STRA = "UniBasic Release 2.3.2"
OLDRELEASE = "2.3.2"
NEWRELEASE = "3.1.0"
STRB = CHANGE(STRA,OLDRELEASE,NEWRELEASE)
PRINT STRB
63
CHAR
CHAR
Syntax
CHAR(expr)
Description
The UniBasic CHAR function changes a numeric expression to its ASCII (American
Standard Code for Information Interchange) character string equivalent. ASCII is a
system for representing all characters in terms of numbers: A = 65, B = 66, etc. expr
may be a constant, variable, numeric function, or any combination of these, and must
evaluate to a positive number from zero to 255, (the range of ASCII character codes).
Note Not all ASCII codes are printable. Some represent terminal controls, and oth-
ers are reserved for special uses. For more information on ASCII character
codes, refer to Appendix A ASCII Character Codes.
Examples
In the following example, the program segment assigns the ASCII string equivalent of
the numeric expression VAL to the variable VSTRING. The final numeric value of
the argument is 90, so VSTRING becomes Z, the character equivalent of 90 in the
ASCII code system.
VAL=90
VSTRING=CHAR(VAL)
In the next example, the program statement sends the ASCII code 12 to the current
print device. In ASCII, this is a form feed.
PRINT CHAR(12)
64
CHARS
CHARS
Syntax
CHARS(array)
Description
The UniBasic CHARS function changes a numeric value in array to its ASCII
(American Standard Code for Information Interchange) character string equivalent.
ASCII is a system for representing all characters in terms of numbers: A = 65, B = 66,
etc. array elements may contain a constant, variable, numeric function, or any combi-
nation of these, and must evaluate to a positive number from zero to 255, (the range of
ASCII character codes).
Note Not all ASCII codes are printable. Some represent terminal controls, and oth-
ers are reserved for special uses. For more information on ASCII character
codes, refer to Appendix A ASCII Character Codes.
Examples
In the following example, the program segment assigns the ASCII string equivalent of
the elements of array VAL to the variable VARRAY. VARRAY now contains
W}X}Y}Z, the character equivalent of 87,88,89, and 90 in the ASCII code system.
VAL = 87:@VM:88:@VM:89:@VM:90
VARRAY = CHARS(VAL)
65
CHECKSUM
CHECKSUM
Syntax
CHECKSUM(str.expr)
Description
The UniBasic CHECKSUM function computes the positional checksum of the string
str.expr you specify. The positional checksum is the sum of the ASCII value of each
character in the string, multiplied by the position of the character in the string.
Tip You can use the CHECKSUM function to check that data was copied cor-
rectly, or information processed properly, by comparing the CHECKSUM of
the original data with the CHECKSUM of the copy.
Examples
In the following example, the program statement prints out 2445, the checksum of
string “123456789.”
PRINT CHECKSUM("123456789")
66
CLEAR
CLEAR
Syntax
CLEAR
Description
The UniBasic CLEAR command sets the values of the variables stored in all local
memory to zero. This includes all matrix elements. Any variables assigned by named
or unnamed COMMON statements are not affected.
Tip CLEAR may at any point within a program, initialize or reinitialize variables.
Examples
In the following example, the program statement clears all variables not held in com-
mon if the variable INITIALIZE is true and BASICTYPE is U. The variable INI-
TIALIZE will also be set to zero (false) if the variable is not held in COMMON.
IF INITIALIZE THEN CLEAR
In the next example, the program segment sets X, Y, and all elements in NAME, to
zero in BASICTYPE P.
COMMON NAME(100)
X = 4
Y = X - 1
CLEAR
Related Topics
COMMON
The UniBasic COMMON command makes the named variables available to all pro-
grams and subroutines that use the same COMMON statement.
CLEARCOMMON
The UniBasic CLEARCOMMON command sets the variables in the named common
you specify to zero.
67
CLEARCOMMON
CLEARCOMMON
Syntax
CLEARCOMMON /common.label/
CLEAR COMMON /common.label/
CLEARCOM /common.label/
CLEAR COM /common.label/
Description
The UniBasic CLEARCOMMON command sets all variables you specify in a
named COMMON statement to zero. If you do not specify common.label,
CLEARCOMMON sets all variables specified in the unnamed COMMON statements
of a program to zero.
Examples
In the following example, the program statement sets to zero all variables named in
COM_1.
CLEARCOMMON /COM_1/
In the next example, the program statement sets to zero all variables held in COM-
MON statements if the variable INITIALIZE.COMMON is true.
IF INITIALIZE.COMMON THEN CLEAR COMMON
Related Topics
CLEAR
The UniBasic CLEAR command clears the values stored in all local memory vari-
ables.
COMMON
The UniBasic COMMON command makes the named variables available to all pro-
grams and subroutines that use the same COMMON statement. Named COMMON
allows for different common statements between subroutines and programs.
68
CLEARDATA
CLEARDATA
Syntax
CLEARDATA
Description
The UniBasic CLEARDATA command clears remaining data from any previously
executed DATA statements. Any subsequent INPUT statements will request data
from the keyboard rather than accepting data remaining in the input queue.
Examples
In the following example, a DATA statement sets up a list of values to be read. An
INPUT statement then reads the first number into the variable VAL. If the value of
VAL is 100, a CLEARDATA statement executes and clears the remaining list of data
items. The last INPUT statement then requests information from the keyboard rather
than getting it from the DATA statement. If the first value was not 100, the value of
VAL2 is 120 because it is assigned by the second item in the DATA list.
DATA 100,120,105,54,120
INPUT VAL
IF VAL = 100 THEN CLEARDATA
PRINT "VALUE": ; INPUT VAL2
Related Topics
DATA
The UniBasic DATA command creates a data queue to be read by subsequent INPUT
statements.
INPUT
The UniBasic INPUT command requests data from the keyboard or a data statement
during program execution.
69
CLEARFILE
CLEARFILE
Syntax
CLEARFILE [file.var] [ON ERROR statements]
Description
The UniBasic CLEARFILE command clears all records from a file but does not
delete the file itself. You may only clear one file at a time with a CLEARFILE
statement.
Tip The CLEARFILE statement clears any of the files that you can open, even if
they reside in a remote account.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CLEARFILE Parameters
Examples
In the following example, the program statement removes all records from the file
referred to by the file variable PASTDUE. The dictionary remains unchanged after the
execution of this statement.
CLEARFILE PASTDUE
70
CLEARFILE
Related Topics
OPEN
The UniBasic OPEN command opens the dictionary or data file that you specify. You
can then read, write to, or delete the file.
OPENSEQ
The UniBasic OPENSEQ command opens an ASCII sequential file.
OSOPEN
The UniBasic OSOPEN command opens a UNIX sequential file.
CLEAR.FILE
The ECL CLEAR.FILE command clears the data and/or dictionary files. For informa-
tion on CLEAR.FILE, refer to UniData Commands Reference.
71
CLEARINPUT
CLEARINPUT
Syntax
CLEARINPUT
INPUTCLEAR
Description
The UniBasic CLEARINPUT command deletes all terminal type ahead characters so
the next INPUT statement forces a response from the user.
Examples
In the following example, the CLEARINPUT statement deletes all terminal type
ahead characters so the user must input whether or not to delete a file.
CLEARINPUT
PRINT "DO YOU WANT TO DELETE THIS FILE?(Y OR N)"; INPUT X,1
Related Topics
CLEARDATA
The UniBasic CLEARDATA command clears the remaining data from any previ-
ously executed DATA statements.
72
CLEARSELECT
CLEARSELECT
Syntax
CLEARSELECT [num.expr] [ALL]
Description
The UniBasic CLEARSELECT command clears active select lists. You can specify
a particular ID list, where num.expr can be 0 through 9. ALL clears all active select
lists. If you do not specify a parameter, the system clears the default ID list (zero). If
you specify an ID list outside the valid range, a run-time error occurs.
You generally create active lists by the execution of the ECL SELECT, SSELECT or
GET.LIST commands, or the UniBasic SELECT or GETLIST commands. These
commands report or process a specific subset of IDs within a file. Since multiple
select lists can be active at one time, the CLEARSELECT statement may clear one or
all of the currently active lists.
Examples
In the following example, the program segment clears active select list 1, which is the
value stored in the variable ID.LIST.
ID.LIST=1
CLEARSELECT ID.LIST
In the next example, the program statement clears the default list zero.
CLEARSELECT
Related Topics
SELECT
The UniBasic SELECT command compiles a list of all record IDs in a file.
GETLIST
The UniBasic GETLIST command generates an active list from a saved list created by
the ECL SELECT and SSELECT commands or the UniBasic SELECT command, and
saved by the SAVE.LIST command or by the UniBasic WRITELIST statement.
73
CLEARSELECT
SELECT
The UniQuery SELECT command creates an active list of record IDs that you may
use with other UniQuery commands or a user-defined process. For information on
SELECT, refer to Using UniQuery.
SSELECT
The UniQuery SSELECT command creates an active list of record IDs (or keys) in ID
order. For information on SSELECT, refer to Using UniQuery.
GET.LIST
The UniQuery GET.LIST command retrieves the records stored by a previous
SAVE.LIST statement or a user process to use in another query statement or UniBasic
program. For information on GET.LIST, refer to Using UniQuery.
Select Lists
For information on select lists, refer to Using UniQuery.
74
CLEARSQL
CLEARSQL
Syntax
CLEARSQL [file.name.expr]
Description
The UniBasic CLEARSQL command clears all active temporary tables that were cre-
ated during the current session (i.e., created with the EXECUTESQL command with a
corresponding INTO clause). If you do not specify file.name.expr, CLEARSQL clears
all the SQL file variables created during this UniBasic session.
Note When a program returns to the UniData prompt, whether or not you execute a
CLEARSQL statement, the system clears all SQL file variables.
Related Topics
EXECUTESQL
The UniBasic EXECUTESQL command passes an SQL statement directly to the
UniData SQL processor.
75
CLOSE
CLOSE
Syntax
CLOSE [file.var] [ON ERROR statements]
Description
The UniBasic CLOSE command closes a dictionary or data file opened as file.var.
Note UniData allows you to OPEN virtually an unlimited number of files in a sin-
gle process. Limitations occur if the total number of files opened across
numerous processes and users exceeds the number of files available to the
UNIX or VMS operating system.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CLOSE Parameters
Examples
In the following example, the program segment opens and closes the file INVEN-
TORY.
OPEN ’’,’INVENTORY.FILE’ TO INVENTORY ELSE ABORT
CLOSE INVENTORY
76
CLOSE
Related Topics
OPEN
The UniBasic OPEN command opens the dictionary or data file you specify. You may
then read from, write to, or delete the file.
77
CLOSESEQ
CLOSESEQ
Syntax
CLOSESEQ seq.file.var [ON ERROR statements]
Description
The UniBasic CLOSESEQ command closes an open sequential access type file. The
CLOSESEQ command releases the exclusive file lock set by the OPENSEQ com-
mand, allowing other users to access it. If any new lines (sequential records) were
added to the file prior to closing, the system writes a new end-of-file mark to the file
after the new lines.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CLOSESEQ Parameters
Examples
In the following example, the statement closes the sequential file referred to by the file
variable DATA.59.
CLOSESEQ DATA.59
78
CLOSESEQ
Related Topics
OPENSEQ
The UniBasic OPENSEQ command opens an ASCII sequential file.
READSEQ
The UniBasic READSEQ command assigns the next record from a previously opened
sequential file to a variable.
WRITESEQ
The UniBasic WRITESEQ command writes an expression at the end of a sequential
file.
WRITESEQF
The UniBasic WRITESEQF command writes an expression at the end of a sequential
file and forces the system to write the data to disk.
79
COL1
COL1
Syntax
COL1( )
Description
The UniBasic COL1 function returns the column position before a substring found by
the execution of the FIELD function. The COL1 function has no arguments. If you do
not execute the FIELD function prior to the COL1 function, the function returns a
zero.
The FIELD function examines a string for a particular delimiter and returns the sub-
string marked by the specified occurrence of that delimiter. While the FIELD function
returns the substring itself, the COL1 function returns the position immediately before
the substring within the string sent to the FIELD function.
Examples
In the following example, the program segment uses the FIELD function to search the
string STRING for the third occurrence of the delimiter “,”. FIELD marks the sub-
string “10”, and assigns it to the variable SSTR. The COL1 function assigns column 6,
the column position of the character before “10”, to the variable SPOS.
STRING = "11,20,10,15,20,15"
SSTR = FIELD(STRING,",",3)
SPOS = COL1()
Related Topics
COL2
The UniBasic COL2 function returns the column position after a substring found by
using the FIELD function.
FIELD
The UniBasic FIELD function returns a substring or group of substrings in a larger
string that is delimited by any ASCII character.
80
COL2
COL2
Syntax
COL2( )
Description
The UniBasic COL2 function returns the column position after a substring found by
using the FIELD function. The COL2 function has no arguments. If you do not exe-
cute the FIELD prior to the COL2 function, the function returns a zero.
The FIELD function examines a string for a particular delimiter and returns the sub-
string marked by the specified occurrence of that delimiter. While the FIELD function
returns the substring itself, the COL2 function returns the position immediately after
the substring within the string sent to the FIELD function.
Examples
In the following example, the program segment uses the FIELD function to search the
string STRING for the third occurrence of the delimiter “,”. FIELD marks the sub-
string “10”, and assigns it to the variable SSTR. The COL1 function assigns column 9,
the column position of the character after “10”, to the variable SPOS2.
STRING = "11,20,10,15,20,15"
SSTR = FIELD(STRING,",",3)
SPOS2 = COL2()
Related Topics
COL1
The UniBasic COL1 function returns the column position before a substring found by
the execution of the FIELD function.
FIELD
The UniBasic FIELD function returns a substring or group of substrings in a larger
string that is delimited by any ASCII character.
81
Comment
Comment
Syntax
* [comment text]
! [comment text]
REM [comment text]
Description
The UniBasic comment commands place remarks in a program by starting the com-
ment line with any of the above symbols. A comment may appear anywhere within a
program, either on a line by itself or following program statements on the same line.
You may also place comments at the end of each line of a multiline statement. If a
comment appears on the same line as another statement, the comment must follow a
semi-colon.
Note Program code may not follow comments on the same line.
Examples
In the following example, the comment commands are used to identify what a pro-
gram is doing.
! Subroutine to test user input validity.
SUBROUTINE TEST
COMMON N,DATA.IN,VAL,SCORE(10)
BEGIN CASE
CASE DATA.IN=VAL; ** answer correct, then
SCORE(N)=1 REM add one to SCORE(N)
PRINT "Got it right!";! print message.
82
COMMON
COMMON
Syntax
COMMON [/common.name/] var1 [,var2][MAT1]...
COM [/common.name/] var1 [,var2][MAT1]...
Description
The UniBasic COMMON command declares variables that can be accessed from
multiple subroutines and programs.
Normally, variables and the values stored in them are only available locally (across
the execution of the routine in which they are declared). When you declare variables
with a COMMON statement, UniData stores the data in such a way that it can be com-
monly available to other routines.
To use COMMON variables, declare the variables with the COMMON command.
UniData initializes the variables with a value of 0. Set up the values as appropriate.
COMMON variables may be normal variables and matrices. Do not declare matrices
with a DIMENSION statement. Matrices in a COMMON statement cannot be dynam-
ically redimensioned.
In later programs or subroutines, where you want to access COMMON variables,
declare the variables with a COMMON statement at the beginning of the routine. (The
values will be in COMMON, but until they are declared, the routine won’t be able to
access them.) Once the variables are declared, they are available to the program or
routine as if they were local variables.
You can declare the variables with different names in later routines. The variables will
be in COMMON in the order in which they were declared in the first COMMON
statement. The order of the names in the later declaration will determine which names
go with which values.
If you declare variables with a COMMON statement that does not include a com-
mon.name, you place the data in “unnamed COMMON.” There is a single unnamed
COMMON that persists across a single chain of execution—from when the variables
are declared until the last program ends and you return to the ECL prompt. When you
return to the ECL prompt, unnamed COMMON is cleared.
If you declare variables with a COMMON statement that includes a common.name,
you place the data in a “named COMMON”. You can have multiple named
COMMONs that persist across a single UniData session. You can run a program,
return to the ECL prompt, run another program, and so forth, and the named
COMMON variables will remain. When you exit that UniData session, the named
COMMON variables are cleared.
83
COMMON
You may enter a COMMON statement on several lines by using a comma at the end
of each line.
The number of variables that a COMMON statement may contain depends on the vir-
tual memory of your system. For information on virtual memory, refer to
Administering UniData on UNIX.
COMMON BASICTYPE
BASICTYPE
With BASICTYPE U and R, UniData uses a single area for unnamed
COMMON and separate areas for each named COMMON. The variables you
declare for the same common area must be the same type and in the same
order in all programs accessing that common area. Once you establish the
variable type for a common element, you cannot change it. Other programs
may declare more or fewer variables, and may even change the name of the
variable. You cannot change a non-dimensioned variable to a dimensioned
variable; you cannot change a two-dimensioned variable to a single-dimen-
sioned variable; declaring a dimensioned size for a variable determines that
variable’s size in all subsequent programs. The system does not allow any
change, including changing the size of the array. CLEARCOMMON sets the
common variable to 0 only (its initial state).
84
COMMON
Parameters
The following table describes each parameter of the syntax:
Parameter Description
COMMON Parameters
Examples
In the following example, the program statement uses an unnamed COMMON state-
ment to declare the matrices, NAME and DATES, as well as the variable DCHANGE.
85
COMMON
COMMON NAME(100),DATES(100,2),DCHANGE
In the next example, the program segment creates two named COMMON areas. The
second COMMON statement continues on a second line with the comma ( , ) continu-
ation character.
COMMON /MENU/ X,Y,XDIM,YDIM,S.CHAR
COMMON /CALC/ RATE(10),AMOUNT(10),DATE1,
DATE2,LATE
In the following example, the program segment in invalid since the COMMON state-
ment must appear first. You cannot redefine a variable in the COMMON statement
after it has been assigned. UniData requires one-to-one correspondence between main
line and subprograms.
VALUE = 253
COMMON VALUE,SUBVALUE,ATTRIBUTE
Related Topics
EXECUTE
The UniBasic EXECUTE command executes an ECL command from within a UniBa-
sic program.
CLEARCOMMON
The UniBasic CLEARCOMMON command sets the variables in the named common
you specify to zero. If you do not specify a named common, the variables listed in the
unnamed common are set to zero
STACKCOMMON
The ECL STACKCOMMON command allows you to control the stack common
areas. For information on STACKCOMMON, refer to UniData Commands
Reference.
CLEAR
The UniBasic CLEAR command clears the values stored in all local memory vari-
ables.
86
CONNECT
CONNECT
Syntax
CONNECT server WITH usr_name, password, application TO connection
[ON ERROR statement]
Description
The UniBasic CONNECT command connects you to server so that you can access
UniData files on another platform on your network.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the CONNECT statement, STATUS is set to one of the follow-
ing values:
0 Success
1 The log file cannot be opened
2 User name could not be found or password is incorrect
3 You have exceeded the maximum number of
UniServer users
4 Unused
5 Unused
6 Other error
7 UniDesktop is not licensed
8 All connections for the user are already allocated
9 Server is not in interfaces file
10 Server is not running
87
CONNECT
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CONNECT Parameters
Example
In the following example, the CONNECT statement connects to the demo server. The
statement will log onto the remote platform using the user name “ubj01”, uses the
password “secret”, specifies to use “unidata” as the application, and names this con-
nection “remote.demo”. If the statement fails to make a connection, the program will
abort and an error message will print out the status.
CONNECT "demo" WITH "ubj01", "secret", "unidata" TO
remote.demo ON ERROR ABORT "CONNECT failed: ":STATUS()
88
CONTINUE
CONTINUE
Syntax
CONTINUE
Description
The UniBasic CONTINUE command transfers control to the next iteration of a FOR/
NEXT or LOOP/REPEAT statement.
Examples
In the following example, the program segment prints the value of I until I reaches
eight. When I is equal to eight, the CONTINUE statement drops you out of the FOR/
NEXT loop, and the next statement in the program executes.
FOR I = 1 TO 10
IF I < 8 THEN CONTINUE
PRINT "I = ":I
NEXT I
Related Topics
EXIT
The UniBasic EXIT command terminates the operation of a FOR/NEXT or LOOP/
REPEAT structure and transfers control to the first statement following the structure.
89
CONVERT
CONVERT
Syntax
CONVERT expr1 TO expr2 IN var
Description
The UniBasic CONVERT command changes all occurrences of the substring expr1
in var to the string expr2. The system compares each character of the replacement
string expr2 and, if necessary, replaces each character of the target string expr1 on an
individual basis; the system does not compare and insert strings as a whole.
Note CONVERT may delete characters from a string expression, but it cannot
insert more characters than it replaces. The length of the replacement sub-
string expr2 must be less than or equal to length of thethe substring it replaces,
expr1.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CONVERT Parameters
Examples
In the following example, the program segment converts all occurrences of 1 to 3 and
all occurrences of 2 to 4. The new contents of NSTRING is now 34,0,03,35,44.
NSTRING = "12,0,01,15,22"
CONVERT "12" TO "34" IN NSTRING
In the next example, the program segment converts all occurrences of AC to X. The
new contents of NSTRING is now XBDEFG. The C is changed to null (deleted).
NSTRING = "ABCDEFG"
CONVERT "AC" TO "X" IN NSTRING
90
CONVERT
In the following example, the statement is invalid. The program segment has a null
effect; the replacement string of “A,B” is longer than the string it is intended to
replace.
NSTRING = "A,C,D,E"
CONVERT "A" TO "A,B" IN NSTRING
Related Topics
String Manipulation
For information on string manipulation, refer to Developing UniBasic Applications.
CONVERT
The CONVERT function performs the same as the CONVERT command.
91
CONVERT
CONVERT
Syntax
CONVERT(expr1, expr2, expr3)
Description
The UniBasic CONVERT function changes all occurrences of the substring expr1 in
expr3 to the string expr2. The system compares each character of the replacement
string expr2 and, if necessary, replaces each character of the target string expr1 on an
individual basis; the system does not compare and insert strings as a whole.
CONVERT may delete characters from a string expression, but it cannot insert char-
acters other than the characters it replaces. The length of the replacement substring
expr2 must be less than or equal to the length of the substring it replaces, expr1.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
CONVERT Parameters
Examples
In the following example, the program segment changes OLDSTR to NEWSTR
which now contains “868,848,838,808.”
OLDSTR = "767,747,737,707"
NEWSTR = CONVERT("7","8",OLDSTR)
In the next example, the program segment displays 1AA33BB667. Note that the fives
in X are dropped since you do not specify any corresponding substitute.
X = "122334455667"
PRINT CONVERT("245","AB",X)
In the following example the statement is invalid. The program segment tries to con-
vert “s” to “st”. Z has the same contents as Y, since S2 is longer than S1.
92
CONVERT
Y = "sasasasasa"
S1 = "s"
S2 = "st"
Z = CONVERT(S1,S2,Y)
93
COS
COS
Syntax
COS(expr)
Description
The UniBasic COS function returns the trigonometric cosine of a numeric expression.
Examples
In the following example, the program statement assigns the cosine of a 60-degree
angle to the variable COSINE. COSINE is assigned the value of .5.
COSINE = COS(60)
In the next example, the program statement prints the cosine of the variable VAL plus
ten.
PRINT COS(VAL+10)
94
COUNT
COUNT
Syntax
COUNT(str.expr1, str.expr2)
Description
The UniBasic COUNT function returns the number of times a substring appears
within a string. The string you want to search, str.expr1, must be longer than the sub-
string str.expr2. After str.expr2 is found, the system searches the string again with the
new starting point after the entire first occurrence of str.expr2. If the str.expr2 is not
found, the COUNT function returns a zero.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
COUNT Parameters
Examples
In the following example, the program segment searches the string STRING for the
number of occurrences of the substring “II” and assigns this number “2” to the vari-
able IC.
STRING = "JAWSII,ROCKYIII,STARTREKIV"
IC = COUNT(STRING,"II")
In the next example, the same program segment compiled under BASICTYPE P,
searches the string STRING for the number of occurrences of the substring II and
assigns the number 3 to the variable IC. The COUNT function in BASICTYPE P,
counts III as 2 occurrences of the substring II.
95
COUNT
$BASICTYPE "P"
STRING = "JAWSII,ROCKYIII,STARTREKIV"
IC = COUNT(STRING,"II")
96
COUNTS
COUNTS
Syntax
COUNTS(expr,str.expr)
Description
The UniBasic COUNTS function returns the number of times a substring appears
within each element of an array. The elements in the array you want to search, expr1,
must be longer than the substring str.expr. After str.expr is found, the system searches
the array again with the new starting point after the entire first occurrence of str.expr.
If str.expr2 is not found, the COUNT function returns a zero.
In BASICTYPE P, after str.expr is found, the system searches the string again
BASICTYPE
with the new starting point after the first character of the first occurrence of
str.expr. Overlapping character strings may be found.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
COUNTS Parameters
Examples
In the following example, the program segment searches the array ARR for the num-
ber of occurrences of the substring “I” and assigns the values to the variable IC. IC
now contains 2}3}1.
ARR = "JAWSII":@VM:"ROCKYIII":@VM:"STARTREKIV"
IC = COUNTS(STRING,"I")
In the next example, the same program segment compiled under BASICTYPE P,
searches the array ARR for the number of occurrences of the substring “II” and
assigns the values to the variable IC. IC now contains 1}2}0.
97
COUNTS
$BASICTYPE "P"
ARR = "JAWSII":@VM:"ROCKYIII":@VM:"STARTREKIV"
IC = COUNTS(STRING,"II")
98
CRT
CRT
Syntax
CRT [print.expr]
DISPLAY [print.expr]
Description
The UniBasic CRT command sends output to the display terminal regardless of the
use of the PRINTER ON/OFF command. print.expr may consist of either:
• String data
• Any number of strings or numeric variables
• UniBasic functions
• Any valid combination of the above
Examples
In the following example, the program segment uses the CRT command to print to the
display terminal. Notice in the latter case that even though a PRINTER ON statement
is issued, the system still directs the output from the CRT command to the display ter-
minal.
CRT "Turn your printer on and press Return to continue"
INPUT GO.ON
PRINTER ON
CRT "Process will take at least 2 hours to complete"
99
DATA
DATA
Syntax
DATA expr1 [,expr2]...
Description
The UniBasic DATA command holds data to be read by subsequent INPUT state-
ments. The expressions (expr1 and expr2) may be literal strings or variables. At the
time of execution of the DATA statements the system determines the specific position
of a value in the data queue. If expr1 is a variable or a complex expression resulting
from an operation (X*Y, for instance), and the you later change the value of the vari-
able (i.e., X changes from 10 to 20), or elements of the expression change, the con-
tents of the data stack remain the same.
The system places DATA statements in the queue in order of execution, whether by a
UniData command or within a UniBasic program. The queue processes on a first-in,
first-out basis. The DATA queue clears when control is returned to the UniData ECL
prompt (:). The DATA queue remains active through programs containing the CHAIN
command and through the use of PERFORM or EXECUTE when running additional
UniBasic programs.
You can load in-line prompts for paragraphs with the DATA command from a
Tip UniBasic program.
The first INPUT statement reads the first value in the DATA queue. Any following
INPUT statements continue to read subsequent values until reaching the end of the
DATA queue. If the system encounters a new DATA statement before the current
DATA queue is empty, the system places the new data values at the end of the queue.
If INPUT statements continue after the DATA statement is empty, the system requests
input information.
Note You may continue DATA statements over several lines by placing a comma
after each line (except for the last line).
Examples
In the following example, the program segment executes a DATA statement contain-
ing variables and constants of both string and numeric types. The first value, 10, is
read by a subsequent input statement and assigns the value to the variable COUNT.
DATA 10,"William","James",TESTVAL,135,
"Test Run"
INPUT COUNT
100
DATE
DATE
Syntax
DATE( )
Description
The UniBasic DATE function returns the current system date in internal format. The
internal format is the number of days after the system starting date of December 31,
1967.
Examples
In the following example, the program statement prints the current system date in the
internal format. If the date is December 31, 1967, the statement prints zero. If the date
is January 1, 1968, the statement prints 1, if the date is January 1, 1987, the statement
prints 6941, if the date is February 15, 1955, the system prints -4702.
PRINT DATE()
Related Topics
ICONV
The UniBasic ICONV function converts string or numeric data to an internal repre-
sentation format based on conversion codes.
OCONV
The UniBasic OCONV function converts string or numeric data from an internal rep-
resentation format to a format based on conversion codes.
TIMEDATE
The UniBasic TIMEDATE function returns a string representation of the current sys-
tem time and date in external format.
101
DCOUNT
DCOUNT
Syntax
DCOUNT(str,delim)
Description
The UniBasic DCOUNT function returns the number of substrings delimited by delim
in a string. If str is null, the system returns a 0. It str has data but does not have a
delimiter, the system returns a 1.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DCOUNT Parameters
Examples
In the following example, the program segment finds three occurrences of the value
mark and prints 3.
STR = 123:@VM:456:@VM:789
SUBS = DCOUNT(STR,@VM)
PRINT SUBS
In the next example, the program segment prints a 1. Even though there is not a delim-
iter as part of the string, there is a value the DCOUNT function recognizes.
STR = 123
DCOUNT(STR,@VM)
PRINT SUBS
102
DCOUNT
Related Topics
COUNT
The UniBasic COUNT function returns the number of times a substring occurs in a
string.
103
DEBUG
DEBUG
Syntax
DEBUG
Description
The UniBasic DEBUG command turns control over to the interactive UniBasic
debugger at the location of the statement. Pressing the BREAK key on your system
(ask your system administrator for its location) also gives control to the debugger.
To use the DEBUG command to display the contents of variables, you must compile
the program with the D option.
When you enter the debugger, the following message displays:
DEBUGGER called before line 1 of program BP/TEST
Related Topics
ABORT
The UniBasic ABORT command terminates the program in progress, and returns the
user to the UniData system level.
UniBasic Debugger
For information on the UniBasic Debugger, refer to Developing UniBasic
Applications.
BASIC
The ECL BASIC command compiles the UniBasic source code program into com-
piled interpretive code to use with the UniData Basic interpreter. The -D option cre-
ates a cross reference table for use with the UniBasic debugger. For information on
BASIC, refer to UniData Commands Reference.
DEBUG.FLAG
The ECL DEBUG.FLAG command invokes or suppresses debug statements within a
UniBasic program. For information on DEBUG.FLAG, refer to UniData Commands
Reference.
104
DEBUG
DEBUGLINE.ATT
The ECL DEBUGLINE.ATT command attaches another terminal for dual-terminal
debugging with the UniBasic debugger. For information on DEBUGLINE.ATT, refer
to UniData Commands Reference.
DEBUGLINE.DET
The ECL DEBUGLINE.DET command terminates dual-terminal debugging with the
UniBasic debugger. For information on DEBUGLINE.DET, refer to UniData
Commands Reference.
ON.ABORT
The ECL ON.ABORT command executes a command you specify if a subsequent
UniBasic program aborts. For information on ON.ABORT, refer to UniData
Commands Reference.
RUN
The ECL RUN command executes a compiled UniBasic program. The -D option
invokes the UniBasic debugger when a program encounters a run-time error. For
information on RUN, refer to UniData Commands Reference.
SETDEBUGLINE
The ECL SETDEBUGLINE command makes a terminal port attachable for dual ter-
minal debugging with the UniBasic debugger. For information on SETDEBUGLINE,
refer to UniData Commands Reference.
UNSETDEBUGLINE
The ECL UNSETDEBUGLINE command releases the debug terminal back to the
system when you are using dual terminal debugging in the UniBasic debugger. For
information on UNSETDEBUGLINE, refer to UniData Commands Reference.
UDT.OPTIONS
The setting of UDT.OPTIONS 14 determines where to return control after exiting a
UniBasic program when you are using the UniBasic debugger and enter ABORT or
END. For information on UDT.OPTIONS, refer to UniData Commands Reference.
105
DEFFUN
DEFFUN
Syntax
DEFFUN function.name [(MAT] arg.1[,[MAT]arg.2]...)] [CALLING catalog.name]
Description
The UniBasic command DEFFUN allows you to call a user-written function. You
must define a function with the UniBasic FUNCTION command within a UniBasic
program before you can call it with DEFFUN.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DEFFUN Parameters
Examples
The following example sets up a user-written function named CALC.SALES.TAX:
PRINT @(-1)
DEFFUN CALC.SALES.TAX(arg.1,arg.2)
PROMPT"
PRINT ‘Enter county name’:;INPUT COUNTY.NAME
PRINT ‘Enter sales amount ‘:;INPUT SALES.AMT
TAX.AMT=0
TAX.AMT=CALC.SALES.TAX(COUNTY.NAME,SALES.AMT)
PRINT ‘County name =’:COUNTY.NAME
PRINT ‘Sales amount =’:SALES.AMT
PRINT ‘Tax amount =’:TAX.AMT
END
106
DEFFUN
Related Topics
FUNCTION
The UniBasic FUNCTION command defines a user-written function and the argu-
ments that the calling program will pass to it.
107
DEL
DEL
Syntax
DEL dyn.array.var <attrib.expr[,val.expr [,subval.expr]]>
Description
The UniBasic DEL command deletes an attribute, value, or subvalue from a dynamic
array along with the corresponding delimiter.
DEL destroys the data within files and removes the corresponding delimiters.
Warning You must use caution when using DEL.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DEL Parameters
Examples
In the following example, the program segment deletes the third attribute of the
dynamic array ARRAY1, which is Anne.
108
DEL
ARRAY1 = ’#543’:@AM:’Dorothy’:@AM:’Anne’:@AM:’Parker’
DEL ARRAY1<3>
In the following example, the statement is invalid. The DEL statement has more
parameters than ARRAY1.
ARRAY1 = ’#543’:@AM:’Dorothy’:@AM:’Anne’:@AM:’Parker’
DEL ARRAY<13,0,1,4>
Related Topics
DELETE
The UniBasic DELETE function deletes the contents and associated delimiter of an
attribute, value, or subvalue from a dynamic array.
Dynamic Arrays
For information on dynamic arrays, refer to Developing UniBasic Applications.
109
DELETE
DELETE
Syntax
DELETE [file.var,] record.ID.expr [ON ERROR statements]
Description
The UniBasic DELETE command deletes a record from a UniData file.
The DELETE statement releases any locks on the record you specify that have been
set by previous MATREADU, READL, READU, or READVU statements. This is the
only difference between the DELETE and DELETEU statements.
DELETE destroys the data within files. You must use caution when using
Warning DELETE.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DELETE Parameters
Examples
In the following example, the program statement eliminates the record with the ID
PEANUT from the most recently opened default file.
DELETE "PEANUT"
110
DELETE
In the next example, the program segment deletes the record whose ID is specified by
the variable DEL_ID from the file previously opened to the PARTS variable.
DEL_ID = "HOOK"
DELETE PARTS, DEL_ID
In the following example the statement is invalid. The program segment is invalid,
since the filename must be opened to a file variable before the system can delete an
item. Here the CUSTOMER file is opened to the variable CUST, but the DELETE
statement attempts to delete CUSTOMER, not CUST. If a default file is not open, you
must specify a file variable.
OPEN ’’ ,’CUSTOMER’ TO CUST ELSE STOP ’NO CUST’
DELETE CUSTOMER, C.ID
Related Topics
DELETEU
The UniBasic DELETEU command deletes the record you specify from a UniData
file while maintaining an existing record lock.
111
DELETE
DELETE
Syntax
DELETE(dyn.array,attrib.expr{,val.expr{,subval.expr}})
Description
The UniBasic DELETE function deletes the contents of an attribute, value, or sub-
value (including the delimiter, if it is at the end of an array) from a dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DELETE Parameters
Examples
In the first example, the program segment deletes the first attribute (125), and the
attribute mark, from the dynamic array ARRAY.
ARRAY = 125:@AM:1:@VM:62:@VM:3:@AM:132:@VM:4:@VM:5:@SM:1
ARRAY=DELETE(ARRAY,1,0,0)
In the next example, the program statement removes the first subvalue of the first
value of the second attribute in the array ARRAY. The new array is assigned to the
dynamic array ARRAY2.
112
DELETE
ARRAY2=DELETE(ARRAY,2,1,1)
In the next example, the program segment deletes the third attribute, which would
delete the A, B, and C.
ARRAY = 1:@AM:2:@AM:’A’:@VM:’B’:@VM:’C’
ARRAY = DELETE(ARRAY,3,0,0)
Related Topics
DELETE
The UniBasic DELETE command deletes the record you specify from a UniData file.
Dynamic Arrays
For more information on dynamic arrays, refer to Developing UniBasic Applications.
113
DELETELIST
DELETELIST
Syntax
DELETELIST list.name.expr
Description
The UniBasic DELETELIST command deletes a saved list created by either the
UniQuery SAVE.LIST command or by the UniBasic WRITELIST command.
list.name.expr is an expression specifying the saved list to delete.
If the list you specify cannot be found, the system displays an error message and takes
no action.
DELETELIST destroys the data within saved lists. You must use caution
Warning when using DELETELIST.
Examples
In the following example, the program statement eliminates the saved list CUST in the
current account.
DELETELIST "CUST"
114
DELETEU
DELETEU
Syntax
DELETEU [file.var,] record.ID.expr [ON ERROR statements]
Description
The UniBasic DELETEU command deletes the specified record record.ID.expr from
a UniData file.
The DELETEU command does not affect any record locks that were set by the user.
This allows the system to delete a record and re-create that same record while still
reserving a lock on that record for the current user.
DELETEU destroys the data within files. You must use caution when using
Warning DELETEU.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DELETEU Parameters
Examples
In the following example, the program statement eliminates the record with the record
ID “JONES” from the most recently opened default file.
DELETEU "JONES"
115
DELETEU
In the next example, the program segment deletes the record, where the record ID is
stored in the variable DEL_ID, in the file previously opened to the variable DIS-
COUNT. If the record you delete is locked, it remains locked after the system deletes
it.
DEL_ID = "ACTION_FILMS"
DELETEU DISCOUNT, DEL_ID
Related Topics
DELETE
The UniBasic DELETE command deletes a record from a UniData file.
RELEASE
The UniBasic RELEASE command unlocks records.
116
DIMENSION
DIMENSION
Syntax
DIMENSION name1(rows[,cols]) [,name2(rows[,cols])]...
DIM name1(rows[,cols]) [,name2(rows[,cols])]...
Description
The UniBasic DIMENSION command creates and dimensions matrices. You may
specify matrices with as many as two dimensions (rows, cols). You must dimension
any matrices before you reference them from within a program. Standard UniBasic
(BASICTYPE U) also retains a zero element for each matrix.
The maximum number of elements you can specify is based on the total amount of
virtual memory available on your system.
After you execute a DIMENSION statement, the UniBasic INMAT function is set to
zero (0) if the matrices were successfully dimensioned and one (1) if there was insuf-
ficient memory. If sufficient memory is not present, the system prints an error mes-
sage and program execution continues.
The DIMENSION command will not perform a dimension in a subroutine when it is
called to the main program, instead the subroutine assumes the dimensions of the main
program when it is called.
In a two-dimensional matrix, there is an element 0,0. Elements such as 0,5 or 1,0 do
not exist. If a matrix is assigned using a MATREAD, MATWRITE, or MATPARSE
statement and more data is available than the matrix can contain, the excess data is
assigned to the 0,0 element.
Note MATREAD, MATWRITE, and MATPARSE load and empty an array from
left to right and from top to bottom.
117
DIMENSION
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DIMENSION Parameters
Resizing Arrays
You can also use the DIMENSION statement to dynamically re-dimension existing
arrays without losing any data if only the dimensions change without changing the
size of the matrix. When you resize a matrix, the system reshuffles the data with the
old elements being placed from left to right and from top to bottom.
While you may change the size of a matrix during program execution, its configura-
tion may not change, (i.e., a two-dimensional matrix may not be changed to a one-
dimensional matrix and vice versa). Also, matrices you pass as arguments to a subrou-
tine may not be re-dimensioned within the subroutine.
Examples
In the following example, the program statement creates three matrices: one-dimen-
sional NAME and TITLES, and the two-dimensional DATES.
DIMENSION NAME(100),TITLES(100),DATES(100,2)
In the next example, these two DIMENSION statements are perfectly legal in the
same program. After the execution of the second DIMENSION statement, the array
has the dimension of 100 by 10. The data in the matrix is reshuffled to fill the new
matrix. Some data is lost, since the new matrix is smaller than the original.
DIMENSION WAGES(50,100)
DIMENSION WAGES(100,10)
In the next example, the program statement creates the matrix TEST with the use of a
variable. The DIMENSION statement declares TEST as a one-dimensional array of
30 elements.
A = 30
DIMENSION TEST (A)
118
DIMENSION
In the following example the statement is invalid. The program statement is invalid
because a matrix size is declared with a non-numeric variable.
fffff TEST = "(10,5)"
DIMENSION TEST
Related Topics
MATREAD
The UniBasic MATREAD command assigns the values found in successive fields of a
record to corresponding elements of a matrix.
MATPARSE
The UniBasic MATPARSE command distributes portions of string to consecutive ele-
ments of a matrix based on a specified delimiter, which is found within the string.
MATWRITE
The UniBasic MATWRITE command writes successive elements of a matrix into cor-
responding attributes of a record.
INMAT
The UniBasic INMAT function displays the status of statements that you have exe-
cuted.
119
DIR
DIR
Syntax
DIR(file.expr)
Description
The UniBasic DIR function returns the file size (in bytes), the last date and time (in
internal format) the file was modified, and the file privileges of the file. The system
stores these values in the first four attributes of the value that returns. file.expr must
evaluate to a UNIX or VMS file name. If you do not specify a path name, the system
searches the current directory.
Examples
In the following example, the program segment retrieves the file statistics of the Uni-
Data file stored in the subdirectory /usr/accounting/gl. The first attribute contains the
file size in bytes; the second attribute contains the date the file was last updated; and
the third attribute contains the time the file was last updated. The system stores the
second and third attributes in the internal format, and the example converts them to the
external format.
FILESTAT = DIR("/usr/accounting/gl")
SIZE = FILESTAT <1>
DATE.MOD = OCONV(FILESTAT<2>,’D2/’)
TIME.MOD = OCONV(FILESTAT<2>,’MT’)
PRINT ’The gl file is ’:SIZE
PRINT ’And was last modified: ’:DATE.MOD,TIME.MOD
120
DISCONNECT
DISCONNECT
Syntax
DISCONNECT connection [ON ERROR statements]
Description
The UniBasic DISCONNECT command disconnects the program from a server.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the DISCONNECT statement, STATUS is set to one of the fol-
lowing:
0 Success
1 The server is not connected
2 Other errors
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DISCONNECT Parameters
121
DOWNCASE
DOWNCASE
Syntax
DOWNCASE(str.expr)
Description
The UniBasic DOWNCASE function converts all characters in a string str.expr to
lower case.
Examples
In the following example, the program segment converts the contents of the variable
USTRING to lower case letters.
USTRING = "WHY am I HAPPY?"
DSTRING = DOWNCASE(USTRING)
Related Topics
UPCASE
The UniBasic UPCASE function converts all characters in a string expression to
upper case.
122
DQUOTE
DQUOTE
Syntax
DQUOTE(str.expr)
Description
The UniBasic DQUOTE function encloses the string you specify within double
quotes. The string may contain any type of character.
Examples
In the following example, the program statement prints “This is “a” test”.
PRINT DQUOTE (’This is "a" test’)
In the next example, the program segment prints “‘This is another test’”.
X = "’This is another test’"
PRINT DQUOTE(X)
Related Topics
QUOTE
The UniBasic QUOTE function encloses an expression with quotes.
SQUOTE
The UniBasic SQUOTE function encloses a string with single quotes.
123
DROUND
DROUND
Syntax
DROUND(val.expr [,precision.expr])
Description
The UniBasic DROUND function performs double-precision rounding on a value.
Note DROUND affects the internal representation of the numeric value. It performs
the rounding without conversion to and from string variables. This increases
the speed of calculation.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
DROUND Parameters
Examples
In the following example, the program statement stores the result in A as a value with
8 digits to the right of the decimal point.
A = DROUND(3.14159265 * R * R,8)
Related Topics
PRECISION
The UniBasic PRECISION command sets the number of places past the decimal point
where you want to truncate a numeric variable.
124
EBCDIC
EBCDIC
Syntax
EBCDIC(expr)
Description
The UniBasic EBCDIC (Extended Binary Coded Decimal Information Code) func-
tion converts the ASCII (American Standard Code for Information Interchange) data
in expr to its corresponding EBCDIC values.
Reminder The standard application converts data to EBCDIC format before the data is
written to tape.
Examples
In the following example, the program statement first prints a message, then prints the
EBCDIC equivalent of the ASCII variable VAL.
PRINT "EBCDIC equivalent":EBCDIC(VAL)
Related Topics
ASCII
The UniBasic ASCII function converts a string from EBCDIC to the corresponding
ASCII values.
125
ECHO
ECHO
Syntax
ECHO {ON | OFF | expr}
Description
The UniBasic ECHO command controls the character display on the display terminal
as characters are entered from the keyboard.
Use ECHO for security purposes where the entry of an ID or password should
Tip not display on the display terminal.
Parameters
The following table describes the valid parameters:
Parameter Description
ECHO Parameters
Examples
In the following example, the program segment enables echoing, since the expression
A+B evaluates to a non-zero value.
A = 1
B = 3
ECHO A+B
126
END
END
Syntax
END
Description
The UniBasic END command declares the end of a program or a block of statements.
Note UniBasic does not require you to use END at the end of a program.
Examples
In the following example, the END command declares the end of the program seg-
ment.
IF X > 0 THEN
PRINT "Incrementing"
A = A + 1
END ELSE
PRINT "Decrementing"
A = A - 1
END
Related Topic
Program Constructs
For more information on program constructs, refer to Developing UniBasic
Applications.
127
ENTER
ENTER
Syntax
ENTER filename
ENTER @variable
Description
The UniBasic ENTER command passes control to a program you specify.
The ENTER command terminates the program that is passing control and
executes the cataloged program. All variables passed between programs must
be included in a COMMON statement in both programs. All other variables
are initialized when you enter the new program.
In the next example, the program segment transfers control to cataloged program
CHECK_2.
NO = 2
PROG = "CHECK_":NO
ENTER @PROG
Related Topics
CHAIN
The UniBasic CHAIN command terminates the UniBasic program in progress and
executes a specified terminal-level command.
128
ENTER
COMMON
The UniBasic COMMON command makes the named variables available to all pro-
grams and subroutines that use the same COMMON statement. Naming COMMON
allows for different common statements between subroutines and programs.
CATALOG
For more information on the ECL CATALOG command, refer to UniData
Commands Reference.
129
EQ
EQ
Syntax
variable EQ expr
Description
The UniBasic EQ function assigns or compares the contents of an expression to a
variable. expr can be a value, string, expression, or variable.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
EQ Parameters
Examples
In the following example, the program statement assigns the value of 60 to the vari-
able PAGELENGTH.
PAGELENGHT EQ 60
In the next example, the program segment tests if A is equal to B. In this case, the
message “NOT EQUAL” prints.
A = 24
B = 23
IF A EQ B THEN
PRINT "EQUAL"
END ELSE
PRINT "NOT EQUAL"
END
130
EQS
EQS
Syntax
EQS(array1,array2)
Description
The UniBasic EQS function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where values are
equal, and a zero in each position for values that are not equal.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY 2 and
returns ARRAY3. ARRAY3 now contains 1}1}1}0}0.
ARRAY1 = ’11’:@VM:’12’:@VM:’13’:@VM:’20’:@VM:’21’
ARRAY2 = ’11’:@VM:’12’:@VM:’13’:@VM:’19’:@VM:’22’
ARRAY3 = EQS(ARRAY1,ARRAY2)
131
EQUATE
EQUATE
Syntax
EQUATE constant1 TO value1 [[,constant2 TO value2]...]
EQUATE constant1 LITERALLY string1 [[,constant2 LITERALLY string2]...]]
EQU constant1 TO value1 [[,constant2 TO value2]...]
EQU constant1 LIT string2 [[,constant2 LIT string2]...]
Description
The UniBasic EQUATE command replaces a constant with a string, value, or vari-
able name at compile time.
The TO form can take any legal UniBasic variable name as a value. If you specify a
string enclosed in quotation marks, at compile time the system replaces all occur-
rences of the constant with the string, including the quotation marks.
If you use the LITERALLY form of the EQUATE statement, at compile time the sys-
tem replaces all occurrences of the constant with a literal string, excluding quotation
marks. You must use quotation marks when you define the literal string in the
EQUATE statement, but the quotation marks will not be inserted at compile time.
Reminder UniBasic’s variable literal string limit is 2048 characters. EQUATE has the
same limit.
You may use variables, matrices, functions, numbers, and strings in the EQUATE
statement. You can use the LITERALLY form of the EQUATE statement to insert
expressions at compile time.
After the execution of an EQUATE statement, you may use the constant symbols
interchangeably at all levels of the program.
Note Before UniData 3.3, EQUATE variables were not stored in the object file and
were invisible to the UniBasic debugger. EQUATE variables are now avail-
able from within the UniBasic debugger.
132
EQUATE
Parameters
The following table describes each parameter of the syntax:
Parameter Description
EQUATE Parameters
Examples
In the following example, all occurrences of the constant BS are replaced with the
value CHAR(8) (clear screen) during program compilation.
EQUATE BS TO CHAR(8)
In the next example, during compilation, the program statement replaces every occur-
rence of the constant TITLE with the string ALGONQUIN.
EQUATE TITLE LITERALLY "ALGONQUIN"
In the next example, during compilation the program statement replaces every occur-
rence of the constant TRUE with the value 1, and every occurence of the constant
FALSE with the value 0.
EQUATE TRUE to 1, FALSE to 0
IF TRUE
PRINT "Income less than target figure."
END
IF FALSE
PRINT "Income equal to or greater than target!"
END
In the next example, during compilation the program statement replaces every occur-
rence of the constant FULLNAME with the expression in the example.
EQUATE FULLNAME LITERALLY "FIRST_NAME:’ ‘:LAST_NAME"
FIRST_NAME = "Mary"
LAST_NAME = "Jones"
PRINT FULLNAME
At compile time, the print statement in this example would be changed to look like
this:
PRINT FIRST_NAME:’ ‘:LAST_NAME
133
EXECUTE
EXECUTE
The UniBasic EXECUTE and PERFORM commands execute ECL commands
(UniData or UniQuery commands), sentences, or paragraphs. Refer to the entry on the
UniBasic PERFORM command for further information.
134
EXECUTESQL
EXECUTESQL
Syntax
EXECUTESQL str.expr [ASYNC | SYNC] [ON connection]
Description
The UniBasic EXECUTESQL command executes an SQL statement.
If the SQL statement includes a SELECT statement with the intent to process items
internal to the program, the SELECT statement must contain an INTO clause with a
resulting file name. Otherwise, the system displays the result of the statement. If you
select only the @ID attribute, the system select lists are used, if available. If the SQL
statement includes an INTO clause, the data is stored in the resulting file and is then
available to the UniBasic program via the READNEXTTUPLE statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
EXECUTESQL Parameters
135
EXECUTESQL
Parameter Description
Examples
In the following example, the program segment executes an SQL command. The
resulting output displays on the display terminal.
OUT.COMMAND = "SELECT NAME, ADDRESS, CITY"
OUT.COMMAND := "FROM CUSTOMER;"
EXECUTESQL OUT.COMMAND
In the next example, the program segment executes the same SQL command with an
INTO clause that stores the SQL output in a file that you can access using the READ-
NEXTRECORD statement.
OUT.COMMAND = "SELECT NAME, ADDRESS, CITY"
OUT.COMMAND := " FROM CUSTOMER INTO SQL_INPUT;"
EXECUTESQL OUT.COMMAND
DONE = 0
LOOP
READNEXTRECORD CUST.REC FROM SQL_INPUT
ELSE DONE =1
UNTIL DONE DO
CONVERT @AM TO " " IN CUST.REC
PRINT CUST.REC
REPEAT
In the next example, the SQL statement selects an @ID only. The system uses a select
list instead of storing the output. In this case, the SQL command does not require an
INTO clause, and the standard UniBasic READNEXT statement processes the IDs
selected.
OUT.COMMAND = "SELECT @ID"
OUT.COMMAND := "FROM CUSTOMER"
OUT.COMMAND := "WHERE STATUS = ‘OPEN’;"
EXECUTESQL OUT.COMMAND
DONE = 0
LOOP
READNEXT @ID ELSE DONE = 1
UNTIL DONE DO
GOSUB PROCESS.RECS:
REPEAT
136
EXECUTESQL
Related Topics
READNEXT
The UniBasic READNEXT command assigns the next record ID from a list of IDs to
a variable.
READNEXTTUPLE
The UniBasic READNEXTTUPLE command assigns an entire record from an SQL
statement (with attributes separated by attribute marks) to a variable.
137
EXIT
EXIT
Syntax
EXIT
Description
The UniBasic EXIT command terminates a FOR/NEXT or LOOP/REPEAT structure
and transfers control to the first statement after the preceding structure. As with the
CONTINUE statement, EXIT forms well-structured programs.
Tip Use EXIT to avoid poorly formed conditions or awkward code segments.
Examples
In the following example, the program segment exits the FOR/NEXT loop when I is
greater than 8.
FOR I = 1 TO 10
IF I > 8 THEN EXIT
PRINT "I = ":I
NEXT I
Related Topics
CONTINUE
The UniBasic CONTINUE command transfers control to the next iteration of a FOR/
NEXT or LOOP/REPEAT statement.
FOR/NEXT
The UniBasic FOR/NEXT command executes statements repeatedly while a variable,
beginning at a specified value, is incremented. The loop continues until the variable
reaches a specified value or the condition in the WHILE or UNTIL clause is reached.
LOOP/REPEAT
The UniBasic LOOP/REPEAT command repeats any contained statements WHILE or
UNTIL a specified condition is met.
138
EXP
EXP
Syntax
EXP(expr)
Description
The UniBasic EXP function raises e to the power of expr.
Reminder e is important because the function ex is its own derivative. If y = ex, then x is
the natural logarithm of y. e has a value of approximately 2.7183.
Examples
In the following example, the program statement raises e to the power of 2, and
assigns this value, 7.3891, to the variable ETOX.
ETOX = EXP(2)
Related Topics
LN
The UniBasic LN function returns the natural base logarithm of a numeric expression.
139
EXTRACT
EXTRACT
Syntax
EXTRACT(dyn.array.expr, attrib.expr,{val.expr [,subval.expr]})
dyn.array.expr <attrib.expr,{val.expr [,subval.expr]}>
Description
The UniBasic EXTRACT function extracts data from an attribute, value, or subvalue
in a dynamic array. The dynamic array itself remains unchanged.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
EXTRACT Parameters
Examples
In the following example, the program segment assigns the string Joan to the variable
MID, which is the second attribute in the dynamic array ARR. The value and subvalue
expressions are zero, resulting in the extraction of an attribute.
140
EXTRACT
ARR = "#543":@AM:"Joan":@AM:"D’Arc"
MID = EXTRACT(ARR,2,0,0)
In the next example, the program segment assigns the string Dagny, the second value
of the third attribute, to the variable MID.
ARRAY = "#143":@AM:"Gustav":@AM:"Mahler":@VM:"Dagny":@VM:"Jens"
MID = EXTRACT(ARRAY,3,2)
In the next example, the program statement demonstrates the short form of the previ-
ous EXTRACT statement.
MID = ARRAY<3,2>
141
FIELD
FIELD
Syntax
FIELD(string.expr,delim.expr,field.expr [,rep.expr])
Description
The UniBasic FIELD function treats a string as an array, with fields delimited by any
specified ASCII character (for example, spaces, commas, or periods), and returns a
substring or group of substrings.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FIELD Parameters
Examples
In the following example, the program segment assigns the second value (“Guy”) in
the array ARR to the array NARRAY.
ARR = "#999":@AM:"Charlemagne":@VM:"Guy":@VM:"Pierre"
NARRAY = FIELD(ARR,CHAR(253),2,1)
In the next example, the program segment assigns the two fields following the third
occurrence of the delimiter “,” in the variable ARR to NARRAY. The system stores
the value “8,7” in NARRAY.
ARR = "10,10,5,8,7,12,15,8"
NARRAY = FIELD(ARR,",",3,2)
142
FIELD
In the next example, the program segment assigns the second group of characters in a
string delimited by spaces in the variable NAME to LNAME. The system stores the
value Smith in LNAME.
NAME = "Harry Smith"
LNAME = FIELD(NAME," ",2)
Related Topics
COL1
The UniBasic COL1 function returns the column position before a substring found by
the execution of the FIELD function.
COL2
The UniBasic COL2 function returns the column position after a substring found by
using the FIELD function.
143
FIELDSTORE
FIELDSTORE
Syntax
FIELDSTORE(str.expr,delimiter,b.pos,option,replace.expr)
Description
The UniBasic FIELDSTORE function inserts an expression into a string.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FIELDSTORE Parameters
144
FIELDSTORE
Options
The value of option changes which operation takes place with the replace.expr. The
following table describes these values and their results.
Value Description
If option > 0 The system replaces the number of substrings equal to the
absolute value of option with the equivalent number of
substrings in replace.expr.
If option = 0 The system inserts the entire replace.expr at the substring
position indicated by the value of b.pos.
If option < 0 The system deletes the number of substrings equal to the
value of option and inserts replace.expr at the substring
location indicated by b.pos.
FIELDSTORE Options
Examples
In the following example, the program segment inserts Arkansas (“AR”) in the string
ASTATES. ASTATES now contains the string “AL:AK:AR:AZ.”
ASTATES = ’AL:AK:AZ’
ASTATES = FIELDSTORE(ASTATES,’:’,3,0,’AR’)
In the next example, the program segment specifies that processing begins at the fifth
value (ugly), that this value is deleted (the -1 option), and that the replace.expr
(orange,black) is to be inserted in the same position. COLORS now contains the string
“yellow,blue,red,green,orange,black,white.”
COLORS = ’yellow,blue,red,green,ugly,white’
COLORS = FIELDSTORE(COLORS,’,’,5,-1,’orange,black’)
145
FILEINFO
FILEINFO
Syntax
FILEINFO(file.var, code)
Description
The FILEINFO function returns information about a file’s configuration.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FILEINFO Parameters
FILEINFO Codes
code is a number indicating the information required. The following table describes
the codes and the return values of the function:
Information
Code File Type Returned Value
Requested
146
FILEINFO
Information
Code File Type Returned Value
Requested
147
FILEINFO
Information
Code File Type Returned Value
Requested
148
FILELOCK
FILELOCK
Syntax
FILELOCK [file.var] [ON ERROR statements] LOCKED statements
Description
The UniBasic FILELOCK command locks the dictionary or data portion of a file
against access by READL, READU, READVU, MATREADL, MATREADU, MAT-
WRITEU, WRITEU, and WRITEVU statements. Other file input/output commands
ignore FILELOCK.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FILELOCK Parameters
Examples
In the following example, the FILELOCK statement locks the file STAT, preventing
lock-checking commands from accessing this file.
FILELOCK STAT LOCKED STOP
149
FILELOCK
Related Topics
FILEUNLOCK
The UniBasic FILEUNLOCK command unlocks a file previously locked with the
FILELOCK command.
150
FILEUNLOCK
FILEUNLOCK
Syntax
FILEUNLOCK [file.var] [ON ERROR statements]
Description
The UniBasic FILEUNLOCK command unlocks a file previously locked with a
FILELOCK command.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FILEUNLOCK Parameters
Examples
In the following example, the FILEUNLOCK statement unlocks the file referred to by
the file variable TAPES.
FILEUNLOCK TAPES
Related Topics
FILELOCK
The UniBasic FILELOCK command locks a file against access by other users using
READL, READU, READVU, and MATREADU statements.
151
FILEUNLOCK
STATUS
The UniBasic STATUS function returns the validity of the previous operation.
152
FIND
FIND
Syntax
FIND expr IN dyn.array[,occur] SETTING f [,v[,s]] {[THEN statements] |
[ELSE statements]}
Description
The UniBasic FIND command determines the position of the given expression in a
dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FIND Parameters
153
FIND
Examples
In the following example, the program segment searches for 31 in the string DA. This
results in F=3, V=1, S=0, since 31 is found in the third attribute as the first multivalue,
and this attribute has no subvalues.
DA = 1:@AM:2:@AM:31:@VM:32:@VM:41:@VM:41:@VM:42:@VM:43
FIND 31 IN DA SETTING F,V,S ELSE PRINT "NOT FOUND"
In the next example, the program segment searches for second occurrence of 41 in the
string DA. This results in F=3, V=4, S=0, since the second occurrence of 41 is found
in the third attribute as the 4 multivalue, and this attribute has no subvalues.
DA = 1:@AM:2:@AM:31:@VM:32:@VM:41:@VM:41:@VM:42:@VM:43
FIND 41 IN DA,2 SETTING F,V,S ELSE PRINT "NOT FOUND"
Related Topics
FINDSTR
The UniBasic FINDSTR command determines the position of a specified substring
within a dynamic array element.
154
FINDSTR
FINDSTR
Syntax
FINDSTR substr IN dyn.array[,occur] SETTING f[,v[,s]] {[THEN statements1] |
[ELSE statements2]}
Description
The UniBasic FINDSTR command determines the position of a given substring in a
dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FINDSTR Parameters
155
FINDSTR
Examples
In the following example, the program segment searches for 3 in the string DA. This
results in F=3, V=1, S=0, since 3 is found in the third attribute as the first multivalue,
and this attribute has no subvalues.
DA = 1:@AM:2:@AM:31:@VM:32:@VM:41:@VM:41:@VM:42:@VM:43
FINDSTR 3 IN DA SETTING F,V,S ELSE PRINT "NOT FOUND"
In the next example, the program segment searches for the second occurrence of 4 in
the string DA. This results in F=3, V=4, S=0, since the second occurrence of 4 is
found in the third attribute as the 4 multivalue, and this attribute has no subvalues.
DA = 1:@AM:2:@AM:31:@VM:32:@VM:41:@VM:41:@VM:42:@VM:43
FINDSTR 4 IN DA,2 SETTING F,V,S ELSE PRINT "NOT FOUND"
Related Topics
FIND
The UniBasic FIND command determines the position of an expression in a dynamic
array.
156
FLUSH
FLUSH
Syntax
FLUSH
The FLUSH command flushes output to the terminal when UDT.OPTIONS 46 is ON.
Note For more information on the ECL command UDT.OPTIONS 46, refer to the
UniData Commands Reference.
157
FMT
FMT
Syntax
FMT(expr, “len [ f.char] [L | R | T | C] [n] [$] [,] [Z] [mask]”)
FMT(expr, pattern.var)
FMT(expr, “[L | R | T | C] # len [f.char] [n] [$] [,] [Z] [mask]”)
expr “[L | R | T | C] # len [f.char] [n] [$] [,] [Z] [mask]”
Description
The UniBasic FMT function formats data in an expression expr through a specific
format mask for display purposes.
In the second form, you can express the pattern format through a variable pattern.var.
In the first form, the FMT statement must contain a L, R, C, or T and a len expression;
additional expressions are optional.
In the third form, the justification is the first element, followed by a pound sign (#) to
truncate data, and the len expression. All other values are the same.
In the fourth form, you do not have to explicitly state FMT, but it follows the same
format pattern syntax.
The FMT function sets the STATUS function to 0, 1, or 2. If the format is successful,
the value is set to 0. If the string expression is invalid or exceeds the allowable string
size, the value is set to 1. If the conversion code is invalid, the value is set to 2.
158
FMT
Parameters
The following table describes each of the syntax elements.
Parameter Description
FMT Parameters
159
FMT
Examples
In the following example, the program segment prints the variable SS.NUM as a for-
matted string using a pattern mask. The result printed is a string with 11 characters,
left-justified: “543-70-4128.”
SS.NUM=543704128
PRINT FMT(SS.NUM,"11L###-##-####")
In the next example, the program segment prints the variable NUM as a 12 character-
wide, right-justified number with two decimal places, preceded by a dollar sign and
composed with commas. The segment prints the value “$16,526.00”
NUM = 16526
PRINT FMT(NUM, "12R2$,")
In the next example, the program segment formats the string OUT.STRING with 0 as
the fill character, right-justified, and in a column of four spaces. The segment prints
0044.
OUT.STRING = 44
OUT.STRING = FMT(OUT.STRING,"4\0R")
PRINT OUT.STRING
In the next example, the program statement saves the variable STR as a right-justified,
eight column string.
STR = STR "R#8"
In the next example, the program segment uses a variable to specify the pattern for-
mat. The system formats the string STR according to the variable PATTERN.
PATTERN = "12R2$,"
STR = STR PATTERN
160
FOOTING
FOOTING
Syntax
FOOTING [ON num.expr] {str.expr [‘option‘]...}
Description
The UniBasic FOOTING command causes the specified string to display at the bot-
tom of every page of a report.
The PRINTER command directs the output of a FOOTING command not sent to a
print file. The execution of PRINTER OFF causes a report, together with its footings,
to appear on the user’s terminal. A PRINTER ON command causes all subsequent
footings, headings, and PRINT output to be sent to the destination specified by the
current SETPTR setting.
The code or codes must be surrounded by one pair of single quotes. You can place
codes anywhere in the footing expression.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FOOTING Parameters
161
FOOTING
Options
The following table describes the valid options.
Option Description
FOOTING Options
Examples
In the following example, the program statement produces a footing using a character
string.
FOOTING "Copyright 1987, Genius, Inc."
In the next example, the program statement prints “Page,” and the current page num-
ber, it advances one line and then prints the string Paul’s Produce. Notice the double
apostrophe in the middle of the strings; which is necessary to print a single apostrophe
in the footer as it will appear on the screen or printer. The ON 2 clause sends the foot-
ing to the print file 2.
FOOTING ON 2 "Page ‘PL’Paul’’s Produce"
Related Topics
SETPTR
For information on the ECL SETPTR command, refer to UniData Commands
Reference.
Device Input/Output
For information on device input/output, refer to Developing UniBasic Applications.
162
FORMLIST
FORMLIST
Syntax
FORMLIST dynamic.array.var [TO list.num.expr]
Description
The UniBasic FORMLIST command creates an active select list from a dynamic
array. FORMLIST uses the attribute marks in dynamic.array.var to create an active
select list that you can use with READNEXT statements or other list processing com-
mands such as external LIST statements.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FORMLIST Parameters
Examples
In the following example, the program segment creates a select list and then uses that
list to print the first five records of the CUSTOMER file.
ARRAY.LIST = 1:@AM:2:@AM:3:@AM:4:@AM:5
FORMLIST ARRAY.LIST TO 0
PRINT "PROCESSING THE FOLLOWING ITEMS:"
PERFORM "LIST CUSTOMER"
END
Related Topics
READLIST
The UniBasic READLIST command assigns the values in an active select list to a
dynamic array.
163
FOR/NEXT
FOR/NEXT
Syntax
FOR var = val1 TO
val2 [STEP val3]
[statements]
[{UNTIL |
WHILE}expr]
statements
NEXT [var]
Description
The UniBasic FOR/NEXT command executes statements repeatedly while increment-
ing a variable over a range until it reaches the end of the range, or until the condition
in the WHILE or UNTIL clause is ended or reached.
You may nest FOR/NEXT constructions. Each FOR statement must be associ-
Tip ated with one NEXT statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FOR/NEXT Parameters
164
FOR/NEXT
Parameter Description
Examples
In the following example, the program segment prints the string “10,8,6,4,2,”. The
loop terminates before printing 0, since the FOR/NEXT statement specifies that when
the variable “I” falls below 1 the loop terminates.
FOR I = 10 TO 1 STEP -2
PRINT I:",":
NEXT I
In the next example, the optional WHILE expression clause creates a secondary con-
dition for the termination of the FOR/NEXT structure. While a normal FOR/NEXT
loop repeats the contained statements 10 times, the WHILE clause results in this
example stopping after only three repetitions. This occurs because the value read from
the DATA statement by the INPUT command exceeds the value of “I” on the third
iteration. The WHILE clause with the same statements results in the loop terminating
after one iteration. After the iteration, variable “I” is less than “K”, satisfying the con-
dition and causing the loop to stop.
K=50
DATA 3,4,2,51,8,10,15,3,2,8
FOR I = 1 TO 10 WHILE I < K
INPUT K
PRINT I,K
NEXT I
165
FUNCTION
FUNCTION
SYNTAX
FUNCTION function.name [([MAT] arg.1[, [MAT] arg.2]...)]
DESCRIPTION
The UniBasic command FUNCTION defines a user-written function and accepts the
arguments that the calling program passes to it. A user-written statement can contain
only one FUNCTION statement, and the FUNCTION statement must be the first non-
comment line.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
FUNCTION Parameters
RELATED TOPICS
DEFFUN
The UniBasic DEFFUN command calls a user-written function.
166
GARBAGECOLLECT
GARBAGECOLLECT
Syntax
GARBAGECOLLECT
Description
The UniBasic GARBAGECOLLECT command releases all reserved but non-active
portions of memory space allocated for UniBasic variables.
167
GE
GE
Syntax
expr1 GE expr2
Description
The UniBasic GE function tests whether the expression expr1 is greater than or equal
to expr2. The expressions may be any valid UniBasic expression, variable, or string.
Examples
In the following example, the program segment tests whether A is greater than or
equal to B. Since A is greater than B, the message “Greater Than or Equal To” prints.
A = 24
B = 22
IF A GE B THEN
PRINT "Greater Than Or Equal To"
END ELSE
PRINT "Less Than"
END
168
GES
GES
Syntax
GES(array1,array2)
Description
The UniBasic GES function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where the value in
array1 is greater than or equal to the value in the corresponding position in array2.
The system returns a zero in each position for values that are less than array2.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY2 and
returns ARRAY3. ARRAY3 now contains 1}1}1}0}0.
ARRAY1 = 10:@VM:20:@VM:30@VM:40:@VM:50
ARRAY2 = 9:@VM:10:@VM:30:@VM:50:@VM:60
ARRAY3 = GES(ARRAY1,ARRAY2)
169
GET
GET
Syntax
GET[X] var[,length] [SETTING count.var] FROM line.expr [UNTIL term.expr]
[RETURNING term.var] [WAITING seconds] [{THEN | ELSE} statements]
Description
The UniBasic GET command receives unprompted input from an attached line. A
prompt does not display, and the system accepts all control characters, including the
carriage return and line feed as input characters.
The way that the GET statement performs varies according to the termination condi-
tions specified, and whether the THEN or ELSE clauses are specified.
You can terminate input from the attached line in four ways:
• When the system reads the number of expected characters.
• When you do not specify the number of characters and do not use an
UNTIL clause. The system accepts only one character. (The only time
GET does not have a maximum amount of characters is when you use the
UNTIL clause without explicitly specifying a length.)
• When any one of the characters you specify by the UNTIL clause is also
in the input. When the system reads one of the specified characters from
the attached line, the GET statement terminates and the system assigns
characters up to the terminating character to the variable var. If you use
the RETURNING clause, the system assigns the terminating character to
the variable term.var.
• When the system reads the record mark character, CHAR(255) and you
specify a number of seconds with the WAITING clause, and none of the
conditions listed above has been met before the number of seconds has
elapsed.
If you use the UNTIL clause without a WAITING clause or an expected length, the
program waits indefinitely until it reads a termination character. After this process, the
system executes the THEN clause.
Note The system never performs an ELSE clause if you use the UNTIL clause
without a WAITING clause or an expected length.
If you use the WAITING clause, the system performs the ELSE clause only if the
number of seconds for time-out elapses. If the input is terminated for any other reason,
the system performs the THEN clause. In either case, whatever data is read from the
attached line is placed in var.
170
GET
In special cases, the system performs the ELSE clause if the line has not been attached
before executing the GET statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GET Parameters
171
GET
Parameter Description
Examples
In the following example, the program segment waits 15 seconds for ten characters of
input from line 0. If time expires before you enter the ten characters, the system
returns the input up to that point and performs the ELSE clause.
GET TMP,10 FROM 0 WAITING 15
ELSE PRINT "Input time has expired"
Related Topics
SEND
The UniBasic SEND command sends output data to a specified line.
PROTOCOL
The ECL PROTOCOL command sets data line transmission characteristics and proto-
cols for a specified line. For information on PROTOCOL, refer to UniData
Commands Reference.
172
GETCOLUMNDATA
GETCOLUMNDATA
Syntax
GETCOLUMNDATA var FROM connection, col.no [ON ERROR statements]
Description
The UniBasic GETCOLUMNDATA statement retrieves the data in the specified col-
umn in the current row of the current result table.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the GETCOLUMNDATA statement, STATUS is set to one of
the following:
0 Success
1 The server is not connected
2 The position is out of bounds
3 Other error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GETCOLUMNDATA Parameters
173
GETCOLUMNDATA
Parameter Description
174
GETCOLUMNNAME
GETCOLUMNNAME
Syntax
GETCOLUMNNAME var FROM connection, col.no [ON ERROR statements]
Description
The UniBasic GETCOLUMNNAME statement retrieves the column name for the
specified column of the result table.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the GETCOLUMNNAME statement, STATUS is set to one of
the following:
0 Success
1 The server is not connected
2 The position is out of bounds
3 Other error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GETCOLUMNDNAME Parameters
175
GETCOLUMNNAME
Parameter Description
176
GETENV
GETENV
Syntax
GETENV(var | “envir.var”)
Description
The UniBasic GETENV function returns the contents of the UNIX environmental
variable or VMS logical name. If the environmental variable appears explicitly, you
must enclose it in quotation marks.
Examples
In the following example, the program statement retrieves the value in UDTBIN into
the variable X.
X = GETENV("UDTBIN")
In the next example, the program retrieves the value in UDTBIN into variable X using
a variable to define UDTBIN.
VAR = "UDTBIN"
X = GETENV(VAR)
177
GETERRMSG
GETERRMSG
Syntax
GETERRMSG()
Description
The UniBasic GETERRMSG function returns the error message from the server
when a UniBasic statement fails. When a UniBasic statement that is part of a remote
execution fails, the GETERRMSG function returns the complete text of the error mes-
sage from various sources, depending on the error.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
178
GETLIST
GETLIST
Syntax
GETLIST list.name [,acct.name] [TO list.num]
[SETTING count.var] {{THEN | ELSE} statements [END]}
Description
The UniBasic GETLIST command creates an active select list from a saved list cre-
ated either by an ECL SAVE.LIST command or the UniBasic WRITELIST com-
mand.
GETLIST requires a THEN or an ELSE clause. The system requires an END state-
ment when you use THEN or ELSE with multiple lines.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GETLIST Parameters
179
GETLIST
Examples
In the following example, the program segment retrieves the previously saved list
CS_STAFF and assigns it to active list 2. If the list isn’t found, the program aborts and
displays an error message.
GETLIST "CS_STAFF" TO 2 ELSE
ABORT "NO CS_STAFF saved list found."
In the next example, the program segment retrieves the saved list CUST to active list 0
(the default). The number of elements in CUST is assigned to the count variable
LIST.CNT. The program then uses the IDs in list 0 to retrieve the records in the
CUSTOMER file.
OPEN ’’, "CUSTOMER" TO CUST ELSE ABORT
X = "CUST"
GETLIST X SETTING LIST.CNT
ELSE PRINT X:" CAN NOT BE FOUND";STOP
FOR I = 1 TO LIST.CNT
READNEXT ID ELSE EXIT
READ REC FROM CUST, ID THEN
PRINT REC
END ELSE
PRINT "CANNOT FIND RECORD":ID
END
NEXT I
END
180
GETNEXTTUPLE
GETNEXTTUPLE
Syntax
GETNEXTTUPLE var FROM connection [{THEN | ELSE} statements]
[ON ERROR statements]
Description
The UniBasic GETNEXTTUPLE command retrieves the current row (tuple) of the
result table. When you retrieve a row, your position in the table is changed to the next
row.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the GETNEXTTUPLE statement, STATUS is set to one of the
following:
0 Success
1 The server is not connected
2 Other error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GETNEXTTUPLE Parameters
181
GETNEXTTUPLE
Parameter Description
182
GETPTR
GETPTR
Syntax
GETPTR(unit.no)
Description
The UniBasic GETPTR function returns a string variable containing the values of the
current printer settings for the unit.no specified.
GETPTR can store the values associated with a print unit so those values can
Tip be reset to their initial values at the end of a process.
The GETPTR function returns a string containing the same set of values as specified
in the SETPTR function, including the print unit and the options:
unit,line,page,top.mar,bot.mar,mode,options.
STATUS
The following table describes the value the STATUS function returns after the GET-
NEXTTUPLE statement executes.
Value Description
0 If success.
1 If there are no more rows.
2 Other error.
Examples
In the following example, the program segment assigns the printer settings to the vari-
able PRINTER.STRING.
PRINTER.STRING = GETPTR(1)
183
GETPTR
Related Topics
SETPTR
The ECL SETPTR command sets the options for a logical printer. For information on
SETPTR, refer to UniData Commands Reference.
184
GETPU
GETPU
Syntax
GETPU(unit.number)
Description
The UniBasic GETPU function returns the full path of the current print or hold file ID
you just created. unit.number is the number of the logical printer unit.
Use the ECL SETPTR command to determine the current printer unit of your
Tip system.
Related Topics
SETPTR
The ECL command SETPTR sets options for the logical printer unit. For more infor-
mation on SETPTR, refer to UniData Commands Reference.
185
GETREADU
GETREADU
SYNTAX
GETREADU( )
DESCRIPTION
The UniBasic function GETREADU returns a dynamic array containing information
about all records that have been locked by any UniBasic command or ECL command
that updates any record.
This command delivers the same information—but, in a different format—that the
ECL command LIST.READU delivers. A value mark separates these pieces of infor-
mation. An attribute mark separates the information about different locks. The number
of locks is returned in @SYSTEM.RETURN.CODE.
The following table describes the values GETREADU returns:
Value Description
186
GETUSERNAME
GETUSERNAME
Syntax
GETUSERNAME(uid)
Description
The UniBasic GETUSERNAME function returns the UNIX or VMS user name for
the user ID you specify by uid. Use the UniBasic @UID variable to obtain the UNIX
user ID or enter “id” at the UNIX level. Once you obtain the UNIX user ID, you can
specify the user ID explicitly by using the GETUSERNAME function.
Examples
In the following example, the program statement assigns the user name in variable X.
X = GETUSERNAME(@UID)
In the next example, the program statement assigns the user name for 1023 in variable
X.
X = GETUSERNAME(1023)
Related Topics
GETUSERGROUP
The UniBasic GETUSERGROUP function returns the UNIX or VMS group number
for the user ID you specify.
@variables
For information on @variables, refer to Appendix B @variables.
187
GETUSERGROUP
GETUSERGROUP
Syntax
GETUSERGROUP(uid)
Description
The UniBasic GETUSERGROUP function returns the UNIX or VMS group number
for the user ID you specify by uid.
Examples
In the following example, the program statement assigns the user group in variable X.
X = GETUSERNAME(@UID)
In the next example, the program statement assigns the user group for 1023 in variable
X.
X = GETUSERNAME(1023)
Related Topics
GETUSERNAME
The UniBasic GETUSERNAME function returns the UNIX or VMS user name for
the user ID you specify.
@variables
For information on @variables, refer to Appendix B @variables.
188
GOSUB
GOSUB
Syntax
GOSUB label[:]
Description
The UniBasic GOSUB command transfers program control to an internal subroutine.
The system requires a valid statement label. Control returns to the main program by a
RETURN statement in the subroutine.
Note You must terminate all non-numeric statement labels with a colon ( : ). This
differentiates non-numeric labels from variables.
Examples
In the following example, the program statement transfers program control to the sub-
routine starting at label YESNO:.
GOSUB YESNO:
In the next example, the program segment prints “Now we go to the subroutine.”,
“Now in subroutine BRANCHOUT.”, and finally, “Back from subroutine BRAN-
CHOUT.”
PRINT "Now we go to the subroutine."
GOSUB BRANCHOUT:
PRINT "Back from subroutine BRANCHOUT."
STOP
BRANCHOUT:
PRINT "Now in subroutine BRANCHOUT."
RETURN
END
Related Topics
ON/GOSUB
The UniBasic ON/GOSUB command transfers program control to a subroutine based
on a numeric expression.
RETURN
The UniBasic RETURN command transfers program control from a subroutine back
to the calling program or subroutine.
189
GOSUB
Program Constructs
For more information on program constructs, refer to Developing UniBasic
Applications.
190
GOTO
GOTO
Syntax
GOTO label [:]
GO label [:]
Description
The UniBasic GOTO command branches unconditionally to a statement label within
a program or subroutine. A statement label must exist in the program or subroutine. If
the label you specify does not exist, the compiler generates an error message and the
program aborts. Once a program executes a GOTO, it does not keep track of the point
of departure, but simply moves to the new statement and begins executing there.
Note You may not use the UniBasic RETURN command in conjunction with a
GOTO statement.
Examples
In the following example, the program statement transfers program control to the
statement label 2510.
GOTO 2510
In the next example, the program statement transfers control to the statement label
“START:”, if the variable RETRY is true.
IF RETRY GOTO START:
Related Topics
GOSUB
The UniBasic GOSUB command transfers program control to a specified internal sub-
routine.
ON/GOTO
The UniBasic ON/GOSUB command transfers program control to a subroutine based
on a numeric expression.
ON/GOSUB
The UniBasic ON/GOSUB command transfers program control to a subroutine based
on a numeric expression.
191
GOTO
Program Constructs
For information on program constructs, refer to Developing UniBasic Applications.
192
GROUP
GROUP
Syntax
GROUP(str, delim, start, rtn.num)
Description
The UniBasic GROUP function extracts a number of continuous groups you specify
from the given string.
GROUP functions similar to option G of the OCONV function (group extraction con-
version), but allows any single character, including a system delimiter, numeric, or
minus sign (-) as a delimiter. Another difference is the start parameter of the GROUP
function specifies the starting group to return, while OCONV specifies the number of
leading groups to skip.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GROUP Parameters
Examples
In the following example, the program statement assigns “1231” to the variable A.
A = GROUP("123124125126","2",1,2)
193
GROUP
In the next example, the program segment prints “Boulder” since it is the second
group separated by ‘:’ and only one group is required to be returned.
ST = "Denver:Boulder:Aurora:Littleton"
PRINT GROUP(ST,‘:’,2,1)
Related Topics
FIELD
The UniBasic FIELD function returns a substring or group of substrings in a larger
string that is delimited by any ASCII character.
OCONV
The UniBasic OCONV function converts string or numeric data from internal repre-
sentation format to output format based on conversion codes.
194
GROUPSTORE
GROUPSTORE
Syntax
GROUPSTORE substr IN str USING start.num,replace.num [,delim]
Description
The UniBasic GROUPSTORE command inserts a given substring, or a portion of a
substring into a string replacing all, part, or none of the string. The unit of replacement
is called an “element.” This may be delimited by the single character delimiter.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
GROUPSTORE Parameters
195
GROUPSTORE
Parameter Description
The replace.num option controls whether GROUPSTORE replaces all, part, or none
of the substring. The following table describes these options:
Value Description
Examples
In the following example, the program segment assigns the value of SUB in the string
A. Since the starting number is 2 and you do not specify a delimiter, the system uses
the attribute mark (@VM) as the delimiter.
A = "123":@AM:"ABC":@AM:"456":@VM:"DEF":@AM:"012":@VM:"GHI"
SUB = "***"
GROUPSTORE SUB IN A USING 2,1
196
GROUPSTORE
In the next example, the program segment replaces the third attribute in A, which
includes two values, with SUB. Though the replace number is 2, the system replaces
only one attribute since there is only one element in SUB.
A = "123":@AM:"ABC":@AM:"456":@VM:"DEF":@AM:"012":@VM:"GHI"
SUB = "###"
GROUPSTORE SUB IN A USING 3,2
In the next example, the program segment inserts SUB before position 1 in A.
A = "123":@AM:"ABC":@AM:"456":@VM:"DEF":@AM:"012":@VM:"GHI"
SUB = "begin"
GROUPSTORE SUB IN A USING 1,0
In the next example, the program segment replaces the first two attributes and their
associated subvalues with SUB using @VM as the delimiter.
A = "123":@AM:"ABC":@AM:"456":@VM:"DEF":@AM:"012":@VM:"GHI"
SUB = "mv1":@VM:"sub1":@SM:"sub2":@VM:"mv2"
GROUPSTORE SUB IN A USING 1,2,@VM
197
GT
GT
Syntax
expr1 GT expr2
Description
The UniBasic GT function tests whether the expression expr1 is greater than expr2.
expr1 and expr2 may be any valid expression, variable, or string.
Examples
In the following example, the program segment tests whether A is greater than B.
Since A is greater than B, the message “Greater Than” prints.
A = 24
B = 22
IF A GT B THEN
PRINT "Greater Than"
END ELSE
PRINT "Less Than"
END
198
GTS
GTS
Syntax
GTS(array1,array2)
Description
The UniBasic GTS function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where the value in
array1 is greater than the value in the corresponding position in array2, and a zero in
each position for values that are less than array2.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY2 and
returns ARRAY3. ARRAY3 now contains 1}1}0}0}0.
ARRAY1 = 10:@VM:20:@VM:30@VM:40:@VM:50
ARRAY2 = 9:@VM:10:@VM:30:@VM:50:@VM:60
ARRAY3 = GTS(ARRAY1,ARRAY2)
199
HASH
HASH
Syntax
HASH(rec.key,modulo,type)
Description
The UniBasic HASH function determines to which group a particular key is hashed
depending on the modulos and the type of the file. HASH returns the group number in
which a record with a key of rec.key is stored. HASH includes a file type parameter.
When rec.key, modulo, and type are passed to the function, it returns the group num-
ber to which the record key will hash.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
HASH Parameters
Related Topics
CREATE.FILE
For more information on CREATE.FILE, refer to UniData Commands Reference.
200
HEADING
HEADING
Syntax
HEADING [ON expr] str.expr [“W”]
Description
The UniBasic HEADING command prints a string you specify at the top of all report
pages on the current print device.
Note The HEADING command clears the screen before displaying a report.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
HEADING Parameters
HEADING Expressions
A heading string str.expr may contain codes that control paging characteristics and
insert the current time, date, or page number in the heading. The following table
describes these codes.
201
HEADING
Code Description
The code or codes must be surrounded by one pair of single quotes. You can place
codes anywhere in the heading expression.
You can use special characters, such as unmatched single and double quotes in
str.expr.
Examples
In the following example, the program statement sends a heading, “Shareholders
Report” with the current page number on the left and the current date on the right, to
print file 3.
HEADING ON 3 "’P’ Shareholders Report ’D’"
In the next example, the program statement prints the current page number and the
current date and time on the top of the default print device. The N code causes the
report to print continuously, not requiring a carriage return after each page.
HEADING "’PTN’"
202
HEADING
Related Topics
FOOTING
The UniBasic FOOTING command prints a string you specify at the bottom of all
report pages on the current print device.
203
HUSH
HUSH
Syntax
HUSH {ON | OFF | expr} [SETTING pre.status.var]
Description
The UniBasic HUSH command enables or disables terminal output.
Parameters
The following table describes the valid parameters:
Parameter Description
HUSH Parameters
Examples
In the following example, the program segment prints 1 and -1 on the terminal screen
since the HUSH command enables the terminal (A + B evaluates to zero). The second
PRINT statement produces nothing on the screen since HUSH ON is set. The third
PRINT command prints C = 1 on the screen since the terminal output is enabled.
A = 1; B = -1
HUSH A + B
PRINT A,B
HUSH ON
PRINT A + B
HUSH OFF SETTING C
PRINT "C = ":C
204
ICONV
ICONV
Syntax
ICONV(expr,conv.code.expr)
Description
The UniBasic ICONV function converts string or numeric data to an internal repre-
sentation format based on conversion codes.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
ICONV Parameters
The following table summarizes the valid conversion codes. Detailed discussions fol-
low under separate headings.
Code Format
D System date
MB Binary
MC Masked character
MD Masked decimal
ML Left justify
MP Packed decimal
MO Octal
ICONV Codes
205
ICONV
Code Format
MR Right justify
MT System time
MX Hexadecimal (also HEX)
ICONV Codes
09/15/85 D 6468
206
ICONV
12/31/67 D 0
December 31, 1967 D 0
31/12/67 DE 0
01/29/1988 D 7334
The MX, MO, and MB are the conversion codes you use with the appropriate str.expr.
The optional 0C indicates that you want the input data to be converted to an ASCII
code format. Using the 0C option may result in more than one ASCII character. Using
0C with binary results in taking each group of eight characters and converting to
ASCII. With octal, the system converts each group of three characters. With hex, the
system converts each group of two characters.
Input data must fall into the domain of the appropriate base. The following table
describes each domain.
Domain
Base
Numbers Letters
Base Domain
207
ICONV
Domain
Base
Numbers Letters
Binary 0-1
Base Domain
Note The system produces a run-time error message if either the value to be con-
verted or the conversion code is invalid.
Code Description
208
ICONV
Code Description
209
ICONV
210
ICONV
Elements Description
T Code name.
DICT Translates to the dictionary of the file indicated by
filename.
filename Name of the file where the translation is directed (any
valid UniData file in your VOC file containing the
required attribute or data).
c One of the following translate subcodes:
V If the record does not exist or if the attribute is null,
returns a null value and prints an error message.
C If the record does not exist or attribute is null, it substi-
tutes id.epr for value of the function.
X If the record does not exist or the attribute is null, the
system returns a null.
n If an attribute is retrieved from a translated attribute and is
multivalued, it indicates which value to retrieve. If n is not
indicated, the system retrieves all values of the attribute.
I-Attribute Decimal number of the attribute to be retrieved during
input conversion (ICONV). If I-Attribute is omitted, 0 is
assumed and record ID is retrieved.
O-Attribute Decimal number of attribute to be retrieved during output
conversion (OCONV). If the O-Attribute is omitted, 0 is
assumed and the record ID is retrieved.
211
ICONV
Examples
ICONV D System date
In the following example, the program segment will print the converted date.
INPUT IN_DATE
INTERNAL = ICONV(IN_DATE,"D")
OUTPUT = OCONV(INTERNAL, "D4/")
PRINT IN_DATE,INTERNAL,OUTPUT
The following table describes various dates you can input in the previous program and
their conversions.
1 8402 01/01/1991
11 8706 11/01/1991
011 8402 01/01/1991
12 8736 12/01/1991
121 8736 12/01/1991
110389 8709 11/03/1989
1/1 8402 01/01/1991
1/1/89 8402 01/01/1989
1/1/02 12420 01/01/2002
212
ICONV
11010101 MB0C U
100 MX or HEX 256
101 MB 5
101010 MO 33288
Code
Value Result
Specification
12:30 MT 45000
12AM MT 0
12PM MT 43200
213
ICONV
Related Topics
OCONV
The UniBasic OCONV function converts string or numeric data from internal repre-
sentation format to output format based on conversion codes.
214
IF/THEN/ELSE
IF/THEN/ELSE
Syntax
IF expr THEN statements [ELSE statements]
IF expr THEN
statements...
END [ELSE
statements...
END]
IF expr ELSE statements
IF expr ELSE
statements
END
Description
The UniBasic IF/THEN/ELSE command executes one of two blocks of statements
based on a conditional expression. If expr is true, the system executes the first group
of statements. If the expression is false, the system executes the second group of state-
ments.
An IF/THEN/ELSE structure may occupy either a single line or several lines. In the
multi-line form, blocks of statements within the THEN and ELSE clauses are defined
by the use of END. In both cases, the ELSE clauses are optional. The THEN statement
must appear on the same line with the IF expression, however, the END ELSE state-
ment may appear on the same or subsequent lines.
The single line form does not require an END statement before the ELSE statements.
Each branch of an IF/THEN/ELSE structure must contain at least one statement. If
you do not want any action for a particular logical branch, you can use the NULL
statement. Each line of the statement may be followed by a comment.
Note The END statement may appear on the same line as the last statement of a IF
or THEN block of statements. It must be separated with a semi-colon.
215
IF/THEN/ELSE
Examples
In the following example, the program statement tests if the variable SUPPLY is less
than the variable DEMAND. If the comparison is true, program control is transferred
to the statement labeled REORDER.
IF SUPPLY < DEMAND THEN GOTO REORDER
In the next example, the program segment compares INCOME to TARGET; the sys-
tem executes the first branch if the comparison is true or executes the second group of
statements if the comparison is false.
IF INCOME < TARGET THEN
PRINT "Income less than target figure."
END ELSE
PRINT "Income equal to or greater than target!"
END
Related Topics
CASE
The UniBasic CASE command creates a series of conditional branches based on a
selection expression.
NULL
The UniBasic NULL command acts as a dummy statement, performing no actions.
216
IN
IN
Syntax
IN( )
Description
The UniBasic IN function captures raw data from the user’s terminal or from a data
queue.
IN may capture function, arrow, and other special keys from the keyboard.
Tip
Examples
In the following example, the program segment assigns the value of “y” to ANSWER.
DATA y
ANSWER = IN()
Related Topics
INPUT
The UniBasic INPUT command requests data fro the terminal or a data statement dur-
ing program execution.
217
INDEX
INDEX
Syntax
INDEX(str.expr1,str.expr2,num.expr)
Description
The UniBasic INDEX function returns the starting position of the num.expr occur-
rence of str.expr2 within str.expr1.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INDEX Parameters
Examples
In the following example, the program segment searches STR.VAR for the second
occurrence of the letter “t” and returns that location, assigning it to the variable LOC.
In this example, the value that it returns is eight.
STR.VAR = "It was the best of times"
LOC = INDEX(STR.VAR,"t",2)
In the next example, the INDEX function operates like the COL() functions used in
conjunction with the FIELD function. It returns the beginning position of the string
“212” within the string variable STR. The result stored in the variable NY.STR is 15.
STR = "303-433-3199, 212-999-1212"
NY.STR = INDEX(STR,"212",1)
218
INDEX
Related Topics
COL1
The UniBasic COL1 function returns the column position before a substring found by
the execution of the FIELD function.
COL2
The UniBasic COL2 function returns the column position after a substring found by
using the FIELD function.
219
INDICES
INDICES
Syntax
INDICES(file.var[, index.name.expr])
Description
The UniBasic INDICES function returns either the names of alternate key indices, or
returns information about a particular alternate key index.
Note If the index you specify does not exist, the function returns a null string.
220
INDICES
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INDICES Parameters
221
INMAT
INMAT
Syntax
INMAT( )
INMAT(matrix.name)
Description
The UniBasic INMAT function, in the first form, returns the number of elements in a
matrix. The second form returns the current dimension of matrix.name. If the array
has two dimensions, the bounds are separated by value marks.
After you open a file, the value of INMAT is set to the modulos of the file. Subsequent
file operations using matrix commands changes the value of INMAT.
INMAT is automatically set by the matrix-oriented commands DIMENSION,
MATREAD, MATREADU, MATPARSE, SELECT and, OPEN statements.
Examples
In the following example, the program segment fills the matrix MAIN.MAT with val-
ues from REC. If there are enough elements in the matrix, the value of INMAT is set
to the number of elements filled. If the number of values exceeds the number of ele-
ments, and the 0 value of the matrix is filled (MAIN.MAT(0)), the value of INMAT is
set to 0.
MATPARSE MAIN.MAT FROM REC, @VM
PRINT INMAT()
In the next example, the program segment dimensions two arrays and then prints the
dimensions using the PRINT statement and INMAT function.
DIM LARGE.ARRAY(23,14)
DIM SMALL.ARRAY(9)
PRINT INMAT(LARGE.ARRAY)
PRINT INMAT(SMALL.ARRAY)
222
INPUT
INPUT
Syntax
INPUT var [,expr [ _ ]] [:] [[FOR | WAITING time.expr] [UNFILTERED]
[{THEN | ELSE} statements]
INPUT var [,-l] [[FOR | WAITING time.expr] [UNFILTERED]
[{THEN | ELSE}statements]
Description
The UniBasic INPUT command requests data from a user or a DATA queue.
Only one variable can be read by each INPUT statement. If you enter Return only, the
variable is assigned a null value.
You can display a message to prompt the user for information by using a
Tip PRINT statement before an INPUT statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INPUT Parameters
223
INPUT
Parameter Description
Use the underscore parameter to allow the user to use the backspace key even
Tip when the maximum specified input length is reached, (i.e., if you specify
“INPUT X,5_” and the users has entered five characters, the user can use the
backspace key to modify the entry).
Use the -1 parameter when you want to periodically check for a command an
Tip application should act upon, in an application which runs continuously.
224
INPUT
Examples
In the following example, the program segment reads the first value established by the
DATA statement and assigns it to the variable TEST, in this case, the value 10.
DATA 10,20,30,40,50
INPUT TEST
In the next example, the program statement prints the prompt, “Enter name:”. The
INPUT statement then allows the user to enter any number of characters, stopping
only when the user presses Return. The first ten characters that the user enters are
assigned to the variable NAME.
PRINT "Enter name: "; INPUT NAME,10_
In the next example, the program segment tests if the terminal type ahead buffer con-
tains any characters. If the variable S.FLAG is assigned the value zero, the buffer is
empty; if it is assigned one, the buffer contains characters. In this case, if characters
have been entered, the system prints the current value of RECS.PROCESSED. The
variable S.FLAG does not contain the characters echoed at the terminal, only a 0
or a 1.
INPUT S.FLAG,-1
IF S.FLAG THEN PRINT RECS.PROCESSED
In the next example, the user has 30 seconds to input data, otherwise the program
prints, “No input within 30 seconds.”
INPUT ANSWER FOR 30
ELSE PRINT "No input within 30 seconds."
Related Topics
INPUT @
The UniBasic INPUT @ command requests data from the terminal or a data statement
at a specific location on the screen.
INPUTERR
The UniBasic INPUTERR command displays a specified error message at the bottom
line of a user’s terminal.
INPUTTRAP
The UniBasic INPUTTRAP command checks for a particular character or characters
in the input, and then branches according to the specified criteria.
225
INPUT
INPUTNULL
The UniBasic INPUTNULL command defines a single character as the null character
in an INPUT @ statement.
DATA
The UniBasic DATA command creates a data queue to be read by subsequent INPUT
statements.
SYSTEM(14)
The SYSTEM(14) function returns the number of type ahead characters in the buffer.
IN
The UniBasic IN function captures raw data from a keyboard or data queue.
226
INPUT @
INPUT @
Syntax
INPUT @ (col,row) [ , | : ] var [,length] [ _ ] [mask]
[{THEN | ELSE} statements ]
Description
The UniBasic INPUT @ command requests data from a user or a DATA queue and
determines the characteristics and location of the input data.
@SYSTEM.RETURN.CODE is set to -1 if an INPUT statement times out.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INPUT @ Parameters
227
INPUT @
Parameter Description
Related Topics
INPUT
The UniBasic INPUT command requests data from the terminal or a data statement
during program execution.
TIMEOUT
For information on the ECL TIMEOUT command, refer to UniData Commands
Reference.
228
INPUTERR
INPUTERR
Syntax
INPUTERR error.expr
Description
The UniBasic INPUTERR command displays an error message at the bottom line of
the user’s terminal. error.expr can be any valid UniBasic statement including a literal
string enclosed in quotation marks.
Tip You can use INPUTERR to prompt for errors when entering data with an
INPUT statement.
You may erase any previous error messages printed on the bottom line of the screen
created by the INPUTERR statement when you execute another INPUT statement.
The user program must control the movement of the cursor so that it does not enter the
bottom line.
Note INPUTERR sends output to the screen regardless of the PRINTER on/off sta-
tus.
Examples
In the following example, the program segment prints an error message at the bottom
of the screen if you do not input the data correctly.
PRINT @(-1)
PRINT @(5,5):’Hourly Wage’
LOOP
PRINT @(16,5)
INPUT HOURLY.WAGE
UNTIL HOURLY.WAGE MATCHES ’1NON.2N’
INPUTERR ’Hourly wage must be entered as x.xx’
REPEAT
PRINT @(5,7):’Accepted.’
END
Related Topics
INPUT
The UniBasic INPUT command requests data from the terminal or a data statement
during program execution.
229
INPUTIF
INPUTIF
Syntax
INPUTIF var [[THEN | ELSE] statements]
Description
The UniBasic INPUTIF command retrieves input from the type ahead buffer and
assigns the input to a variable.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INPUTIF Parameters
230
INPUTNULL
INPUTNULL
Syntax
INPUTNULL ‘expr’
Description
The UniBasic INPUTNULL command defines a single character as the null character
in an INPUT @ statement. expr specifies any character as a null character and must be
enclosed with single quotation marks. The default null character is an underscore ( _ ).
Examples
In the following example, the pound sign (#) is set as the new null character.
INPUTNULL ’#’
231
INPUTTRAP
INPUTTRAP
Syntax
INPUTTRAP string.expr GOTO label [:] [,label [:]]
INPUTTRAP string.expr GOSUB label [:] [,label [:]]
Description
The UniBasic INPUTTRAP command sets a trap for a particular character or charac-
ters in a program. INPUTTRAP allows you to specify characters which, if entered at
an INPUT @ statement, will branch to another statement label. For information about
the GOTO and GOSUB commands, refer to the entries in this manual.
To set a trap for an uppercase and a lowercase character, use the following:
Tip
INPUTTRAP ’Aa’ GOTO 10,10
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INPUTTRAP Parameters
Examples
In the following example, the program statement will branch to label ASUB if you
enter H or the statement will branch to label BSUB if you enter B.
INPUTTRAP ’HB’ GOTO ASUB,BSUB
INPUT@ (10,10) VALUE
232
INPUTTRAP
Related Topics
INPUT@
The UniBasic INPUT @ command requests data from the terminal or a data statement
at a specified location on the screen.
233
INS
INS
Syntax
INS expr BEFORE dyn.array<attrib.expr[,val.expr [,subval.expr]]>
Description
The UniBasic INS command inserts an expression, with the appropriate delimiter,
before the attribute, value or subvalue mark you specify in a dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INS Parameters
Examples
In the following example, the program segment inserts Zelda with a new attribute
mark before the second attribute.
ARRAY = "H.L. Mencken":@AM:"John":@AM:"Mary"
INS "Zelda" BEFORE ARRAY<2>
In the next example, the program segment inserts Stephen at the end of the array since
val.expr is -1.
ARRAY = "Carmen":@AM:"Sally":@AM:"Billy":@AM:"Mark"
INS "Stephen" BEFORE ARRAY<-1>
234
INS
235
INSERT
INSERT
Syntax
INSERT(dyn.array.expr,attrib.expr,val.expr, subval.expr, insert.expr)
Description
The UniBasic INSERT function inserts an expression (with its delimiter), before or
after the specified attribute, value, or subvalue mark in a dynamic array.
There is no short form for the INSERT function; however, you may append
Tip data using the short version of the REPLACE function.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
INSERT Parameters
Examples
In the following example, the program statement inserts HARRY at the end of the val-
ues in attribute 2.
STR = INSERT(STR,2,-1,0,’HARRY’)
In the next example, the program statement inserts HARRY in the first value of
attribute 2.
STR = INSERT(STR,2,1,0,’HARRY’)
236
INSERT
In the next example, the program statement inserts HARRY in the first subvalue of the
first value of attribute 2.
STR = INSERT(STR,2,1,1,’HARRY’)
In the next example, the program segment inserts Alias in the second attribute posi-
tion.
ARRAY = "#111":@AM:"Jones":@AM:"Smith"
ARRAY2 = INSERT(ARRAY,2,0,0,"Alias")
Related Topics
Dynamic Arrays
For information on dynamic arrays, refer to Developing UniBasic Applications.
DELETE
The UniBasic DELETE command deletes a record from a file.
INS
The UniBasic INS command inserts data before a attribute, value, or subvalue mark in
a dynamic array.
FIELDSTORE
The UniBasic FIELDSTORE function replaces, inserts, or deletes substrings within a
character string.
237
INT
INT
Syntax
INT(num.expr)
Description
The UniBasic INT function returns the integer value of numeric expression num.expr.
Note This function does not round num.expr, but truncates the argument to its inte-
ger part.
Examples
In the following example, the program segment prints 1, the integer part of the number
1.734.
A = 1.734
PRINT INT(A)
238
ITYPE
ITYPE
Syntax
ITYPE(itype.expr)
Description
The UniBasic ITYPE function allows a UniBasic program to access a UniData virtual
attribute from the dictionary of a UniData file. You must compile the function using
the COMPILE.DICT command. The value of the function is the same as if it were run
using UniQuery or UniData SQL.
ITYPE generally requires that both the dictionary and data portion of the file are open.
The @ID and @RECORD variables must also be assigned. These variables resolve
the value of the ITYPE function. If neither the ID of the file nor data from the record
are used in the ITYPE, you do not need to assign them.
Note Conversion or formatting codes in the dictionary record of the virtual attribute
you are using does not affect the value ITYPE returns.
Examples
The following virtual attribute exists in the dictionary file of UniData’s CUSTOMER
file.
YTD.SALES:
V
SUM(MONTHLY.SALES)
MD2
Annual Sales
12R2,$
M
The following program segment opens both the CUSTOMER file and the dictionary
of the CUSTOMER file, then reads the compiled virtual attribute into a value called
YTD.SALES. After prompting for a customer ID and reading the record, you can then
evaluate the virtual attribute by using the ITYPE function (in this case it performs a
summation on the value of MONTHLY.SALES in the @RECORD). Note that an
internal OCONV function converts the amount to an output format for display pur-
poses. The conversion and format functions in the dictionary item will not work.
239
ITYPE
Related Topics
Virtual Attributes
For information on virtual attributes, refer to Using UniData.
@variables
For information on @variables, refer to Appendix B @variables.
240
LE
LE
Syntax
expr1 LE expr2
Description
The UniBasic LE function tests whether the expression expr1 is less than or equal to
expr2.
expr1 and expr2 may be any valid UniBasic expression, variable or string.
Examples
In the following example, the program segment tests whether A is less than or equal to
B. Since A is less than B, the message “Less Than or Equal To” prints.
A = 21
B = 22
IF A LE B THEN
PRINT "Less Than Or Equal To"
END ELSE
PRINT "Greater Than"
END
241
LES
LES
Syntax
LES(array1,array2)
Description
The UniBasic LES function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where the value in
array1 is less than or equal to the value in the corresponding position in array2, and a
zero in each position for values that are greater than array2.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY2 and
returns ARRAY3. ARRAY3 now contains 1}1}1}0}0.
ARRAY1 = 9:@VM:10:@VM:30:@VM:50:@VM:60
ARRAY2 = 10:@VM:20:@VM:30@VM:40:@VM:50
ARRAY3 = LES(ARRAY1,ARRAY2)
242
LEN
LEN
Syntax
LEN(str.expr)
Description
The UniBasic LEN function returns the length of character expression str.expr.
Examples
In the following example, the program segment displays 14, the length of the string
NAME.
NAME = "Arthur Fiedler"
PRINT LEN(NAME)
Related Topics
String Manipulation and Extraction
For information on string manipulation and extraction, refer to Developing UniBasic
Applications.
243
LENS
LENS
Syntax
LENS(dyn.array)
Description
The UniBasic LENS function returns the length of the values within each element of
the dynamic array dyn.array in characters.
Examples
In the following example, the program segment creates a new array ARRAY1, which
contains the length of each element of ARRAY.
ARRAY = ’1’:@VM:’22’:@VM:’333’:@VM:’4444’:@VM:’55555’
ARRAY1 = LENS(ARRAY)
Related Topics
String Manipulation and Extraction
For information on string manipulation and extraction, refer to Developing UniBasic
Applications.
244
LN
LN
Syntax
LN(num.expr)
Description
The UniBasic LN function returns the natural base logarithm of numeric expression
num.expr. This function is the inverse of the EXP function.
Examples
In the following example, the program statement assigns the natural logarithm of 12 to
the variable VAL. The result is 2.4849.
VAL = LN(12)
Related Topics
EXP
The UniBasic EXP function returns a value in exponential form.
245
LOCATE
LOCATE
Syntax
LOCATE expr IN dyn.array<attribute.expr [,val.expr [,subval.expr]]> [BY key.expr]
SETTING var [THEN statements END] ELSE statements END
Description
The UniBasic LOCATE command locates an expression within a dynamic array.
Note If you use the INSERT function to update sorted arrays, use the BY clause
with caution. The LOCATE statement using a BY clause in an unsorted array
can cause unpredictable results. For example, the following array:
"A":@VM:"B":@VM:"C"
causes the LOCATE statement to return an index value of 3 for inserting a ’D’.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
LOCATE Parameters
246
LOCATE
Parameter Description
Sorting Keys
Normally, a search proceeds in the physical order of the array elements. You can alter
the search order by using the optional BY clause. The order in which the system
searches the array elements is determined by the type of sort clause you specify. The
247
LOCATE
elements are not physically rearranged, but are examined according to the sort key you
specify. The following table describes the valid sort keys.
Note Using the LOCATE command on a dynamic array does not alter the array in
any way.
The BASICTYPE P form locates expr in dyn.array within the search parameters of
attrib and val. The location of the item, if found, is placed in index. If you do not spec-
ify an attribute or value position, the search occurs at the attribute level. If you specify
an attribute, the search occurs at the value level. If you specify both, the search occurs
at the subvalue level. key.exp determines how the array is sorted and searched.
248
LOCATE
Examples
In the following example, the program statement searches the entire array FILMS,
attribute by attribute, for the literal string “HUD”. If the search is successful, the
attribute index of the string is assigned to the variable NDX. if the string is not found,
NDX is set to the last value plus one, and the system executes the STOP command.
The search is performed on the attribute level and if an attribute has the value HUD1,
the ELSE clause still executes because the LOCATE statement compares the entire
attribute.
LOCATE "HUD" IN FILMS<1> SETTING NDX ELSE STOP
In the next example, the program segment searches the array FILMS, starting at
attribute 5, value 2, subvalue 1, for the contents of the variable TITLE. Array elements
are examined in ascending order, and comparisons are left-justified. If the value in
TITLE is found, the system executes the first PRINT statement; otherwise, the system
executes the second PRINT statement.
LOCATE TITLE IN FILMS<5,2,1> BY "AL" SETTING NDX THEN
PRINT "THIS TITLTE IS IN THE LIBRARY"
END ELSE
PRINT "TITLE NOT FOUND, TRY AGAIN."
END
Related Topics
FIND
The UniBasic FIND command determines the position of an expression in a dynamic
array.
FINDSTR
The UniBasic FINSTR command determines the position of a substring within a
dynamic array.
249
LOCK
LOCK
Syntax
LOCK expr [THEN statements END] [ELSE statements END]
Description
The UniBasic LOCK command reserves a computer resource for the current UniBa-
sic program.
Use LOCK to reserve system printers or other resources for specific use by a
Tip single program.
Reminder It is your responsibility to assign the resource numbers and ensure there are no
conflicts in assignment. Resources are not automatically unlocked by the ter-
mination of the locking program. They must be released by using the
UNLOCK command. The ECL QUIT command unlocks resources reserved
by programs during a user session. Resources can also be released by execut-
ing the ECL CLEAR.LOCKS command at the system level.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
LOCK Parameters
250
LOCK
Parameter Description
Examples
In the following example, the program statement reserves resource 12 if another pro-
gram is not using it. If resource 12 is already in use, the current program suspends exe-
cution and waits until resource 12 is unlocked.
LOCK 12
In the next example, the program segment locks resource 44 if it is available. If it has
already been locked, the program attempts to lock resource 45. If both resources are
unavailable, the program stops.
T1 = 44; T2 = 45
LOCK T1 ELSE LOCK T2 ELSE STOP
Related Topics
CLEAR.LOCKS
For information on the ECL CLEAR.LOCKS command, refer to UniData Commands
Reference.
LIST.LOCKS
For information on the ECL LIST.LOCKS command, refer to UniData Commands
Reference.
UNLOCK
The UniBasic UNLOCK command unlocks computer resources reserved by the
LOCK statement.
251
LOCK
QUIT
For information on the ECL QUIT command, refer to UniData Commands
Reference.
252
LOOP/REPEAT
LOOP/REPEAT
Syntax
LOOP
[statements]
[UNTIL expr [DO]
until_statements]
[WHILE expr [DO]
while_statements]
REPEAT
LOOP {WHILE | UNTIL} expr DO
statements
REPEAT
LOOP
statements
{WHILE | UNTIL} expr DO REPEAT
Description
The UniBasic LOOP/REPEAT command repeats any contained statements WHILE
or UNTIL a specified condition is met, depending on the clause you use. statements
can precede and/or follow the test condition. The structure may be written on one line,
space permitting, or it may extend over as many lines as necessary. REPEAT is
required and finishes the LOOP operation.
The first set of statements are executed on the first entry into the loop, then the
WHILE or UNTIL clause is evaluated. If expr is true (using the WHILE keyword) or
false (using the UNTIL keyword), then the system executes the second set of state-
ments. If you have statements after a WHILE or UNTIL clause, the DO clause is
required; otherwise it is optional. When REPEAT is reached, the program execution
returns to the first set of statements.
Tip Loops should be constructed so that termination occurs based on the WHILE
or UNTIL condition. The LOOP statement is flexible enough that almost any
logical progression can be incorporated.
253
LOOP/REPEAT
Parameters
The following table describes each parameter of the syntax:
Parameter Description
LOOP/REPEAT Parameters
Examples
In the following example, the program segment prints and increments POS until POS
reaches the value of 10.
POS=0
LOOP WHILE POS < 10 DO
PRINT POS
POS +=1
REPEAT
In the next example, the program segment prints “Counting” and then increments C. It
then evaluates C to see if it is less than eight, and if so, executes the second statement.
On the eighth iteration, the top statement is executed and the loop stops because the
condition (C > 8) is met. The program continues execution at the statement following
REPEAT. The second statement is not executed on the final iteration.
C = 0
PRINT "Counting:"
LOOP
C = C+1
UNTIL C > 8 DO
PRINT "C = ":C
REPEAT
254
LOOP/REPEAT
Related Topics
FOR/NEXT
The UniBasic FOR/NEXT command executes statements repeatedly while a variable,
beginning at a specified value, is incremented. The loop continues until the variable
reaches a specified value or the condition in the WHILE clause is reached.
255
LOWER
LOWER
Syntax
LOWER(dyn.array.expr)
Description
The UniBasic LOWER function converts all attribute marks to value marks and all
value marks to subvalue marks in a dynamic array.
Examples
In the following example, the program segment lowers the dynamic array D.STR.
D.STR = "A":@AM:"B":@AM:"C":@VM:"D"
D.STR = LOWER(D.STR)
Related Topics
RAISE
The UniBasic RAISE function raises all delimiters in a dynamic array to the next
level.
256
LT
LT
Syntax
expr1 LT expr2
Description
The UniBasic LT function tests whether the expression expr1 is less than expr2.
expr1 and expr2 may be any valid UniBasic expression, variable or string.
Examples
In the following example, the program segment tests whether A is less than B. Since A
is less than B, the message “Less Than” prints.
A = 21
B = 22
IF A LT B THEN
PRINT "Less Than"
END ELSE
PRINT "Greater Than"
END
257
LTS
LTS
Syntax
LTS(array1,array2)
Description
The UniBasic LTS function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where the value in
array1 is less than the value in the corresponding position in array2, and a zero in
each position for values that are greater than array2.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY2 and
returns ARRAY3. ARRAY3 now contains 1}1}0}0}0.
ARRAY1 = 9:@VM:10:@VM:30:@VM:50:@VM:60
ARRAY2 = 10:@VM:20:@VM:30@VM:40:@VM:50
ARRAY3 = LTS(ARRAY1,ARRAY2)
258
MAT
MAT
Syntax
MAT matrix = expr
MAT matrix = MAT matrix2
Description
The UniBasic MAT command assigns new values to all elements of a matrix based on
an expression. The second form assigns the contents of one matrix to another matrix.
If a matrix is assigned the values of a second matrix, the assignment proceeds from
element to element in consecutive order. That is, the first element of the first array is
assigned to the first element of the second array, the second element is assigned to the
second element, etc. The two matrices do not have to contain the same dimensions,
but must contain the same number of elements. The system does not alter the second
matrix by the assignment process.
You must dimension all matrices before assignment. You may place MAT in any
looping structure and assign the elements with a variable or function.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MAT Parameter
259
MAT
Examples
In the following example, the program segment assigns 1.5 to all elements of the array
FEES.
DIM FEES(100,100)
MAT FEES = 1.5
In the next example, the program segment assigns the values in matrix FEE2 to the
matrix FEE1. Note the differing dimensions but the same number of elements in the
two matrices.
DIM FEE1(2,4),FEE2(4,2)
MAT FEE1 = MAT FEE2
1 2 3 4 10 11
5 6 7 8 12 13
14 15
16 17
Matrix FEE1
10 11 12 13
14 15 16 17
Note how the elements are assigned: from left to right, top to bottom, element by ele-
ment. The system maintains all values in matrix FEE2. The positions are shifted to fit
the dimensions of matrix FEE1.
Related Topics
DIMENSION, DIM
The UniBasic DIMENSION or DIM command declares the name and dimensions of
matrices.
260
MATBUILD
MATBUILD
Syntax
MATBUILD dyn.array FROM matrix [, start.num [, end.num [USING delim]]]
Description
The UniBasic MATBUILD command generates a dynamic array from a dimensioned
matrix based on specified starting and ending positions and the delimiter given. The
matrix can be multidimensional. The statement retrieves elements from the multidi-
mensional matrix according to the order in which its elements are stored.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATBUILD Parameter
261
MATBUILD
Parameter Description
Examples
In the following example, A is a matrix with 5 elements:
A(1)=11, A(2)=22, A(3)=33, A(4)=44, and A(5)=55
The following program statement:
MATBUILD SUBSTR FROM A ,2,4
Related Topics
DIMENSION, DIM
The UniBasic DIMENSION or DIM commands declare the name and dimensions of
matrices.
MAT
The UniBasic MAT command assigns new values to all elements of a matrix based on
an expression.
262
MATBUILD
MATPARSE
The UniBasic MATPARSE command distributes portions of a string to consecutive
elements of a named matrix based on a specified delimiter.
263
MATCH MATCHES
MATCH
MATCHES
Syntax
var MATCH "[~] {len [X, A ,N]} [text]"
var MATCHES "[~] {len [X, A, N]} [text]"
Description
The UniBasic MATCH or MATCHES functions determine if a variable matches a
specific pattern of characters or numbers you specify. If the var matches the pat-
tern.expr, MATCH returns a one. If the var does not match the pattern.expr, MATCH
returns a zero.
The text string must match exactly. The codes and a text string may be mixed to
search for specific patterns separated by characters.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATCH Parameters
264
MATCH MATCHES
Parameter Description
Examples
In the following example, the program segment determines if the variable SSN is a
valid social security number.
SSN = "522-13-5124"
SSNTEST = SSN MATCH "3N’-’2N’-’4N"
265
MATCHFIELD
MATCHFIELD
Syntax
MATCHFIELD(str.expr,"[~] {len [X, A, N]} [text]", field.expr)
Description
The UniBasic MATCHFIELD function returns a portion of a string that matches a
search substring. The string being compared must match entirely the format specified.
If there is no match, the system returns a null string.
The text string must match exactly. The codes and a text string may be mixed to
search for specific patterns separated by characters.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATCHFIELD Parameters
266
MATCHFIELD
Parameter Description
Examples
In the following example, the program segment returns the value 56 because the entire
string matches the specified criteria and the third field is the middle two numbers.
SSN = "534-56-5565"
MID = MATCHFIELD(SSN,"3N’-’2N’-’4N",3)
In the next example, the program segment searches the string and returns the second
and fourth fields and prints “99922”.
STRING = "ALL999WERE22ABSENT"
NUM1 = MATCHFIELD(STRING,’3A3N4A2N6A’,2)
NUM2 = MATCHFIELD(STRING,’3A3N4A2N6A’,4)
PRINT NUM1:NUM2
267
MATPARSE
MATPARSE
Syntax
MATPARSE matrix FROM str.expr, delim.expr
Description
The UniBasic MATPARSE command distributes portions of the delimited string to
consecutive elements of the named matrix, based on a delimiter found within the
string.
If there are more elements in the string being parsed than are available in the matrix,
the system places the portion of the string that cannot be parsed in the zero element of
the array. The INMAT function is used to determine if the array being parsed is too
large for the matrix. If the value of INMAT is equal to 0, the zero element contains an
assigned value. If the value of INMAT is equal to a positive number, this number rep-
resents the number of elements of the array that were assigned values.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATPARSE Parameters
268
MATPARSE
The length of the delimiter affects the function of the MATPARSE statement. The fol-
lowing table describes the length of the delimiter and its effect.
Length Effect
Examples
In the following example, the program segment fills the matrix ALPHA with consecu-
tive characters from a literal string. A null delimiter is given, causing one character to
be assigned to each matrix cell. In this case, the value of the INMAT function is 7.
DIM ALPHA(7)
MATPARSE ALPHA FROM "ABCDEFG",""
Resulting matrix:
ALPHA(1) = "A"
.
.
.
ALPHA(7) = "G"
In the next example, the program segment dimensions the matrix T and then fills it
with data from a dynamic array. The delimiter specified is the attribute mark, so each
attribute is assigned to consecutive elements of the array. Note that the string “ITEM”
has five elements but the matrix is dimensioned with four elements. After the MAT-
PARSE command, the INMAT function is 0 and the value of the zero element, T(0) is
443.
DIM T(4)
ITEM = "123:@AM:33:@AM:199:@AM:821:@AM:443"
MATPARSE T FROM ITEM, CHAR(254)
269
MATPARSE
Resulting matrix:
T(1) = 123
T(2) = 33
T(3) = 199
T(4) = 821
In the next example, the program segment fills the first column of the array with the
contents of the attributes (as defined by the delimiters), while the second column of
the matrix contains the delimiters that defined that attribute. Delimiters are user-
defined.
DIM R(4,2)
ITEM = "2,5.3;9,,5"
MATPARSE R FROM ITEM, ",."
Resulting matrix:
R(1,1) = 2
R(1,2) = ,
R(2,1) = 5
R(2,2) = .
R(3,1) = 3;9
R(3,2) = ,,
R(4,1) = 5
R(4,2) = null
Related Topics
MAT
The UniBasic MAT command assigns new values to all elements of a matrix.
INMAT
The UniBasic INMAT function displays the status of statements that you have exe-
cuted.
270
MATREAD
MATREAD
Syntax
MATREAD matrix FROM [file.var,] record.ID.expr [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic MATREAD command assigns the values found in successive attributes
of a record to corresponding elements of a matrix.
If there are fewer attributes in the record than elements in the matrix, the system fills
the remaining matrix elements with null values. If the matrix cannot hold all the
attributes of the record, the system stores the remaining information in the zero ele-
ment of the matrix. The value of the INMAT function is set to the number of attributes
in the record, unless the number of attributes exceeds the dimensions of the matrix. In
that case, the system sets INMAT to 0 (and the remaining attributes assigned to the
zero element).
Note You must name and dimension matrices before a MATREAD statement is
executed.
After the execution of a MATREAD statement, the system sets the INMAT function
the number of attributes that were loaded. If there are more attributes in the record
than elements in the array, the system assigns a value of zero to INMAT.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATREAD Parameters
271
MATREAD
Parameter Description
Examples
In the following example, the program segment reads the record with ID NAMES
from the default file and assigns the successive attributes to the matrix TEST. If there
is not a default file or the record is not found, the program assigns the value 0 to the
variable FOUND.
DIM TEST(10,10)
MATREAD TEST FROM "NAMES" ELSE FOUND = 0
In the next example, the program segment reads the record with ID NAMES and
assigns the data in the file CUSTFILE to the matrix TEST.
OPEN "","CUSTFILE" TO CF ELSE STOP "NO CUSTFILE"
MATREAD TEST FROM CF,"NAMES" ELSE FOUND = 0
272
MATREAD
In the next example, the MATREAD statement uses a THEN clause and an ELSE
clause.
FILE.ERR = 0
DIM CUST.ITEM(22)
MATREAD CUST.ITEM FROM CUST.FILE,CUST.ID THEN
GOSUB PROCESS.CUSTOMER:
END ELSE
MAT CUST.ITEM = "
FILE.ERR = 1
END
Related Topics
MATREADL
The UniBasic MATREADL command assigns the values found in successive
attributes of a record to corresponding elements of a matrix while placing a read-only
lock on the specified record, allowing other users to read the record while preventing
them from updating the record.
MATREADU
The UniBasic MATREADU command writes successive elements of a matrix into
corresponding attributes of a record but will not release any locks set by the READU,
READVU, or MATREADU commands.
273
MATREADL
MATREADL
Syntax
MATREADL matrix FROM [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements] {THEN | ELSE} statements [END]
Description
The UniBasic MATREADL command assigns the values found in successive
attributes of a record to corresponding elements of a matrix and sets a read-only lock
on the specified record, allowing other users to read the record while preventing them
from updating the record.
The system respects locks set by MATREADL with READU, MATREADU,
READVU, WRITEU, MATWRITEU, or WRITEVU commands. If you use the
READ, MATREAD, READV, WRITE, MATWRITE, or WRITEV commands
(which do not check locks), the lock has no effect on the record you access.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATREADL Parameters
274
MATREADL
Parameter Description
Examples
In the following example, the program segment reads a tape record with the ID speci-
fied in TAPE.ID from the TAPES.FILE. If the record is found, control transfers to the
subroutine TAPE.PROCESS; otherwise, the program displays a message and aborts.
If the record is locked, the program displays a message.
MATREADL TAPE.REC FROM TAPES.FILE,TAPE.ID THEN
GOSUB TAPE.PROCESS:
PRINT "TAPE PROCESSED:":TAPE.ID
END
LOCKED PRINT "RECORD LOCKED"
ELSE PRINT "RECORD NOT FOUND:":TAPE.ID; ABORT
275
MATREADL
Related Topics
MATREAD
The UniBasic MATREAD command assigns the values found in successive fields of a
record to corresponding elements of a matrix.
MATREADU
The UniBasic MATREADU command assigns the values found in successive fields
of a record to corresponding elements of a matrix while placing an exclusive lock on
the record, allowing other users to read the record while preventing them from updat-
ing the record.
LIST.READU
For information on LIST.READU, refer to UniData Commands Reference.
276
MATREADU
MATREADU
Syntax
MATREADU matrix FROM [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements] {THEN | ELSE} statements [END]
Description
The UniBasic MATREADU command assigns the values found in successive
attributes of a record to corresponding elements of a matrix and sets an exclusive lock
on the record you specify with record.ID.expr, prohibiting outside access until the
update is complete.
The MATREADU statement sets the INMAT function. INMAT returns a zero if data
is stored in the zero element (0,0) because the number of attributes read exceeded the
matrix size; otherwise it returns the number of elements assigned to the matrix.
A record that you lock with the MATREADU statement remains locked until you exe-
cute one of the following statements: MATWRITE, WRITE, WRITEV, RELEASE,
or STOP. The system releases all locks when the program (but not a called subroutine)
containing the MATREADU terminates.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATREADU Parameters
277
MATREADU
Parameter Description
Examples
In the following example, the program segment reads the record with ID “NAMES”
from the default file. The record is locked, preventing access by another program until
the record is updated or released.
DIM TEST(10,10)
MATREADU TEST FROM "NAMES" ELSE GOSUB 105
278
MATREADU
In the next example, the program segment reads the record with the ID CUST.ID and
assigns each attribute to successive elements in the matrix CUST.REC. If the record is
found, the system executes the optional THEN clause; if the record is locked, the sys-
tem displays RECORD LOCKED. If the record is not found, the system displays a
message to that effect.
MATREADU CUST.REC FROM CUSTFILE,CUST.ID THEN
PRINT "PROCESSING CUSTOMER: ":CUST.ID
GOSUB PROCESS.CUSTOMER:
END LOCKED
PRINT ’RECORD LOCKED ’
END ELSE
PRINT ’RECORD NOT FOUND FOR CUSTOMER ’:CUST.ID
END
Related Topics
MATREAD
The UniBasic MATREAD command assigns the values found in successive fields of a
record to corresponding elements of a matrix.
MATREADL
The UniBasic MATREADL command assigns the values found in successive
attributes of a record to corresponding elements of a matrix while placing a read-only
lock on the record, allowing other users to read the record while preventing them from
updating the record.
LIST.READU
For information on LIST.READU, refer to UniData Commands Reference.
279
MATWRITE
MATWRITE
Syntax
MATWRITE matrix {ON | TO} [file.var,] record.ID.expr [ON ERROR statements]
Description
The UniBasic MATWRITE command writes successive elements of a matrix to the
corresponding attributes of the record record.ID.expr.
MATWRITE writes successive elements from the array to the record you specify. The
first element in the array is written to the first attribute in the record, and so on. If the
matrix contains trailing nulls (the matrix size exceeds the virtual record being stored
in the matrix), the trailing nulls are not written. If the zero element is not null, its con-
tents are written subsequent to the final element in the array; i.e., as element N+1.
The MATWRITE statement releases any locks set on a record by the MATREADU,
READL, READU or READVU statements.
Note After the execution of a MATWRITE statement, the STATUS function is set
to zero if the record accessed was locked prior to being written to. If the STA-
TUS function returns -2, the record accessed is not locked.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATWRITE Parameters
280
MATWRITE
Parameter Description
[ON | TO] [file.var,] Specifies the file to which to write the record.
You must specify an ON or TO clause. If you
do not specify a file variable, the system
accesses the most recently opened default file.
record.ID.expr Specifies the record to which to write the
attributes.
[ON ERROR statements] Specifies statements to execute if the
MATWRITE statement fails with a fatal error
condition because the file is not open, if the file
is a read-only file, or if the file contains another
write error. If you do not specify the ON
ERROR clause and a fatal error occurs, the
program terminates.
Examples
In the following example, the program segment writes the matrix RECEIPTS to the
file REC87, as a record with ID “RENTALS.”
COMMON RECEIPTS(12)
MATWRITE RECEIPTS ON REC87,"RENTALS"
Related Topics
MATWRITEU
The UniBasic MATRWRITEU command writes successive elements of a matrix into
corresponding attributes of a record without releasing a record lock.
281
MATWRITEU
MATWRITEU
Syntax
MATWRITEU matrix {ON | TO} [file.var,] record.ID.expr
[ON ERROR statements]
Description
The UniBasic MATWRITEU command writes successive elements of a matrix to the
corresponding attributes of a specified record but does not release any locks set by
READU, READVU, or MATREADU statements.
Note After the execution of a MATWRITE statement, the STATUS function is set
to zero if the record accessed was locked prior to being written to. If the STA-
TUS function returns -2, the record accessed is not locked.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MATWRITEU Parameters
282
MATWRITEU
Parameter Description
Examples
In the following example, the program statement writes the matrix NEW.CLIENTS to
the file CLIENTS as a record with an ID of ‘050887’. If the record is locked, the sys-
tem maintains the lock.
MATWRITEU NEW.CLIENTS TO CLIENTS,’050887’
Related Topics
MATWRITE
The UniBasic MATWRITE command writes successive elements of a matrix into cor-
responding attribute of a record and releases a record lock.
283
MAXIMUM
MAXIMUM
Syntax
MAXIMUM(dyn.array.var)
Description
The UniBasic MAXIMUM function returns the maximum numeric element found in
the dynamic array you specified with dyn.array.var. This function ignores non-
numeric elements. If the array you specify contains only non-numeric elements,
MAXIMUM returns a null value. If there is a null element in the array, the system
treats it as zero.
The system treats all system marks (attribute, value, and subvalue marks) indiscrimi-
nately; that is, any value between two marks, no matter what the mark, is taken as an
element with respect to this function.
Examples
In the following example, the program segment prints 22 on screen.
X = "12":@VM:"2":@FM:"dd":@FM:"9":@FM:"22"
PRINT MAXIMUM(X)
In the next example, the program segment prints 0 since the string W contains a
NULL element and no other numeric elements.
W = "A":@FM:"B":@VM:"":@SM:"C"
PRINT MAXIMUM(W)
Related Topics
The UniBasic MINIMUM function returns the minimum numeric element found in a
dynamic array.
284
MDPERFORM
MDPERFORM
Syntax
MDPERFORM str.expr [CAPTURING, dyn.arrry.var]
[RETURNING, dyn.array.var] [RTNLIST int.expr] [PASSLIST int.expr]
[PASSCOM]
MDPERFORM str.expr [RETURNING, dyn.array.var]
[CAPTURING, dyn.arrry.var] [RTNLIST int.expr] [PASSLIST int.expr]
[PASSCOM]
Description
The UniBasic MDPERFORM command executes various UniData commands, sen-
tences, or paragraphs within a UniBasic program while transferring lists to and from
the executed commands.
Note MDPERFORM does not pass and return select lists unless you explicitly
specify them. In this way, there is full control and protection over the
resource.
STACKCOMMON
The ECL STACKCOMMON command extends COMMON flexibility (although
using STACKCOMMON requires additional memory).
If STACKCOMMON is OFF when one program executes another program, the
unnamed common is passed to the executed program and any changes are passed back
to the executing program.
If STACKCOMMON is ON when one program executes another program, unnamed
common is not passed to the program you execute, instead the program’s unnamed
common is pushed onto a stack and the executed program’s unnamed common is ini-
tialized to zero. When the program is called back, the system moves the executing lev-
els and returns to the original value of the program. Unnamed common is never passed
to an phantom program.
285
MDPERFORM
Parameters
The following table describes each parameter of the syntax:
Parameter Description
MDPERFORM Parameters
286
MDPERFORM
Parameter Description
Examples
In the following example, the program segment lists all the items in the VOC file and
returns the result in select list 2.
287
MDPERFORM
list_var = 2
MDPERFORM "list dict VOC all" RTNLIST list_var
In the next example, the program segment first performs a selection on the CUS-
TOMER file and passes the result back in select list 1, then sorts the result.
list_var = 1
cmd1 = "select CUSTOMER with @ID = ’200’"
cmd2 = "sort CUSTOMER by DATE_OUT"
MDPERFORM cmd1 RTNLIST list_var
MDPERFORM cmd2 PASSLIST list_var
In the next example, the program segment builds different commands based on condi-
tions generated by MDPERFORM. According to the value of input_var, three differ-
ent UniQuery commands are executed.
list_var = 1
frg1 = "select CUSTOMER with "
frg2 = " NAME like ’...Jones...’ "
frg3 = " DATE_DUE > ’04/22/87’ "
frg4 = " AMT_DUE < 30"
frg5 = " by NAME"
BEGIN CASE
CASE input_var = 1
MDPERFORM frg1:frg2:frg5 RTNLIST list_var
CASE input_var = 2
MDPERFORM frg1:frg3:frg5 RTNLIST list_var
CASE input_var = 3
MDPERFORM frg1:frg4:frg5 RTNLIST list_var
END CASE
In the next example, the program segment performs the command in cmd3, using the
passed list specified by list_var and sends output to a dynamic array cpt_var.
MDPERFORM cmd3 PASSLIST list_var CAPTURING cpt_var
Related Topics
EXECUTE
The UniBasic EXECUTE command executes a UniData or UniQuery command from
within a UniBasic program.
EXECUTESQL
The UniBasic EXECUTESQL command passes an SQL statement directly to the Uni-
Data SQL processor.
PERFORM
The UniBasic PERFORM command executes a UniData command, sentence, or para-
graph from within a UniBasic program.
288
MDPERFORM
PCPERFORM
The UniBasic PCPERFORM command executes a UNIX or VMS command from
within a UniBasic program.
UDTEXECUTE
The UniBasic UDTEXECUTE command executes a command to perform in
ECLTYPE U, regardless of the BASICTYPE of the program.
289
MINIMUM
MINIMUM
Syntax
MINIMUM(dyn.array.var)
Description
The UniBasic MINIMUM function returns the minimum numeric element found in a
dynamic array.
The system ignores non-numeric elements with this function. If dyn.array.var con-
tains only non-numeric elements, the function returns a null value. If there is a null
element in the array, it is treated as a numeric zero.
All system marks (attribute, value, and subvalue marks) are treated indiscriminately;
that is, any value between two marks, no matter what the mark is, is taken as an ele-
ment.
Examples
In the following example, the program segment prints 2 on the screen.
X = "12":@VM:"2":@AM:"dd":@AM:"9":@AM:"22"
PRINT MINIMUM(X)
In the next example, the program segment assigns U a null value since V contains only
non-numeric elements.
V = "Null":@AM:"assignment":@AM:"test"
U = MINIMUM(V)
Related Topics
MAXIMUM
The UniBasic MAXIMUM function returns the maximum numeric element found in a
dynamic array.
290
MOD REM
MOD
REM
Syntax
MOD(num.expr1, num.expr2)
REM(num.expr1, num.expr2)
Description
The UniBasic MOD and REM functions returns the remainder of the division of
num.expr2 into num.expr1. These functions handle integers and decimals. The sign of
the result is the same as that of num.expr1.
The formula used by MOD and REM is:
MOD(x,y) = x - (INT(x/y) * y)
where x and y stand for numeric expressions. The first expression x is divided by y and
the integer function INT truncates the result. The system multiplies the resulting inte-
ger by y, and finally subtracts the result from the value of the first expression x.
Examples
In the following example, the program segment assigns the variable Z the remainder
of the division of Y into X. The remainder in this case is 2.
X = 12 ; Y = 5
Z = MOD(X,Y)
291
NE
NE
Syntax
expr1 NE expr2
Description
The UniBasic NE function tests whether the expression expr1 is not equal to expr2.
expr1 and expr2 may be any valid expression, variable or string.
Examples
In the following example, the program segment tests whether A is not equal to B.
Since A is greater than B, the message “Not Equal” prints.
A = 24
B = 22
IF A NE B THEN
PRINT "Not Equal"
END ELSE
PRINT "Equal"
END
292
NES
NES
Syntax
NES(array1, array2)
Description
The UniBasic NES function compares each value in array1 to its corresponding value
in array2. The system returns an array with a one in each position where the value in
array1 is not equal to the value in the corresponding position in array2, and a zero in
each position for values that are equal to array2.
Examples
In the following example, the program segment compares ARRAY1 to ARRAY2 and
returns ARRAY3. ARRAY3 now contains 0}0}0}1}1.
ARRAY1 = 10:@VM:20:@VM:30@VM:40:@VM:50
ARRAY2 = 10:@VM:20:@VM:30:@VM:50:@VM:60
ARRAY3 = NES(ARRAY1,ARRAY2)
293
NEG
NEG
Syntax
NEG(expr)
Description
The UniBasic NEG function changes the value of expr to its opposite sign. If the
value of expr is positive, NEG returns a negative value. If the value of expr is nega-
tive, NEG returns a positive value.
Examples
In the following example, the program segment changes the value of variable A to a
negative number and prints -1.
A = 1
A = NEG(A)
PRINT A
294
NEXT
NEXT
Syntax
NEXT [var]
Description
The UniBasic NEXT command defines the end of a FOR/NEXT structure. var is the
variable being incremented. This variable serves as documentation only; a program
functions identically with or without this variable.
Related Topics
FOR/NEXT
The UniBasic FOR/NEXT command executes statements repeatedly while a variable,
beginning at a specified value, is incremented. The loop continues until the variable
reaches a certain value or the system reaches the condition in the WHILE clause.
LOOP
The UniBasic LOOP/REPEAT command repeats any contained statements while or
until a condition is met.
295
NOCONVERT
NOCONVERT
Syntax
NOCONVERT {OFF | ON}
Description
The UniBasic NOCONVERT command controls the conversion of the special char-
acter CHAR(0). Generally, any UniData commands covering non-UniData files or
tape input/output, converts CHAR(0) to CHAR(128) on an input read and converts
CHAR(128) to CHAR(0) on an output write. This may cause problems under some
circumstances, especially if you use the character CHAR(128) in an application or is
stored data. NOCONVERT provides a way of switching the conversion OFF or ON.
The default is OFF.
The following table describes the UniBasic commands that NOCONVERT effects.
Affected Commands
READT OSWRITE
WRITET OSBREAD
OSREAD OSBWRITE
Reminder The PRINT and CRT functions don’t work with strings that contain a
CHAR(0).
The following table describes the functions that work with strings containing
CHAR(0), regardless of the NOCONVERT status.
Functions
296
NOCONVERT
Functions
COUNT DCOUNT
INDEX LEN
SEQ SWAP
297
NOT
NOT
Syntax
NOT(expr)
Description
The UniBasic NOT function inverts the logical result of the argument expr. If the
expression is true, the function returns a 0 (false); if the expression is not true, the
function returns 1 (true).
Examples
In the following example, the program segment compares X to Y (false, since X is not
greater than Y) and inverts the result, evaluating to true instead. The THEN statement
then executes, sending program control to the label specified by RETRY:
X = 1 ; Y = 2
IF NOT(X > Y) THEN GOTO RETRY:
298
NOTS
NOTS
Syntax
NOTS(dyn.array)
Description
The UniBasic NOTS function inverts the logical result of each element of a dynamic
array. If the element is true, the function returns a 0 (false) in the corresponding posi-
tion of the new array. If the expression is not true, the function returns 1 (true) in the
corresponding position of the new array.
Examples
In the following example, the program segment evaluates the dynamic array A, inverts
each result of the evaluation, and returns the results in a corresponding array. B now
contains 0}1}0}0.
A = 1:@FM:0:@FM:1:@FM:30
B = NOTS(A)
299
NULL
NULL
Syntax
NULL
Description
The UniBasic NULL command acts as a dummy statement. You may use the NULL
statement anywhere a statement is required.
Use NULL when a statement or command clause is mandatory but you do not
Tip want any action to occur.
Examples
In the following example, if the length of the variable NAME$ is zero, nothing is
printed.
PRINT "NAME: ": ; INPUT NAME$
BEGIN CASE
CASE LEN(NAME$) = 0
NULL
CASE LEN(NAME$) > 0
PRINT "HI, ":NAME$
END CASE
In the next example, if the CUSTR.REC is found, the program branches to the subrou-
tine PROCESS.CUST. If the record is not found, action is not taken.
READ CUST.REC FROM CUSTOMER,CUST.ID THEN
GOSUB PROCESS.CUST:
END ELSE NULL
300
NUM
NUM
Syntax
NUM(expr)
Description
The UniBasic NUM function determines if an expression is numeric. If expr is
numeric, NUM returns a one; otherwise, it returns a zero. expr can be any valid Uni-
Basic expression.
The NUM function accepts some non-numeric characters and still returns a 1. The fol-
lowing table describes these characters.
Character Description
+ Plus sign
- Negative sign
. Decimal point
Examples
In the following example, the program segment prints zero since VAR contains alpha-
betic characters.
VAR = ’ABC’
PRINT NUM(VAR)
In the next example, the program segment prints a 1 since VAR contains an integer.
VAR = -123
PRINT NUM(VAR)
301
NUMS
NUMS
Syntax
NUMS(dyn.array)
Description
The UniBasic NUMS function determines if each element of an array is numeric. If
the element is numeric, NUM returns a 1 in the corresponding position of the new
array; otherwise, it returns a 0.
The NUMS function accepts some non-numeric characters and still returns a 1. The
following table describes these characters.
Character Description
+ Plus sign
- Negative sign
. Decimal point
Examples
In the following example, the program segment determines if each element of array
CHARACTERS is numeric. The resulting array B contains 1}1}1}0}0.
CHARACTERS = 123:@FM:456:@FM:-789:@FM:"ABC":@FM:"CDE"
B = NUMS(CHARACTERS)
302
OCONV
OCONV
Syntax
OCONV(str.expr, conv.code.expr)
Description
The UniBasic OCONV function converts string or numeric data from internal format
to output format based on conversion codes.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OCONV Parameters
Code Format
D System date
G Extracts one or more strings separated by a delimiter
L Length
MB Binary
MC Masked character
MD Masked decimal
ML Left justify
MP Packed decimal
MP1 Converts data without truncating at the first null '\0' char-
acter or altering the null character
OCONV Codes
303
OCONV
Code Format
MO Octal
MR Right justify
MT System time
MX Hexadecimal (also HEX)
S SOUNDEX conversion
304
OCONV Date (D)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The date (D) code converts an integer into a corresponding date. The conv.code.expr
takes the following form:
D {y} {c} {fmt} {[f1, f2, f3]}{Month}
D indicates a date. y is a digit from 1 to 4 indicating the number of digits for the year,
the default value is 4. c is the separation character.
The internal form of the date takes the number 0 as December 31, 1967 and increases
by one for each day thereafter. Dates previous to this date are negative. Dates are out-
put in the following forms:
mm dd yy{yy}
day month year
The space between digits can be replaced with any delimiter symbol (slash, period,
comma, asterisk, etc.).
Note The UniData ECL UDT.OPTIONS 4 ON converts the text of dates to upper
case letters. For instance, May 13, is converted to MAY 13.
The fmt variable allows you to specify an output format. The following table describes
the valid output format codes.
Code Description
305
OCONV Date (D)
Code Description
M Specifies the month. Can be used with one of the fmt modi-
fiers to specify an alphabetic month.
Q Converts to quarter numeric format.
QA Converts to quarter alphanumeric format.
W Converts to weekday numeric format.
WA Converts to weekday alphanumeric format.
Y Specifies the year.
Note Following SMA-Standards, UniBasic treats Monday as the first day of the
week (1). The UniData ECL UDT.OPTIONS 29 ON converts Sunday to 7
instead of 0.
The fmt option can be used with one of the above format modifiers to alter the output
of the converted date. The options can consist of A,Z and/or a value between 1 and 32.
The number and letter used indicate to the system an alphabetic month. If A is used
with a 3 (A3) the month is be printed with a three-digit abbreviation (JUN); otherwise,
the entire month name is printed. Z suppresses leading zeros (if day is 01 it prints 1). Z
can also be used with a numeric value; if the value is 0, the item is suppressed.
fmt values (F1, F2, F3) must be specified with a corresponding MDY indicator.
Note If the output string is invalid or if the conversion code is invalid, the system
produces a run-time error.
Examples
In the following example, the program statement prints a three-character month name,
zero-suppresses the numeric day, and prints a four-digit year, (suppressing zeros if
necessary).
MDYA3,Z,Z4
306
OCONV Date (D)
In the next example, some sample format codes are applied to values and the results
are shown.
Related Topics
STATUS
The UniBasic STATUS function will be set for the date conversion. A value of 0 indi-
cates a successful conversion of a valid date; 1 indicates an invalid input date and 2
indicates an invalid conversion specification. A date conversion on a null returns a
STATUS of 1.
UDT.OPTIONS
The ECL UDT.OPTIONS 29 ON command converts Sunday to 7 instead of 0. For
information on UDT.OPTIONS, refer to UniData Commands Reference.
307
OCONV Date (D)
The UniData ECL UDT.OPTIONS 4 ON converts the text of dates to upper case let-
ters. For instance, May 13, is converted to MAY 13.
308
OCONV Group (G)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The group (G) code extracts one or more strings separated by a delimiter. The
conv.code.expr takes the following form:
G{m}*n
The following table describes each option of the conversion code.
Option Description
Examples
In the following example, the program segment prints “(303)”.
X = "(303)+555+0988"
PRINT OCONV(X,"G0+1")
309
OCONV Length (L)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The length (L) code places constraints on the length of the type of data that is returned.
The conv.code.expr takes the following form:
Ln{,m}
The following table describes each option of the conversion code.
Option Description
Examples
In the following example, the program segment prints “123” and a null since X is less
than five characters and greater than 3. A null prints since Y is longer than five charac-
ters.
X = 123; Y = 456789
PRINT OCONV(X,"L3,5")
PRINT OCONV(Y,"L3,5")
310
OCONV Masked Character (MC)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The mask character (MC) code converts alphabetic characters to upper or lowercase,
or extracts alphabetic or numeric characters from strings.
The following table describes the valid masked character format code.
Code Function
311
OCONV Masked Character (MC)
Code Function
312
OCONV Masked Decimal (MD)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The masked decimal (MD) code outputs a decimal string based on the conv.code.expr.
The str.expr can be any numeric value with related numeric formatting codes. Minus
signs, brackets (indicating a negative value), dollar signs, commas, decimal points and
the two special suffixes CR and DB (indicating negative or positive value) are
allowed.
The masked decimal (MD
BASICTYPE
The conv.code.expr has the following syntax:
MDn {f} {,} {$} [- | < | E | C | D] {P} {Z} {T} {xc} {E}
The MDn is required and indicates a Masked Decimal conversion with n places past
the decimal point. n can be a number between 0 and 9. f is an optional scaling factor
between 0 and 9. If you do not specify f, it is assumed to be equal to n (if the P option
is used, neither f nor n is used). The following table describes the optional OCONV
masked decimal codes.
Code Description
313
OCONV Masked Decimal (MD)
Code Description
xc Specifies the character ‘c’ is used to mask any spaces left after the
data has been formatted for output. The ‘x’ indicates the size of
the mask. If a dollar sign is present it appears in the left most posi-
tion of the attribute before the mask.
If the conversion is unsuccessful, or if the input value is null, the returned value is
null.
Examples
The following table describes some OCONV masked decimal conversion codes and
their results.
314
OCONV Left Justify (ML)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The left justify (ML) justifies text or a number. str.expr can be any valid text or a
numeric value with or without a decimal. The conv.code.expr has the following syn-
tax:
MLn {f} {,} {$} {C} {Z} [(format.code)]
ML is required and indicates a left justify conversion. n can be a number between 0
and 9. f is an optional scaling factor between 0 and 9. If you do not specify f, the sys-
tem assumes f is equal to n. The internal format produced is a simple integer number.
If n is less than the number of digits right of the decimal point, the resulting value is
rounded before truncating excess digits. The following table describes the optional
OCONV left justify codes.
Code Description
If the conversion to external format is unsuccessful, the system returns the original
value.
Examples
In the following example, the system converts the value 123456789 to 123-45-6789.
OUTPUT.VAL = OCONV("123456789","ML(###-##-####)")
315
OCONV Left Justify (ML)
Related Topics
ICONV
The UniBasic ICONV function converts string or numeric data from external format
to internal format based on conversion codes.
316
OCONV Packed Decimal (MP)
Syntax
OCONV(expr, MP)
Description
The packed decimal (MP) code converts an integer in packed decimal representation
into its external format. The ICONV function also has an MP code, which performs
the input conversion.
317
OCONV Packed Decimal (MP1)
Syntax
OCONV(expr, MP1)
Description
The packed decimal (MP1) code converts an integer in packed decimal representation
into its external format without truncating at the first null ‘\0’ character nor altering
the null character.
318
OCONV Right Justify (MR)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The right justify (ML) justifies text or a number. str.expr can be any valid text or a
numeric value with or without a decimal. the conv.code.expr has the following syntax:
MRn {f} {,} {$} {C} {Z} [(format.code)]
MR is required and indicates a right justify conversion. n can be a number between 0
and 9. f is an optional scaling factor between 0 and 9. If you do not specify f, the sys-
tem assumes f is equal to n. The internal format produced is a simple integer number.
If n is less than the number of digits right of the decimal point, the resulting value is
rounded before truncating excess digits. The following table describes the optional
OCONV right justify codes.
Code Description
If the conversion to external format is unsuccessful, the system returns the original
value.
Examples
In the following example, the system converts the value 123456 to 1,234.56.
OUTPUT.VAL = OCONV("123456","MR2$,")
319
OCONV Right Justify (MR)
Related Topics
ICONV
The UniBasic ICONV function converts string or numeric data from external format
to internal format based on conversion codes.
320
OCONV Time (MT)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The time (MT) code converts the internal time of day from an integer between 0 and
86400 (the number of seconds in a day) to the format you specify. The conv.code.expr
follows the following format:
MT {H} {S} {c}
The MT is required to indicate a time conversion. The optional values are H, which
indicates a 12-hour format with AM or PM suffixes; S indicates that seconds are to be
included in the output and c is the separation character. The default separation charac-
ter is the colon (:). Time is output in the following form:
HH MM {SS}
If an invalid string is input to the MT conversion, a run-time error message will be
produced. The UniBasic STATUS function will be set to 1 if the input string contains
any invalid characters.
Examples
The following table describes some OCONV Time codes and their results.
4500 MT 01:15
4500 MTS, 01:15:00
4500 MTS, 01,15,00
321
OCONV Hex (MX), Octal (MO), Binary (MB)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The hex (MX), octal (MO), and binary (MB) conversion codes convert data from dec-
imal into different bases. The conv.code.expr takes the following forms:
The MX (or HEX), MO, and MB are the conversion codes used with the appropriate
str.expr. The optional 0C indicates you want the input data to be converted to an
ASCII code format. Using the 0C option may result in more than one ASCII character.
Using 0C with binary results in taking each group of eight characters and converting
to ASCII. With octal, each group of three characters is converted. With hex, each
group of two characters is converted.
The system produces a run-time error message if the conversion code is invalid.
Examples
The following table describes some OCONV MX, MO, and MB conversion codes and
their results.
322
OCONV Hex (MX), Octal (MO), Binary (MB)
33288 MO 101010
Qat MX0C 516174
U MB0C 01010101
323
OCONV Pattern Match (P)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The pattern match (P) code returns only those data values that match a specified pat-
tern. If data does not match exactly the stipulated pattern, null is returned. The
conv.code.expr takes the following form:
P(op){;(op).....}
The following table describes the elements of the OCONV pattern match conversion
code.
Option Description
The following table describes the valid pattern match operators. Any combination of
the following pattern match operators are allowed.
Operator Description
324
OCONV Range (R)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The range (R) code returns only those data values that fall within specified ranges.The
conv.code.expr takes the following form:
Rn,m{;n,m.....}
The following table describes the OCONV range valid conversion code options.
Option Description
When implementing negative ranges, you must specify the highest negative number
must first. Any delimiter (such as a semicolon or comma), except system delimiters,
can be used to separate the numbers in a range. The minus sign (-) should not be used
as a delimiter since it might refer to a negative number in the range. If range specifica-
tions are not met, the system returns a null.
Examples
In the following example, the program segment prints “123” and a null since X is
within the range and Y is not.
X = 123; Y = 456789
PRINT OCONV(X,"R100,200")
PRINT OCONV(Y,"R100,200")
325
OCONV (S)
OCONV (S)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The SOUNDEX (S) code converts string or numeric data from internal representation
format to a phonetic output format based on SOUNDEX conversion codes. The S con-
version code may be used in an OCONV virtual attribute formula to convert alpha-
betic characters to their SOUNDEX equivalent.
Examples
In the following example, the virtual attribute SDX_LNAME has the following for-
mula that converts LNAME to its SOUNDEX expression:
OCONV(LNAME,"S")
326
OCONV Text Extraction (T)
Syntax
OCONV(str.expr, conv.code.expr)
Description
The text extraction (T) code extracts a fixed attribute from an attribute value. The
conv.code.expr takes the following form:
“T{m,}n”
When this conversion is applied to a string, the OCONV function extracts a contigu-
ous string of characters of length n, starting from character m.
If “Tn” is indicated, n characters are extracted from left to right. If “Tm,n” is indi-
cated, n characters starting at column m are extracted.
Examples
The following table describes some OCONV Text Extraction codes and their results.
327
OCONV File Translation (Tfile)
Syntax
OCONV(id.expr, conv.code.expr)
Description
The file translation (Tfile) allows you to retrieve attributes from another file. The
conv.code.expr has the following syntax:
T{DICT} [filename;cn;I-Attribute;O-Attribute]
where id.expr evaluates to an ID in the file (i.e., filename)
The following table describes the elements of the conversion code expression.
Elements Description
T Code name.
DICT Translates to the dictionary of the file indicated by its
filename.
filename Name of the file where the translation is directed (any
valid UniData file in your VOC file containing the
required attribute or data).
c One of the following translate subcodes:
VIf the record does not exist or if the attribute is null,
returns a null value and prints an error message.
CIf the record does not exist or attribute is null, it substi-
tutes id.expr for the value of the function.
XIf the record does not exist or the attribute is null, the
system returns a null.
n If an attribute is retrieved from a translated attribute and is
multivalued, it indicates which value to retrieve. If n is not
indicated, the system retrieves all values of the attribute.
I-Attribute Decimal number of the attribute to be retrieved during
input conversion (ICONV). If I-Attribute is omitted, the
system assumes 0 and retrieves the record ID.
328
OCONV File Translation (Tfile)
Elements Description
Examples
In the following example, the program statement translates the TAPE_ID to the
TAPES file and returns the name of the tape.
TAPE_ID = CUSTOMER.REC<7,X>
TAPE_NAME = OCONV("TAPE_ID","TTAPES;X;;1")
329
OCONVS
OCONVS
Syntax
OCONVS(dyn.array.expr, conv.code.expr)
Description
The UniBasic OCONVS function converts string or numeric data from internal format
to output format based on a conversion code, for each element of a dynamic array.
Note OCONVS conversion codes are the same as OCONV conversion codes. For
information on conversion codes, refer to “OCONV”.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OCONVS Parameters
Examples
In the following example, the program segment converts each element of ARR1 to an
output format.
ARR1 = 1234:@VM:5678:@VM:9876
ARR2 = OCONVS(ARR1,MR2$)
330
ON/GOSUB
ON/GOSUB
Syntax
ON expr GOSUB label[:][, label[:]...]
Description
The UniBasic ON/GOSUB command transfers program control to one of a list of sub-
routine labels, based on a numeric expression.
ON GOSUB may appear on one line, or may be spread over as many successive lines
as necessary. Labels that appear must be separated by commas.
When the program encounters a RETURN statement in the called subroutine, the sys-
tem transfers control back to the statement immediately following the ON GOSUB
statement. If the subroutine contains a RETURN TO label statement, control resumes
at the label you specify in the RETURN statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
ON/GOSUB Parameters
331
ON/GOSUB
Parameter Description
Examples
In the following example, the program segment divides the variable BALANCE by
100. If the result is less than or equal to one, the program transfers control to subrou-
tine U100. If the value is two, it transfers control to U200, etc. If the value is greater
than or equal to four, then the system transfers control to subroutine U400.
ON BALANCE/100 GOSUB U100,U200,U300,U400
In the next example, the program segment transfers control to a subroutine after
prompting the user for a screen item to modify. In this case, depending on the number
the user enters, the system transfers control to one of the five subroutines in the
GOSUB clause. If the data the user enters is non-numeric or less than 1, the system
transfers control to the first subroutine. If the user enters a value greater than 5, the
system transfers control to the last subroutine (500).
GOSUB DISPLAY.SCREEN:
PRINT "Enter Item number to modify (1-5): ":
INPUT ACTION
ON ACTION GOSUB 100,200,300,400,500
Related Topics
GOSUB
The UniBasic GOSUB command transfers program control to an internal subroutine.
ON/GOTO
The UniBasic ON/GOTO command transfers program control to a statement label.
332
ON/GOTO
ON/GOTO
Syntax
ON expr GOTO label1[:] [, label2[:] ...]
Description
The UniBasic ON/GOTO command transfers program control to a statement label
based on a numeric expression.
The ON GOTO statement, like the GOTO statement, is a one-way transfer of program
control within the main program. If you use an ON GOTO statement to transfer con-
trol to a subroutine with a RETURN statement, the subroutine’s RETURN statement
only works if a previous GOSUB statement is still waiting for a RETURN in the sub-
routine, otherwise the program aborts with a run-time error.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
ON/GOTO Parameters
333
ON/GOTO
Parameter Description
Examples
In the following example, the program statement transfers program control to the
statement label TEST if the variable X is less than or equal to 1. If X is 2, the system
transfers control to statement label 2500. If X is greater than or equal to 3, the system
transfers control to statement label YESNO.
ON X GOTO TEST,2500, YESNO:
Related Topics
ON/GOSUB
The UniBasic ON/GOSUB command transfers program control to a subroutine.
334
OPEN
OPEN
Syntax
OPEN “expr”, “filename” [READONLY] [TO file.var] [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic OPEN command opens a file, allowing you to read, write, or delete the
file.
Tip Use OPEN to open UniData hashed files to be read with the READ command
and written to with the WRITE command.
The INMAT function returns the file modulos after the execution of an OPEN state-
ment. If the file is a directory or DIR type, INMAT returns 0.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OPEN Parameters
335
OPEN
Parameter Description
336
OPEN
Parameter Description
{THEN | ELSE} You only need a THEN or an ELSE clause. If you use
statements THEN, you do not have to use ELSE. The system
[END] requires an END statement when you use THEN or
ELSE with multiple lines.
The system executes the ELSE clause statements if
the following conditions exist: if you specify a file
variable and that file cannot be found; if you do not
specify a file and if there is no default file. UniBasic
allows you to open an unlimited number of files in
any given program. For information on file perfor-
mance, refer to Administering UniData on UNIX.
Multiple statements may appear after THEN, ELSE,
or LOCKED. If the statements are placed on multiple
lines, an END at the end of the statement is required.
The statements can also be placed on the same line
with the appropriate keyword, separated by semi-
colon(s), without using END.
Examples
In the following example, the program statement opens the data file ACCREC as a
read-only file. Since you do not specify a file variable, ACCREC becomes the current
default file.
OPEN ’’, ’ACCREC’ READONLY ELSE STOP ’Cannot open ACCREC’
In the next example, the program statement opens the dictionary file ACCPAY,
assigning it to the file variable AP. If the system does not find the file, “File Not
Found” displays.
OPEN ’DICT’, ’ACCPAY’ TO AP ELSE PRINT ’File Not Found’
In the next example, the program segment opens the CUSTOMER file to the file vari-
able CUST. If it is not found, the system executes the ELSE statements, printing an
error and setting a flag to 1.
OPEN ’’, CUSTOMER’ TO CUST ELSE
PRINT ‘NO CUSTOMER’
OPEN.ABORT = 1
END
IF OPEN.ABORT THEN PRINT ’Aborting on open error’;STOP
337
OPEN
Related Topics
CLOSE
The UniBasic CLOSE command closes a file that has been opened with the OPEN
command.
INMAT
The UniBasic INMAT function displays the status of statements that were executed.
338
OPENSEQ
OPENSEQ
Syntax
OPENSEQ seq.filename, record.id [READONLY] TO seq.file.var
[ON ERROR statements] [LOCKED statements] {THEN | ELSE} statements [END]
Description
The UniBasic OPENSEQ command opens a sequential file for access, starting at the
record you specify. Once you open a record, you can read it using the READSEQ
command.
Use OPENSEQ to open files that use CHAR(10) as a delimiter. You can then
Tip use READSEQ to read the next line delimited by CHAR(10) and WRITESEQ
to write a line delimited by CHAR(10).
The STATUS function is set to the following values after you execute an OPENSEQ
statement.
• 0 if the record in the file you specify does not exist.
• 1 if the file you specify is not a sequential-access file.
• 2 if the file does not exist.
• 3 if you use the READONLY clause and the record does not exist.
• 4 if you use the STATUS function after OPENSEQ, indicating an
unknown error (such as having too many files open or permission prob-
lems).
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OPENSEQ Parameters
339
OPENSEQ
Parameter Description
340
OPENSEQ
Parameter Description
Examples
In the following example, the program statement opens the sequential file FILMS in
the directory DAYLOG, assigning it the file variable FILM.LOG.
OPENSEQ ‘DAYLOG’,‘FILMS’ TO FILM.LOG ELSE GOTO CLOSED:
Related Topics
READSEQ
The UniBasic READSEQ command assigns the next record from a previously opened
sequential file to a variable.
WRITESEQ
The UniBasic WRITESEQ command writes an expression at the end of a sequential
file.
WRITESEQF
The UniBasic WRITESEQF command writes an expression at the end of a sequential
file and forces the system to physically write the data to the disk.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
341
OPENSEQ
STATUS
The UniBasic STATUS function returns the validity of the previous operation.
342
OSBREAD
OSBREAD
Syntax
OSBREAD var FROM file.var AT byte.expr LENGTH length.expr
[ON ERROR statements]
Description
The UniBasic OSBREAD command reads data from a file starting at a byte location
for a certain length of bytes, assigning the data to a variable. OSBREAD performs an
operating system block read on a UNIX or VMS file. The OSBREAD command
allows you to read a specified block for processing.
Reminder You must first open the file using the OSOPEN command.
The STATUS function is set to the following values after you execute an OSBREAD
statement.
• 0 if the read is successful.
• 1 for an invalid filename.
• 2 if access is denied by the operating system.
• 4 if the file does not exist.
• 5 for any other undefined error.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSBREAD Parameters
343
OSBREAD
Parameter Description
Examples
In the following example, the program statement reads 10,000 bytes of the file RFILE
starting from the beginning of the file and assigns that data to the variable TEST.
OSBREAD TEST FROM ’RFILE’ AT 0 LENGTH 10000
In the next example, the program segment reads 15000 bytes from a UNIX or VMS
file, starting at the first byte. It then converts ASCII value 10 (a line feed) to a value
mark and processes each line sequentially.
OSBREAD BLOCK FROM INPUT.DIR AT 0 LENGTH 15000
CONVERT CHAR(10) TO @FM IN BLOCK
LOOP
REMOVE REC FROM BLOCK SETTING MORE.RECS
GOSUB PROCESS.REC:
WHILE MORE.RECS REPEAT
Related Topics
OSOPEN
The UniBasic OSOPEN command opens a UNIX or VMS sequential file.
344
OSBREAD
OSBWRITE
The UniBasic OSBWRITE command writes data to a file starting at a byte location.
345
OSBWRITE
OSBWRITE
Syntax
OSBWRITE expr {ON | TO} file.var AT byte.expr [ON ERROR statements]
Description
The UniBasic OSBWRITE command writes an expression to a file starting at a spec-
ified byte location. OSBWRITE is a sequential write that writes a file segment directly
out to the UNIX or VMS file.
You do not have to specify a length expression since only the number of bytes in expr
is written to the file.
Reminder You must first open the file using the OSOPEN command.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSBWRITE Parameters
346
OSBWRITE
Parameter Description
Examples
In the following example, the program statement writes the data in TEST to the file
RFILE starting from the beginning of the file.
OSBWRITE TEST ON RFILE AT 0
In the next example, the program segment reads REC.ID from a select list, reads the
associated record from the CUST file and appends the record onto a variable
(BLOCK), terminating each record with an ASCII 10 (or line feed). When it is com-
plete, the code writes the block to the UNIX filename opened to the variable
CUST.SEQ.
DONE = 0
LOOP
READNEXT REC.ID ELSE DONE = 1
UNTIL DONE DO
READ REC FROM CUST,REC.ID ELSE REC = ’ ’
IF REC THEN
REC = REC.ID:@FM:REC
BLOCK := REC:CHAR(10)
END
REPEAT
OSBWRITE BLOCK ON CUST.SEQ AT 0
Related Topics
OSOPEN
The UniBasic OSOPEN command opens a UNIX or VMS sequential file.
OSBREAD
The UniBasic OSBREAD command reads data from a file starting at a specified byte
location.
347
OSCLOSE
OSCLOSE
Syntax
OSCLOSE file.var [ON ERROR statements]
Description
The UniBasic OSCLOSE command closes a sequential file (including the path name
from the root directory) that you have opened with the OSOPEN statement.
The STATUS function is set to 0 if the file is closed successfully, or to 5 if the close
fails.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSCLOSE Parameters
Examples
In the following example, the program statement closes the file UNDEF.
OSCLOSE UNDEF
Related Topics
OSOPEN
The UniBasic OSOPEN command opens a UNIX or VMS sequential file.
348
OSDELETE
OSDELETE
Syntax
OSDELETE filename [ON ERROR statements]
Description
The UniBasic OSDELETE command deletes a UNIX or VMS sequential file.
The STATUS function is set to the following values after you execute an OSDELETE
statement.
• 0 if there is no error.
• 1 for an invalid directory.
• 2 if the system cannot access the file (permissions, etc.).
• 4 if the specified file does not exist.
• 5 if there is any other undefined error.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSDELETE Parameters
349
OSDELETE
Examples
In the following example, the program statement deletes the file NAMES in the cur-
rent directory.
OSDELETE "NAMES"
In the next example, the program statement deletes the file cust.rec in the UNIX sub-
directory /u/trans.
OSDELETE ’/u/trans/cust.rec’
Related Topics
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
350
OSOPEN
OSOPEN
Syntax
OSOPEN filename [READONLY] TO file.var [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic OSOPEN command opens a sequential file for access.
Use OSOPEN to open sequential files that do not use CHAR(10) as the line
Tip delimiter. You may then use OSBREAD to read a block of data from the file,
or OSBWRITE to write a block of data to the file.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSOPEN Parameters
351
OSOPEN
Parameter Description
Examples
In the following example, the program statement opens the file INVENTORY as
INVENT. If the system cannot access the file for any reason, the file is not opened.
OSOPEN ’INVENTORY’ TO INVENT ELSE STOP "Can’t open INVENTORY"
Related Topics
OSCLOSE
The UniBasic OSCLOSE command closes a sequential file opened with the OSOPEN
command.
OSBREAD
The UniBasic OSBREAD command reads data from a file starting at a specified byte
location.
352
OSOPEN
OSBWRITE
The UniBasic OSBWRITE command writes data to a file starting at a specified byte
location.
353
OSREAD
OSREAD
Syntax
OSREAD var FROM name.expr [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic OSREAD command reads an entire sequential file and assigns the con-
tents of the file to a variable.
Tip Do not use OSREAD on large files. If the file is too large for the program’s
memory, the program aborts and a run-time error message is generated. If this
occurs, use OSBREAD or READSEQ.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSREAD Parameters
354
OSREAD
Parameter Description
Examples
In the following example, the program segment reads the data stored in the VMS file
‘BILLING’ in the subdirectory ‘DSK$1:[SYS.DATA]’ and assigns it to the variable
BILL.REC.
OSREAD BILL.REC FROM DSK$1:[SYS.DATA] BILLING ELSE
PRINT "NO BILLING RECORD FOUND"
END
Related Topics
NOCONVERT
The UniBasic NOCONVERT command controls the conversion of the special charac-
ter CHAR(0).
OSWRITE
The UniBasic OSWRITE command writes a sequential file.
OSBREAD
The UniBasic OSBREAD command reads data from a file starting at a specified byte
location.
READSEQ
The UniBasic READSEQ command assigns the next record from a sequential file.
355
OSREAD
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
356
OSWRITE
OSWRITE
Syntax
OSWRITE expr {ON | TO} filename.expr [ON ERROR statements]
Description
The UniBasic OSWRITE command writes the contents of an expression to a sequen-
tial file.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
OSWRITE Parameters
Examples
In the following example, the program segment writes the contents of MAIL.LIST to
the file called “mergefile” in the UNIX subdirectory ‘/u/maildir’.
OSWRITE MAIL.LIST ON "/u/maildir/mergefile"
357
OSWRITE
Related Topics
NOCONVERT
The UniBasic NOCONVERT command controls the conversion of the special charac-
ter CHAR(0).
OSREAD
The UniBasic OSREAD command reads an entire sequential file and assigns it to a
variable.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
358
PAGE
PAGE
Syntax
PAGE [ON num.expr] [expr]
Description
The UniBasic PAGE command prints the current output page. The system prints the
page with spaces and any specified header or footer.
If you do not specify any parameters, the result depends on the last PRINTER ON or
PRINTER OFF command executed. If the last PRNTER command executed was
PRINTER OFF, the new page is generated on the user’s terminal; if the last PRINTER
command executed was PRINTER ON, the new page is generated on the system line
printer.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PAGE Parameters
Examples
In the following example, the program statement, depending on the printer status (ON
or OFF), completes the current page with any footings, then a new page is advanced.
PAGE
359
PAGE
In the next example, the program statement sends the completed page to the file
assigned to print unit 5. If the print unit specified cannot be found, nothing is printed.
PAGE ON 5
Related Topics
Terminal and Printer Input/Output
For information on terminal and printer input/output, refer to Developing UniBasic
Applications.
SETPTR
For information on the ECL SETPTR command, refer to UniData Commands
Reference.
360
PCPERFORM
PCPERFORM
Syntax
PCPERFORM str.expr [CAPTURING, dyn.array.var]
Description
The UniBasic PCPERFORM command executes a UNIX or VMS command from
within a UniBasic program.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PCPERFORM Parameters
Examples
In the following example, the program statement executes the SHOW TIME com-
mand at the VMS level.
PCPERFORM "SHOW TIME" CAPTURING DATE.TIME
In the following example, the program statement executes the date command at the
UNIX level.
PCPERFORM "date" CAPTURING DATE.TIME
In the next example, the program statement performs the VMS rename command,
renaming the file cust.rec to cust.save in the current VMS directory.
PCPERFORM ’rename cust.rec cust.save’
361
PCPERFORM
In the next example, the program statement performs the UNIX mv command, mov-
ing the file cust.rec to cust.save in the current directory.
PCPERFORM ’mv cust.rec cust.save’
Related Topics
EXECUTE
The UniBasic EXECUTE and PERFORM commands execute ECL commands
(UniData or UniQuery commands), sentences, or paragraphs.
MDPERFORM
The UniBasic EXECUTE command executes ECL commands (UniData or UniQuery
commands), sentences, or paragraphs, from within a UniBasic program and transfers
lists to and from the executed commands.
362
PERFORM
PERFORM
Syntax
PERFORM “str.expr” [[ASYNC | SYNC] ON connection]
[CAPTURING dyn.array.var] [RETURNING dyn.array.var]
[RTNLIST list.num.expr] [PASSLIST list.num.expr] [PASSCOM]
EXECUTE “str.expr” [[ASYNC | SYNC] ON connection]
[CAPTURING dyn.array.var] [RETURNING dyn.array.var]
[RTNLIST list.num.expr] [PASSLIST list.num.expr] [PASSCOM]
Description
The UniBasic PERFORM and EXECUTE commands execute an ECL (Environ-
mental Control Language) command from within a UniBasic program.
You may execute multiple commands with a single EXECUTE statement by separat-
ing each command within a string variable by attribute marks. When the EXECUTE
statement occurs, the system separates each command and executes them in order.
STACKCOMMON
The ECL STACKCOMMON command extends COMMON flexibility (although
using STACKCOMMON requires additional memory). If STACKCOMMON is OFF
and one program executes another program, the unnamed common is passed to the
executed program and any changes are passed back to the executing program. If
STACKCOMMON is ON when one program executes another program, unnamed
common is not passed to the program you execute, instead the program’s unnamed
common is pushed onto a stack and the executed program’s unlabeled common is ini-
tialized to zero. When the program is called back, the system moves the executing lev-
els and returns to the original value of the program. Unnamed common is never passed
to an phantom program.
BASICTYPE Compiling
When you compile EXECUTE and PERFORM in BASICTYPE P, they use a
BASICTYPE
different parser than when you compile them under BASICTYPE U. The P-
type parser scans a file of commands that are defined in the Spectrum-SMA
standards or in McDonnell Douglas’ REALITY operating system. If the com-
mand is found in this file, it will be parsed using the P-type parser. If the com-
mand is not found in the REALITY file, it will be parsed as if the program had
363
PERFORM
Note If you want to execute a standard UniData, UniQuery, or ECL command from
within a program compiled with BASICTYPE P, you can use the UniBasic
command UDTEXECUTE.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PERFORM Parameters
364
PERFORM
Parameter Description
365
PERFORM
Parameter Description
Reminder The error message numbers you capture with RETURNING will vary,
depending upon which version of UniData you are running.
Examples
In the following example, the program statement performs the command in cmd3 and
sends output to a dynamic array cpt_var.
PERFORM cmd3 CAPTURING cpt_var
In the next example, the EXECUTE statement creates a record ID list using the
SELECT statement for processing within the program. This is done in conjunction
with a READNEXT statement.
EXECUTE "SSELECT CUST"
EOF = 0
LOOP
READNEXT CUST.ID ELSE EOF =1
UNTIL EOF DO
*statements
REPEAT
366
PERFORM
In the next example, the program segment executes a paragraph from within a UniBa-
sic program using the EXECUTE statement:
PARA = "PA":@AM:"DISPLAY HELLO"
EXECUTE PARA
Related Topics
EXECUTESQL
The UniBasic EXECUTESQL command passes an SQL statement directly to the Uni-
Data SQL processor.
PCPERFORM
The UniBasic PCPERFORM command executes a UNIX or VMS command.
MDPERFORM
The UniBasic MDPERFORM command executes various UniData commands, sen-
tences, or paragraphs, and transfers lists to and from the executing commands.
UDTEXECUTE
The UniBasic UDTEXECUTE command executes a command in ECLTYPE U,
regardless of the BASICTYPE used with the program.
367
PRECISION
PRECISION
Syntax
PRECISION num.expr
Description
The UniBasic PRECISION command determines how many places to the right of the
decimal point the system truncates numbers. num.expr may be a value from zero to 10.
If the num.expr is not within this range, the system does not change the current display
precision. The default precision is four places.
Note UniBasic uses the PRECISION statement somewhat differently than other
BASIC implementations. If you notice a degradation in arithmetic accuracy,
use the PRECISION statement to increase the accuracy of sequential arith-
metic operations.
Examples
In the following example, the program statement results in all the numeric variables
being truncated after eight digits from the decimal point prior to being converted to a
string variable.
PRECISION 8
In the next example, the program statement truncates all digits right of the decimal
point.
PRECISION 0
In the next example, the program statement sets the display precision based on the
variable DEC.
PRECISION DEC
Related Topics
Mathematic Functions
For information on mathematic functions, refer to Developing UniBasic Applications.
368
PRECISION
FLOAT.PRECISION
For information on the ECL FLOAT.PRECISION command, refer to UniData
Commands Reference
369
PRINT
Syntax
PRINT [ON num.expr] [print.expr]
Description
The UniBasic PRINT command prints data on the display terminal or the line printer,
or sends data to a print file.
You must separate multiple items in a PRINT statement by either commas or colons.
Each comma between two items separates the items by the corresponding number of
tab stops. Tab stops are set to 10 spaces. If you separate statements by a colon, the sys-
tem concatenates the items.
Unless a print expression ends with a colon, a PRINT statement automatically exe-
cutes a carriage return after printing a line. If the output from the PRINT statement
exceeds the current page width, it wraps to the next line.
Note The PRINT statement interprets two consecutive non-printing ASCII charac-
ters (i.e., CHAR(192):CHAR(192)) as one character when displaying data.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PRINT Parameters
370
PRINT
Parameter Description
Examples
In the following example, the program segment prints HI THERE on the line printer.
PRINTER ON
PRINT "HI THERE"
In the next example, the program statement sends the value of variable X with a string
to the file specified by unit 10.
PRINT ON 10 "X = ":X
In the next example, the PRINT statement prints X, Y, and a string separated by tabs,
prints X+Y next to the string, tab twice, then prints another string, then prints the aver-
age of X and Y using the INT function.
X = 5 ; Y = 7
PRINT X,Y,"Total = ":X+Y,,"Average = ":INT((X+Y)/2)
Each item is separated by tabs, the result of the comma separation character. A colon
causes all data items to be concatenated.
Related Topics
CRT
The UniBasic CRT command sends output only to the screen or CRT, regardless of
the use of the PRINTER ON/OFF command.
PRINTER
The UniBasic PRINTER command directs the output of PRINT statements.
371
PRINTER
PRINTER
Syntax
PRINTER {ON | OFF}
Description
The UniBasic PRINTER command directs output of PRINT, FOOTING, HEADING
and PAGE statements not sent to a file (those without the ON clause). If you specify
ON, the system directs all output to the system line printer; if you specify OFF, the
system directs all output to the display terminal.
Reminder Issuing a PRINTER ON command does not ensure the printer is turned on,
properly configured, or even present in the user’s system. If proper communi-
cation between the printer and the computer system is not present when a
printer-enabled command is issued, (a PRINT statement after a PRINTER ON
command, for example), the system generates an error.
Examples
In the following example, the program statement sends all future report output (data
from PRINT, FOOTER HEADER and PAGE commands) to the line printer.
PRINTER ON
In the next example, the program statement directs PRINT statements to the display
terminal.
PRINTER OFF
372
PRINTER CLOSE
PRINTER CLOSE
Syntax
PRINTER CLOSE [ON num]
Description
The UniBasic PRINTER CLOSE command sends data stored in either a print file or
a print buffer to the print queue for printing. When you use the ON clause to direct the
PRINTER CLOSE command to a particular print file, it does not physically close that
file. Instead, it sends the contents of the file to a print buffer, leaving the file in an
empty state. If more data is sent to the same print file, it comprises the start of a new
group of data to be printed. As many as 31 print files may be open at any one time.
The PRINTER CLOSE statement does not generate a new line at the end of a page.
UniBasic is in control of page feeds or generating new line equivalents.
Reminder Data in a print file is automatically sent to the print queue if the program exits
or you use a PRINTER CLOSE statement.
Examples
In the following example, the program statement sends the current contents of print
file 5 to the print queue.
PRINTER CLOSE ON 5
Related Topics
SETPTR
For information on the ECL SETPTR command, refer to UniData Commands
Reference.
373
PRINTERR
PRINTERR
Syntax
PRINTERR [expr] [FROM file.var]
Description
The UniBasic PRINTERR command prints error messages stored in either the sys-
tem error message file ERRMSG or a specified file.
Note To get a message from the user-defined error message file, you must open the
file first. You must specify L (carriage return/line feed) explicitly.
Code Function
374
PRINTERR
Code Function
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PRINTERR Parameters
Examples
In the following example, the system ERRMSG file contains error message 4432 and
a user-defined file S_ERR contains error message E009. These messages contain the
following:
375
PRINTERR
The following code segment produces an error message if the file you enter for
FNAME cannot be found or you enter 12 for VAR1.
OPEN "S_ERR" TO E_FILE ELSE STOP "S_ERR NOT FOUND"
INPUT FNAME
INPUT VAR1
ER1 = "4432":@FM:FNAME
ER2 = "E009":@FM:"VAR1"
OPEN FNAME TO TFILE ELSE
PRINTERR ER1
STOP
END
IF VAR1 > 10 THEN PRINTERR ER2 FROM E_FILE
If you enter file_test for FNAME and file_test and cannot be found, the program seg-
ment produces the following error message.
[4432] FILE test_file DOES NOT EXIST
CAN’T PROCEED!
19 Oct 1989
10:34:19
If you enter 12 for VAR1, the program segment produces the following error message.
=>ERR [E009]
VAR1 IS NOT PROPERLY SPECIFIED
Related Topics
PRINT
The UniBasic PRINT command prints data on the display terminal or line printer. The
print expression may contain any literal string, numeric or string variables, or UniBa-
sic functions.
376
PROCREAD
PROCREAD
Syntax
PROCREAD var {THEN | ELSE} statements [END]
Description
The UniBasic PROCREAD command assigns the string value of the primary input
buffer of the calling Proc to a variable. PROCREAD can be used to access the primary
input buffer of a calling Proc.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
PROCREAD Parameters
Examples
In the following example, the program segment assigns the string value on the primary
input buffer to ARGUMENTS.
PROCREAD ARGUMENTS ELSE
PRINT "ERROR!"
PRINT "DIALOUT"MUST BE CALLED FROM A PROC"
ABORT
END
377
PROCREAD
Related Topics
PROCWRITE
The UniBasic PROCWRITE command writes data into the primary input buffer of the
calling Proc.
378
PROCWRITE
PROCWRITE
Syntax
PROCWRITE expr
Description
The UniBasic PROCWRITE command writes data into the primary input buffer of
the calling Proc. PROCWRITE erases any previous data in the primary input buffer
and replaces the data with the given data.
Examples
In the following example, the program segment writes the contents of ANSWER to
the primary input buffer.
PRINT "SEND RESULTS TO THE PRINTER? (Y OR N)"
INPUT ANSWER, Y
IF ANSWER = "Y" THEN
PRINTER ON
.
.
.
END
PROCWRITE ANSWER
Related Topics
PROCREAD
The UniBasic PROCREAD command assigns the string value of the primary input
buffer of the calling Proc to a variable.
379
PROGRAM
PROGRAM
Syntax
PROGRAM prog.name
Description
The UniBasic PROGRAM command defines the name of the current main program.
This statement is optional and is for documentation purposes only. The PROGRAM
statement must be the first non-comment statement in the program.
Examples
In the following example, the program segment declares the program name as
BOOKS.
REM This is a program to do the books
PROGRAM BOOKS
Related Topics
SUBROUTINE
The UniBasic SUBROUTINE command defines the name of a subroutine.
380
PROMPT
PROMPT
Syntax
PROMPT str.expr
Description
The UniBasic PROMPT command sets the prompt for user input to a specified one-
character string. If str.expr is longer than one character, the system only uses the first
character as the new prompt.
Note If you supply the data from a DATA statement rather than an INPUT state-
ment, the data the program receives displays after the prompt.
Tip If you set the prompt to a null character, the system does not echo the input
data to the display terminal.
Examples
In the following example, the contents of variable PSTRING (in this case an asterisk)
becomes the new prompt. If an input statement is used in the program, an asterisk
appears at the current cursor position.
PSTRING = "*"
PROMPT PSTRING
In the next example, the program statement sets the prompt at a null character. The
system will not echo the data you input.
PROMPT ""
381
PWR
PWR
Syntax
PWR(num.expr1, num.expr2)
Description
The UniBasic PWR function raises expr1 to the power of expr2.
Examples
In the following example, the program segment raises variable X to the power of 3,
first using an exponentiation operator, then using the PWR function to raise X to the
power of 3. The results are identical.
X = 2
PRINT X**3
PRINT PWR(X,3)
382
QUOTE
QUOTE
Syntax
QUOTE(str.expr)
Description
The UniBasic QUOTE function encloses a string expression with quotes.
Examples
In the following example, the program segment encloses the string stored in VAR2 by
double quotes and stores that string in VAR3. This stores the string “STRING2” in
VAR3.
VAR2 = "STRING2"
VAR3 = QUOTE(VAR2)
383
RAISE
RAISE
Syntax
RAISE(str.expr)
Description
The UniBasic RAISE function raises all UniData special delimiters to the next level.
The system raises attribute marks to record marks, value marks to attribute marks, and
subvalue marks to value marks.
Examples
In the following example, the program segment raises all delimiters to the next level.
ARRAY = ’Harry Sims’:@VM:’114 W. Smith’:@SVM:Suite 220’
ARRAY = RAISE(ARRAY)
Related Topics
LOWER
The UniBasic LOWER function lowers all UniData special delimiters to the next
level.
384
READ
READ
Syntax
READ dyn.array.var FROM [file.var,] record.ID.expr [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic READ command reads a record from a file and assigns its contents to a
dynamic array. The system assigns the first attribute of the record to the first position
of the array, the second attribute to the second position, and so on.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READ Parameters
385
READ
Parameter Description
After execution of a READ command, the STATUS function is set to zero if the read
is successful. If any other read error occurs (i.e., you do not have permissions to a file)
STATUS returns a 2. If the record is locked, STATUS returns the user number of the
user who locked the record.
If the record you specify cannot by found, the system executes the statements
BASICTYPE
after the ELSE clause and the dyn.array.var is set to null. In BASICTYPE P
or R, there is no change to dyn.array.var.
Examples
In the following example, the program statement searches the most recently opened
file for a record called “NAMES.” If it exists, its contents are assigned to the array
variable X. If it does not exist, “None found” displays.
READ X FROM "NAMES" ELSE PRINT "None found"
In the next example, the program segment reads a record from the CUSTOMER file
with an ID equal to the value in CUST.ID. If found, the system executes the subrou-
tine PROCESS.CUST; otherwise, the system prints a message and the program
branches to the label REPROMPT:
READ CUST.REC FROM CUSTOMER, CUST.ID THEN
GOSUB PROCESS.CUST
END ELSE
PRINT ’NO CUSTOMER REC FOR ’CUST.ID
END
In the next example, the program segment searches the file FILE1 for the record with
ID “ADDS.” If it is not there, the system executes the ELSE statement; this searches
FILE2 for the same record. In either case, a successful search assigns the value of the
record to the array variable Y. If neither file contains the record, the program returns
to label 150. The READ command ignores any update locks. When file integrity is of
special concern, use the READU, READVU, or MATREADU commands. To ensure
that any updates in progress complete, these commands should be employed by all
programs.
386
READ
In the following example, the program statement is invalid since the record ID is omit-
ted.
READ REC FROM CUSTOMER ELSE PRINT ‘NO CUSTOMER’
387
READBCK
READBCK
Syntax
READBCK dyn.array.var [FROM file.var] [ON ERROR statements]
[THEN statements] ELSE statements
Description
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index. READBCK reads the record from the file and assigns the record’s
contents to a dynamic array. The system assigns the record ID to the @ID variable.
READBCK retrieves the record ID related with the current alternate key value. Ini-
tially, you must set the current value using the SETINDEX command. When you exe-
cute READBCK immediately following the SETINDEX command, the system
retrieves the record ID related to the current alternate key value. Each time the system
performs this function again, the previous alternate key value in the index becomes the
current alternate key value. Using this command in a loop, the program is able to
retrieve records in the descending order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READBCK Parameters
388
READBCK
Parameter Description
Examples
In the following example, the program segment sets the index to the first record that
contains Smith and then reads the record just before Smith.
OPEN ’’, ’CUSTOMER’ TO tmp ELSE STOP
SETINDEX ’LNAME’, ’Smith’ ON tmp
READBCK rec FROM tmp THEN PRINT msg ELSE STOP
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READ
The UniBasic READ command retrieves a record from a file and assigns its value to a
dynamic array variable.
389
READBCKL
READBCKL
Syntax
READBCKL dyn.array.var [FROM file.var] [ON ERROR statements]
[LOCKED statements] [THEN statements] ELSE statements
Description
The UniBasic READBCKL command retrieves one record ID from a B+ tree based
alternate key index and places a read-only lock on the record. READBCKL reads the
record from the file and assigns the record’s contents to a dynamic array. The system
assigns the record ID to the @variable @ID. READBCKL retrieves the record ID
related with the current alternate key value.
Initially, you must set the current value using the SETINDEX command. When you
execute READBCKL immediately following the SETINDEX command, the system
retrieves the record ID related to the current alternate key value. Each time the system
performs this function again, the previous alternate key value in the index becomes the
current alternate key value. Using this command in a loop, the program is able to
retrieve records in the descending order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READBCKL Parameters
390
READBCKL
Parameter Description
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READBCK
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index.
391
READBCKU
READBCKU
Syntax
READBCKU dyn.array.var [FROM file.var] [ON ERROR statements]
[LOCKED statements] [THEN statements] ELSE statements
Description
The UniBasic READBCKU command retrieves one record ID from a B+ tree based
alternate key index and places an exclusive lock on the record. READBCKU reads the
record from the file and assigns the record’s contents to a dynamic array. The system
assigns the record ID to the @variable @ID. READBCKU retrieves the record ID
related with the current alternate key value. Initially, you must set the current value
using the SETINDEX command. When you execute READBCKU immediately fol-
lowing the SETINDEX command, the system retrieves the record ID related to the
current alternate key value. Each time the system performs this function again, the
previous alternate key value in the index becomes the current alternate key value.
Using this command in a loop, the program is able to retrieve records in the descend-
ing order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READBCKU Parameters
392
READBCKU
Parameter Description
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READU
The UniBasic READU command retrieves a record from a file, assigns its value to a
dynamic array variable, and sets an exclusive lock on the record being read.
READBCK
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index.
393
READFWD
READFWD
Syntax
READFWD dyn.array.var [FROM file.var] [ON ERROR statements]
[THEN statements] ELSE statements
Description
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index. READFWD reads the record from the file and assigns the
record’s contents to a dynamic array. The system assigns the record ID to the @vari-
able @ID. READFWD retrieves the record ID related with the current alternate key
value. Initially, you must set the current value using the SETINDEX command. When
you execute READFWD immediately following the SETINDEX command, the sys-
tem retrieves the record ID related to the current alternate key value. Each time the
system performs this function again, the previous alternate key value in the index
becomes the current alternate key value. Using this command in a loop, the program is
able to retrieve records in the descending order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READFWD Parameters
394
READFWD
Parameter Description
Examples
In the following example, the program segment sets the index to the first record that
contains Miller and then reads the next record.
OPEN ’’, ’CUSTOMER’ TO tmp ELSE STOP
SETINDEX ’LNAME’, ’Miller’ ON tmp
READFWD rec FROM tmp THEN PRINT msg ELSE STOP
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READBCK
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index.
READ
The UniBasic READ command retrieves a record from a file and assigns its value to a
dynamic array variable.
395
READFWDL
READFWDL
Syntax
READFWDL dyn.array.var [FROM file.var] [ON ERROR statements]
[LOCKED statements] [THEN statements] ELSE statements
Description
The UniBasic READFWDL command retrieves one record ID from a B+ tree based
alternate key index and places a read-only lock on the record. READFWDL reads the
record from the file and assigns the record’s contents to a dynamic array. The system
assigns the record ID to the @variable @ID. READFWDL retrieves the record ID
related with the current alternate key value. Initially, you must set the current value
using the SETINDEX command. When you execute READFWDL immediately fol-
lowing the SETINDEX command, the system retrieves the record ID related to the
current alternate key value. Each time the system performs this function again, the
previous alternate key value in the index becomes the current alternate key value.
Using this command in a loop, the program is able to retrieve records in the descend-
ing order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READFWDL Parameters
396
READFWDL
Parameter Description
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READL
The UniBasic READL command retrieves a record from a file and assigns its value to
a dynamic array variable and sets a read-only lock on the record being read.
397
READFWDU
READFWDU
Syntax
READFWDU dyn.array.var [FROM file.var] [ON ERROR statements]
[LOCKED statements] [THEN statements] ELSE statements
Description
The UniBasic READFWDU command retrieves one record ID from a B+ tree based
alternate key index and places a read-only lock on the record. READFWDU reads the
record from the file and assigns the record’s contents to a dynamic array. The system
assigns the record ID to the @variable @ID. READFWDU retrieves the record ID
related with the current alternate key value. Initially, you must set the current value
using the SETINDEX command. When you execute READFWDU immediately fol-
lowing the SETINDEX command, the system retrieves the record ID related to the
current alternate key value. Each time the system performs this function again, the
previous alternate key value in the index becomes the current alternate key value.
Using this command in a loop, the program is able to retrieve records in the descend-
ing order of the values of an indexed attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READFWDU Parameters
398
READFWDU
Parameter Description
Related Topics
SETINDEX
The UniBasic SETINDEX command initializes the current alternate key value in the
B+ tree based alternate key index.
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READU
The UniBasic READU command retrieves a record from a file, assigns its value to a
dynamic array variable, and sets an exclusive lock on the record being read.
399
READL
READL
Syntax
READL dyn.array.var FROM [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements [END]] {THEN | ELSE} statements [END]
READL dyn.array.var FROM [file.var,] record.ID.expr
[LOCKED statements [END]] [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic READL command reads the specified record from a file and assigns its
contents to a dynamic array and sets a multiple-access read-only lock on the record
being accessed.
Tip This is a read-only lock. You should not lock a record with this command if
your intention is to update the record.
The system assigns the first attribute of the record to the first position of the array , the
second attribute to the second position, and so on.
Reminder As with the other locking read or write commands, the execution of a READL
does not prevent access by the MATREAD, MATWRITE, READ, READV,
WRITE or WRITEV statements.
After execution of a READL command, the STATUS function is set to zero if the read
is successful. If any other read error occurs (i.e., you do not have permissions to a file)
STATUS returns a 2. If the record is locked, STATUS returns the user number of the
user who locked the record.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READL Parameters
400
READL
Parameter Description
Examples
In the following example, the program segment reads the record T1234 in the file
STOCK, assigning its contents to the dynamic array variable LAST.STOCK. The
statement sets a read-only lock on the file. If the system cannot read the file due to a
previously established lock, the system prints the message RECORD LOCKED.
READL LAST.STOCK FROM STOCK,‘T1234’
LOCKED PRINT ‘RECORD LOCKED’
ELSE PRINT ‘STOCK ITEM NOT PRESENT’
END
401
READL
Related Topics
READ
The UniBasic READ command retrieves a record from a file and assigns its value to a
dynamic array variable.
402
READLIST
READLIST
Syntax
READLIST dyn.array.var [FROM list.num] {THEN | ELSE} statements [END]
Description
The UniBasic READLIST command assigns the values remaining in an active list to
a dynamic array. Each active list element becomes an attribute in the dynamic array.
If you create a list under an account other than the current one, you may spec-
ify the account with acct.name. The SETTING clause sets the number of ele-
ments in the list to count.var.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READLIST Parameters
403
READLIST
Parameter Description
Examples
In the following example, the program segment selects the customer file and provides
a loop to process each record in sequence. If the first attribute of the record has the
value ‘P’ the program places the remaining active items in a variable called
LIST.ITEM, then writes that item on the file SL and stops processing.
EXECUTE "SELECT CUSTOMER WITH ACTIVE = ‘Y’ BY STATUS"
DONE = 0
LOOP
READNEXT CUST.ID ELSE DONE = 1
WHILE NOT(DONE) DO
READ CUST.REC FROM CUSTOMER,CUST.ID ELSE
PRINT ‘NO CUSTOMER RECORD: ’:CUST.ID
END
IF CUST.REC<1> = ‘P’ THEN
READLIST LIST.ITEM ELSE LIST.ITEM = " "
WRITE LIST.ITEM ON SL, ‘UNPROCESSED’
STOP ‘PROCESS ENDING DUE TO CUSTOMER STATUS’
END
REPEAT
In BASICTYPE P, if the list TAPE1 is saved in the current account and has the fol-
lowing contents:
TAPE1 = "V20001":@AM:"V1020":@AM:"V4056":@AM:"V2112"
The following code segment reads TAPE1 to array T and prints the contents of T and
4, the number of elements in the list:
READLIST T FROM "TAPE1" SETTING N
THEN
PRINT "NUMBER OF ELEMENTS IN LIST: ":N
PRINT "CONTENTS OF LIST": T
END
ELSE PRINT "CANNOT READ LIST";ABORT
404
READLIST
Related Topics
FORMLIST
The UniBasic FORMLIST command creates an active select list using a dynamic
array variable.
SELECT
The UniBasic SELECT command creates an active list of all record IDs in a file.
SELECT
For information on the ECL SELECT command, refer to UniData Commands
Reference.
405
READNEXT
READNEXT
Syntax
READNEXT id.var {, val.var[, subval.var]} [FROM list.num.expr]
[ON ERROR statements] {THEN | ELSE} statements [END]
Description
The UniBasic READNEXT command assigns the next record ID, from an active
select list, to a variable.
Note READNEXT does not actually read the record with the ID found, but assigns
that ID to a variable. Once assigned, you can use the variable within a READ
statement to access the appropriate record.
The SETTING clause assigns the number of elements in the list to the
variable count.var.
406
READNEXT
of the attribute in the second BY.EXP clause,... and so on for each successive
BY.EXP clause.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READNEXT Parameters
Examples
In the following example, the program segment gets the next ID from the list and
assigns it to the variable CUST. If the list is exhausted, then a message displays.
READNEXT CUST.ID ELSE PRINT "END OF LIST ENCOUNTERED"
In the next example, the program segment reads 10 IDs from the list opened as list 1,
then reads the records associated with those IDs. If the list has fewer than 10 IDs, the
program jumps to 1525. If a record ID is not found in the default system file, the pro-
gram displays a message.
407
READNEXT
FOR I = 1 TO 10
READNEXT ID FROM 1 ELSE SHORT.LIST = 1 THEN
READU REC FROM CUST,ID ELSE PRINT "NOT FOUND"
END
NEXT I
In the next example, the program segment selects records from the customer file using
the BY.EXP keyword, which sorts on the multivalued keyword INV.NBR. The pro-
gram then proceeds to read through the list, item by item, assigning each successive
ID and value position to CUST.ID and INV.VAL respectively. As long as records
exist, the THEN clause is performed. When the list is exhausted, the ELSE clause is
executed and the loop is exited.
PERFORM "SELECT CUSTOMER BY.EXP INV.NBR"
DONE = 0
LOOP
READNEXT CUST.ID,INV.VAL THEN
GOSUB PRINT.INV
END ELSE DONE = 1
UNTIL DONE DO
PRINT ’PROCESSING ’:CUST.ID
REPEAT
Related Topics
SELECT
For information on the UniQuery SELECT command, refer to Using UniQuery.
408
READNEXTTUPLE
READNEXTTUPLE
Syntax
READNEXTTUPLE dyn.array.var FROM file.name.expr ELSE statements [END]
Description
The UniBasic READNEXTTUPLE command assigns the next entire record, from a
list of IDs, to a variable, with attributes separated by attribute marks from a UniData
SQL statement.
READNEXTTUPLE creates a dynamic array with each attribute, or column, in the
SQL output separated by an attribute mark (@AM).
Do not use the Unidata SQL UNNEST command in the Unidata SQL state-
Tip ment. The system may not return the entire record with attribute marks, value
marks, and/or subvalue marks if you use UNNEST.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READNEXTTUPLE Parameters
Examples
In the following example, the program segment executes an SQL statement and stores
the output in an internal result file called SQL_INPUT. The READNEXTTUPLE
409
READNEXTTUPLE
statement then reads the records stored in SQL_INPUT until the last record item is
read. The process converts the attribute marks to spaces and prints each record read.
OUT.COMMAND = "SELECT NAME, ADDRESS, CITY"
OUT.COMMAND := " FROM CUSTOMER INTO SQL_INPUT; "
EXECUTESQL OUT.COMMAND
DONE = 0
LOOP
READNEXTTUPLE CUST.REC FROM "SQL_INPUT" ELSE
DONE = 1
END
UNTIL DONE DO
CONVERT @AM TO " " IN CUST.REC
CONVERT @VM TO","IN CUST.REC
PRINT CUST.REC
REPEAT
Related Topics
EXECUTESQL
The UniBasic EXECUTESQL command passes an SQL statement directly to the
UniData SQL processor.
UniData SQL
For information on Unidata SQL, refer to the Using Unidata SQL.
410
READSELECT
READSELECT
Syntax
READSELECT dyn.array.var [FROM sel.var] {THEN | ELSE} statements [END]
Description
This command provides a way in BASICTYPE P to read an active select list into a
dynamic array. Refer to the READLIST command for further details.
411
READSEQ
READSEQ
Syntax
READSEQ var FROM seq.file.var {THEN | ELSE} statements [END]
Description
The UniBasic READSEQ command reads the next record from a sequential file and
assigns the data read to a variable.
Note Each read from the sequential file searches for a line feed character
(CHAR(10)) to determine the end of the record. The READSEQ process
maintains a pointer to the current position in the file (where the last record ter-
minated).
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READSEQ Parameters
412
READSEQ
Examples
In the following example, the program statement reads the next record in the file
PORT.FILE and assigns it to the variable TAX.REC.
READSEQ TAX.REC FROM PORT.FILE ELSE STOP "Can’t READSEQ TAX.REC"
Related Topics
OPENSEQ
The UniBasic OPENSEQ command opens a sequential file for access.
WRITESEQ
The UniBasic WRITESEQ command writes an expression at the end of a sequential
file.
WRITESEQF
The UniBasic WRITESEQF command writes an expression at the end of a sequential
file and forces the system to physically write the data to disk.
413
READT
READT
Syntax
READT [UNIT (mu.expr)] var {THEN | ELSE} statements [END]
Description
The UniBasic READT command reads the next available record from a tape and
assigns it to a variable.
Reminder Before you use the READT command, you must attach a tape drive for use
with the T.ATT command. For information on tape commands, refer to
UniData Commands Reference. You must use the TAPELEN option for the
T.ATT command and specify the length you desire for the tape in megabytes.
This is for UniData tapes only. For information on the ECL T.ATT command,
refer to UniData Commands Reference.
Code Meaning
414
READT
Value Description
0 Successful read
1 End of file encountered
2 End of tape encountered
3 Tape not assigned
4 Parity error
5 Unknown hardware error
6 Other unspecified error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READT Parameters
415
READT
Parameter Description
Examples
In the following example, the program segment first uses the UniData ECL T.ATT
command to reserve the tape unit 0 with no conversion. Then the program segment
reads all the records on the tape (until the end of the file or the end of the tape) and
calls an internal subroutine that processes the record.
PERFORM "T.ATT"
DONE = 0
LOOP
READT UNIT (00) TAX.RECORD ELSE DONE = 1
UNTIL DONE DO
GOSUB PROCESS.RECORD
REPEAT
Related Topics
NOCONVERT
The UniBasic NOCONVERT command controls the conversion of the special charac-
ter CHAR(0).
REWIND
The UniBasic REWIND command rewinds a tape back to its beginning.
416
READT
WRITET
The UniBasic WRITET command writes an expression as a record to a tape.
STATUS
The UniBasic STATUS function returns the validity of the previous operation.
417
READU
READU
Syntax
READU dyn.array.var FROM [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements] {THEN | ELSE} statements [END]
READU dyn.array.var FROM [file.var,] record.ID.expr [LOCKED statements]
[ON ERROR statements] {THEN | ELSE} statements [END]
Description
The UniBasic READU command reads a record from a file and assigns its contents to
a dynamic array and can lock the record being read, preventing simultaneous access
by other users or programs.
Reminder The record is locked only against access by other READU or MATREADU
statements. Statements that do not check update locks (READ, MATREAD,
etc.) access a locked file.
After execution of a READU command, the STATUS function is set to zero if the
read is successful. If any other read error occurs (i.e., you do not have permissions to a
file) STATUS returns a 2. If the record is locked, STATUS returns the user ID of the
user who locked the record.
Note The system releases record locks when you execute a WRITE or a RELEASE
statement.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READU Parameters
418
READU
Parameter Description
Examples
In the following example, the program segment assigns the record, read from the
default file, with the ID “IDENT” to the variable INFO and sets an update lock on that
record. The system prints “Record locked” if the record is locked by another program
or prints “File not found” if the record does not exist. If a default file is not found, the
program aborts.
READU INFO FROM "IDENT" LOCKED PRINT "Record locked"
ELSE PRINT "File not found"
419
READU
In the next example, the program segment reads a record from the CUSTOMER file
and assigns the value to CUST.REC. If the record is found, the system prints a mes-
sage and calls a subroutine. If the record is locked or not found, the system executes a
similar set of statements. The STATUS function will return which user has locked the
record.
READU CUST.REC FROM CUSTOMER,CUST.ID THEN
PRINT "RECORD FOUND...NOW UPDATING"
GOSUB UPDATE.CUST:
END LOCKED
PRINT ‘RECORD LOCKED BY USER NUMBER ’:STATUS()
GOTO RE.READ:
END ELSE
PRINT ‘RECORD ‘:CUST.ID:’ NOT FOUND’
GOTO RE.PROMPT:
END
Related Topics
READ
The UniBasic READ command retrieves a record from a file and assigns its value to a
dynamic array variable.
READL
The UniBasic READL command retrieves a record from a file and assigns its value to
a dynamic array variable and sets a read-only lock on the record you access.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
420
READV
READV
Syntax
READV var FROM [file.var,] record.ID.expr, attribute.expr
[ON ERROR statements] {THEN | ELSE} statements [END]
Description
The UniBasic READV command assigns the data from a particular attribute of a
record to a variable.
Note READV ignores any update locks on a record. To update a record, you should
use the READVU command.
Tip You generally use the READV command when only one or two attributes are
needed from a record. This improves efficiency. If more attributes are neces-
sary or to update more attributes, use the READ or MATREAD commands.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READV Parameters
421
READV
Parameter Description
Examples
In the following example, the program segment reads CUST.NAME from the CUS-
TOMER file using the variable CUST.ID. In this case the first item, or attribute 1,
from the file is read. If the record exists, the system appends the dynamic array
NAME.ARRAY with CUST.NAME as the last value of the first attribute; otherwise,
the system executes the ELSE clause.
READV CUST.NAME FROM CUSTOMER,CUST.ID,1 THEN
NAME.ARRAY1,-1 = CUST.NAME
END ELSE
PRINT ’NO FILE FOR CUSTOMER ’:CUST.ID
END
In the next example, you can use the READV command with attribute.expr equal to
zero to verify that a record exists (for instance, if you are assigning IDs sequentially in
the CUSTOMER file). Each time you need to create a new ID, you need to verify that
the ID that you selected is not in use. The following code accomplishes this task,
incrementing the ID until an ID is available:
LOOP
READV CHECK FROM CUSTOMER,NEXT.ID,0 ELSE CHECK = 0
UNTIL CHECK NE 0 DO
NEXT.ID += 1
REPEAT CUST.ID = NEXT.ID
422
READV
Related Topics
READVU
The UniBasic READVU command retrieves an attribute from a record, assigns its
value to a variable, and sets an exclusive lock on the record.
READVL
The UniBasic READVL command retrieves an attribute from a record, assigns its
value to a variable, and sets a read-only lock on the record.
423
READVL
READVL
Syntax
READVL var FROM [file.var,] record.ID.expr, attribute.expr
[ON ERROR statements] [LOCKED statements] {THEN | ELSE} statements [END]
Description
The UniBasic READVL command assigns the data from a particular attribute of a
record in a file to a variable and sets a read-only lock on the record.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READVL Parameters
424
READVL
Parameter Description
Examples
In the following example, the program statement reads the third attribute of record
CARS from the system default file and sets a read-only lock on the record. If the data
is not found, the system displays the message “NOT FOUND”.
READVL MODEL FROM "CARS",3 ELSE PRINT "NOT FOUND"
In the next example, the program segment retrieves the sixth attribute of the record
with the ID 424111234 from the STUDENT file and sets a read-only lock on the
record. If the record is locked, the system displays the message “Record locked”. If
the record is found, the system transfers control to subroutine COURSE_PROCESS;
otherwise, the program aborts after printing the message “Record not found”.
425
READVL
SID = "424111234"
C_NO = 6 READVL COURSE_NO FROM STUDENT,SID,C_NO
LOCKED PRINT "Record locked"
THEN GOSUB COURSE_PROCESS:
ELSE PRINT "Record not found"
ABORT
END
Related Topics
READU
The UniBasic READU command retrieves a record from a file, assigns its value to a
dynamic array variable, and sets an exclusive lock on the record.
READVU
The UniBasic READVU command retrieves an attribute from a record, assigns its
value to a variable, and sets a lock on the record.
426
READVU
READVU
Syntax
READVU var FROM [file.var,] record.ID.expr, attribute.expr
[ON ERROR statements] [LOCKED statements] {THEN | ELSE} statements [END]
Description
The UniBasic READVU command assigns the data from a particular attribute of a
particular record in a file to a variable and sets an exclusive lock on the record.
The update lock stays in effect until you execute either a RELEASE or WRITE state-
ment; however, the commands WRITE, WRITEV, MATWRITE, READ, READV
and MATREAD ignore any record locks.
You can improve efficiency by using the READVU command when you need
Tip only one or two attributes from a record. If more attributes are necessary or to
update more attributes, use the READU or MATREADU commands.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READVU Parameters
427
READVU
Parameter Description
Examples
In the following example, the program statement reads the first attribute of record
SUPPL from the default system file. An update lock is set on this record.
READVU NAME FROM "SUPPL",1 ELSE NULL
In the next example, the program segment reads the seventh attribute of the record
named in the variable ID from the INV file and stores the attribute in the variable
SUPPL. If the record is locked or if the default file cannot be found, a read-error mes-
sage is displayed.
428
READVU
Related Topics
READV
The UniBasic READV command retrieves an attribute from a record and assigns its
value to a variable, ignoring all locks on the record.
READVL
The UniBasic READVL command retrieves an attribute from a record, assigns its
value to a variable, and sets a read-only lock on the record.
429
READXFWD
READXFWD
Syntax
READXFWD dyn.array.var [FROM file.var] [ON ERROR statements]
[THEN statements] ELSE statements
Description
The UniBasic command READXFWD reads forward one record in a B+tree alternate
key index, in much the same manner as the READFWD command, but does not return
a record. READXFWD allows a programmer to move forward through the database to
read alternate keys and record IDs without incurring the overhead of retrieving a
record every time.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READXFWD Parameters
430
READXFWD
Parameter Description
Related Commands
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READBCK
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index.
READXBCK
The UniBasic READXBCK command reads backward one record ID from a B+ tree
based alternate key index, without incurring the overhead of retrieving a record, as the
READBCK command does.
431
READXBCK
READXBCK
Syntax
READXBCK dyn.array.var [FROM file.var] [ON ERROR statements]
[THEN statements] ELSE statements
Description
The UniBasic command READXBCK reads backward one record in a B+tree alter-
nate key index, in much the same manner as the READBCK command, but does not
return a record. READXBCK allows a programmer to move backward through the
database to read alternate keys and record IDs without incurring the overhead of
retrieving a record every time.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
READXBCK Parameters
432
READXBCK
Parameter Description
Related Commands
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READBCK
The UniBasic READBCK command retrieves one record ID from a B+ tree based
alternate key index.
READXFWD
The UniBasic READXFWD command reads forward one record ID from a B+ tree
based alternate key index, without incurring the overhead of retrieving a record, as the
READFWD command does.
433
RECORDLOCKED( )
RECORDLOCKED( )
Syntax
RECORDLOCKED (file.var, rec.id.expr)
Description
The RECORDLOCKED function has been added to determine if a record has been
locked by a user. When UDT.OPTIONS 35 is ON, this function returns a value of -2,
indicating that another user has a READU lock. This means you can lock the same
record at a lower execute level.
Return
Description
Value
The STATUS function value is set to the user number of the user who has the lock,
unless the function returns 0 or an error value.
434
RECORDLOCKED( )
Parameters
The following table describes each parameter of the syntax:
Parameter Description
RECORDLOCKED() Parameters
435
RECORDLOCKL
RECORDLOCKL
Syntax
RECORDLOCKL [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements]
Description
The UniBasic RECORDLOCKL command sets a read-only lock on a record.
The read only lock allows other users to read the record but not write to the
Tip record. You may use the WRITE, WRITEV or MATWRITE statements to
write to the record when it is locked.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
RECORDLOCKL Parameters
436
RECORDLOCKL
Examples
In the following example, the program statement sets a read-only lock on the record
HOLY in the most recently opened default file. If the record is already locked by
another user, the program to waits until the record is released.
RECORDLOCKL "HOLY"
In the next example, the program segment sets a lock on the record with the ID Alice
from file CUSTOMER. If the record is locked, the system display the message “THE
RECORD IS ALREADY LOCKED”.
RECORDLOCKL CUSTOMER,"Alice"
LOCKED PRINT "THE RECORD IS ALREADY LOCKED"
Related Topics
FILELOCK
The UniBasic FILELOCK command locks a file against access by READL, READU,
READVU, and MATREADU statements.
FILEUNLOCK
The UniBasic FILEUNLOCK command unlocks a file previously locked by the a
FILELOCK statement.
RELEASE
The UniBasic RELEASE command unlocks a record previously locked.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
437
RECORDLOCKU
RECORDLOCKU
Syntax
RECORDLOCKU [file.var,] record.ID.expr [ON ERROR statements]
[LOCKED statements]
Description
The UniBasic RECORDLOCKU command sets an exclusive lock on a record, pre-
venting any other user or program from accessing the record.
Tip You can use the READ, MATREAD, READV, WRITE, MATWRITE, or
WRITEV to access a file that is locked.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
RECORDLOCKU Parameters
438
RECORDLOCKU
Examples
In the following example, the program statement sets an exclusive lock on the record
WELL in the most recently opened default file.
RECORDLOCKU "WELL"
In the next example, the program segment sets a lock on the record with the ID Won-
der from the CUSTOMER file. If the record is locked, the system displays the mes-
sage “THE RECORD IS ALREADY LOCKED”.
RECORDLOCKU "WELL" RECORDLOCKU CUSTOMER,"Wonder"
LOCKED PRINT "THE RECORD IS ALREADY LOCKED"
Related Topics
FILELOCK
The UniBasic FILELOCK command locks a file against access by READL, READU,
READVU, and MATREADU statements.
FILEUNLOCK
The UniBasic FILEUNLOCK command unlocks a file previously locked by a FILE-
LOCK statement.
RELEASE
The UniBasic RELEASE command unlocks a record previously locked.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
439
RELEASE
RELEASE
Syntax
RELEASE [file.var [, record.ID.expr]] [ON ERROR statements]
Description
The UniBasic RELEASE command unlocks records previously you have previously
locked.
Note If there are no current active locks, or if the file does not have any locks, or if
the record not locked, the RELEASE statement does not have any effect.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
RELEASE Parameters
Examples
In the following example, the program statement releases all update locks set by the
current program. All files opened by the user are affected.
440
RELEASE
RELEASE
In the next example, the program statement releases the record “COLO” in the file
CONTACTS. Other locked records in this file remain locked.
RELEASE CONTACTS,"COLO"
Related Topics
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
FILELOCK
The UniBasic FILELOCK command locks a file against access by READL, READU,
READVU, and MATREADU statements.
FILEUNLOCK
The UniBasic FILEUNLOCK command unlocks a file previously locked by the a
FILELOCK statement.
RECORDLOCKL
The UniBasic RECORDLOCKL command sets a read-only access lock on a record.
RECORDLOCKU
The UniBasic RECORDLOCKU command sets an exclusive lock on a record that
prevents any other user or program from accessing the record.
441
REMOVE
REMOVE
Syntax
REMOVE var FROM dyn.var [AT col.pos] SETTING delim.code
Description
The UniBasic REMOVE command removes successive elements from a dynamic
array and assigns the element to a variable. REMOVE does not change the value of
the dynamic array.
REMOVE searches a dynamic array for system substring delimiters. If the system
finds a delimiter, it assigns the contents of a string up to the delimiter to the variable.
The system removes both the substring and the delimiter from the dynamic array. A
pointer is maintained that holds the position of the last substring you remove, so that
successive REMOVE statements move progressively through a dynamic variable until
you reach the end of the dynamic array. When the system reaches the last element, the
delimiter code is set to zero and the process is complete.
Note In some implementations of BASIC, the zero position is taken as first posi-
tion. UniBasic takes the first position as 1. In general, this isn’t a problem
except where the program specifies the starting position other than the begin-
ning (such as when using the INDEX function).
Parameters
The following table describes each parameter of the syntax:
Parameter Description
REMOVE Parameters
442
REMOVE
Parameter Description
The SETTING clause assigns the variable delim.code a value based on the delimiter
code. The following table describes the values of the delimiter codes.
Delimiter ASCII
Description
Code Value
0 string end
1 record mark 255
2 attribute mark 254
3 value mark 253
4 subvalue mark 252
5 text mark 251
6 250
7 249
Examples
In the following example, the program segment processes the dynamic array string
CLIENT.
443
REMOVE
DIM VAR(5,2)
CLIENT = "G.Flaubert":@VM:"Guy":@SM:"12":@VM:"Yvette":@SM:"7"
FOR I = 1 TO 5
REMOVE VAR(I,1) FROM CLIENT SETTING VAR(I,2)
NEXT I
CLIENT = CLIENT;*reset REMOVE pointer
Notice how each pair in the array VAR becomes a substring and the delimiter that
defined it.
In the next example, the program segment starts at the beginning of the array
AMOUNTS and successively removes each INV.AMT from the array, calculates a
3.5% tax amount and adds it into the variable TAX.AMT. When MARK = 0 (the end
of the array), the LOOP is exited.
COL = 1
LOOP
REMOVE INV.AMT FROM AMOUNTS AT COL SETTING MARK
TAX.AMT += INV.AMT*.035
WHILE MARK DO REPEAT
In the next example, the program segment demonstrates the difference between Uni-
Basic and other implementations of BASIC.
ARRAY = "AB":@AM:"CD":@AM:"EF"
COL = 1
LOOP
REMOVE LINE FROM ARRAY AT COL SETTING MARK
PRINT LINE, COL, MARK
WHILE MARK REPEAT
In the next example, the program segment illustrates the efficiency of the REMOVE
statement versus the EXTRACT statement in terms of processing time.
444
REMOVE
MAINLINE
OPEN ’ ’, ’VOC’ TO VOC ELSE STOP ’CANNOT OPEN VOC FILE!’
READ ITEM FROM VOC, ’BIGTEST’ THEN
LINE.CNT = DCOUNT (ITEM, @AM)
PRINT "Bigtest in file VOC: "; LINE.CNT: " lines, ":
PRINT LEN(ITEM): "bytes."
GOSUB TIME.EXTRACT
GOSUM TIME.REMOVE
END ELSE
PRINT ’COULD NOT READ ITEM BIGTEST’
END
STOP
TIME.EXTRACT:
LINE.IDX = 1
START.TIME = TIME()
LOOP
UNTIL LINE.IDX LINE.CNT DO
LINE = ITEM<LINE.IDX>
LINE.IDX += 1
REPEAT
END.TIME = TIME()
PRINT "EXTRACT: ": OCONV(END.TIME-START.TIME, ’MTS’):
RETURN
TIME.REMOVE
START.TIME = TIME()
LOOP
REMOVE LINE FROM ITEM SETTING MORE.LINES
WHILE MORE.LINES DO
REPEAT END.TIME = TIME()
PRINT "REMOVE: ": OCONV(END.TIME-START.TIME, ’MTS’):
RETURN
445
REMOVE
REMOVE
Syntax
REMOVE(dyn.array.var, delim.var)
Description
The UniBasic REMOVE function returns a substring (delimited an item, attribute,
value, subvalue, or text mark) from a dynamic array, then assigns the substring to a
variable. REMOVE does not change the value of the dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
REMOVE Parameters
The following table describes the delimiter codes the REMOVE function returns.
Delimiter ASCII
Meaning
Code Value
0 string end
1 record mark 255
2 attribute mark 254
3 value mark 253
4 subvalue mark 252
446
REMOVE
Delimiter ASCII
Meaning
Code Value
Related Topics
REMOVE
The UniBasic REMOVE command gives you an alternate way to assign a dynamic
array’s successive substrings to a variable.
447
REPLACE
REPLACE
Syntax
REPLACE(dyn.array.expr, attrib.expr, val.expr, subval.expr, replace.expr)
Or:
dyn.array.expr<attrib.expr, val.expr, subval.expr> = replace.expr
Description
The UniBasic REPLACE function replaces data in a dynamic array with an expres-
sion according to a specified attribute, value, or subvalue in a dynamic array.
For instance, if an attribute, value, or subvalue evaluates to less than zero, the replace-
ment string is placed after the last attribute, value, or subvalue, as appropriate. If the
position given does not exist (attribute six specified in an array with two attributes, for
example), the necessary number of attribute, value, and subvalue marks are added in
order to create the specified position.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
REPLACE Parameters
448
REPLACE
Parameter Description
Examples
In the following example, the program statement replaces attribute 1 with the value in
the variable NAME.
CUST.REC = REPLACE(CUST.REC,1,0,0,NAME)
In the next example, the program statement replaces the first value of attribute 2 with
the value ‘220 W. 44TH’.
CUST.REC = REPLACE(CUST.REC,2,1,0,’220 W. 44TH’)
In the next example, the program segment replaces “Gone with the Mortgage”.
STG = "Movies":@AM:"The Sacrifice":@VM:"Gone with the Mortgage"
:@AM:"Rocky IV"
NEW.STG = REPLACE(STG,2,2,0,"Gone with the Wind")
PRINT NEW.STG
449
REPLACE
In the next example, the first REPLACE places Harry Smith in the first attribute posi-
tion. The second REPLACE places an array with two values in the fifth attribute.
CUST.REC =’’
CUST.REC = REPLACE(CUST.REC,1,0,01’Harry Smith’)
CUST.REC = REPLACE(CUST.REC,5,0,0,"v220":@VM:"v230")
Related Topics
DELETE
The UniBasic DELETE command deletes a record from a file.
INSERT
The UniBasic INSERT command inserts an expression with its delimiter before or
after an attribute, value, or subvalue mark in a dynamic array.
450
RESIZET
RESIZET
Syntax
RESIZET [UNIT(mu.expr)] expr [THEN statements] ELSE statements
Description
The UniBasic RESIZET command changes the block size the WRITET command
uses. When there is a variable length record, the record length is less than the block
length and the remaining portion of the block is filled as blanks.
Tip Use this command when the block size in one file is not the same as the block
size in T.ATT.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
RESIZET Parameters
451
RESIZET
Code Meaning
Examples
In the following example, the program segment changes the block size the WRITET
statement uses to the length of REC.
RESIZET LEN(REC) ELSE PRINT ’RESIZET ERROR’
WRITET REC ELSE PRINT ‘WRITET ERROR’
Related Topics
SETTAPE
For information on the ECL SETTAPE command, refer to UniData Commands
Reference.
T.ATT
For information on the ECL T.AT command, refer to UniData Commands Reference.
452
RETURN
RETURN
Syntax
RETURN [TO label[:]]
Description
The UniBasic RETURN command transfers program control from a subroutine back
to the calling program or subroutine.
If you do not specify a TO clause, control passes to the statement immediately follow-
ing the original GOSUB or CALL statement in the calling program or subroutine.
Note You may only use the TO clause with subroutines contained within the main
program; i.e., “internal” subroutines.
Examples
In the following example, the program segment returns the calling program if you
input Y.
PROMPT " "
PRINT "Begin procesing?":
GOSUB YES.NO.PROMPT
.
.
.
STOP
YES.NO.PROMPT
INPUT ANS, 1_
IF ANS = ’Y’ THEN ANS = ’Y’ ELSE ANS = ’N’
RETURN
Related Topics
CALL
The UniBasic CALL command transfers program control to an external subroutine,
either from the main program or from another subroutine
GOSUB
The UniBasic GOSUB command transfers program control to an internal subroutine.
453
REUSE
REUSE
Syntax
REUSE(dyn.array.expr)
Description
The UniBasic REUSE function causes the last element of a dynamic array to be
repeated until the number of array elements match if the dynamic array is shorter than
another array with which you multiply, add, or subtract it to.
If you do not use the REUSE function, the array is extended with either 1s or 0s,
depending on the operation: for division, a the system uses a one; in all other opera-
tions (addition, subtraction, and multiplication), the system uses a zero.
Examples
In the following example, the program segment multiplies the arrays without using the
REUSE function.
VIEWERS = 100:@VM:200:@VM:300
COST = 40:@VM:1
VCOST = VIEWERS*COST
VCOST becomes the same length as the longest of the two arrays used in the opera-
tion. The final value is a result of the array COST extended with a zero value; how-
ever, if you use the REUSE function:
VCOST = VIEWERS*REUSE(COST)
454
REWIND
REWIND
Syntax
REWIND [UNIT(mu.expr)] {THEN | ELSE} statements [END]
Description
The UniBasic REWIND command rewinds the tape back to its beginning.
Reminder Before you can use the REWIND command, you must reserve a tape drive for
use with the T.ATT command. For information on ECL T.ATT, refer to
UniData Commands Reference.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
REWIND Parameters
455
REWIND
Code Meaning
Examples
In the following example, the program segment first uses the ECL T.ATT command
to reserve the tape unit 0 with no conversion code. Then a routine is performed that
reads all the records on the tape (until the end of the file or the end of the tape) and
calls an internal subroutine that processes the record. After the process is finished, the
REWIND command rewinds the tape.
PERFORM "T.ATT DO"
DONE = 0
LOOP
READT UNIT (00) TAX.RECORD ELSE DONE = 1
UNTIL DONE DO
GOSUB PROCESS.RECORD
REPEAT REWIND UNIT (00) ELSE PRINT ’REWIND UNSUCCESSFUL’
Related Topics
READT
The UniBasic READT command assigns the next record from a magnetic tape device
to a variable.
Tape Commands
For information on the ECL tape commands (i.e., T.ATT), refer to UniData
Commands Reference.
456
RND
RND
Syntax
RND(num.expr)
Description
The UniBasic RND function returns a random integer within the range 0 to
(num.expr - 1).
Examples
In the following example, the program statement prints a random number anywhere
from 0 to 9.
PRINT RND(10)
Related Topics
RNDSEED
The UniBasic RNDSEED command generates the same sequence of random numbers
each time you run a program
457
RNDSEED
RNDSEED
Syntax
RNDSEED expr
Description
The UniBasic RNDSEED command allows you to “seed” the pseudo random number
generator. The RND function gives you a different sequence of numbers each time.
RNDSEED generates the same sequence of random numbers each time you run a pro-
gram.
expr may be any string expression evaluating to a seed point. If you use the same expr,
the sequence of random numbers the system generates with the RND function is the
same.
Related Topics
RND
The UniBasic RND function returns a random integer.
458
SADD
SADD
Syntax
SADD(x, y)
Description
The UniBasic SADD function adds two string numbers and returns the result as a
string number. SADD is the string addition function. Arguments may be any valid
numbers or string numbers of any magnitude and precision.
Tip Using string numbers rather than standard numbers degrades processing
speed.
If either x or y contains non-numeric data, the system displays an error message and
returns a result of 0.
The SADD function results in a string number, so you can use the function in any
expression in which a string number is valid. Since string numbers may exceed the
range of numbers that standard arithmetic operators can accommodate, you may not
want to use the SADD function in any expression in which a standard number is valid.
Note The result of the SADD function may not exceed the maximum allowable
number determined by your hardware.
Examples
In the following example, the program statement assigns to variable B the sum of the
string constant (1.4149) and variable A.
B = SADD("1.4149",A)
459
SCMP
SCMP
Syntax
SCMP(x, y)
Description
The UniBasic SCMP function compares two string numbers and returns a value
depending upon the result of the comparison. SCMP is the string comparison function.
Arguments may be any valid numbers or string numbers of any magnitude and preci-
sion. If either x or y contains non-numeric data, the system displays an error message;
the comparison results in zero. The following table describes the values SCMP
returns.
x<y -1
x=y 0
x>y 1
Using string numbers rather than standard numbers slows processing speed.
Tip
Examples
In the following example, the program segment compares FA to FB. If the result of
the IF statement is true (the SCMP function returns 1), the system executes the PRINT
statement.
IF SCMP (FA,FB) GT 0 THEN
PRINT A:" IS GREATER THAN ":B
460
SDIV
SDIV
Syntax
SDIV(x, y)
Description
The UniBasic SDIV function divides two string numbers and returns the result as a
string number. SDIV divides x by y. Arguments may be any valid numbers or string
numbers of any magnitude and precision; however, result precision is limited to 14
significant digits.
If either x or y contains non-numeric data, the system displays an error message; the
division results in 0. If y is equal to 0, the system displays an error message stating that
division by 0 is illegal and returns a result of 0.
The SDIV function results in a string number, so you can use the function in any
expression in which a string number is valid. Since string numbers may exceed the
range of numbers that standard arithmetic operators can accommodate, you may not
want to use the SDIV function in any expression in which a standard number is valid.
Examples
In the following example, the program statement divides the constant (1.4149) by
variable A and assigns the result to variable B.
B = SDIV("1.4149",A)
461
SELECT
SELECT
Syntax
SELECT file.var [TO {list.num.expr | list.var.expr}] [ON ERROR statements]
SELECT dyn.array [TO {list.num.expr | list.var.expr}] [ON ERROR statements]
Description
The UniBasic SELECT command creates a list of all record IDs in a file. Records
appear in the list in the order they were originally stored.
You may access the list you create with a SELECT statement with a READNEXT
statement.
The UniBasic SELECT command functions differently than the ECL SELECT com-
mand. The UniBasic SELECT makes one group of IDs at a time available to a READ-
NEXT statement immediately after the SELECT statement without having to wait for
the whole ID list to be available.
Note If changes occur in a group that has not been selected yet, those changes are
reflected in the program; (i.e., if an you delete an ID before the group is
selected and processed in the UniBasic program, that ID will not appear in the
list).
462
SELECT
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SELECT Parameters
When using the ECL SELECT command, SYSTEM(11) returns the number of items
remaining in the list. With the UniBasic SELECT command, SYSTEM(11) returns
the number of items remaining in the group.
Examples
In the following example, the program statement creates a list of all record IDs in the
CUSTOMER file.
SELECT CUSTOMER
In the next example, the program segment creates a list of all IDs in the file TAPES
and assigns the ID list to list number 1, it then uses the READNEXT command to read
463
SELECT
the IDs from the list sequentially, executing a subroutine, PROCESS.TAPES, each
time.
SELECT TAPES TO 1
LOOP
READNEXT TAPE.ID FROM 1 ELSE TAPE.ID = " "
WHILE TAPE.ID
GOSUB PROCESS.TAPES
REPEAT
Related Topics
SELECT
For information on the UniQuery SELECT Command, refer to UniData Commands
Reference.
464
SELECTINDEX
SELECTINDEX
Syntax
SELECTINDEX index.name.expr[, key.val.expr] FROM file.var [TO list.num.expr]
Description
The UniBasic SELECTINDEX command creates select lists based on alternate key
indices. SELECTINDEX has two forms: the first form selects by alternate key index,
the second form selects by alternate key value.
If the index name does not exist, the select list is empty and the STATUS function
returns 1; if the index name does exist, STATUS returns 0.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SELECTINDEX Parameters
Examples
In the following example, SELECTINDEX uses the alternate key index “LNAME”
and creates a list of all the last names contained in the STUDENT file.
SELECTINDEX "LNAME" FROM STUDENT
465
SELECTINDEX
In the next example, SELECTINDEX uses the alternate key value “SMITH” and cre-
ates a list of all occurrences of SMITH contained in the STUDENT file.
SELECTINDEX "LNAME", "SMITH" FROM STUDENT
Related Topics
INDICES
The UniBasic INDICES function returns either the names of alternate key indices, or
information about a particular alternate key index.
466
SELECTINFO
SELECTINFO
Syntax
SELECTINFO([list.num.expr,] code.expr)
Description
The UniBasic SELECTINFO function returns the state of a select list. list.num.expr
is an expression evaluating to the number of the select list (0-9). code.expr is an
expression evaluating to the type of information you want. The SELECTINFO
key is 1.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SELECTINFO Parameters
Value Description
467
SEND
SEND
Syntax
SEND[X] expr[:expr2...] [:] TO line.expr {THEN | ELSE} statements [END]
Description
The UniBasic SEND command sends output data to a specified line. You usually use
SEND after a line is attached by the sending environment.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SEND Parameters
468
SEND
Parameter Description
Note SEND with the X option suppresses the output of a pair > (return/line feed);
however SENDX does not allow the quotation marks and the colon (‘:’) to
exist as part of syntax, although it is implied.
Examples
In the following example, the program statement sends the string to line 0 unless line 0
is not attached by the current environment. If the line 0 is not attached by the current
environment, the system displays the message, “Line not attached”.
SEND BEGIN_TRANSMISSION TO 0
ELSE PRINT "Line not attached"
In the next example, the program statement converts the string to HELLO WORLD
before sending it to line zero.
TESTVAR = "48454C404F WORLD"
SENDX TESTVAR TO 0 ELSE PRINT "Line not attached"
Related Topics
GET
The UniBasic GET command receives unprompted input from an attached line.
PROTOCOL
The ECL PROTOCOL command sets data line transmission characteristics and proto-
cols for a specified line. For information on PROTOCOL, refer to UniData
Commands Reference.
469
SEQ
SEQ
Syntax
SEQ(“char.expr”)
Description
The UniBasic SEQ function converts the character expression to a single ASCII code
value. The SEQ function is the complement of the CHAR function.
Examples
In the following example, the program statement prints the ASCII code corresponding
to the character “#” (in this case, 35).
PRINT SEQ("#")
Related Topics
CHAR
The UniBasic CHAR function changes ASCII numeric data to a character expression.
470
SEQS
SEQS
Syntax
SEQS(“char.expr”)
Description
The UniBasic SEQS function converts the character expressions in each element of a
dynamic array to a single ASCII code value.
Examples
In the following example, the program statement prints the ASCII code corresponding
to the value in each element of the dynamic array ARR1. The result is 65}66}67}68.
ARR1 = "A":@AM:"B":@AM:"C":@AM:"D"
PRINT SEQS(ARR1)
Related Topics
CHARS
The UniBasic CHARS function changes ASCII numeric data in each element of a
dynamic array to a character expression.
471
SETINDEX
SETINDEX
Syntax
SETINDEX index.name.expr [, [rop] key.val.expr [, id.expr]] [ON file.var]
Description
The UniBasic SETINDEX command initializes a key in an alternate key index.
Note You are only allowed to have the current alternate key value for one index of
a file at a time, even though the number of indices on a file is unlimited. Each
time you use SETINDEX, the current value is set to one in the new index and
the subsequent READFWD/READBCK statement reads the record associated
with the alternate key values in the new index.
STATUS() Values
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SETINDEX Parameters
472
SETINDEX
Parameter Description
The following table describes the valid rop operators. If you do not specify rop, the
default is EQ.
SETINDEX Operators
Tip The system uses and maintains this value for the READBCK, READFWD,
and related statements. Normally, you should use LT, LE, or
473
SETINDEX
Examples
In the following example, the program segment sets the pointer at the first occurrence
of the data element containing ‘Miller’ and is described by the dictionary item,
‘LNAME’.
OPEN ' ', 'CUSTOMER' TO tmp
ELSE STOP
SETINDEX 'LNAME', 'Miller' ON tmp
Related Topics
READFWD
The UniBasic READFWD command retrieves one record ID from a B+ tree based
alternate key index.
READBCK
The UniBasic READBCK command retrieves on record ID from a B+ tree based
alternate key index.
474
SETTABLE
SETTABLE
Syntax
SETTABLE [NEXT | table.no [RELATIVE | ABSOLUTE]] ON connection
[ON ERROR statements]
Description
The UniBasic SETTABLE command makes the specified table the current table in
the current result set. The result set is a set of tables returned when UniData executes a
batch of commands. For each command in a batch, the server returns a result table.
The number of tables in the result set is equal to the number of commands in the batch.
You can only move forward in the result set. You cannot move to a table number less
than the current one.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the SETTABLE statement, STATUS is set to one of the follow-
ing:
0 Success
1 The server is not connected
2 Other errors
475
SETTABLE
Parameters
The following table describes each parameter of the syntax:
Parameter Description
[NEXT | table.no] NEXT makes the next table in the result set
the current table. table.no makes a specified
table number in the result set the current table.
[RELATIVE | RELATIVE specifies that table.no is relative
ABSOLUTE] to the position of the current table in the result
set. ABSOLUTE specifies that table.no is
unrelated to the position of the current table in
the result set. It is relative to where the table is
in the result set.
ON connection Specifies the handle to a server you specified
with the CONNECT command.
[ON ERROR statements] The ON ERROR clause allows the program to
continue to perform if the SETTABLE state-
ment fails. It then executes the statements you
specify.
SETTABLE Parameters
476
SETROW
SETROW
Syntax
SETROW [{NEXT | [PREVIOUS | PRIOR] | CURRENT} row.num
{RELATIVE | ABSOLUTE}] ON connection [ON ERROR statements]
Description
The UniBasic SETROW command sets the specified row to the current row in the
current table. You can go back up to 1000 rows from the current row.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the SETROW statement, STATUS is set to one of the
following:
0 Success
1 The server is not connected
2 Position is out of bounds
3 Other error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SETROW Parameters
477
SETROW
Parameter Description
478
SIN
SIN
Syntax
SIN(num.expr)
Description
The UniBasic SIN function returns the trigonometric sine of the numeric expression
num.expr.
Examples
In the following example, the program segment assigns the sine of the number 25 to
the variable SIN.X. In this case .4226.
X = 25
SIN.X=SIN(X)
In the next example, the program statement prints 1.0000, the sine of 90.
PRINT SIN(90)
479
SLEEP
SLEEP
Syntax
SLEEP [hh:mm[:ss]] [seconds]
RQM [hh:mm[:ss]] [seconds]
Description
The UniBasic SLEEP and RQM commands halt program execution for the time
specified in seconds, or until the time you specify.
Tip You may use SLEEP or RQM to have a processing or reporting program wait
until midnight before running in order to better use your system resources.
SLEEP is also useful when waiting for the release of locked system resources.
Reminder The original purpose of RQM was to release remaining execution time
reserved for a program, allowing other programs to use the time. If a particu-
lar program is very computation-intensive, RQM may improve overall system
performance.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SLEEP Parameters
Examples
In the following example, the program statement halts program execution for ten sec-
onds.
SLEEP 10
In the next example, the program statement suspends program execution until 11:45
PM.
SLEEP 23:45
480
SLEEP
In the next example, the program statement halts program execution for one second.
SLEEP
481
SMUL
SMUL
Syntax
SMUL(x, y)
Description
The UniBasic SMUL function multiplies two string numbers and returns the result as
a string number. SMUL is the string multiplication function. Arguments may be any
valid numbers or string numbers of any magnitude and precision. Using string num-
bers rather than standard numbers degrades processing speed.
If either x or y contains non-numeric data, the system displays an error message and
returns a result of zero.
Note The SMUL function results in a string number, so you can use the function in
any expression in which a string number is valid. Since string numbers may
exceed the range of numbers that standard arithmetic operators can accommo-
date, you may not want to use the SMUL function in any expression in which
a standard number is valid.
Examples
In the following example, the program statement multiplies the constant (1.4149) by
variable A and assigns the result to variable B.
B = SMUL("1.4149",A)
482
SOUNDEX
SOUNDEX
Syntax
SOUNDEX(expr)
Description
The UniBasic SOUNDEX function converts an expression into a phonetic code. You
may use it to compare alphabetic strings, such as names, where alternate spelling or
misspelling should not cause a mismatch. expr is an expression evaluating to a string
value.
SOUNDEX evaluates the expression by:
• Returning the first alphabetic letter.
• Converting the remainder of the string to uppercase.
• Ignoring letters A, E, H, I, O, U, W, Y, and non-alphabetic characters.
• Converting each valid letter to a phonetic code.
• Testing for duplication. If a character is next to another character that has
the same phonetic code, it is not included.
• Adjusting the length of the code to four characters by truncating codes
longer than four characters or padding zeros to any expression less than
four characters long.
The following table shows SOUNDEX sample output values:
Expression SOUNDEX
STEPHEN S315
STEVEN S315
TERMINATE T655
RRR R600
483
SOUNDEX
The following table displays the phonetic code for each letter that UniData evaluates.
Code Letters
1 BFPV
2 CGJKQSXZ
3 DT
4 L
5 MN
6 R
484
SPACE
SPACE
Syntax
SPACE(expr)
Description
The UniBasic SPACE function returns the number of spaces you specify with expr in
string form.
Reminder Functions may appear within PRINT statements, if concatenated with the
proper operator.
Examples
In the following example, the program statement prints HI and THERE separated by
15 spaces.
PRINT "HI":SPACE(15):"THERE"
485
SPACES
SPACES
Syntax
SPACES(dyn.array.expr)
Description
The UniBasic SPACES function returns the number of spaces each element of the
dynamic array dyn.array.expr contains.
Examples
In the following example, the program segment prints the number of spaces each ele-
ment of the dynamic array ARR1 contains.
ARR1 = 1:@AM:2:@AM:3:@AM:4:@AM:5
ARR2 = SPACES(ARR1)
This results in ARR2 containing one space in the first element, two spaces in the sec-
ond element, etc.
486
SPLICE
SPLICE
Syntax
SPLICE(expr1,“expr”, expr2)
Description
The UniBasic SPLICE function concatenates two strings or arrays and inserts an
expresion between them.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SPLICE Parameters
Examples
In the following example, the program segment concatenates PHONE to NUMBER
and inserts a dash (-) in between the two strings.
PHONE = "555"
NUMBER = "1234"
PRINT SPLICE (PHONE,"-",NUMBER)
In the following example, the program segment concatenates each element of array
ARR1 to array ARR2 and inserts a plus sign (+) in-between the two elements.
ARR1 = 1:@AM:2:@AM:3
ARR2 = 4:@AM:5:@AM:6
PRINT SPLICE (ARR1,"+",ARR2)
487
SQUOTE
SQUOTE
Syntax
SQUOTE(str.expr)
Description
The UniBasic SQUOTE function encloses a string, (regardless of its contents) with
single quotes.
Examples
In the following example, the program statement prints ‘This is ‘a’ test’ on screen.
PRINT SQUOTE("This is ’a’ test")
In the next example, the program segment prints ‘This is another test’
X = "This is another test"
PRINT SQUOTE(X)
Related Topics
QUOTE
The UniBasic QUOTE function encloses an expression with quotes.
488
SQRT
SQRT
Syntax
SQRT(num.expr)
Description
The UniBasic SQRT function returns the square root of a positive numeric argument.
Examples
In the following example, the program statement prints SQUARE ROOT OF 16 IS 4.
PRINT "SQUARE ROOT OF 16 IS ":SQRT(16)
489
SSUB
SSUB
Syntax
SSUB(x, y)
Description
The UniBasic SSUB function subtracts the second string number from the first string
number and returns the result as a string number. SSUB is the string subtraction func-
tion. Arguments may be any valid numbers or string numbers of any magnitude and
precision.
If either x or y contains non-numeric data, the system displays an error message and
returns a result of zero.
The SSUB function results in a string number, so you can use the function in any
expression in which a string number is valid. Since string numbers may exceed the
range of numbers that standard arithmetic operators can accommodate, you may not
want to use the SSUB function in any expression in which a standard number is valid.
Examples
In the following example, the program statement assigns to variable B the difference
of the string constant (1.4149) and variable A.
B = SSUB("1.4149",A)
490
STATUS
STATUS
Syntax
STATUS( )
Description
The UniBasic STATUS function returns a value that specifies the condition of the
command you just executed.
Each command has a unique set of values it returns for the STATUS function. For
information on the values a particular command returns, refer to the documentation
for that command.
Examples
In the following example, the STATUS function returns a value of 0, indicating a suc-
cessful conversion of a valid date. STATUS would return a 1 if 7334 is an invalid
input date or would return a 2 if D is an invalid conversion specification.
PRINT OCONV(7334,"D")
PRINT STATUS
491
STOP
STOP
Syntax
STOP [expr]
Description
The UniBasic STOP command halts execution of the current program. If you specify
an expression, the system prints the expression on the display terminal prior to halting
the program. expr may be any expression that contains variables, functions, and arith-
metic or string operators.
STOP returns to the UniData prompt, calling menu, or calling paragraph depending on
how you executed the program.
The ABORT command returns you to the system level regardless of what pro-
Tip cess initiated the program.
STOP [message-id]
STOP [expr,...]
The message-id must evaluate to a key contained in the system error message
file. ERRMSG file. expr may be any expression that contains variables, func-
tions, and arithmetic or string operators.
Examples
In the following example, the program segment attempts to read a record from a file.
If the record does not exist, the program aborts and prints the message RECORD IS
MISSING at line 10, column 10 on the terminal.
CUST.ID = 1234
OPEN ’’, ’CUSTOMER’ READONLY TO CUSTOMER ELSE STOP "Cannot Open"
READ REC FROM CUSTOMER, CUST.ID ELSE
STOP @(10,10):’RECORD IS MISSING’
END
In the next example, the segment prints a prompt if an error flag ERR.FLAG has been
set and reads the user’s input into the variable ANS. If ANS equals Y, the program
stops.
492
STOP
ERR.FLAG = 1
IF ERR.FLAG THEN
PRINT "STOP PROGRAM?"
INPUT ANS
IF ANS = "Y" THEN STOP
END
In the next example, in BASICTYPE P, the program segment prints an error message
from record 10075 in the ERRMSG FILE if the program aborts.
If A < 0 THEN ABORT 10075
Related Topics
ABORT
The UniBasic ABORT command terminates the program in progress and returns you
to the UniData system level.
PRINTERR
The UniBasic PRINTERR command prints error messages stored in either the system
error message file ERRMSG or the user-defined error message file.
493
STR
STR
Syntax
STR(str.expr, num.expr)
Description
The UniBasic STR function returns a string composed of a number of repetitions of a
string.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
STR Parameters
Examples
In the following example, the program statement prints a string of 25 hyphen charac-
ters on the user’s terminal.
PRINT STR("-",25)
494
STRS
STRS
Syntax
STRS(dyn.array.expr)
Description
The UniBasic STRS function returns the each element of the dynamic array dyn.array
the number of times you specify with expr.
Examples
In the following example, the program segment prints the each element of the
dynamic array ARR1 ten times.
ARR1 = 1:@AM:2:@AM:3:@AM:4:@AM:5
ARR2 = STRS(ARR1,10)
PRINT ARR2
495
SUBROUTINE
SUBROUTINE
Syntax
SUBROUTINE sub.name [(argument1 [, argument2] ...)]
Description
The UniBasic SUBROUTINE command determines the beginning of an external
subroutine.
The SUBROUTINE statement must be the first non-comment line in a subroutine.
You can specify arguments to pass data between the main program and the subroutine.
If you pass arguments, the number of arguments in the CALL statement and the SUB-
ROUTINE statement must match. Variables you pass between a main program and
subroutine need not have the same names. Changes made to arguments in the subrou-
tine retain their new values when the system exits the subroutine and control reverts to
the calling program.
Note All subroutines must be cataloged using the ECL CATALOG command prior
to being called. For further information on the CATALOG command, refer to
UniData Commands Reference.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SUBROUTINE Parameters
Examples
In the following example, the main program prompts the user for two numbers. These
are sent to the subroutine COMP, together with an empty variable C. COMP, using
unique variable names, calculates the average, returning the value in the third variable.
496
SUBROUTINE
Related Topics
CALL
The UniBasic CALL command transfers program control to an external subroutine,
either from the main program of from another subroutine.
PROGRAM
The UniBasic PROGRAM command defines the name of the current main program
for documentation purposes.
CATALOG
For information on the ECL CATALOG command, refer to UniData Commands
Reference.
497
SUBSTRINGS
SUBSTRINGS
Syntax
SUBSTRINGS(dyn.array, num.expr1, num.expr2)
Description
The UniBasic SUBSTRINGS function extracts strings from elements within a
dynamic array.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SUBSTRINGS Parameters
Examples
In the following example, the program segment extracts the first character of each ele-
ment of the dynamic array LASTNAMES.
LASTNAMES = "Smith":@AM:"Jones":@AM:"Johnson":@AM:"Howard"
LINITIAL = SUBSTRINGS("LASTNAMES",1,1)
PRINT LINITIAL
498
SUM
SUM
Syntax
SUM(dyn.array [, <attribute.expr [, value.expr]>] [, start.expr [, stop.expr]])
Description
The UniBasic SUM function adds the numeric values in the dynamic array dyn.array
according to dynamic array delimiters. SUM begins with the lowest level of delimiter
and sums all values to the next level.
The UniBasic SUM function has new extensions that allow you to input a range, start-
ing position, and level for which to perform the sum. (3.1.5)
Parameters
The following table describes the parameters of the SUM command:
Parameter Description
SUM Parameters
Examples
In the following example, the program segment begins with an array of two values,
each with two subvalues. The SUM function sums the subvalues and returns a string
with two numeric values.
NUM.ARRAY = 12:@SM:10:@VM:15:@SM:15
VAL1 = SUM(NUM.ARRAY)
Results in:
VAL1 = 22:@VM:30
499
SUM
In the next example, the program statement sums VAL1 and returns the numeric value
52 with no dynamic array delimiters.
VAL1 = SUM(VAL1)
500
SWAP
SWAP
Syntax
SWAP str.expr1 WITH str.expr2 IN var
Description
The UniBasic SWAP command replaces all occurrences of one string in a variable
with a second string. The search string does not have to be the same length as the
replacement string.
Tip SWAP functions like CONVERT but swaps one string for another.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
SWAP Parameters
Examples
In the following example, the program segment replaces all occurrences of the string
“AB” with the string “AZ” in the variable VAR. The new string assigned to VAR is
“THE TAZ WAS GRAZBED”.
VAR = "THE TAB WAS GRABBED"
SWAP "AB" WITH "AZ" IN VAR
In the next example, SWAP does not replace a character with a character but a string
with a string. This results in HARRY BELAFONTE printing.
STRING = ‘MARION BELAFONTE’
SWAP ‘MARION’ WITH ‘HARRY’ IN STRING
PRINT STRING
501
SWAP
Related Topics
CONVERT
The UniBasic CONVERT command changes all occurrences of characters in a string
to other characters.
502
SYSTEM
SYSTEM
Syntax
SYSTEM(expr)
Description
The UniBasic SYSTEM function retrieves certain system level parameters set either
by previous UniBasic statements or by ECL commands such as SETPTR, TERM, and
query statements.
Note The SYSTEM function is similar to the STATUS function and to several of
the @variables feature in Appendix B @variables. The values of the SYS-
TEM function after the execution of UniBasic command are the same as the
values of the STATUS function under the same condition.
Parameters
expr must evaluate to a number from 0 to 16. If you specify zero, then the value of
SYSTEM is determined by a previously executed UniBasic command. If you select a
number is from 1 to 16, then the system corresponds to predefined system parameters
as described in the following table:
Parameter Description
SYSTEM Parameters
503
SYSTEM
Parameter Description
504
SYSTEM
Parameter Description
Examples
In the following example, the program segment turns on the printer if data is currently
being sent to the display terminal.
IS.ON = SYSTEM(1)
IF IS.ON = 0 THEN
PRINT ’TURNING THE PRINTER ON’
PRINTER ON
END
505
TAN
TAN
Syntax
TAN(num.expr)
Description
The UniBasic TAN function returns the trigonometric tangent of a numeric expres-
sion num.expr.
Examples
In the following example, the program statement prints .2679, the tangent of the argu-
ment 15.
PRINT TAN(15)
506
TIME
TIME
Syntax
TIME( )
Description
The UniBasic TIME function returns the internal system time of day, expressed as the
number of seconds elapsed since midnight.
Examples
In the following example, the program statement prints the current internal system
time of day. If the time is 1:01 A.M., the system prints the value 3660, the number of
seconds since midnight.
PRINT TIME()
In the next example, the TIME function is used in conjunction with the OCONV func-
tion for conversion to an “external” format:
PRINT OCONV(TIME(),"MT")
Related Topics
DATE
The UniBasic DATE function returns the current system date in internal format.
TIMEDATE
The UniBasic TIMEDATE function returns a string representation of the current sys-
tem time and date in external form.
507
TIMEDATE
TIMEDATE
Syntax
TIMEDATE( )
Description
The UniBasic TIMEDATE function returns a string representation of the current sys-
tem time and the date in external form.
The format the TIMEDATE function returns is:
hh:mm:ss dd mmm yyyy
Examples
In the following example, the program statement assigns the string representation of
the current system time and date to the variable TSTRING.
TSTRING = TIMEDATE()
If the current time and date is July 1st, 1991, at 11:45 AM, TSTRING is:
"11:45:00 01 JUL 1991"
Related Topics
DATE
The UniBasic DATE function returns the current system date in internal format.
TIME
The UniBasic TIME function returns the internal system time of day, expressed as the
number of seconds elapsed since midnight.
508
TRANSACTION ABORT
TRANSACTION ABORT
Syntax
TRANSACTION ABORT
Description
The UniBasic TRANSACTION ABORT command cancels the active transaction.
UniData discards the pending writes. As a result, other users never know that a trans-
action was in progress, and none of the updates associated with the transaction take
place.
A transaction may abort due to any of several conditions in addition to the
TRANSACTION ABORT statement. They include:
• A program that finishes before a transaction commit is issued (STOP or
END).
• A CHAIN to another program.
• An error that terminates the program before a transaction commit is
issued.
• A user breaks out of the program before a transaction commit is issued.
This can be controlled programmatically by disabling the break key dur-
ing a transaction.
• A forced logout or a process is killed, thereby terminating a program
before a transaction commit is issued.
The system handles these abort conditions in the same way as the TRANSACTION
ABORT statement, i.e., it cancels the transaction.
Tip You should be aware of these various abort conditions and control the result-
ing action from within the program where possible and appropriate. For
example, write statements that fail execute the ON ERROR clause if it exists,
otherwise the program aborts and the transaction also aborts.
509
TRANSACTION ABORT
Examples
In the following example, the transaction process will abort if var is a null.
TRANSACTION START
THEN PRINT "Transaction started."
ELSE PRINT "Transaction start failed, STATUS = ":STATUS(): STOP
READU var FROM file.var, record1
var += 2
IF var = 10 THEN TRANSACTION ABORT; GOTO ERR:
WRITE var TO file.var, record1
TRANSACTION COMMIT
THEN PRINT "Transaction committed."
ELSE PRINT "Transaction Aborted, STATUS = ":STATUS(); STOP
510
TRANSACTION COMMIT
TRANSACTION COMMIT
Syntax
TRANSACTION COMMIT [THEN statement(s)] [ELSE statement(s)]
Description
The UniBasic TRANSACTION COMMIT command concludes the active transac-
tion. UniData writes all pending writes to the appropriate files. If a TRANSACTION
COMMIT statement executes without an active transaction, the system executes the
ELSE clause, otherwise the system executes the THEN clause. You must specify a
THEN or an ELSE clause. You may specify both clauses.
The system performs the following steps during a transaction commit:
• Disables the break key
• Writes all updates
• Releases all record locks locked inside the transaction
• Executes the THEN clause, if it exists
• Enables the break key
If the transaction cannot commit and the ELSE clause executes, the system performs
the following steps:
• Aborts the transaction
• Executes the ELSE clause, if it exists
• Releases all record locks inside the transaction
STATUS Values
The following table describes the values the UniBasic STATUS function returns when
you use it with the TRANSACTION COMMIT command:
Value Description
STATUS Values
511
TRANSACTION COMMIT
Value Description
Examples
In the following example, the TRANSACTION COMMIT command ends the transac-
tion process and writes the new record to the database.
TRANSACTION COMMIT
THEN PRINT "Transaction committed."
ELSE PRINT "Transaction aborted, STATUS = ":STATUS(); STOP
512
TRANSACTION START
TRANSACTION START
Syntax
TRANSACTION START [THEN statement(s)] [ELSE statement(s)]
Description
The UniBasic TRANSACTION START command initiates a new transaction and
temporarily stores all updates until a TRANSACTION COMMIT or TRANSAC-
TION ABORT statement. A transaction start that you issue when another transaction
is active (nested transactions) executes the ELSE clause, if present, and the associated
statements. Otherwise, the system executes the THEN clause, if present, and the asso-
ciated statements. You must specify a THEN or an ELSE clause. You may specify
both clauses.
Parameters
The following table describes the parameters:
Parameter Description
STATUS Values
The following table describes the values the UniBasic STATUS function returns when
you use it with the TRANSACTION START command:
Value Description
STATUS Values
513
TRANSACTION START
Value Description
Note For information on the STATUS function, refer to the Developing UniBasic
Applications.
Examples
In the following example, the TRANSACTION START command starts the transac-
tion process:
TRANSACTION START
THEN PRINT "Transaction started."
ELSE PRINT "Transaction start failed, STATUS = ":STATUS();STOP
514
TRIM
TRIM
Syntax
TRIM(str.expr[,char[,type]])
Description
The UniBasic TRIM function removes any spaces from a string expression. If the sys-
tem does not find any spaces, the string remains unchanged.
TRIM removes any leading or trailing spaces from a string and converts any contigu-
ous spaces in a string to one space. Single blanks between text are not removed.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
TRIM Parameters
You may also specify the type of removal to perform. The following table describes
each type of removal.
Type Description
TRIM Types
515
TRIM
Type Description
Examples
In the following example, the program statement removes the trailing blanks from the
variable NAME.
NAME = " Zenith, R. "
NAME = TRIM(NAME)
This results in
NAME = "Zenith,R."
In the next example, the program segment removes the asterisks from the variables X
and Y in BASICTYPE P.
X = TRIM("***NOT***ICE***","*")
Y = TRIM("***NOT***ICE***","*","A")
Related Topics
TRIMB
The UniBasic TRIMB function deletes any trailing blanks of a string.
TRIMF
The UniBasic TRIMF function deletes any leading blanks of a string.
516
TRIMB
TRIMB
Syntax
TRIMB(str.expr)
Description
The UniBasic TRIMB function removes any trailing spaces from a string expression.
If the system does not find any trailing spaces, the string remains unchanged.
Examples
In the following example, the program statement removes the trailing blanks from the
variable NAME.
NAME = " Zenith, R. "
NAME = TRIMB(NAME)
Related Topics
TRIM
The UniBasic TRIM function removes any leading, trailing, or contiguous spaces in a
string.
TRIMF
The UniBasic TRIMF function removes any leading spaces in a string.
517
TRIMF
TRIMF
Syntax
TRIMF(str.expr)
Description
The UniBasic TRIMF function removes any leading spaces from the string expres-
sion. If the system does not find any leading spaces, the string remains unchanged.
Examples
In the following example, the program segment removes the leading spaces from the
variable NAME, storing the resulting string.
NAME= " Zenith, R. "
NAME = TRIMF(NAME)
Related Topics
TRIM
The UniBasic TRIM function removes any leading, trailing, or contiguous spaces in a
string.
TRIMB
The UniBasic TRIMB function removes any trailing spaces in a string.
518
TRIMS
TRIMS
Syntax
TRIMS(dyn.array)
Description
The UniBasic TRIMS function removes any spaces from each element of a dynamic
array. If the system does not find any spaces, the element remains unchanged.
TRIMS removes any leading or trailing spaces from a string and converts any contig-
uous spaces in a string to one space. Single blanks between text are not removed.
Examples
In the following example, the program segment removes any spaces from each ele-
ment of the dynamic array ARR1.
ARR1 = " Jones ":@AM:" Smith ":@AM:" Johnson "
ARR1 = TRIMS(ARR1)
519
UDTEXECUTE
UDTEXECUTE
Syntax
UDTEXECUTE str.expr [[ASYNC | SYNC] ON connection]]
[CAPTURING cap.var] [RETURNING cap.var] [PASSCOM]
Description
The UniBasic UDTEXECUTE command executes a command in ECLTYPE U,
regardless of the BASICTYPE you compiled the program with. This command is sim-
ilar to using the EXECUTE command in a program compiled in BASICTYPE U.
STACKCOMMON
The ECL STACKCOMMON command extends COMMON flexibility (although
using STACKCOMMON requires additional memory). If STACKCOMMON is OFF
when one program executes another program, the unnamed common is passed to the
executed program and any changes are passed back to the executing program. If
STACKCOMMON is ON when one program executes another program, unnamed
common is not passed to the program you execute, instead the program’s unnamed
common is pushed onto a stack and the executed program’s unlabeled common is ini-
tialized to zero. When the program is called back, the system moves the executing lev-
els and returns to the original value of the program. Unnamed common is never passed
to an phantom program.
520
UDTEXECUTE
Parameters
The following table describes each parameter of the syntax:
Parameter Description
UDTEXECUTE Parameters
Related Topics
EXECUTE and PERFORM
The UniBasic EXECUTE and PERFORM commands execute an ECL command from
within a UniBasic program.
521
UNASSIGNED
UNASSIGNED
Syntax
UNASSIGNED(var.name)
Description
The UniBasic UNASSIGNED function checks a variable in a program to see if it is
currently assigned a value. If the variable is not assigned a value, the function returns
1; otherwise, it returns 0.
Examples
In the following example, the program statement returns 0 if FILENAME is currently
assigned a value; returns 1 if a value is not currently assigned.
X = UNASSIGNED(FILENAME)
522
UNLOCK
UNLOCK
Syntax
UNLOCK [num.expr]
Description
The UniBasic UNLOCK command unlocks predefined computer resources reserved
by the LOCK command. Resource numbers may range from 0 to 63. If you do not
specify a resource number, the system releases all locks you have set. If there are no
locked resources at the time of execution, the statement does not have any effect.
Reminder The system does not automatically releases all locks when the user exits the
program.
Examples
In the following example, the program statement unlocks all computer resources
reserved by the current user.
UNLOCK
Related Topics
LOCK
The UniBasic LOCK command reserves a computer resource for the current UniBasic
program.
LIST.LOCKS
For information on the ECL LIST.LOCKS command, refer to UniData Commands
Reference.
523
UPCASE
UPCASE
Syntax
UPCASE(string.expr)
Description
The UniBasic UPCASE function converts lower case characters in a string to upper-
case characters. Numeric values are not changed.
Examples
In the following example, the program segment converts “be bold!!” to “BE BOLD!!”
STRING = ’be bold!!’
PRINT UPCASE(STRING)
Related Topics
DOWNCASE
The UniBasic DOWNCASE function converts upper case characters in a string to
lowercase characters.
524
USE
USE
Syntax
USE database ON connection [ON ERROR statements]
Description
The UniBasic USE command specifies what database to use when connected to a
server. Each server can access more than one database and VOC file. For information
on how to set up databases so you can access them, refer to Administering UniServer.
This command is used to develop UniDesktop/Open Client applications. For informa-
tion on how to develop UniDesktop/Open Client applications, refer to Developing
UniDesktop/Open Client Applications.
STATUS
After the execution of the USE statement, STATUS is set to one of the following:
0 Success
1 Server is not connected
2 Database couldn’t be found
3 Database has a different UDTHOME than the server
4 Other errors
Parameters
The following table describes each parameter of the syntax:
Parameter Description
USE Parameters
525
USE
Parameter Description
526
WAIT
WAIT
Syntax
WAIT connection [ON ERROR statements]
Description
The UniBasic WAIT command holds the execution of a UniBasic program until the
results of an asynchronous execution are returned. When UniData executes an EXE-
CUTESQL, EXECUTE, PERFORM, UDTEXECUTE or CALL statement in an asyn-
chronous manner, the program does not wait for the results of the execution and
continues executing the program. The WAIT command specifies when to stop execu-
tion and wait for the results.
STATUS
After the execution of the WAIT statement, STATUS is set to one of the following:
0 Success
1 The server is not connected
2 Other errors
527
WAIT
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WAIT Parameters
528
WEOF
WEOF
Syntax
WEOF [UNIT(mu.expr)] {THEN | ELSE} statements [END]
Description
The UniBasic WEOF command writes an EOF (end-of-file) mark to a magnetic tape.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WEOF Parameters
529
WEOF
Code Meaning
Value Description
0 Successful read
1 End of file encountered
2 End of tape encountered
3 Tape not assigned
4 Parity error
5 Unknown hardware error
6 Other unspecified error
Examples
In the following example, the program statement writes an end-of-file mark to tape 0.
If the system is unable to write the end of file mark, the system executes the ELSE
clause.
WEOF UNIT(00) ELSE "Unable to write an end-of-file"
530
WEOF
Related Topics
READT
The UniBasic READT command assigns the next record from a magnetic tape device
to a variable.
REWIND
The UniBasic REWIND command rewinds a magnetic tape back to its beginning.
WRITET
The UniBasic WRITET command writes an expression as a record to a magnetic tape.
531
WEOFSEQ
WEOFSEQ
Syntax
WEOFSEQ seq.file.var [ON ERROR statements]
Description
The UniBasic WEOFSEQ command writes an end-of-file mark at the record pointer
position in a sequential file.
Parameter Description
WEOFSEQ Parameters
Examples
In the following example, the program statement writes an end-of-file mark to the file
TRIAL.RUN at the current pointer position.
WEOFSEQ TRIAL.RUN
Related Topics
OPENSEQ
The UniBasic OPENSEQ command opens a sequential file for access.
532
WEOFSEQ
READSEQ
The UniBasic READSEQ command assigns the next record from an open sequential
file to a variable.
WRITESEQ
The UniBasic WRITESEQ command writes an expression at the end of a sequential
file.
Sequential Input/Output
For information on sequential input/output, refer to Developing UniBasic
Applications.
533
WRITE
WRITE
Syntax
WRITE expr {ON | TO} [file.var,] record.ID.expr [ON ERROR statements]
Description
The UniBasic WRITE command writes an expression to a record.
The record being accessed is automatically locked by the system during the execution
of the write operation to maintain file integrity (this is not a programmable lock). If
the STATUS function is set to -2 after the execution of a WRITE statement, the record
was locked prior to the write; if the STATUS function is equal to 0, the record was
unlocked.
Note The system displays an error message when trying to write to an inaccessible
file.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITE Parameters
534
WRITE
Parameter Description
Examples
In the following example, the program statement writes the variable SRO to the
default system file as a record with ID M87.
WRITE SRO TO "M87"
In the next example, the program statement writes the contents of the variable OVER-
STOCK to the file named in variable FNAME as a record, with ID OS.
WRITE OVERSTOCK TO FNAME,"OS"
535
WRITELIST
WRITELIST
Syntax
WRITELIST var ON list.name
Description
The UniBasic WRITELIST command writes the contents of a variable to a saved list
in SAVEDLISTS of the current account.
Note WRITELIST only saves the first value of the attribute into the saved list (i.e.,
if the attribute is a singlevalued attribute, the system saves the value in that
attribute to the list; if the attribute contains multivalues or subvalues, the sys-
tem only saves the first multivalue or subvalue). The values you save can then
be used as item IDs to retrieve the data record.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITELIST Parameters
Related Topics
READLIST
The UniBasic READLIST command assigns the values remaining in an active list to a
dynamic array.
GET.LIST
For information on the ECL GET.LIST command, refer to UniData Commands
Reference.
536
WRITESEQ
WRITESEQ
Syntax
WRITESEQ expr [APPEND] {ON | TO} seq.file.var [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic WRITESEQ command writes an expression as a record on a sequential
file from a current record pointer position.
Tip Perform the READSEQ command to position the record pointer set prior to
performing WRITESEQ.
Note WRITESEQ may or may not physically write a record to disk. The system
stores records in the system buffer until its capacity is reached; only then are
they written to disk.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITESEQ Parameters
537
WRITESEQ
Parameter Description
Examples
In the following example, the program segment writes the expression
BAD.ACCOUNTS to the file ACCOUNTS. A message displays if the record pointer
is not at the end-of-file.
WRITESEQ BAD.ACCOUNTS TO ACCOUNTS
ELSE PRINT "NOT AT END-OF-FILE"
Related Topics
WRITESEQF
The UniBasic WRITESEQF command writes an expression at the end of a sequential
file and forces the computer to physically write the data to disk.
538
WRITESEQF
WRITESEQF
Syntax
WRITESEQF expr [APPEND] {ON | TO} seq.file.var [ON ERROR statements]
{THEN | ELSE} statements [END]
Description
The UniBasic WRITESEQF command writes an expression as a record on a sequen-
tial file from a current record pointer position and forces the system to immediately
write the data to the disk.
Perform the READSEQ command to position the record pointer set prior to
Tip performing WRITESEQF.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITESEQF Parameters
539
WRITESEQF
Parameter Description
Examples
In the following example, the program statement writes the variable CHK.WRITE to
the file PAYROLL. All records currently in the output buffer are written to disk along
with this record.
WRITESEQF CHK.WRITE ON PAYROLL ELSE GOTO 100:
Related Topics
WRITESEQ
The UniBasic WRITESEQF command writes an expression at the end of a sequential
file.
540
WRITET
WRITET
Syntax
WRITET [UNIT(mu.expr)] expr {THEN | ELSE} statements [END]
Description
The UniBasic WRITET command allows you to write the value of an expression as a
record onto tape.
Note Before you can use the WRITET command you must reserve a tape drive for
use with the T.ATT command. For detailed information on tape commands,
refer to UniData Commands Reference.
Code Meaning
541
WRITET
Value Description
0 Successful read
1 End of file encountered
2 End of tape encountered
3 Tape not assigned
4 Parity error
5 Unknown hardware error
6 Other unspecified error
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITET Parameters
542
WRITET
Parameter Description
Examples
In the following example, After using the T.ATT command, system writes the vari-
able TAX.RECORD to tape.
PERFORM "T.ATT"
WRITET UNIT (00) TAX.RECORD ELSE PRINT ‘TAPE PROBLEM’
Related Topics
READT
The UniBasic READT command assigns the next record from a magnetic tape device
to a variable
Tape Commands
For information on ECL tape commands (i.e., T.ATT), refer to UniData Commands
Reference.
543
WRITEU
WRITEU
Syntax
WRITEU expr {ON | TO} [file.var,] record.ID.expr [ON ERROR statements]
Description
The UniBasic WRITEU command writes an expression to a record and does not
release the record if it was previously locked by one of the lock processes in the
MATREADU, READL, READU, or READVU statements.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITEU Parameters
Examples
In the following example, the program statement writes the variable IDEA.57 to the
file IDEAS as a record with the ID ‘LAST’. The lock remains in place if the record
was locked prior to performing WRITEU.
544
WRITEU
Related Topics
WRITEV
The UniBasic WRITEV command writes an expression of an attribute of a data
record.
545
WRITEV
WRITEV
Syntax
WRITEV expr {ON | TO} [file.var,] record.ID.expr, attrib.expr
[ON ERROR statements]
Description
The UniBasic WRITEV command writes an expression to an attribute of a data
record, and writes only a single attribute rather than an entire record.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITEV Parameters
546
WRITEV
Parameter Description
Examples
In the following example, the program statement writes the variable NAME to the first
attribute in the customer record with CUST.ID in the file CUSTOMER.
WRITEV NAME ON CUSTOMER,CUST.ID,1
In the next example, the program segment reads an attribute in the record with ID of
TAPE.ID in the file TAPES into the variable NBR.TIMES.
READV NBR.TIMES FROM TAPES,TAPE.ID,
NBR.TIMES.ATTRIBUTE
NBR.TIMES += 1
WRITEV NBR.TIMES ON TAPES,TAPE.ID, NBR.TIMES.ATTRIBUTE
The position of the attribute within the actual record is stored in the variable
NBR.TIMES.ATTRIBUTE. After reading the variable, the system increments and
writes the variable back using the WRITEV command.
Related Topics
READV
The UniBasic READV command retrieves an attribute from a record and assigns its
value to a variable.
WRITE
The UniBasic WRITE command writes an expression to a record of a previously
opened file.
File Input/Output
For information on file input/output, refer to Developing UniBasic Applications.
547
WRITEVU
WRITEVU
Syntax
WRITEVU expr {ON | TO} [file.var,] record.ID.expr, attrib.expr
[ON ERROR statements]
Description
The UniBasic WRITEVU command writes an expression to an attribute of a data
record, and writes only a single attribute rather than an entire record, but does not
release a lock set previously by any locking READ statement. As with the WRITEV
statement, the record ID and attribute number are mandatory.
The ON ERROR clause allows the program after the WRITEVU statement to con-
tinue to perform under the following fatal error conditions: if the file is not open, if an
I/O error occurs in the write accessing process, or if the file is a read-only file. If you
do not specify the ON ERROR clause, the program terminates under such fatal error
conditions.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
WRITEVU Parameters
548
WRITEVU
Parameter Description
Examples
In the following example, the program statement writes the variable NEW.TAPES in
the file TAPES to the record with ID TAPE.ID as an attribute in the position
NEW.ATTRIBUTE.
WRITEVU NEW.TAPES ON TAPES, TAPE.ID,NEW.ATTRIBUTE
549
XLATE
XLATE
Syntax
XLATE(file.expr, rec.id.expr, attrib.expr, "code")
Description
The UniBasic XLATE function returns the contents of an attribute.
Parameters
The following table describes each parameter of the syntax:
Parameter Description
XLATE Parameters
XLATE Codes
The following table describes the XLATE valid codes.
Code Description
XLATE Codes
550
XLATE
Code Description
XLATE Codes
Related Topics
TRANS
For information on the TRANS function, refer to Using UniData.
551
Appendix A SOFTWARE PRODUCTS
This appendix describes each ASCII (American Standard Code for Information Inter-
change) code.
000 NUL 0
001 SOH 1
002 STX 2
003 ETX 3
004 EOT 4
005 ENQ 5
006 ACK 6
007 BEL 7
008 BS 8
009 HT 9
010 LF A
552
ASCII Character Codes
011 VT B
012 FF C
013 CR D
014 SO E
015 SI F
016 DLE 10
017 DC1 11
018 DC2 12
019 DC3 13
020 DC4 14
021 NAK 15
022 SYN 16
023 ETB 17
024 CAN 18
025 EM 19
026 SUB 1A
027 ESC 1B
028 FS 1C
029 GS 1D
030 RS 1E
031 US 1F
032 (space) 20
033 ! 21
034 " 22
035 # 23
553
ASCII Character Codes
036 $ 24
037 % 25
038 & 26
039 ’ 27
040 ( 28
041 ) 29
042 * 2A
043 + 2B
044 , 2C
045 - 2D
046 . 2E
047 / 2F
048 0 30
049 1 31
050 2 32
051 3 33
052 4 34
053 5 35
054 6 36
055 7 37
056 8 38
057 9 39
058 : 3A
059 ; 3B
060 < 3C
554
ASCII Character Codes
061 = 3D
062 > 3E
063 ? 3F
064 @ 40
065 A 41
066 B 42
067 C 43
068 D 44
069 E 45
070 F 46
071 G 47
072 H 48
073 I 49
074 J 4A
075 K 4B
076 L 4C
077 M 4D
078 N 4E
079 O 4F
080 P 50
081 Q 51
082 R 52
083 S 53
084 T 54
085 U 55
555
ASCII Character Codes
086 V 56
087 W 57
088 X 58
089 Y 59
090 Z 5A
091 [ 5B
092 \ 5C
093 ] 5D
094 ^ 5E
095 _ 5F
096 ‘ 60
097 a 61
098 b 62
099 c 63
100 d 64
101 e 65
102 f 66
103 g 67
104 h 68
105 i 69
106 j 6A
107 k 6B
108 l 6C
109 m 6D
110 n 6E
556
ASCII Character Codes
111 o 6F
112 p 70
113 q 71
114 r 72
115 s 73
116 t 74
117 u 75
118 v 76
119 w 77
120 x 78
121 y 79
122 z 7A
123 { 7B
124 | 7C
125 } 7D
126 ~ 7E
127 DEL 7F
128 Ç 80
129 ü 81
130 é 82
131 â 83
132 ä 84
133 à 85
134 å 86
135 ç 87
557
ASCII Character Codes
136 ê 88
137 ë 89
138 è 8A
139 ï 8B
140 î 8C
141 ì 8D
142 Ä 8E
143 Å 8F
144 É 90
145 æ 91
146 Æ 92
147 ô 93
148 ö 94
149 ò 95
150 û 96
151 ù 97
152 ÿ 98
153 Ö 99
154 Ü 9A
155 ¢ 9B
156 £ 9C
157 ¥ 9D
158 ¤ 9E
159 ƒ 9F
160 á A0
558
ASCII Character Codes
161 í A1
162 ó A2
163 ú A3
164 ñ A4
165 Ñ A5
166 ª A6
167 º A7
168 ¿ A8
169 “ A9
170 ” AA
171 ‹ AB
172 › AC
173 ¡¦ AD
174 « AE
175 » AF
176 ã B0
177 õ B1
178 Ø B2
179 ø B3
180 œ B4
181 Œ B5
182 À B6
183 Ã B7
184 Õ B8
185 § B9
559
ASCII Character Codes
186 ‡ BA
187 † BB
188 ¶ BC
189 © BD
190 ® BE
191 ™ BF
192 „ C0
193 … C1
194 ‰ C2
195 • C3
196 – C4
197 — C5
198 ° C6
199 Á C7
200 Â C8
201 È C9
202 Ê CA
203 Ë CB
204 Ì CC
205 Í CD
206 Î CE
207 Ï CF
208 Ò D0
209 Ó D1
210 Ô D2
560
ASCII Character Codes
211 D3
212 D4
213 Ù D5
214 Ú D6
215 Û D7
216 Ÿ D8
217 ß D9
218 DA
219 DB
220 DC
221 DD
222 DE
223 DF
224 E0
225 E1
226 E2
227 E3
228 E4
229 E5
230 E6
231 E7
232 E8
233 E9
234 EA
235 EB
561
ASCII Character Codes
236 EC
237 ED
238 EE
239 EF
240 F0
241 F1
242 F2
243 F3
244 F4
245 F5
246 F6
247 F7
248 F8
249 F9
250 FA
251 Text Mark FB
252 Sub Value Mark FC
253 Value Mark FD
254 Attribue Mark FE
255 Record Mark FF
562
Appendix B SOFTWARE PRODUCTS
@variables
This appendix describes the @variables available in UniBasic, the compiler @vari-
ables, and the various return codes returned by the @SYSTEM.RETURN.CODE
@variable.
563
@variables
@Variables
The following table describes the valid @variables.
@variable Description
@variables
564
@variables
@variable Description
@variables (continued)
565
@variables
@variable Description
@variables (continued)
566
@variables
@variable Description
@variables (continued)
567
@variables
@variable Description
@variables (continued)
568
@variables
Compiler @variables
The following @variables cause compiler to insert special delimiters for dynamic
arrays at compile time.
@variable Description
Compiler @variables
569
@variables
@SYSTEM.RETURN.CODE Values
@SYSTEM.RETURN.CODE returns various values depending upon the command
executed just prior to evaluating @SYSTEM.RETURN.CODE.
@SYSTEM.RETURN.CODE is available in UniBasic, but is affected by a wide vari-
ety of commands, both UniBasic commands and ECL commands.
570
@variables
571
@variables
572
Index SOFTWARE PRODUCTS
573
Index
574
Index
B CATS, 61
CHAIN, 62
b+ tree CHANGE, 63
alternate key index, 388, 390, 392, 394, 396, 398 changing
base logarithm, 245 block size, 451, 451
BASICTYPE, 25 numeric expressions to ASCII, 64
executing commands in BASICTYPE U, 520 numeric values to ASCII, 65
returning current, 504 opposite sign, 294
bell, 18 strings, 92
binary conversion, 322 CHAR, 64, 296
BITAND, 43 CHAR(0), 296
BITNOT, 45 CHAR(128), 296
BITOR, 44 converting, 296
BITXOR, 46 character
blink mode, 17 trapping, 232
block size character string
changing, 451 converting, 208
returning, 503 CHARS, 65
BPIOCP, 47 checking
braces, 23, 51 if a select list is active, 467
bracket function, 296 variables for assignment, 522
branching CHECKSUM, 66
expressions, 57 CLEAR, 67
statements, 191 CLEAR COM, 68
BREAK, 49 CLEAR COMMON, 68
break key, 49 CLEARCOM, 68
buffer CLEARCOMMON, 68
print, 373 CLEARDATA, 69
CLEARFILE, 70
clearing
C active select lists, 73
C subroutine active temporary tables, 75
calling, 56 data que, 69
CALCULATE, 23, 51 named common, 68
CALL, 52, 52, 453 records, 70
CALLC, 56 screens, 17
calling SQL file variables, 75
C subroutines, 56 unnamed COMMON, 68
programs, 52 CLEARINPUT, 72
subroutines, 52 CLEARSELECT, 73
capturing CLEARSQL, 75
error messages, 287, 365, 521 CLOSE, 76
text, 286, 286, 365, 365, 521 CLOSESEQ, 78
CASE, 57 closing
CAT, 60 data files, 76
575
Index
576
Index
577
Index
578
Index
579
Index
DIMENSION, 117 E
dimensioning
arrays, 117 EBCDIC, 39, 125
matrices, 117 EBCDIC to ASCII, 39
DIR, 120 ECHO, 126
directing ECL command
output of print statements, 372 executing, 285
disabling, 204 enabling
break key, 49 break key, 49
DISCONNECT, 121 terminal output, 204
parameter, 121 terminal pagination, 47
displaying enclosing
characters, 126 strings in double quotes, 123
error messages, 229 strings in quotes, 383
output to display terminal, 99 strings in single quotes, 488
distributing END, 127, 215
strings to a matrix, 268 end
division FOR/NEXT structure, 295
returning remainder, 291 end-of-file mark
string numbers, 461 writing, 529
double quotes ENTER, 128
enclosing a string in, 123 entering
double-precision rounding, 124 UniBasic debugger, 49, 104
DOWNCASE, 122 environmental variable, 177
DQUOTE, 123 EQ, 130
DROUND, 124 EQS, 131
dummy statement, 300 EQU, 132
dynamic array equal
adding values, 499 not, 292, 293
assigning records, 400 EQUATE, 132
assigning records to, 385 ERRMSG, 374, 492
concatenating, 487 ERRMSG file, 34
extracting strings, 498 error message
generating, 261 capturing, 287, 365, 521
maximum numeric element, 284 creating the file, 374
removing elements, 442 file, 374, 492
removing spaces, 519 printing, 374
repeating elements of, 495 retrieving, 178
repeating last element, 454 system error message file, 492
replacing data, 448 EXECUTE, 363
returning substrings, 446 EXECUTESQL, 135
specifying delimiters, 262 executing, 520
ECL commands, 363
ECL statements, 62
paragraphs, 285
sentences, 285
580
Index
581
Index
582
Index
G I
GARBAGECOLLECT, 167
ICONV, 205
GE, 168
binary, 207
generating
file translation, 210
dynamic arrays, 261
hex, 207
GES, 169
left justify, 209
GET, 170
masked character, 208
GETCOLUMNDATA, 173
masked decimal, 209
parameters, 173
octal, 207
GETCOLUMNNAME, 175
packed decimal, 210
GETENV, 177
right justify, 210
GETERRMSG, 178
time, 210
GETLIST, 179
IF/THEN/ELSE, 215
GETNEXTTUPLE, 181
ignoring
GETPTR, 183
locks, 421
GETPU, 185
IN, 217
GETREADU, 186
INCLUDE file, 26
GETUSERGROUP, 188
incrementing
GETUSERNAME, 187
values, 164
GOSUB, 189, 453
583
Index
584
Index
585
Index
586
Index
587
Index
588
Index
589
Index
seeding sine
random numbers, 458 inverse, 40
SELECT, 462 returning, 479
select list single quote
assigning record ID, 406 enclosing a string, 488
checking if active, 467 size limitation
clearing, 73 avoiding, 62
creating from saved lists, 179 SLEEP, 480
returning state, 467 sleeping
SELECTINDEX, 465 one second, 504
SELECTINFO, 467, 467 SMUL, 482
SEND, 468 sorting key, 247
sending SOUNDEX, 483
data to a line, 468 SPACE, 485
output to display terminal, 99 space
sentence removing from a string, 515
executing, 285 removing leading, 518
SEQ, 297, 470 removing trailing, 517
SEQS, 471 returning, 485
sequential access file SPACES, 486
closing, 78 special characters, 217
sequential file, 31 spelling
closing, 348 finding alternate spelling, 483
deleting, 349 SPLICE, 487
opening, 339, 351 splicing
reading, 354 dynamic arrays, 487
reading next record, 412 strings, 487
writing, 357 split factor percentage
writing end-of-file mark, 532 returning, 147
writing to, 537, 539 SQL file variable
sequential write, 346 clearing, 75
SETINDEX, 472 SQL INTO clause, 135
SETPTR, 183 SQRT, 489
SETROW, 477 square bracket, 21
parameters, 477 square root
SETTABLE, 475 returning, 489
SETTING, 170, 171 SQUOTE, 488
setting SSUB, 490
exclusive locks, 438 stack
local memory to zero, 67 returning condition, 504
read-only lock, 436 STACKCOMMON, 85, 285, 363, 520
sign statement
changing, 294 dummy, 300
SIN, 479 executing repeatedly, 164
label, 333
590
Index
591
Index
592
Index
WRITELIST, 536
WRITESEQ, 537
WRITESEQF, 539
WRITET, 296, 451, 541
WRITEU, 544
WRITEV, 546
WRITEVU, 548
writing
attributes to a record, 546, 548
data to a file, 346
directly to the disk, 539
end-of-file mark, 529
end-of-file mark to a sequential file, 532
expressions to a record, 534, 544
matrices to records, 280, 282
primary input buffer of a calling Proc, 379
to a saved list, 536
to a sequential file, 537, 539
to sequential files, 357
to tape, 541
X
X, 171
XLATE, 550
XOR logical function, 46
593
UniBasic
A UniData Application
Development Tool