Programming in Infobasic
Programming in Infobasic
Programming in Infobasic
Introduction to Arrays:
Every variable that we use, occupies a part of the memory. Usually character variables
occupy 1 byte of memory, which have the capacity to store just one character. In case a
series of characters (string) like ‘TEMENOS’ has to be stored (a string), then a character
variable would not suffice. There comes the need for arrays. We now need 7 bytes of
continuous memory allocation in order to store the string. Only if all the characters in the
string are stored sequentially, retrieval and storage will become easier and faster. Moreover
all the 7 bytes should have the same name. This is exactly the functionality of an array.
To sum it up, an array is nothing but continuos memory allocation, where in all the bytes
have the same name as that of the array and can be distinguished with the help of a
subscript which always starts with a ‘0’.
Array1
T E M E N O S
0 1 2 3 4 5 6 7
In case you wish to access each of the elements in the array separately, use the subscript.
Dynamic Arrays :
Dynamic arrays are, as the name implies, dynamic in both the number and dimensions and
their extents. Dynamic arrays are especially useful in providing the ability to manipulate
variable length records with a variable length of fields and/or values within fields etc. A
dynamic array is just a string of characters that contain one or more delimiter characters.
The delimiter characters are :
Each field is separated by a field marker and a field may contain more than one value
separated by a value marker. Any value may have more than one sub-value separated by a
sub-value marker.
Temenos - India 22
Example :
Array1[10] We have now declared an array named Array1 with size 10.
Each field is separated by a field marker and a field may contain more than one value separated by a value
marker. Any value may have more than one sub-value separated by a sub-value marker.
Dimensioned Arrays :
Dimensioned array provide more efficient means of creating and manipulating tables of data
elements where the number of dimensions and the extent (number of elements) of each
dimension is known and is not likely to change. Dimensioned arrays have to be declared
using the DIMENSION statement.
Now let us learn a few commands and functions supported by Infobasic so that programming
in Infobasic becomes simpler.
Open :
Use the OPEN statement to open a Universe file. Several Universe files can be opened in a
single program, but they need to use separate ‘OPEN’ statements.
Syntax:
OPEN filename TO file.variable THEN statements ELSE statements
Example:
OPEN REGISTER.DETAILS TO F.REGISTER.DETAILS THEN….. ELSE …….
The above statement will open a file named ‘REGISTER.DETAILS’. In case it is able to open
the file successfully then the statements following the ‘THEN’ will be executed else the
statement following the ‘ELSE’ will be executed.
Note:
Always assign the name of the file to a file variable. All statements that read, write to, delete, or clear
that file must refer to it by the name of the file variable.
Temenos - India 23
Read :
Use the READ statement to read the contents of an open file in Universe. An id has to be
supplied to the READ statement so that the record pertaining to that id, if exists can be
picked up from the file and can be stored in an array. Later, the user can manipulate the
array and extract the necessary values.
Syntax:
READ dynamic.array FROM file.variable, record.ID THEN statements ELSE statements
Example:
READ R.DETAILS1 FROM F.REGISTER.DETAILS ,1 THEN …. ELSE …..
The above statement will look for a record with id ‘1’ in the file REGISTER.DETAILS referred
by the file variable F.REGIATER.DETAILS, if found will extract the record and put it in the
dynamic array R.DETAILS1 and the statements following the ‘THEN’ will be executed. If the
id is not found in the file then the statements following the ELSE will be executed.
Write :
Use the WRITE statement to write onto any Universe file. You need to supply the id of the
record and all the other values while writing on to a file.
Syntax:
WRITE expression TO file.variable, record.ID THEN statements ELSE statements.
Example:
WRITE REG.DET TO F.REGISTER.DETAILS,2
(REG.DET is an array that contains all the values to be written on to the file)
The above statement will write the contents of the array REG.DET as a record with id 2 on to
the file REGISTER.DETAILS whose file variable is F.REGISTER.DETAILS. If the write
succeeds then the statements following the ‘THEN’ will be executed else the statements
following the ELSE will be executed.
Now that we are fairly familiar with file related commands, let us learn about array
manipulation commands.
Locate :
Use a LOCATE statement to search a dynamic.array for an expression and to return a value
indicating one of the following:
Syntax:
LOCATE expression IN dynamic.array SETTING variable THEN statements ELSE statements
Temenos - India 24
Remove :
Syntax:
REMOVE element FROM dynamic.array SETTING variable
Example :
REMOVE ID1 from LIST1 SETTING POS
The above statement will remove the first value from the dynamic array LIST1, and will set a
value to the variable POS (a non-zero value). All values in the dynamic array LIST1 should
be delimited by system delimiters like field markers or user defined delimiters like ‘*’ etc so
that the extraction happens without any problem.
Matread :
Syntax:
MATREAD array FROM file.variable, record.ID THEN statements ELSE statements
Example:
MATRED Array1 from F.REGISTER.DETAILS,ID1 THEN ….. ELSE …..
The above statement will search for a record with id specified in the variable ID1, if found, it
will transfer the record to the array Array1.
OPENSEQ :
Used to open a sequential file and lock it.
Syntax :
OPENSEQ path to filevariable
ON ERROR statements
LOCKED statements
THEN statements
ELSE statements
Using OPENSEQ if you try to open a file that does not exist, you can either flash an error
message using the ON ERROR clause or you could create the file using the CREATE
statement in the else clause.When you open a sequential file for reading or writing, it is
compulsory to have exclusive access to the file. Therefore the LOCKED and the ELSE
clauses must be a part of the OPENSEQ statement.
Example :
OPENSEQ “/u1/training/training.file” to FV.TRGFILE
ON ERROR STOP “Unable to open the file. File does not exist”
Temenos - India 25
END
ELSE
CREATE FV.TRGFILE ELSE STOP “Unable to create file”
END
READSEQ
The READSEQ statement is used to read from a sequential file. This command extracts the
next line from the file opened to filevariable using a new line character CHAR(10) as the
delimiter. Once the end of the file is encountered, ELSE clause gets executed.
Syntax
WRITESEQ
This command is used to write onto a sequential file. This command writes the result of the
expression as the next line to the file opened to filevariable using the new line character
CHAR(10) as the delimiter.
Syntax
CLOSESEQ
The CLOSESEQ statement is used to close a sequential file. It writes an end-of-file-mark on
to the file to make the file available to other users.
Syntax
CLOSESEQ filevariable
ON ERROR statements
Ensure that you close the file opened with OPENSEQ with a CLOSESEQ command as it is
only then the READU lock on the file would get released.
UNIVERSE EDITOR
Temenos - India 26
ED file id id... (edit multiple id's in 'file')
B any - BREAK the current line after 'any' into two lines.
CAT any - CONCATENATE the next line onto the current line,
separated by 'any'.
Temenos - India 27
DUP - DUPLICATE the current line.
F any - FIND the next line that starts with the string 'any'.
F# any - FIND the next line that contains the string 'any'
starting in column '#'.
G# - GO TO line '#'
Temenos - India 28
L any - LOCATE the next line that contains the string 'any'.
LOAD name - LOAD the record 'name' from the current FILE;
line #'s will be prompted.
LOAD f name - LOAD the record 'name' from file 'f'; line #'s
will be prompted.
M any - Search for next line that MATCHES the pattern 'any'.
PL# - PRINT the current line and the next '#' lines; do
not change the current line pointer.
PL-# - PRINT the current line and the prior '#' lines;
do not change the current line pointer.
SAVE - SAVE (FILE) a copy of this record under the original name.
SAVE name - SAVE (FILE) a copy of this record under the specified 'name'.
SAVE f name - SAVE (FILE) a copy of this record as record 'name' in file 'f'.
Temenos - India 29
SIZE - Display the SIZE of this record (# of LINES/FIELDS, # of
BYTES).
Universe Basic
The Universe basic language is a procedural language that is best suited to store and
retrieve data from Universe. With English like commands it makes programming easy.
Programs written in Basic are called subroutines. The BASIC compiler is used to compile
these subroutines. Once the subroutines are compiled, an object code for the subroutine is
produced. We will discuss more about compiling and execution of subroutines in
forthcoming modules.
Universe Basic does not follow the old ‘Top down approach’ in programming. Instead, in
Universe Basic programs are split into paragraphs. A paragraph is a small portion in the
program that contains code to do a specific job. These paragraphs are then called in the
sequence required. This makes the program more readable and easy to debug. For
example a program could contain paragraphs like ‘Initialize’ which could contain code
relating to initialization of variables, a paragraph called ‘OpenFiles’ which could contain code
that is used to open existing files etc.
Once a program is written, save it with the same name as that of the program in a specific
directory. Usually programs are stored in a directory called ‘BP’. ‘BP’ stands for basic
programs. Once this is done, the next step is to compile and execute the program. Universe
Temenos - India 30
Basic – the procedural language compiler compiles the program and produces an object
code. For example, if you compile a program called ‘FIRSTPROGRAM’, a file with the name
‘FIRSTPROGRAM.O’ will get produced. This file with the extension ‘.O’ will get stored in a
directory named ‘BP.O’. This file contains the object code of the program which is required
during execution.
To execute the Universe Basic program, the Run machine of Universe is used.
RUN PROGRAM-NAME
RUN FIRSTPROGRAM
SUBROUTINE subroutine-name( )
GOSUB paragraph-name
GOSUB paragraph-name
RETURN
Paragraph-name:
Statement
Statement
Statement
RETURN
Paragraph-name:
Statement
Statement
Statement
RETURN
END
Variables
As you would be aware by now, we need variables to store data. Unlike other programming
languages Universe basic does not support data types.
All variables are by default treated as strings. Universe Basic variables just need to be
initialized, not declared.
Looping Structures
Temenos - India 31
LOOP
LOOP
STATEMENT
WHILE CONDITION
STATEMENT
STATEMENT
REPEAT
FOR LOOP
FOR COUNTER = 1 TO 10
STATEMENTS
STATEMENTS
NEXT COUNTER
IF THEN ELSE
IF condition THEN
Statement1
Statement2
END ELSE
Statement3
END
CASE
DO CASE
CASE Condition1
Statement1
CASE Condition2
Statement2
OTHERWISE
Statement3
ENDCASE
The following sample program reads the Customer file and displays Name and Residence.
SUBROUTINE LIST.CUST
EOLIST = 0
LOOP
WHILE EOLIST = 0
Temenos - India 32
REC.FOUND = 1
CUSTREC = ‘’
PRINT CUSTREC<2>
PRINT CUSTREC<17>
END
REPEAT
RETURN
END
There are two main insert files in GLOBUS namely I_COMMON and I_EQUATE(They are
like the #include files in C,C++ etc).I_COMMON contains all common variables that are
available for all programs. I_EQUATE is another important include file that initializes all
common variables declared in I_COMMON.
Ensure that you include these files in your subroutines. There are many other include files in
GLOBUS which we will learn as we proceed further. All the other include files are specific to
applications.
SUBROUTINE LIST.CUST
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
GOSUB INITIALIZE
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INITIALIZE:
FN.CUSTOMER = “F.CUSTOMER”
FV.CUSTOMER = “”
SEL.LIST = ‘’
CUSTERR = 0
NO.OF.REC = 0
R.CUSTREC = “”
CUSTERR = “”
RETURN
OPENFILES:
CALL OPF(FN.CUSTOMER,FV.CUSTOMER) Globus Subroutine
RETURN
PROCESS:
SEL.CMD = “SELECT “ : FN.CUSTOMER
CALL EB.READLIST(SEL.CMD,SEL.LIST,””,NO.OF.REC,CUSTERR) Globus Subroutine
Temenos - India 33
LOOP
REMOVE CUSTID FROM SEL.LIST SETTING POS
WHILE CUSTID
CALL F.READ(FN.CUSTOMER,CUSTID,R.CUSTREC,FV.CUSTOMER,CUSTERR)Globus
subroutine
PRINT R.CUSTREC<EB.CUS.SHORT.NAME>
PRINT R.CUSTREC<EB.CUS.RESIDENCE>
REPEAT
RETURN
END
The above mentioned command will not only compile the program but will also catalog it.
The process of making an entry in the VOC for a particular program is called cataloging.
Note : Th above program cannot be executed from Universe level as it has Globus subroutines. It can
only be executed from Globus.
Temenos - India 34