SABA - T24 Technical Training (Programming) v1.1
SABA - T24 Technical Training (Programming) v1.1
for
SABA African Bank
T24 Development Training
T24 Info basic Programming
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
Agenda
4
Arrays
• Dynamic Arrays (Cont.)
– Uses delimiters to store data of various fields
ASCII Decimal Description
254 Field Marker
253 Value Marker
252 Sub-Value Marker
5
Sample Record From The TEMENOS.TRG
Example of Customer Record
6
How will this record get stored in a dynamic array?
7
Storage In A Dynamic Array
TemenosTrgFMIndiaVMUKVMGenevaFMTechnicalVMFunctional
FM
jBASESMT24VMLendingSMFinancialsFMFMTrainer.1
8
Structure Of An Infobasic Program
PROGRAM – Executed from the database prompt
SUBROUTINE – Execute from within T24
*Comments *Comments
PROGRAM <Programname> SUBROUTINE <Subroutinename>
Statement 1 Statement 1
Statement 2 Statement 2
Statement 3 Statement 3
RETURN 9
Compiling And Jaring Routines
10
Writing A Simple Infobasic Program
Program to display ‘Hello World’
Using any text editor
PROGRAM HELLO
CRT “Hello World”
END
tRun HELLO
Hello World 12
Control Structures
• IF THEN ELSE
IF <condition> THEN
<statements>
END
ELSE
<statements>
END
13
Control Structures
• BEGIN CASE … END CASE
BEGIN CASE
CASE <variable> = <value>
<statements>
CASE <variable> = <value>
<statements>
CASE <variable> = <value>
<statements>
CASE 1
<statements>
END CASE
14
Control Structures
• FOR
15
Control Structure
DISPLAY Commands
CRT
SYNTAX :
CRT @(COLUMN,ROW): TEXT / VARIABLE
Syntax :
FIND <string> IN <array> SETTING var1,var2,var3 THEN/ELSE <statements>
Example :
ARRAY = ‘ABCD’:@FM:’1000’:@VM:’2000’
FIND ‘2000’ IN ARRAY SETTING Y.POS1,Y.POS2,Y.POS3 ELSE NULL
RESULT: 2,2,1
RESULT: 2,1,1
SYNTAX : LEN(string)
Example :
CRT LEN(“THESYS”)
Output : 6
CHAR
SYNTAX: CHAR(expr)
Example:
X = CHAR(65)
X returns the value “A”
SEQ
SYNTAX : SEQ(expr)
Example : SEQ(“A”) returns 65.
SYNTAX : COUNT(expr)
Example
A=“THESYS”
CRT COUNT(A,’S’)
Output : 2
DEL
Example
DEL TESTREC<0,0,0>
Example :
REC=34:@VM:55:@VM:88
R=DCOUNT(REC,@VM)
Actual Statements
Actual Statements
RETURN
END 27
Insert Files
• I_COMMON
– Defines all common variables
• I_EQUATE
– Equates a number of common variables
• Insert files are available under T24.BP
• Common variables get loaded when a user signs on
• Some common variables are loaded when specific applications
are opened/specific actions are performed
Example : R.USER, ID.NEW
28
Example 2
29
Algorithm
• Step 1. Open the Customer File
• Step 2. Read the Customer file and extract the record with id
100069
• Step 3. From the extracted record obtain the mnemonic and
nationality
• Step 4. Display the customer id,mnemonic and nationality.
30
Open A File (Cont.)
• OPF – Open File
CALL OPF(FN.CUS,F.CUS)
FN.CUS = ‘F.CUSTOMER’ (File Name)
F.CUS = ‘’ (File Path)
31
Read A File
• Use the T24 subroutine
CALL F.READ(1,2,3,4,5)
1 - File name
2 - ID of the record to be read
3 - Dynamic array that will hold the read record
4 - File Path
5 – Error Variable
CALL F.READ(FN.CUS,”100069”,R.CUSTOMER,F.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.
32
Record Returned By F.READ
33
Extract Values
R.CUSTOMER<1>
R.CUSTOMER<15>
34
I_F.CUSTOMER File
35
Display Parts Of A Record
Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
36
Display Parts Of A Record(Cont.)
CRT “Customer Id: “:Y.CUS.ID
CRT “Customer Mnemonic: “:Y.MNEMONIC
CRT “Customer Nationality: “:Y.NATIONALITY
37
Solution 2
*Subroutine to display the details of customer 100069
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’
F.CUS = ‘’
Y.CUS.ID = 100069
Y.MNEMONIC = ‘’
Y.NATIONALITY = ‘’
R.CUSTOMER = ‘’
CUS.ERR1 = ‘’
RETURN
38
Solution 2 (Cont.)
OPENFILES:
CALL OPF(FN.CUS,F.CUS)
RETURN
PROCESS:
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
RETURN
END
39
Solution 2
• Compile and catalog the routine
– tCompile CUS.DISPLAY.DETAILS
• Make an entry in the PGM.FILE
with the type set to ‘M’.
41
Debugging …….
Source changed to BP/CUS.DISPLAY.DETAILS
0011 DEBUG
jBASE debugger->S
0012 FN.CUS = 'F.CUSTOMER'
jBASE debugger->S
0013 F.CUS = ''
jBASE debugger->S
0014 Y.CUS.ID = 1038
jBASE debugger->S
0015 Y.MNEMONIC = ''
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'
42
Example 3
43
Algorithm
• 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 nationality
Repeat Steps 3 to 6 for all customers
44
Select
• Assign the select statement to a variable
• SEL.CMD = “SELECT “:FN.CUS
Note the space
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET.CODE)
47
Insight Into EB.READLIST – Execute Select
SEL.CMD = “SELECT “:FN.CUS:” WITH SECTOR > 1000”
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET.CODE)
48
Insight Into EB.READLIST - Internal Select
SEL.CMD = “SELECT “:FN.CUS
CALL EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.REC,RET.CODE)
How does EB.READLIST execute this SELECT statement?
• Picks up the SELECT statement
• Realizes that there are no conditions and no sorted select Xin SEL.CMD
• Performs an OPF for the file that you wish to select
– CALL OPF(FN.CUS.F.CUS)
• Performs ‘SELECT F.CUS’
– This is faster than ‘EXECUTE SEL.CMD’ as it is not actually selecting the file
– It is only positioning the file pointer to the start of the file and then will extract one ID after another and store it in
SEL.LIST
49
Insight Into EB.READLIST - Internal Select
• Use the facility of internal select in EB.READLIST when
– You wish to process most of the records of a file
– You do not want records in a sorted order
50
Repeating A Set Of Statements
51
Solution 3
*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
52
Solution 3
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
53
Solution 3
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
54
Solution 3
• Add a DEBUG statement in the routine
• Compile and catalog the routine
• Make an entry in the PGM.FILE with the type set to ‘M’.
• Execute the routine from the command line.
55
Example 4
Amend example 3 to store the extracted all the customer Ids,
their mnemonics and nationalities in a dynamic array in the
following format
CusId*Mnemonic*NationalityFMCusId*Mnemonic*Nationality
56
Algorithm
• 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
57
Algorithm
• Step 6. Store the customer id, mnemonic and the nationality in
a dynamic array
• Repeat Steps 3 to 6 for all customers
58
Append Data In An Array
ARRAY<-1> = NewValue
ARRAY<-1> = Y.CUS.ID:’*’:Y.MNEMONIC:’*’:Y.NATIONALITY
59
Append Data In An Array (Cont.)
What if an array delimited with VM’s need to formed?
ARRAY<1,-1> = Value
60
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
61
Solution 4
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
62
Solution 4
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
63
Solution 4
• Add a DEBUG statement in the routine
• Compile and catalog the routine
• Make an entry in the PGM.FILE with the type set to ‘M’.
• Execute the routine from the command line.
64
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’. 65
Algorithm
• Step 1 . Create the local reference field CHARGE using the
LOCAL.TABLE application and attach it to the ACCOUNT
application using the LOCAL.REF.TABLE application.
• Step 2. Open the ACCOUNT file
• Step 3.Select all accounts with category = 6001(this category
might differ from one T24 installation to another).
• Step 4.For each of the accounts selected, read the
corresponding record from the ACCOUNT file
66
Algorithm (Cont.)
• Step 4. Check the working balance of the account and if the
balance is less than 5000 then write the entire ACCOUNT
record into the ACCOUNT file with the local reference field
CHARGE set to ‘Y’
• Step 5.Update the F.JOURNAL file.
• Repeat steps 3 to 5 for all accounts using the LOOP and
REPEAT statements.
67
Update a local reference field
R.ACCOUNT<AC.LOCAL.REF,1> = ‘Y’
68
Write into a hashed file
CALL F.WRITE(FN.ACC,Y.AC.ID,R.ACCOUNT)
• Parameters :
– File name
– Record Id
– Record to be written
69
Update the F.JOURNAL file
CALL JOURNAL.UPDATE(Y.AC.ID)
70
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’
F.ACC = ‘’
Y.ACC.ID = ‘’
R.ACCOUNT = ‘’
Y.ACC.ERR = ‘’
RETURN
71
Solution 5
OPENFILES:
CALL OPF(FN.ACC,F.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.ACC.ID,R.ACCOUNT,F.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.ACC.ID = ‘’
R.ACCOUNT = ‘’
REPEAT
RETURN
END
72
Sequential Files Access
• Till now all data files in T24 are hashed files and are of type J4.
• It is possible to read and write into sequential files (non hashed
files).
• These sequential files are mainly used to send data to third
party systems from T24 or receive data from third party
systems in T24.
• There are separate sets of commands used to access these
sequential files.
73
Workshop 6
• Write a program that will write a string “Infobasic
programming” onto a sequential file.
74
Algorithm
• Step1 . Create a non-hashed file with the name
“TEMENOS.SEQ”
• Step 2. Open the non-hashed file. Store the name of the file on
to a variable.
• Step 3. Write the message “Infobasic Programming” on to the
file. Use the command WRITESEQ to write the message on to
the file.
• Step 4. Close the file once the operations are complete .Use
the CLOSESEQ command to close a sequential file.
75
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”
CLOSESEQ SEQ.FILE.POINTER
END
76
Workshop 7
• Write a program that will read the data that has been written
on to the sequential file TEMENOS.SEQ .
77
Algorithm
• Step 1 : Open the sequential file
• Step 2 : Read the data from the sequential file and display it
• Step 3 : Close the sequential file
78
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
79
Solution 7
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
80
Subroutines With Arguments
• Subroutines can take in any number of parameters
• Subroutines can return any number of values
• When defining a subroutine, the parameters for that
subroutine are defined
81
Example 8 And Solution 8
• Create a subroutine that will accept 2 integer values, multiply
them and return the result in a variable.
SUBROUTINE DEMO.CALLED.RTN(ARG.1,ARG.2,ARG.3)
ARG.3 = ARG.1 * ARG.2
RETURN
END
82
Solution 8 (Cont.)
Step 2
Create another subroutine that would supply the values and call the
DEMO.CALLELD.RTN.
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
83
Defining Functions
• Functions can be created in infobasic using the FUNCTION
statement
• Functions can taken in any number of arguments
• Functions can and will return only one value using the RETURN
statement
• Functions can be defined in a subroutine before it is called
using the DEFFUN function
84
Example 9 And Solution 9
Step 1
Create a function that will accept 2 integer values, multiply them
and
return the result in a variable.
FUNCTION DEMO.FUNCTION(ARG.1,ARG.2)
RET.VALUE = ARG.1 * ARG.2
RETURN(RET.VALUE)
END 85
Solution 9 (Cont.)
Step 2
Create a subroutine that will call the function
DEMO.FUNCTION.
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
86
Thanks
87