Programming in Infobasic: Objectives
Programming in Infobasic: Objectives
Objectives
1.1 Introduction
As you would be aware by now, Globus uses jBase as the bank end to store
its data. All programs that make up Globus are written in a language called Infobasic. Infobasic is a
very simple yet powerful programming language. With its English like statements, it makes
programming very simple. A salient feature of Infobasic is that it does not support data types. All
variables in Infobasic are treated as Dynamic Arrays (Refer 2.1 Arrays). Since Infobasic does not
support data types, the need to declare variables does not arise.
2.1 Arrays
Before we understand the various commands and the way to write programs in
Infobasic, it is very essential to understand the concept of arrays.
Every variable that we use occupies a portion of the memory. Usually character
variables occupy 1 byte of memory, which have the capacity to store just one character. Incase a
series of characters (string) like ‘GLOBUS’ has to be stored, then a character variable would not
suffice. There comes the need for arrays. We now need 6 bytes of continuous memory blocks in order
to store the string. Sequential storage of characters that form a string will make storage and retrieval
easier and faster. Moreover all the 6 bytes should have the same name. This is exactly the functionality
of an array.
Array 1
G L O B U S
0 1 2 3 4 5
Note :
Incase you wish to access ‘G’ in ‘GLOBUS’ then specify Array1[0]
There are two different types of arrays that are supported by Infobasic. They are
I. Dynamic Arrays
II. Dimensioned Arrays
I. Dynamic Arrays
Dynamic arrays are, as the name implies, dynamic in both the number,
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.
Note :
All variables in Infobasic are treated as dynamic arrays. Dynamic arrays do not need any
explicit declaration. Initialisation would suffice.
ARRAY = ‘’ A dynamic array being initialised. Incase the array needs to store a numeric
value
I. 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:
To declare a dimensioned array use DIMENSION Array2[5,3]
5 - > Refers to the number of rows
3 - > Refers to the number of columns
A customer record is a dimensioned array. All the fields that form the customer record are
dynamic arrays.
There are two different types of programs that we can write in Infobasic. One is
‘PROGRAM’ itself and the other is ‘SUBROUTINE’.
Any program that is executed from the database prompt is termed as a ‘PROGRAM’
and a program that is executed from within Globus is termed as a subroutine.
*Comments *Comments
PROGRAM ProgramName SUBROUTINE SubroutineName
Statement1 Statement1
Statement 2 Statement 2
Statement 3 Statement 3
RETURN
END END
Figure 3.1 Structure of a program and subroutine
Compiling Subroutines
When Globus is installed, a directory named globuslib and lib get installed under the
home directory (run directory) of the user. The directory globuslib is supposed to contain the object
code of all core subroutines and the directory lib is supposed to contain the object code of all local
subroutines. When a subroutine is compiled, an object code is produced. For instance when a
subroutine TEMENOS whose source is under the BP directory is compiled an object code $TEMENOS
is produced and is placed under the directory BP (The source directory). A subroutine also needs to be
catalogued. The process of cataloguing refers an environmental variable JBCDEV_LIB to obtain the
path where it has to place the object file that has been created. Once the path is obtained, the object
code is placed under one of the library files under that path. Therefore, all object codes of all
subroutines get stored under a library file under the path pointed by the environmental variable
JBCDEV_LIB. The library files mentioned above are controlled by a configuration file named
jLibDefinition, which is present under the jBase config directory (Referred by the environmental
variable JBCGLOBALDIR). The jLibDefinition file specifies the naming convention of the library files
and the maximum size of them as well. jBase decides, under which library file the object code has to
reside. If none of the existing library files under the directory pointed by the JBCDEV_LIB have space
to store a new object code then jBase will automatically create a new library file by referring the
jLibDefinition file. jBase will also swap object codes from one library file to another in order to utilize the
existing space inside the library files to the maximum.
JBCDEV_LIB=$HOME/lib
JBCOBJECTLIST=$HOME/lib.$HOME/globuslib
When Globus, 2 directories namely globusbin and bin get installed under the home
directory(run directory) of the user. The directory globusbin is supposed to contain the core Globus
executables and the directory bin is supposed to contain the non-core/local executables. When a
program is compiled an executable is produced. For instance when a program TEMENOS whose
source is in the BP directory is compiled, an executable with the name $TEMENOS gets created under
the BP(Source directory). The process of cataloguing refers an environmental variable JBCDEV_BIN
to obtain the directory into which this executable needs to be placed.
JBCDEV_BIN=$HOME/bin
PATH=$HOME/bin:$HOME/globusbin:$PATH
Example 1
Step 1
Write a program to display the string “HELLO WORLD” and store it under the BP directory.
Consolidated Solution 1
JED BP HELLO
New record.
PROGRAM HELLO
CRT "HELLO WORLD"
END
JED is the jBase editor. Please refer to ‘Using JED Editor’ notes that have been attached to this course
material.
Step 2
Compile and catalog the program. Since this is a local program, the executable needs to go to bin and
not globusbin. Therefore check the value of JBCDEV_BIN. If it is pointing to any other directory other
than bin change it to point to bin.
echo $JBCDEV_BIN
Note the output. If it is anything other than the bin directory then change the value of JBCDEV_BIN as
follows
export JBCDEV_BIN=$HOME/bin
Please note that the above statement will only change the value of JBCDEV_BIN for the current
session. If you want this change to be permanent, then make the change in the .profile file, logout and
login for the change the take effect.
Execute the program by typing the following statement at the database prompt .
HELLO
Just like any other programming language, Infobasic also supports a number of control
structures namely
I. If Then Else
II. Begin Case End Case
III. For Loop
IV. Open Loop
I. If Then Else
For each of these statements the format of the THEN and ELSE clauses is the same.
If the THEN or ELSE clause is restricted to one statement, on the same line as the test statement, the
THEN or ELSE can be specified in the simple format.
If the THEN or ELSE clause contains more than one statement, or you wish to place it
on a separate line, you must use the multiline format, which encloses the statements and terminates
them with an END.
Example :
Use the CASE statement to alter the sequence of instruction execution based on the
value of one or more expressions. If expression in the first CASE statement is true, the following
Example:
USERNAME = @LOGNAME
BEGIN CASE
CASE USERNAME = “TOM”
DEPARTMENT = “HR”
III. CASE
For Loop USERNAME = “DICK”
DEPARTMENT = “ADMIN”
CASE 1 if none of the Case statements match
Use the For Loop to execute a setthen
of statements repeatedly until
this statement a specific
would get condition is
met or for specific number of times. The counted loop uses a variable to hold the iteration count. This
executed
commences at the start value
“DEPARTMENT NOT for the loop is automatically incremented by a step value at each
FOUND”
END CASE
iteration. Once it has passed the end value, the loop terminates.
Example :
FOR COUNTER = 1 TO 10
CRT “TEMENOS GLOBUS” The string TEMENOS GLOBUS will
get
NEXT COUNTER printed 10 times
The open loop specifies a more powerful loop construction which will continue to
iterate until a condition is met to terminate this. The condition is held in the WHILE clause. The
REPEAT statement takes the control back to the first line after the LOOP statement.
Example :
LOOP
CRT “Input 2 Numbers”
INPUT Y.NUM1
INPUT Y.NUM2
WHILE Y.NUM1:Y.NUM2 Note that a condition is being checked using the While
clause. ‘:’ is the concatenation operator in Infobasic. The
While statement specified here checks if Y.NUM1 and
Y.NUM2 contain values.
CRT “Total “ : Y.NUM1 + Y.NUM2
REPEAT
Note :
Following are the boolean operators used in Infobasic
=EQ Equality
V. FOR Loop Inequality
#<>NE
>GT Greater Than
>=GE A FOR loopGreater
can beThan/Equal
used when a repeated set of statements need to be performed for specific
<=LT of times. Less Than
number
<=LE Less Than/Equal
MATCHES Pattern Match
FOR COUNTER = 1 TO 10
CRT “TEMENOS”
NEXT COUNTER
Infobasic has a number of built in functions that help in rapid code development. Some
of the commonly used build in functions are listed below.
I. LEN
II. COUNT
III. DCOUNT
IV. UPCASE
V. DOWNCASE
VI. CHANGE
VII. OCONV
I. LEN
Example :
Var1 = LEN(“TEMENOS”)
Var1 = 8
II. COUNT
Use the COUNT function to return the number of times a substring is repeated in
a string value.
Example :
Var1 = “abc,def,ghi”
Var2 = COUNT(Var1,”,”) The COUNT function here is used to count the
number of “,” in the string held in the variable var1
Var2 = 3
III. DCOUNT
Use the DCOUNT function to return the number of delimited fields in a data string.
Example :
Var1 = “abc,def,ghi”
Var2 = DCOUNT(Var1,”,”) The DCOUNT function here is used to count the
number of fields delimited by the delimiter “,” in the
string held in the variable var1
Var2 = 4
IV. UPCASE
Use the UpCase function to convert the passes string to UPPER CASE.
Example :
Var1 = UPCASE(“temenos”)
Var1 = TEMENOS
V. DOWNCASE
Use the DownCase function to convert the passed string to lower case
Example :
Var1 = DOWNCASE(“TEMENOS”)
Var1 = temenos
VI. CHANGE
Example :
VII. OCONV
Use the OCONV function to convert string to a specified format for external output.
The result is always a string expression.
Example :
DATE=OCONV('9166',"D2") 3 Feb 93
You would be aware by now that Infobasic allows us to create programs as well as
subroutines, which are to be executed from within Globus.
Actual Statements
Actual Statements
RETURN
END
Insert files are similar to ‘Include’ files that you might have used in ‘C’ and ‘C++’
programs. There are number of insert files available. Each one of them contains some inbuilt
functionality, which can be used in our programs/subroutines. This enables re-usability of code.
I_COMMON and I_EQUATE are two main insert files available in Globus.
I_COMMON defines all common global variables that can be used across subroutines and the file
I_EQUATE initializes those common variables. It is a good practice to include these files in every
subroutine we write irrespective of whether we are to use common global variables or not. These insert
files are available under the directory GLOBUS.BP.
Example 2
Write a subroutine that will display the details (Id, Mnemonic and Nationality) of a customer whose id is
100069
Solution 2
Step 1
Algorithm:
Step 1 :
In order to open the Customer file we can use the command OPEN.
When we use the OPEN to open a file, we need to supply the exact file name(along
with the prefix). If programs are written using OPEN statements , they do not become portable across
branches of a bank as each branch will have a different mnemonic to identify itself uniquely.
For Instance
Bank XYX
In Branch1
In a subroutine we open the customer file by using UniVerse OPEN statement
OPEN FBR1.CUSTOMER
In Branch2
In order to overcome this problem or program portability, we need to use the core
Globus subroutine OPF instead of Open.
OPF :
Syntax :
CALL OPF(Parameter1,Parameter2)
Parameter 1 The name of the file to be opened prefixed with a F.
Parameter 2 -> Path of the file to be opened. This is usually specified as ‘ ‘
Example :
FN.CUS = ‘F.CUSTOMER’
F.CUS = ‘’
CALL OPF(FN.CUS,F.CUS) Code to open the Customer file
Working Of OPF :
Both the above mentioned parameters are to be stored in variables and then passed to the
OPF subroutine.
FN.CUS = ‘F.CUSTOMER’
The name of the variable that is to store the file name has to begin with “FN.” followed
by a string that denotes the file that is to be opened. Just supply the value “F.” followed by the name of
the file to open like above to the variable FN.CUS.
When the OPF subroutine gets executed, the COMPANY file is read inorder to obtain
the mnemonic of the bank. Then the FILE.CONTROL record of the file is read to find out the type of
file(INT,CUS or FIN). Once the file type is extracted, the ‘F.’ in the file name gets replaced with
“FBankMnemonic” - FBNK thus making subroutines portable across branches.
F.CUS = ‘’
The name of the variable that will hold the path of the file has to begin with a ‘F.’
followed by a string that denotes the file that is to be opened. This string has to be the same as that of
the file name(FN) variable. This variable should be equated to a null(‘’).
When OPF gets executed, the VOC entry for the file is read and the path of the data file gets populated
in this variable.
Step 2 :
In order to read the Customer file use the Globus subroutine F.READ.
Syntax :
F.READ(FileName,Id of the record to be read,Dynamic array that will hold the read record,Filepath,Error variable)
Y.CUSID = “100069”
CALL F.READ(FN.CUS,Y.CUSID,R.CUSTOMER,F.CUS,CUS.ERR1)
Note R.CUSTOMER is a dynamic array that will hold the extracted customer record. It
does not require declaration, but initializing it to a ‘’ would be a good programming practice. The error
variable CUS.ERR1 will hold ‘null’ if the read is successful else will hold a numeric value. Note that the
id of the record has been supplied using a variable.
Contents Of R.CUSTOMER
Note that the values of fields have been delimited using a field marker() and multi values have
been delimited using the value marker(ÿ). There aren’t any sub values in this customer record.
DAOHENGBKDAO HENG BANK INCDAO HENG BANK INC119 ASIAN MANSION 209 DELA ROSA S
TLEGASPI VILLAGE MAKATI CITY MAN
PH1111908100999PH4PH200001012
00001011118_RICKBANAT1ÿ28_ANDREABARNES100061210421
8_RICKB
Step 3 :
ANAT1US00100011
In order to obtain the mnemonic and the nationality of the customer, we need to access the dynamic
array R.CUSTOMER. To extract values from a dynamic array, angular brackets
“< >” need to be used.(Use ‘()’ for dimensioned arrays)
We can extract data from the dynamic array by specifying field positions as follows
Y.MNEMONIC = R.CUSTOMER<1>
or by specifying the actual name of the field.It is always advisable to use field names because field
positions could change from one release of Globus to another. Here 1 is the field position of the
field mnemonic in the CUSTOMER file.
How does one know the field numbers and the field names?
Most of the files in Globus have insert files, which begin with ‘I_F.’ followed by the name of the file.
They will be available under GLOBUS.BP.These files hold the names and the field positions of the
various fields. These fields could have prefixes/suffixes.
For the customer insert file
Prefix used is : EB.CUS
Suffix used is : NIL
Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
Step 4 :
To display the Id, Mnemonic and Nationality values extracted we could use the
Infobasic command CRT.
Syntax :
CRT VariableName/”String”
Example :
Consolidated Solution 2
Note :
In the above subroutine, the code has been split and made part of 3 different
paragraphs. In order to achieve modularity and to make maintenance of code easier, it is
advisable to make use of paragraphs. Every paragraph has to have a name and has to end with
a RETURN statement.A GOSUB ParagraphName statement takes the control to that specific
paragraph. Once the statements inside the paragraph get executed, the RETURN statement
takes the control back to the line after the GOSUB statement that actually invoked this
paragraph. This type of modular programming needs to be used for a lengthy subroutine.
Incase the number
TemenosofTraining
lines that constitute the subroutine is very less, the programmer could 49
Publications
choose to write code using the Top Down approach of programming where there will be no
paragraphs at all.
Note
Note :
We need to compile and catalogue this subroutine now. Use
EB.COMPILE BP CUS.DISPLAY.DETAILS
Compile and catalogue. Check variables JBCDEV_LIB and JBCOBJECTLIST and change if
necessary.
As you would be aware by now, anything that needs to be executed from the ‘Awaiting
Application’ prompt in Globus needs to have an entry in the PGM.FILE. Inorder to execute out
subroutine from within Globus, we need to make an entry in the PGM.FILE. Ensure that you set the
type in the PGM.FILE to ‘M’ (Mainline program). The ID of the PGM.FILE entry should be the name of
the file which stores the subroutine.
Note :
Debug Statement
If we type CUS.DISPLAY.DETAILS in the Awaiting Application prompt we would see the
output.
The DEBUG statement shows the execution of a subroutine line by line
Let us add the DEBUG statement to the subroutine and see the display (Add it at the
point from where you wish to see the execution of the subroutine line by line)
SUBROUTINE CUST.DISPLAY.DETAILS
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INIT:
DEBUG
Ensure that you compile and catalogue after making any changes to the subroutine.
Type the name of the subroutine in the ‘Awaiting Application’ prompt and see the execution of
the subroutine line by line.
Note :
Some DEBUGger commands
S - To execute the line
V variablename - To see the contents of a variable
Q or QUIT- Quit out of the subroutine and return to the Database prompt.
Example 3
Modify example 1 to display the id, mnemonic and nationality of all customers.
Solution 3
Algorithm
Step 1
You would be aware by now that we need to use OPF to open any file in Globus.
FN.CUS = ‘F.CUSTOMER’
F.CUS = ‘’
CALL OPF(FN.CUS,F.CUS)
Step 2
We need to select all the customer ids from the Customer file. In order to achieve this
we need to execute a Select statement that will pick up all the Customer ids. Select statements can be
executed within subroutines. In order to execute select statements within a subroutine, we need to first
assign the select statement to a variable and then execute the contents of the variable using the core
Globus subroutine EB.READLIST. Please note that a Select statement can only return the ids from
the file on which the Select statement is based.
EB.READLIST
EB.READLIST is a core Globus subroutine that is used to execute a Select statement within a
subroutine
Syntax :
1 - The select statement to be executed. Give the name of the variable that holds the select statement
here.
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,CUS.ERR)
Step 3 And 4
Consolidated Solution 3
Modify Example 2 to store the extracted mnemonic and nationality of all customers in an
array(do not display them) delimited by a ‘*’. The array should contain data as follows
CusId*Mnemonic*NationalityFMCusId*Mnemoic*Nationality
Solution 4
Algorithm :
Step 1, 2 ,3 ,4 And 5
As discussed earlier we could go ahead and use OPF, F.READ, LOOP, REMOVE
and REPEAT to accomplish the above mentioned steps.
Step 6
In order to append the extracted values into an array we could use the following
method.
ArrayName<-1> = Value
In our case, once we extract the mnemonic and the nationality of the customer
we could concatenate the id, mnemonic and the nationality of the customer delimited with a ‘*’ and then
store it in a dynamic array.
Every time a new value comes in, the existing values get pushed down by one
position. This is achieved by the ‘-1’ that we specify along with the array name. All values get
appended, delimited by a field marker ‘FM’.
MAINARRAY<-1> = Y.CUSID:’*’:Y.MENMONIC:’*’:Y.NATIONALITY
The array will look like this after all values have been concatenated
Note -
To have values in an array delimited by value markers use
ArrayName<1,-1> = Value1:’*’:Vale2:’*’:Value3:’*’:Value4
To have values in an array delimited by sub value markers use
ArrayName<1,1,-1>
Temenos = Value1:’*’:Vale2:’*’:Value3:’*’:Value4
Training Publications 54
Consolidated Solution 4
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INIT:
FN.CUS = 'F.CUSTOMER'
F.CUS = ''
Y.CUS.ID = ''
R.CUSTOMER = ''
CUS.ERR1 = ''
Y.MNEMONIC = ''
Y.NATIONALITY = ''
SEL.CMD = ''
SEL.LIST = ''
NO.OF.REC = 0
RET.CODE = ''
CUS.DETAILS.ARRAY = ''
RETURN
OPENFILES:
CALL OPF(FN.CUS,F.CUS)
RETURN
PROCESS:
SEL.CMD = "SELECT ":FN.CUS
CALL EB.READLIST(SEL.CMD,SEL.LIST,'',NO.OF.REC,RET.CODE)
LOOP
REMOVE Y.CUS.ID FROM SEL.LIST SETTING POS
WHILE Y.CUS.ID:POS
CALL F.READ(FN.CUS,Y.CUS.ID,R.CUSTOMER,F.CUS,CUS.ERR1)
Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
CUS.DETAILS.ARRAY<-1> =
Y.CUS.ID:'*':Y.MNEMONIC:'*':Y.NATIONALITY
REPEAT
RETURN
END
Note :
In order to execute the above subroutine, we need to compile and catalogue it. An
entry in the PGM.FILE has to be made to execute it from within Globus. In order to see
the execution of the subroutine line by line, we need to add the DEBUG statement.
Summary
Infobasic does not support data types. Variables need not be declared in Infobasic.
All variables in Infobasic are treated as dynamic arrays
Dynamic arrays expand or reduce in size depending on the amount of data
Additional Information:
LOCATE
LOCATE statement is used to locate the position of a string or determine the position
to insert in to maintain a specific sequence.
Syntax
Additional Information
Sort.Expr :
Example
DAYS = “MON:”FM:”TUE”:FM:”WED”:FM:”THU”:FM:”FRI”
LOCATE “WED” IN DAYS SETTING FOUND ELSE FOUND = 0
CRT “Position of WED in DAYS dynamic array :”:FOUND
LOCATE “SAT” IN DAYS BY “AL” SETTING POS ELSE
INS “SAT” BEFORE DAYS<POS>
END
CRT “Position where SAT has been inserted :”:POS
CRT “Days dynamic array after inserting SAT :”:DAYS
Output
Syntax:
CALL F.WRITE(FN.CUS,Y.CUS.ID,R.CUSTOMER)
F.DELETE
F.DELETE is also a core Globus subroutine that is used to delete a record from a file.
Syntax :
CALL F.DELETE(FN.CUS,Y.CUSID)
Infobasic has a number of built in commands as well that enable rapid code
development. Find below some very commonly used Infobasic commands,
I. OPENSEQ
II. READSEQ
III. WRITESEQ
IV. CLOSESEQ
V. MATREAD
VI. MATWRITE
VII. LOCATE
I. OPENSEQ
OPENSEQ is used open a sequential file. If the file that you are trying to open does
not exist, and you wish to create it you could create it by specifying CREATE statement in the ELSE
clause, OPENSEQ has the capability to do it(Achieved by the ELSE clause)
Syntax
OPENSEQ “path of the file and the file name” TO filevariable ON ERROR
STOP “message”
END ELSE
CREATE filevariable ELSE STOP “message”
END
Example
READSEQ is used to read data from a sequential file. While reading data from a afile,
READSEQ uses the new line character CHAR(10) as the delimiter. Once the end of the file is reached
the ELSE clause statements are executed.
Syntax
Example
III. WRITESEQ
WRITESEQ is used to write to a sequential file. It writes the expression as the next
line to the file opened to file.variable using a new line character CHAR(10) as the delimiter.
Syntax
Example
IV. CLOSESEQ
CLOSESEQ is used to write an end-of-file mark and to make the file available to other
users. It is very important that you use CLOSESEQ on any file opened with OPENSEQ, because
CLOSESEQ releases the READU lock that was taken by the OPENSEQ statement.
Syntax
CLOSESEQ file.variable
ON ERROR statements
Example
CLOSESEQ TEM1
ON ERROR CRT “Unable to write an end-of-file mark on temenos.txt”
V. MATREAD
Example
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.
VI. MATWRITE
MATWRITE is used to build a dynamic array from a specified dimensioned array and
write it to the file opened to file.variable using a key of record.id.
Syntax
Example
DIM ARRAY1(5)
MATREAD ARRAY1 FROM TEM1,101 ELSE
MAT ARRAY1 = ‘’
END
MATWRITE ARRAY1 ON TEM1,100
Note :
Use HELP BASIC functionname/commandname at the database prompt to get help
on any of the Infobasic commands or functions.