Programming in Infobasic

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

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.

For example, if you wish to access ‘T’ in the ‘TEMENOS’ – Array1[0]

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 :

ASCII Decimal Description

254 Field Marker


253 Value Marker
252 Sub-Value Marker

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.

The delimiter characters between various fields are :

ASCII Decimal Description

254 Field Marker


253 Value Marker
252 Sub-Value Marker

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.

Example: DIMENSION Array2[5,3]

Commands and functions in Infobasic :

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:

The search can start anywhere in dynamic.array.

Syntax:
LOCATE expression IN dynamic.array SETTING variable THEN statements ELSE statements

expression evaluates to the string to be searched for in dynamic.array. If expression or


dynamic.array evaluate to the null value, variable is set to 0 and the ELSE statements are
executed.

Temenos - India 24
Remove :

Use the REMOVE statement to remove a value from a dynamic array.

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 :

Matread is a command that is used to read the contents of a dimensioned/dynamic array.


You can specify the id of the record to be picked up from the array. In case the read is
successful, then the statements following the ‘THEN’ statements are executed else the
statements following the ‘ELSE’ statement are executed.

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

READSEQ VARIABLE FROM filevariable


THEN statements
ELSE statements

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

WRITESEQ expression TO fielvariable


ON ERROR statements
THEN statements
ELSE statements

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.

Using the ED editor:

UNIVERSE EDITOR

The EDITOR can be called with the following formats:

ED (file and record id's will be prompted)

ED file (record id's will be prompted)

ED file id (edit the record 'id' in 'file')

Temenos - India 26
ED file id id... (edit multiple id's in 'file')

ED file* (edit all records in 'file')

SELECT ... (may precede 'ED file' command)

Special ASCII characters may be entered as:

...^nnn... where nnn is the decimal character code

...^^... will enter a single UP ARROW character.

The following commands may be used in the Editor:

A - Do the last 'A any' (APPEND) command again.

A any - APPEND 'any' to this line.

B - Set the current line pointer to the BOTTOM line.

B any - BREAK the current line after 'any' into two lines.

C - Do the last 'CHANGE' command again.

C/// - CHANGE one or more lines. Formats permitted are:


C/from/to C/from/to/# C/from/to/ C/from/to/#G
C/from/to/G# C/from/to/B C/from/to/BG
C/from/to/GB

where / is any delimiter character.


from is the character string to be replaced.
to is the character string to substitute.
# is the number of lines to CHANGE. (The default is
one)
G - CHANGE all instances in line.
B - CHANGE all lines in the defined BLOCK.

CAT any - CONCATENATE the next line onto the current line,
separated by 'any'.

COL - Display relative COLUMN POSITIONS on the CRT.

COPY - COPY a BLOCK (source block is unchanged).

D - DELETE the current line.

D# - DELETE '#' lines starting with the current line.

DELETE - DELETE the entire record from the FILE.

DROP - DROP (DELETE) all lines in the defined BLOCK.

Temenos - India 27
DUP - DUPLICATE the current line.

DUP# - DUPLICATE the current line '#' times.

EX - EXIT the editor.

F - Do the last 'FIND' command again.

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 '#'.

FD - Delete the entire record from the file.

FI - FILE the record.

FILE - FILE the record under the originally specified name.

FILE name - FILE the record under the specified 'name'.

FILE f name - FILE record 'name' in file 'f'.

FORMAT - FORMAT a BASIC program to show logical structure


by indenting.

G# - GO TO line '#'

G< - GO TO line defined by the beginning of the current


BLOCK.

G> - GO TO line defined by the end of the current


BLOCK.

HELP - Prompt user to display HELP information on the


CRT.

HELP any - Display HELP information on CRT for 'any'.

I - INSERT new lines AFTER the current line. Prompt


for successive lines of INPUT until NULL input.

IB - INSERT new lines BEFORE the current line. Prompt


for successive lines of INPUT until NULL input.

I any - INSERT the line 'any' AFTER the current line.

IB any - INSERT the line 'any' BEFORE the current line.

L - Do the last 'LOCATE' command again.

Temenos - India 28
L any - LOCATE the next line that contains the string 'any'.

L# - LIST '#' lines starting with the current line on to the


CRT.

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 - Do the last 'MATCH' command again.

M any - Search for next line that MATCHES the pattern 'any'.

MOVE - MOVE a BLOCK (source block is deleted).

N - Go on to next selected record; used when SELECT


list is active.

OOPS - RESTORE the record to the condition prior to the


last change.

P - PRINT on CRT the same number of lines specified


with last 'P#'.

P# - PRINT on CRT '#' lines starting with the current line.

PB - PRINT on CRT all lines in the defined BLOCK.

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.

Q - QUIT - EXIT the editor.

QUIT - QUIT - EXIT the editor.

R - Do the last 'REPLACE' (R any) command again.

R any - REPLACE this line with 'any'.

R/// - CHANGE one or more lines (same as C/// command.)

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).

SPOOL - SPOOL entire record to PRINTER.

SPOOL# - SPOOL '#' lines to the PRINTER.

X - EXIT (QUIT) from the editor and abandon an active


SELECT list.

+# - Advance current line POINTER by '#' lines.

-# - Back up current line POINTER by '#' lines.

# - Set the current line POINTER to the '#' line.

< - Define the first line of a BLOCK.

> - Define the last line of a BLOCK.

^ - Switch UP ARROW on/off to display non-printing


characters as ^nnn where nnn is the decimal
equivalent of ASCII code.

Programming in Infobasic/GLOBUS subroutines:

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.

How to create, compile and catalog Universe Basic programs?

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.

 Compile the program

BASIC *DIRECTORY-NAME PROGRAM-NAME


*The name of the directory under which the
*program is stored
BASIC BP FIRSTPROGRAM

 Execute the program

RUN PROGRAM-NAME
RUN FIRSTPROGRAM

Structure of a Basic Program

SUBROUTINE subroutine-name( )

GOSUB paragraph-name
GOSUB paragraph-name
RETURN

Paragraph-name:
Statement
Statement
Statement
RETURN

Paragraph-name:
Statement
Statement
Statement
RETURN

END

Variables, Statements and loops

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

Like other programming languages Universe Basic supports looping structures.

Temenos - India 31
LOOP
LOOP
STATEMENT
WHILE CONDITION
STATEMENT
STATEMENT
REPEAT

FOR LOOP
FOR COUNTER = 1 TO 10
STATEMENTS
STATEMENTS
NEXT COUNTER

Branching flow control statements

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.

Sample 1 : To execute from Universe

SUBROUTINE LIST.CUST

OPEN “”,”FBNK.CUSTOMER” TO F.CUST ELSE PRINT “OPEN ERR”

EXECUTE “SELECT FBNK.CUSTOMER BY @ID”

EOLIST = 0

LOOP

READNEXT CUSTID ELSE EOLIST = 1

WHILE EOLIST = 0

Temenos - India 32
REC.FOUND = 1
CUSTREC = ‘’

READ CUSTREC FROM F.CUST,CUSTID ELSE REC.FOUND = 0


IF REC.FOUND EQ 1 THEN

PRINT CUSTREC<2>
PRINT CUSTREC<17>
END
REPEAT

RETURN
END

Sample 2 : To execute from Globus

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

Compile the above program using the following command


 EB.COMPILE BP LIST.CUST

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.

To execute the above program use the following command


 RUN BP LIST.CUST

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

You might also like