InfoBasic Programming Language
InfoBasic Programming Language
Agenda
• Introduction to Infobasic
• Arrays and types of arrays
• Introduction to subroutines and programs
• Important functions/commands in Infobasic
• Steps to create a subroutine in T24
• Compiling and cataloguing routines and programs
• T24 routines – file operations
• T24 routines – sequential file access
• T24 – Creation of functions and routines with
arguments
07 January 2005
Introduction To Infobasic
07 January 2005
Arrays
T E M E N O S
0 1 2 3 4 5 6
07 January 2005
Arrays In Infobasic
• Dynamic Arrays
– Dynamic in nature
– Variable length
– Need not be declared
– Can hold any type of data
– Automatically increase or decrease in size depending on the
data
– All variables in Infobasic are dynamic arrays
• Dimensioned arrays
– Have a fixed number of rows and columns
– Can hold any type of data
– Needs to be declared
– Used when dimensions and extents are known and are not
likely to change
07 January 2005
Dynamic Array
CUSTOMER.NAME = ‘’
RATE = 0
DATE = “121202”
07 January 2005
Arrays
07 January 2005
Sample Record From The TEMENOS.TRG
1 Name TemenosTrg
2.1 Address India
2.2 Address UK
2.3 Address Geneva
3.1 Course Category Technical
4.1.1 Course Name jBASE
4.1.2 Course Name T24
3.2 Course Category Functional
4.2.1 Course Name Lending
4.2.2 Course Name Financials
5 Free Text
6 Inputter TRAINER.1
07 January 2005
How will this record get stored in a dynamic
array?
07 January 2005
Storage In A Dynamic Array
TemenosTrgFMIndiaVMUKVMGenevaFMTechnicalVMFunctionalFM
jBASESMT24SMLendingSMFinancialsFMFMTrainer.1
07 January 2005
Dimensioned Array
DIM ARRAY1(4,3)
4 – Rows
3 – Columns
07 January 2005
Dimensioned Array (Cont.)
DIM ARRAY2(4)
4 – Rows
Unlimited columns (Each row will be a dynamic array)
07 January 2005
Structure Of An Infobasic Program
*Comments *Comments
PROGRAM <Programname> SUBROUTINE <Subroutinename>
Statement 1 Statement 1
Statement 2 Statement 2
Statement 3 Statement 3
RETURN
END END
07 January 2005
Compiling And Cataloguing Routines
COMPILE CATALOG
COMPILE CATALOG
Error – Exit
No Error JBCDEV_BIN
= $HOME/bin
Produce executable
$TRG.PRG1
TRG.BP $HOME/bin
$TRG.PRG1 TRG.PRG1
07 January 2005
Executing Routines
Make an entry in
the PGM.FILE
JBCOBJECTLIST =
$HOME/globuslib;$HOME/lib
Execute the
routine
07 January 2005
Executing Programs
Go to the
database prompt
jsh..> TRG.PRG1
PATH =
.;$HOME/globusbin;$HOME/bin;$PATH
Execute the
program
07 January 2005
Writing A simple Infobasic Program
PROGRAM HELLO
CRT “Hello World”
END
07 January 2005
Compile And Execute The Program
jsh..>HELLO
Hello World
07 January 2005
Workshop 1
Control Structures
• IF THEN ELSE
IF <condition> THEN
<statements>
END
ELSE
<statements>
END
07 January 2005
Control Structures
BEGIN CASE
CASE <variable> = <value>
<statements>
CASE <variable> = <value>
<statements>
CASE <variable> = <value>
<statements>
CASE 1
<statements>
END CASE
07 January 2005
Control Structures
• FOR
07 January 2005
Control Structures
• Open Loop
LOOP
CRT “Input 2 Numbers”
INPUT Y.NUM1
INPUT Y.NUM2
WHILE Y.NUM1:Y.NUM2
CRT “Total “ : Y.NUM1 + Y.NUM2
REPEAT
07 January 2005
Built In Infobasic Functions
07 January 2005
Structure Of A Subroutine
SUBROUTINE SubroutineName
$INSERT I_COMMON
$INSERT I_EQUATE
Actual Statements
Actual Statements
RETURN
END
07 January 2005
Insert Files
• I_COMMON
– Defines all common variables
• I_EQUATE
– Equates a number of common variables
07 January 2005
Example 2
07 January 2005
Algorithm
07 January 2005
Open A File
OPEN FBNK.CUSTOMER…….
But…….
07 January 2005
Open A File (Cont.)
CALL OPF(FN.CUS,F.CUS)
07 January 2005
Read A File
CALL F.READ(FN.CUS,”100069”,R.CUSTOMER,FV.CUS,CUS.ERR1)
F.READ always checks if the record is in cache. If yes, fetches the record
from the cache, else retrieves the record from the databse.
07 January 2005
Record Returned By F.READ
Contents of R.CUSTOMER
DAOHENGBK DAO HENG BANK INC DAO HENG BANK INC 119 ASIAN MANSION 209
DELA ROSA ST LEGASPI VILLAGE MAKATI CITY MAN PH 1111
90 8100 999 PH 4 PH 20000101 20000101
1 1 18_RICKBANAT1ÿ28_ANDREABARNES1 0006121042 18_RI
CKBANAT1 US0010001 1
07 January 2005
Extract Values
R.CUSTOMER<1>
R.CUSTOMER<15>
07 January 2005
I_F.CUSTOMER File
07 January 2005
Display Parts Of A Record
Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
07 January 2005
Display Parts Of A Record(Cont.)
07 January 2005
Solution 2
07 January 2005
Solution 2 (Cont.)
OPENFILES:
CALL OPF(FN.CUS,FV.CUS)
RETURN
PROCESS:
CALL F.READ(FN.CUS,Y.CUS.ID,R.CUSTOMER,FV.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
RETURN
END
07 January 2005
Solution 2
07 January 2005
Debugging …….
DEBUG
FN.CUS = ‘F.CUSTOMER’
FV.CUS = ‘’
Y.CUS.ID = 100069
07 January 2005
Debugging……….
07 January 2005
Workshop 2
Example 3
07 January 2005
Algorithm
07 January 2005
EB.READLIST
CALL EB.READLIST(1,2,3,4,5)
07 January 2005
EB.READLIST (Cont.)
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET.CODE)
07 January 2005
Insight Into EB.READLIST – Execute Select
07 January 2005
Insight Into EB.READLIST - Internal Select
07 January 2005
Insight Into EB.READLIST - Internal Select
07 January 2005
Repeating A Set Of Statements
07 January 2005
Solution 3
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'
FV.CUS = ''
Y.CUS.ID = ''
R.CUSTOMER = '‘
CUS.ERR1 = ''
Y.MNEMONIC = ''
Y.NATIONALITY = ''
SEL.CMD = ''
SEL.LIST = ''
NO.OF.REC = 0
RET.CODE = ''
RETURN
07 January 2005
Solution 3 (Cont.)
OPENFILES:
CALL OPF(FN.CUS,FV.CUS)
RETURN
PROCESS:
END
07 January 2005
Solution 3
07 January 2005
Workshop 3
Example 4
07 January 2005
Algorithm
07 January 2005
Algorithm
07 January 2005
Append Data In An Array
ARRAY<-1> = NewValue
ARRAY<-1> = Y.CUS.ID:’*’:Y.MNEMONIC:’*’:Y.NATIONALITY
07 January 2005
Append Data In An Array (Cont.)
07 January 2005
Solution 4
*Subroutine to store the id, mnemonic and nationality of all *customers in an array
SUBROUTINE CUS.DISPLAY.DETAILS
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INIT:
FN.CUS = 'F.CUSTOMER'
FV.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
07 January 2005
Solution 4 (Cont.)
OPENFILES:
CALL OPF(FN.CUS,FV.CUS)
RETURN
PROCESS:
END
07 January 2005
Solution 4
07 January 2005
Workshop 4
Example 5
Example 5
As a part of the COB process in T24, all savings
accounts that have balance less than 5000 need to be
charged a fee. For this purpose you are expected to
create a local reference field by name CHARGE in the
Account application and write a subroutine that will
check the working balance of all savings accounts, and
if the working balance is lesser than 5000 then set the
value in the local reference field CHARGE to ‘Y’. As a
part of the COB process in T24, one of the COB
routines will deduct a charge from all accounts which
have this field set to ‘Y’.
07 January 2005
Algorithm
07 January 2005
Algorithm (Cont.)
07 January 2005
Update a local reference field
R.ACCOUNT<AC.LOCAL.REF,1> = ‘Y’
07 January 2005
Write into a hashed file
CALL F.WRITE(FN.ACC,Y.AC.ID,R.ACCOUNT)
• Parameters :
– File name
– Record Id
– Record to be written
07 January 2005
Update the F.JOURNAL file
CALL JOURNAL.UPDATE(Y.AC.ID)
07 January 2005
Solution 5
*Subroutine to check if the balance in all savings accounts are less than 5000 and if so,
*update a local reference field in the ACCOUNT file called CHARGE to ‘Y’.
SUBROUTINE ACC.BAL.CHECK
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.ACCOUNT
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
INIT:
FN.ACC = ‘F.ACCOUNT’
FV.ACC = ‘’
Y.AC.ID = ‘’
R.ACCOUNT = ‘’
Y.ACC.ERR = ‘’
RETURN
07 January 2005
Solution 5
OPENFILES:
CALL OPF(FN.ACC,FV.ACC)
RETURN
PROCESS:
SEL.CMD = “SELECT “:FN.ACC:” WITH CATEGORY = 6001”
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET,CODE)
LOOP
REMOVE Y.ACC.ID FROM SEL.LIST SETTING POS
WHILE Y.ACC.ID:POS
CALL F.READ(FN.ACC,Y.AC.ID,R.ACCOUNT,FV.ACC,Y.ACC.ERR)
IF R.ACCOUNT<AC.WORKING.BALANCE> < 5000 THEN
R.ACCOUNT<AC.LOCAL.REF,1> = ‘Y’
CALL F.WRITE(FN.ACC,Y.ACC.ID,R.ACCOUNT)
CALL JOURNAL.UPDATE(Y.ACC.ID)
END
Y.AC.ID = ‘’
R.ACCOUNT = ‘’
REPEAT
RETURN
END
07 January 2005
What if another user updates the same Account record
while you are trying to update?
07 January 2005
Always read and lock a record if you wish to update it.
07 January 2005
F.READU
Use F.READU
• Similar to F.READ
• Read and lock a record
• The lock will be released when
– The record is written back to the file
– There is an explicit RELEASE statement after obtaining the
lock
– The routine terminates
07 January 2005
F.READU
CALL F.READU(1,2,3,4,5,6)
1 – File Name
2 – ID
3 – Record
4 – File variable
5 – Error variable
6 – Retry Option
– P msg - prompt user with msg to retry if record locked
– R nn xx - retry xx times with a nn seconds sleep interval
– I - ignore the lock and return
– E - return immediately with an error message
– ‘’ – Retry continuously
07 January 2005
Code With F.READU
PROCESS:
SEL.CMD = “SELECT “:FN.ACC:” WITH CATEGORY = 6001”
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET,CODE)
LOOP
REMOVE Y.ACC.ID FROM SEL.LIST SETTING POS
WHILE Y.ACC.ID:POS
CALL F.READU(FN.ACC,Y.AC.ID,R.ACCOUNT,FV.ACC,Y.ACC.ERR,’’)
IF R.ACCOUNT<AC.WORKING.BALANCE> < 5000 THEN
R.ACCOUNT<AC.LOCAL.REF,1> = ‘Y’
CALL F.WRITE(FN.ACC,Y.ACC.ID,R.ACCOUNT)
JOURNAL.UPDATE(Y.ACC.ID)
END
Y.AC.ID = ‘’
R.ACCOUNT = ‘’
REPEAT
RETURN
END
07 January 2005
Solution 5
07 January 2005
Are there better ways to read data from a file?
07 January 2005
CACHE.READ
07 January 2005
CACHE.READ (Cont.)
07 January 2005
CACHE.READ (Cont.)
CACHE.READ(FileName,ID,Record,Error)
07 January 2005
CACHE.READ (Cont.)
When
• ID is passed to CACHE.READ
– Check if it exists in cache else will read from disk and load it
to cache
• If ‘SelectIDs’ is passed to CACHE.READ
– Peform a call to EB.READLIST. Since there are no
conditions and it is not a sorted select, an internal selected
will be executed
• If ‘SSelectedID’ or ‘SSelectARs’ is passed
– Perform a call to EB.READLIST. Since it is sorted select, will
actually select the file
07 January 2005
Insight Into Reading And Writing Records
• READ
• F.READ
• F.READU
• F.READV
• DBR
• TRANS
• WRITE
• F.WRITE
07 January 2005
Important T24 Routines
• OVERLAY.EX
• FATAL.ERROR
07 January 2005
Workshop 5
Example 6
07 January 2005
Algorithm
07 January 2005
Algorithm (Cont.)
Parameters:
SEQ.FILE.NAME = ‘TEMENOS.SEQ’
RECORD.NAME = ‘1’
07 January 2005
Opening A Sequential File
07 January 2005
Algorithm (Cont.)
CLOSESEQ FilePointer
CLOSESEQ SEQ.FILE.POINTER
07 January 2005
Solution 6
PROGRAM SEQFILE.ACCESS.WRITE
SEQ.FILE.NAME = ‘TEMENOS.SEQ’
RECORD.NAME = ‘1’
OPENSEQ SEQ.FILE.NAME,RECORD.NAME TO SEQ.FILE.POINTER ELSE
CREATE SEQ.FILE.POINTER ELSE
CRT “Unable to create file pointer to file “:SEQ.FILE.NAME
STOP
END
END
CRT “Openseq was successful on file “:SEQ.FILE.NAME
WRITESEQ “Infobasic programming” TO SEQ.FILE.POINTER ELSE
CRT “Unable to perform WRITESEQ”
END
CLOSESEQ SEQ.FILE.POINTER
END
07 January 2005
Workshop 6
Example 7
Write a program that will read the data that has been
written on to the sequential file TEMENOS.SEQ .
07 January 2005
Algorithm
07 January 2005
Reading A Sequential File
READSEQ
07 January 2005
Reading A Sequential File
07 January 2005
Solution 7
PROGRAM SEQFILE.ACCESS.READ
SEQ.FILE.NAME = ‘TEMENOS.SEQ’
RECORD.NAME = ‘1’
OPENSEQ SEQ.FILE.NAME,RECORD.NAME TO SEQ.FILE.POINTER ELSE
CREATE SEQ.FILE.POINTER ELSE
CRT “Unable to create file pointer to file “:SEQ.FILE.NAME
STOP
END
END
CRT “Openseq was successful on file “:SEQ.FILE.NAME
READSEQ Y.MSG FROM SEQ.FILE.POINTER THEN
CRT “Message Extracted :”:Y.MSG
END
ELSE
CRT “Unable to read from file “
END
CLOSESEQ SEQ.FILE.POINTER
END
07 January 2005
More On OPENSEQ
SEQ.FILE.NAME = ‘./TEMENOS.SEQ/1’
07 January 2005
Workshop 7
Subroutines With Arguments
07 January 2005
Example 8 And Solution 8
SUBROUTINE DEMO.CALLED.RTN(ARG.1,ARG.2,ARG.3)
ARG.3 = ARG.1 * ARG.2
RETURN
END
07 January 2005
Solution 8 (Cont.)
Step 2
SUBROUTINE DEMO.CALLING.RTN
VAR.1 = 10
VAR.2 = 20
VAR.3 = ‘’
CALL DEMO.CALLED.RTN(VAR.1,VAR.2,VAR.3)
PRINT ‘Result “:VAR.3
RETURN
END
07 January 2005
Defining Functions
07 January 2005
Example 9 And Solution 9
Step 1
FUNCTION DEMO.FUNCTION(ARG.1,ARG.2)
RET.VALUE = ARG.1 * ARG.2
RETURN(RET.VALUE)
END
07 January 2005
Solution 9 (Cont.)
Step 2
SUBROUTINE DEMO.SUB.CALLING.RTN
VAR.1 = 10
VAR.2 = 20
DEFFUN DEMO.FUNCTION(VAL.1,VAL.2)
VAR.3 = DEMO.FUNCTION(VAR.1,VAR.2)
CRT “Result :”:VAR.3
RETURN
END
07 January 2005
Consolidated Workshop