Info Basic
Info Basic
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]
38
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
39
‘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
Just like programs written in any programming language need to be compiled, Infobasic
programs also need to be compiled. Compilation is the process of converting the code into assembly
language that the machine can understand. Once programs/subroutines are compiled, object codes get
produced. These object codes get stored in specific directories.
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
Compiling Programs
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
40
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.
Please ensure that PATH first points to $HOME/lib, as, if there is a program with the same name and
its executable resides in globusbin or any other directory that is specified first in PATH, then that
program only would get executed.
41
source directory name where the source code of the program resides.
Step 4:
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
statements up to the next CASE statement are executed. Execution continues with the statement
following the END CASE statement. If the expression in a CASE statement is false, execution continues
by testing the expression in the next CASE statement. If it is true, the statements following the CASE
statement up to the next CASE or END CASE statement are executed. Execution continues with the
statement following the END CASE statement. If more than one CASE statement contains a true
expression, only the statements following the first such CASE statement are executed. If no CASE
42
statements are true, none of the statements between the BEGIN CASE and END CASE statements
are executed.
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 “DEPARTMENT NOT for
at the start value FOUND”
the loop is automatically incremented by a step value at each
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 loop Greater
can beThan/Equal
used when a repeated set of statements need to be performed for specific
<=LT
number of times. Less Than
<=LE Less Than/Equal
MATCHES Pattern Match
Example
FOR COUNTER = 1 TO 10
CRT “TEMENOS”
NEXT COUNTER
43
7.1 Built In Infobasic Functions
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
Note :
DCOUNT basically counts the number of delimiters and adds one to the result and
displays. When the number of delimiters need to be obtained, use the COUNT function.
When the actual number of values need to be obtained, use the DCOUNT function.
44
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.
SUBROTUINE SubroutineName
$INSERT I_COMMON Insert Files
$INSERT I_EQUATE
Actual Statements
Actual Statements
RETURN
END
45
Figure 4.1 Structure Of A Subroutine
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
If the above subroutine with the OPEN statement were to be executed in this branch,
the subroutine would return a fatal error saying that it cannot open the file. The name
of the customer file in this branch is FBR2.CUSTOMER.
In order to overcome this problem or program portability, we need to use the core
Globus subroutine OPF instead of Open.
OPF :
46
OPF is a core Globus subroutine that is used to open files.
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)
Example :
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. 47
DAOHENGBKDAO HENG BANK INCDAO HENG BANK INC119 ASIAN MANSION 209 DELA ROSA S
TLEGASPI VILLAGE MAKATI CITY MAN
Step 3 :
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
Therefore to extract the mnemonic and nationality of the customer we need to use the
following code
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.
48
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 of lines that constitute the subroutine is very less, the programmer could
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.
49
How Do We Execute This Subroutine From Globus?
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.
50
0015 Y.MNEMONIC = ''
jBASE debugger->S
0016 Y.NATIONALITY = ''
jBASE debugger->S
0017 R.CUSTOMER = ''
jBASE debugger->S
0018 CUS.ERR1 = ''
jBASE debugger->S
0019 RETURN
jBASE debugger->S
0020 OPENFILES:
jBASE debugger->S
0021 CALL OPF(FN.CUS,F.CUS)
jBASE debugger->S
0022 RETURN
jBASE debugger->S
0023 PROCESS:
jBASE debugger->V FN.CUS
FN.CUS : FBNK.CUSTOMER
jBASE debugger->V F.CUS
F.CUS : File '../mbdemo.data/st/FBNK.CUST000'
jBASE debugger->S
0024 CALL F.READ(FN.CUS,Y.CUS.ID,R.CUSTOMER,F.CUS,CUS.ERR1)
jBASE debugger->S
0025 Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
jBASE debugger->S
0026 Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
jBASE debugger->S
0027 CRT "Customer Id: ":Y.CUS.ID
jBASE debugger->V Y.MNEMONIC
Y.MNEMONIC : TAKIZAKIT
jBASE debugger->V Y.NATIONALITY
Y.NATIONALITY : JP
jBASE debugger->S
Customer Id: 1038
0028 CRT "Customer Mnemonic: ":Y.MNEMONIC
jBASE debugger->S
Customer Mnemonic: TAKIZAKIT
0029 CRT "Customer Nationality: ":Y.NATIONALITY
jBASE debugger->S
Customer Nationality: JP
0030 RETURN
jBASE debugger->Q
Are you sure ?Y
jBASE debugger , QUIT from program 'EX'
jsh geneva ~ -->
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
51
Step 1. Open the Customer File
Step 2. Select all the customer ids
Step 3. Remove one customer id from the selected list
Step 4. For the extracted customer id extract the corresponding record from the customer file
Step 5. From the extracted record extract the mnemonic and nationality
Step 6. Display the customer id, mnemonic and the nationality
Repeat Steps 3 to 6 for all customers
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.
2 - The name of a dynamic array that will hold the result of the select statement. Please note that a
select statement here can only select ids from the respective file. Therefore this dynamic arrays will
only hold the ids of the records that have been selected. All the ids will be delimited by a field
marker(FM).
3 - This is an optional parameter. This is the name of a file in the hard disk that can hold the result of
the select statement. Usually this is set to NULL (‘’)
4 - A variable that will hold the number of records selected.
5 - A variable to hold the return code. Will contain null if the select statement was successful else will
contain 1 or 2.
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,CUS.ERR)
Step 3 And 4
Consolidated Solution 3
52
*Subroutine to display the mnemonic and nationality of all customers
SUBROUTINE CUS.DISPLAY.DETAILS
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
DEBUG
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 = ''
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>
CRT "Customer Id: ":Y.CUS.ID
CRT "Customer Mnemonic: ":Y.MNEMONIC
CRT "Customer Nationality: ":Y.NATIONALITY
REPEAT
RETURN
END
Note :
Use the REMOVE statement to successively extract dynamic array
elements that are separated by system delimiters. When a system delimiter is
encountered, the extracted element is assigned to variable.
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.
Example 4
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 :
53
Step 1. Open the Customer File
Step 2. Select all the customer ids
Step 3. Remove one customer id from the selected list
Step 4. For the extracted customer id extract the corresponding record from the customer file
Step 5. From the extracted record extract the mnemonic and nationality
Step 6. Store the customer id, mnemonic and the nationality in a dynamic array
Repeat Steps 3 to 6 for all customers
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> = Value1:’*’:Vale2:’*’:Value3:’*’:Value4
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 = ''
54
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
Dimensioned arrays need to be declared using the DIM statement
FM, VM and SM are delimiters to separate fields, multi values in a field and sub values in a
field respectively
JBCDEV_LIB is the variable that holds the path where the object code of subroutines need to
be stored
JBCOBJECTLIST contains the search path of subroutines
JBCDEV_BIN contains the path where the executables of programs need to be stored
PATH contains the search path of jBase executables in addition to the search path of Unix
executables.
globusbin contains all the core Globus executables
globuslib contains the object code of all core Globus subroutines
lib and bin are used to store object codes and executables of local subroutines and programs
respectively.
jLibDefinition is the jBase configuration file that controls the creation of library files in jBase.
OPF is a Globus routine that is used to open files
F.READ is a Globus routine that is used to read a record from a file
EB.READLIST is a Globus routine that is used to execute a select statement
EB.COMPILE is used to compile and catalog subroutines
To append data into an array with FM as delimiter use Arrayname<-1>
Additional Information:
LOCATE
55
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
F.WRITE
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)
56
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
II. READSEQ
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
57
THEN statements
ELSE statements
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
Syntax
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
58
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.
59