0% found this document useful (0 votes)
4 views116 pages

JBASIC Programming

The document outlines a course on jBasic programming, detailing its objectives, agenda, and fundamental concepts such as program structure, environmental variables, and control structures. It introduces jBasic as a programming language derived from BASIC, emphasizing its features like dynamic arrays and user-defined functions. The document also covers practical aspects like program compilation, execution, and debugging, along with examples of programs and subroutines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views116 pages

JBASIC Programming

The document outlines a course on jBasic programming, detailing its objectives, agenda, and fundamental concepts such as program structure, environmental variables, and control structures. It introduces jBasic as a programming language derived from BASIC, emphasizing its features like dynamic arrays and user-defined functions. The document also covers practical aspects like program compilation, execution, and debugging, along with examples of programs and subroutines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 116

JBASIC PROGRAMMING

OBJECTIVE

Objectives of the course are to


introduce jBasic language with its features
Understand language related jbase environmental variables
Structure of Program and subroutine
Various functions and statements
Some important Core subroutines in T24

2
COURSE AGENDA(DAY 1)

SESSION I SESSION II
Introduction to jBasic Jbase environmental
variables
Features of jBasic
Programs , Subroutines
Introduction to Jbasic
programs Control structures
BREAK

SESSION III SESSION IV


Jbasic functions Work shops

3
COURSE AGENDA(DAY 2)

SESSION I SESSION II
File Management Subroutines with
parameters
User Defined Functions
Examples

BREAK

SESSION III SESSION IV


Core T24 Subroutines Review of Jbase
Examples Review of Jbasic

4
INTRODUCTION

5
INTRODUCTION TO JBASIC

T24 uses jBase as a backend to store data and jBasic as a


programming language to write programs.
jBasic is Derived from Dartmouth’s BASIC Language.
Since jbase uses BASIC language , it is termed as ‘jBasic’

6
FEATURES OF JBASIC

Written in simple English statements.


Very powerful language.
All variable are treated as dynamic array.
Variable declaration is not necessary.

7
ARRAYS

An array is nothing but continuous memory allocation, where


all the bytes have the same name and can be distinguished
with the help of a subscript that starts from “0”
For example : ARRAY1 = ‘GLOBUS’
To retrieve the value ‘G’ from ARRAY1 we need to specify like
this ARRAY1[1,1]

8
ARRAYS

There are two different types of arrays.


– Dimensioned arrays
– Dynamic arrays

Dimensioned arrays
– More efficient means of creating and manipulating tables of data.
– The number of dimensions and the extent 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 DIM Array2(6,4)
• 6 refers to the number of rows
• 4 refers to the number of columns

9
ARRAYS

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.
Delimiter characters
– ASCII Decimal Description
• 254 Field Marker
• 253 Value Marker
• 252 Sub-Value Marker
– Each field can be delimited by a Field marker, Value marker or Sub-Value
marker.
• Field Marker is denoted as 1
• Value Marker is denoted as 1.1 First level
• Sub-Value Marker is denoted as 1.1.1 – Second level

10
JBASIC PROGRAMS

There are two different types of programs that we can write in


jBasic.
– PROGRAM
– 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 ‘Subroutine’.
Usually any program or subroutine developed by the user is
stored under a directory named XXX.BP and the core Globus
programs or subroutines are stored under GLOBUS.BP.
Never store user written programs/subroutines in the
GLOBUS.BP directory.

11
JBASE ENVIRONMENTAL VARIABLES

12
JBCDEV_BIN

Variable that holds the Path of the Directory where User


executables will be stored when the Program is catalogued.
Example: jsh jglobus ~ -->echo $JBCDEV_BIN
Output : c:\mib13007lh\jbmib\jbnk\bnk.run\bin

13
JBCDEV_LIB

Variable that holds the Path of the Directory where User


LIBRARIES will be stored when the Subroutine is
catalogued.
Example: jsh jglobus ~ --> echo $JBCDEV_LIB
Output : c:\mib13007lh\jbmib\jbnk\bnk.run\lib

14
JBCOBJECTLIST

Holds the Path of the Directory where jBase Shared Object


Libraries are Located.
At the time of Execution of subroutine the system refers this
directory.
Example: jsh jglobus ~ -->echo $JBCOBJECTLIST
Output : c:\mib13007lh\jbmib\jbnk\bnk.run\globuslib; c:\
mib13007lh \jbmib\jbnk\bnk.run\lib

15
JLIBDEFINITION

The jLibDefinition file is used by default to configure the size


and naming convention for each shared library.
If the "lib" directory already exists then the jLibDefinition file is
read from the "lib" directory.
If this is the first time the "lib" directory is created then the
jLibDefinition file is read from the "config" subdirectory of
the jBase release directory.

16
STRUCTURE OF
PROGRAMS AND SUBROUTINES

17
STRUCTURE OF JBASIC PROGRAMS

All Programs have to compulsorily begin with the Keyword


PROGRAM <program name> and end with END.
The program name and the name of the file should be the
same.

18
STRUCURE OF JBASIC SUBROUTINES

All subroutines have to compulsorily begin with the Keyword


SUBROUTINE <Subroutine Name> and end with
RETURN and END.
The subroutine name and the name of the file should be the
same.

19
COMPILATION

Compilation is the process of converting source code into


object code.
BASIC is the command used to compile from jShell prompt.
Example: BASIC XXX.BP TEST.PRG
As a result of compilation a file with prefix $ will be created
and stored in the same directory.
Example: $TEST.PRG

20
CATALOG

Catalog is the process of converting object code into main


program executables.
CATALOG is the command used to catalog from jShell prompt.
Example: CATALOG XXX.BP TEST.PRG
DECATALOG command can be used to remove released
excutables.

21
RUN

RUN is the command used to execute the program


executables.
We can directly execute by entering <program name> in
jShell prompt if it is cataloged.
EXECUTE and PERFORM are the command used to execute
Program/JQL commands inside the Program.
ENTER is the command that passes the control to another
program and the control will not come back to the calling
program.

22
DEBUGGER

Debugger facilitates the programmer for the examination of


Source code and thus by removing defects in code.
Whenever a DEBUG statement seen in Program, Debugger will
be invoked.

23
EXAMPLE : PROGRAMS

Program to display “Hello World” and store it under the BP


directory
JED XXX.BP HELLO.PRG
PROGRAM HELLO.PRG
CRT “HELLO WORLD”
END.
Type FI in JED Command prompt to save the program.
To compile the program type EB.COMPILE XXX.BP
HELLO.PRG from jBase prompt
To see the output type HELLO.PRG from jBase prompt

24
EXAMPLE : SUBROUTINES

Write a Subroutine to display “Hello World” and store it under


the XXX.BP directory
JED XXX.BP TEST.SUB
SUBROUTINE TEST.SUB
CRT “HELLO WORLD”
RETURN
END.
Type FI in JED Command prompt to save the program.

25
STEP TO EXECUTE SUBROUTINES

To compile the program type EB.COMPILE XXX.BP TEST.SUB


from jBase prompt
After Compiling Subroutine Create a PGM Entry with Type =
‘M’

26
STEP TO EXECUTE SUBROUTINES

After creating a valid PGM entry for the subroutine to be


executed as Mainline routine.
Then type subroutine name (TEST.SUB) from the Globus
command line prompt to execute.

27
INSERT FILES

Insert files are similar to ‘Include’ file that you might have
used in ‘C’ and ‘C++’ programs.
There are number of insert files available. Each one of them
have their own functionality which can be used in our
programs/subroutines to enable re-usability of code.

28
I_COMMON AND I_EQUATE

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.

I_EQUATE initializes those common variables.

It is a good practice to include these files in every subroutine


we write irrespective of whether we use the common
variable or not.

29
CONTROL SRTUCUTURES IN JBASIC

30
CONTROL STRUCTURES

The various Control structures are


– IF-THEN-ELSE Structure
– LOOP-REPEAT Structure
– FOR-NEXT Structure
– CASE Structure

31
IF-THEN-ELSE STRUCTURE

The if clause is used to determine the operations to be run


following either the true or false result of the statement.
If the expression on the THEN clause is true, the statements
following the ‘THEN’ clause are executed, otherwise the
statements following the ‘ELSE’ clause are executed.

32
IF-THEN-ELSE STRUCTURE

IF-THEN-ELSE Structure – Skeleton


IF expression THEN
statements
END ELSE
statements
END
IF expression THEN statements ELSE statements

33
IF-THEN-ELSE STRUCTURE

IF expression THEN
statements
END ELSE
IF expression THEN
statements
END ELSE
statements
END
END

34
LOOP - REPEAT STRUCTURE

Facilitates repeated execution of a set of statements.


Control exits from structure when WHILE expression evaluates
to false or UNTIL expression evaluates to true.

35
LOOP - REPEAT STRUCTURE

LOOP - REPEAT Structure - Skeleton


LOOP
set of statements
WHILE/UNTIL expression
set of statements
REPEAT

36
LOOP - REPEAT STRUCTURE - EXAMPLE

PROGRAM TEST.LOOP
X=0
LOOP
UNTIL X>4 DO
PRINT "X= “ :X
X=X+1
REPEAT
END

37
LOOP - REPEAT STRUCTURE - EXAMPLE

Output :
X = 0
X = 1
X = 2
X = 3
X = 4

38
FOR - NEXT STRUCTURE

Facilitates repeated execution of a set of statements.


Control exits from structure after pre-determined number of
executions.

39
FOR - NEXT STRUCTURE- EXAMPLE

Example :
FOR I = 1 TO 10
PRINT ‘Counter Variable:’: I
NEXT
I is the counter variable.
The PRINT statement executes for a pre-determined 10 times
(i.e) till the value of I is 10

40
FOR - NEXT STRUCTURE- EXAMPLE

Output:
COUNTER VARIABLE:1
COUNTER VARIABLE:2
COUNTER VARIABLE:3
COUNTER VARIABLE:4
COUNTER VARIABLE:5
COUNTER VARIABLE:6
COUNTER VARIABLE:7
COUNTER VARIABLE:8
COUNTER VARIABLE:9
COUNTER VARIABLE:10

41
FOR - NEXT STRUCTURE- EXAMPLE

Example :
FOR I = 1 TO 10 STEP 2
PRINT ‘Counter Variable:’: I
NEXT
I is the counter variable.
The PRINT statement executes for a pre-determined 5 times, I
being incremented by two each time.

42
FOR - NEXT STRUCTURE- EXAMPLE

Output :
COUNTER VARIABLE:1
COUNTER VARIABLE:3
COUNTER VARIABLE:5
COUNTER VARIABLE:7
COUNTER VARIABLE:9

43
CASE STRUCTURE

Expressions/statements evaluated in sequential order.


when a true expression is encountered, the corresponding
statements are executed and control exits from the CASE
structure.
when no true expression is encountered, then the statements
under CASE 1 are executed and control exits from the
CASE structure.
when no true expression is encountered, and in the absence
of CASE 1 expression, then no statements are executed and
control exits from the CASE structure.

44
CASE STRUCTURE

CASE Structure - Skeleton


BEGIN CASE
CASE relation expression I
set of statements
CASE relation expression II
set of statements
CASE 1
set of statements
END CASE

45
CASE STRUCTURE - EXAMPLE

Example :
PROGRAM TEST.CASE
NAME="MICHAEL"
BEGIN CASE
CASE NAME[1,2]='DA'
PRINT NAME
CASE NAME[1,2]='RI'
PRINT NAME
CASE NAME[1,2]='BA'
PRINT NAME
CASE 1
PRINT 'NO MATCH'
END CASE
END
Output : No Match

46
OTHER FLOW CONTROL STATEMENTS

EXIT
– exit from loop structure prematurely.

END
– mandatory last statement in a program.
– Signifies end of program.

STOP
– terminates execution of program and the control transfers back to the
process that invoked the program.

CALL
– executes an external subroutine.

EXECUTE
– executes unix / jBase commands.

47
OTHER FLOW CONTROL STATEMENTS

GOSUB
– transfer the control of the program to an internal subroutine
available within the program.

RETURN
– used in conjunction with GOSUB. Transfers the control from
the subroutine back to the next statement after GOSUB in the
main program.

GOTO
– transfers control of the program to a statement within the
program. The control does not transfer back even when a
return statement is encountered

48
RELATIONAL OPERATORS

Used to compare numeric, character string, or logical data.


Result of the comparison, either true (1) or false (0), can be
used to make a decision regarding program flow.
Relational operators are
– EQ or = Equal to
– NE or # >< <> Not Equal to
– LT or < Less than
– GT or > Greater than
– LE or <= =< Less than or equal to
– GE or >= => Greater than or equal
to

49
LOGICAL OPERATORS

They are operators that combine two or more relational


expressions.
Logical operators in info Basic are
– AND
– OR
– NOT

Example:
– IF EMP.DESG EQ ‘MGR’ AND EMP.SAL GT 10000 THEN In the
logical expression above, the logical operator ‘AND’ combines
the two relational expressions ‘EQ’ and ‘GT’.

50
BASIC COMMANDS

$INSERT
– Inserts and compiles info Basic source code from another
program into the program being compiled

REM
– Identifies a line as a comment line. Same as the *, !, and $*
signs

SUBROUTINE
– Identifies a series of statements as a subroutine.

51
JBASIC FUNCTIONS

52
INPUT

To Accept a Value for a Variable From User


SYNTAX :
– INPUT VARIABLE, LENGTH

Example :
– INPUT NAME,10
• In this Example The User is Restricted to enter 10 characters only.

– INPUT @(COL,ROW):Variable, len


– INPUT @(10,5):N,10

53
PROMPT

Used to change the prompt character displayed at the use of


INPUT Statement.
SYNTAX :
– PROMPT expr

Example :
– PROMPT “#”

54
CRT

Used to place Text & Data on the terminal


SYNTAX :
– CRT @(COLUMN,ROW): TEXT / VARIABLE

Example : CRT A,B,C


– CRT @(10,5): “AMERICAN EXPRESS BANK”

55
PRINT

This statement is used to print the value of a variable or text.


Can be used in conjunction with INPUT statement to prompt
the user for input.
Example :
– PRINT @(10,12):A,B
– PRINT @(10,12): “ENTER THE NAME”:
– INPUT NAME,12

56
LOCATE

Used to search a string in a dynamic array and get itS


position.Returns the field Position only.
SYNTAX :
LOCATE <string> IN <array> {<field pos,multivalue pos>}
SETTING <var> THEN/ELSE <statements>
Example :
Y.ARRAY = 'KALLIS':@FM:'JONTY':@VM:'NICKY'
LOCATE 'NICKY' IN Y.ARRAY<1,1> SETTING POS ELSE NULL
PRINT POS
RESULT: 2

57
FIND

Find Searches the entire string in a dynamic array.


Finds the location of a specified string within a Dynamic array.
Syntax :
FIND <string> IN <array> SETTING var1,var2,var3
THEN/ELSE <statements>
Example :
Y.ARRAY = ‘ABCD’:@FM:’1000’:@VM:’2000’
FIND ‘2000’ IN Y.ARRAY SETTING Y.POS1,Y.POS2,Y.POS3
ELSE NULL
RESULT: 2,2,1

58
FINDSTR

FindSTR searches the string as a Substring in a dynamic array.


Syntax :
FINDSTR <string> IN <array> SETTING var1,var2,var3
THEN/ELSE <statements>
Example :
Y.ARRAY = ‘KALLIS’:@FM:’JONTY’:@VM:’NICKY’
FINDSTR ‘ONT’ IN Y.ARRAY SETTING Y.POS1,Y.POS2,Y.POS3
ELSE NULL
RESULT: 2,1,1

59
ICONV

Converts entered data into internal format onto the disk.


SYNTAX:
ICONV(string,conversion code)

60
CONVERSION CODES - ICONV

String Conversion Code Result

15.00 ‘MD2’ 1500

12 MARCH 95 ‘D’
9933
12.3.95 ‘DE’ 9933

61
OCONV

Converts internal format data into format specified.


SYNTAX:
ICONV(string,conversion code)

62
CONVERSION CODES - OCONV

String Conversion Code Result

1500 ‘MD2’
15.00
9933 ‘D’ 12 MAR
95

60000 ‘MT’ 16:40

63
STRING MANIPULATION

TRIMF Removes leading spaces from a string.


SYNTAX TRIMF(string)
TRIMB Removes trailing spaces from a string.
SYNTAX TRIMB(string)
TRIM Removes both leading &trailing spaces

SYNTAX TRIM(string)

64
LEN

Returns the number of Characters in a string


SYNTAX : LEN(string)
Example : CRT LEN(“THESYS”)
Output : 6

65
FIELD

Extracts a sub-string from a Character string using delimiters.


SYNTAX : FIELD(string,delimiter,occur,fields )
Example 1:
X = “A/B/C/D”
Y = FIELD(X,”/”,2,2)
RESULT : Y has a value of B/C
Example 2:
X = “1-2-3-4-5-6”
Y = FIELD(X,”-”,3,2)
RESULT : Y has a Value 3-4

66
INDEX

Returns the starting column position of a specific occurrence


of a specified sub string within a character string.
SYNTAX:
INDEX(string,sub string,occur)
Example :
A = “AMERICAN EXPRESS BANK”
B = INDEX(A,”AN”,2)
Result : B returns the value 19

67
ALPHA

Used to determine whether the expression is Alphabet or Not.


If the expression contains any special characters or numeric
value it evaluates false else true.
SYNTAX: OUTPUT
CRT ALPHA(‘ABCDEF’) 1
CRT ALPHA(‘10ABCDEF’) 0
CRT ALPHA(‘ABC DEF’) 0

68
CHAR

This function returns the ASCII character for a given number.


SYNTAX:
CHAR(expr)
Example:
X = CHAR(65)
X returns the value “A”

69
SEQ

This function returns the ASCII value for a given character.


SYNTAX :
SEQ(expr)
Example :
SEQ(“A”) returns 65.

70
COUNT

This function returns the number of times a sub-string


occurred in a string.
SYNTAX :
COUNT(expr)
Example
A=“THESYS”
CRT COUNT(A,’S’)
Output : 2

71
DEL

Deletes the data contents of a field, value or subvalue in a


dynamic array.
Example :
DEL <array>

72
INS

Insert new value before a specified field, value or subvalue in


a Dynamic Array.
Example
INS ‘xxx’ BEFORE ARRAY<1,2,1>

73
DCOUNT

Returns the number of sub-strings delimited by a specified


delimiter in a string value.
Used to find number of values in field.
Example :
REC=34:@VM:55:@VM:88
R=DCOUNT(REC,@VM)
Result : R has a Value of 3

74
COUNT

Counts number of occurrences of a specified string in a string


value.
SYNTAX:
COUNT(string.expr, substr.expr)
Example :
REC=34:@VM:55:@VM:88
R=COUNT(REC,@VM)
Result : R has a Value of 2.

75
MAXIMUM

Returns the element with the highest numeric Value in a


given Dynamic array.
SYNTAX:
MAXIMUM(dynamic.array.name)

76
MINIMUM

Returns the element with the lowest numeric value in a given


Dynamic array.
SYNTAX:
MINIMUM(dynamic.array.name)

77
JDEBUGGER COMMANDS

•To invoke Jdebugger, include DEBUG in the


program/subroutine
•Alternatively at runtime with –jd option before
programname
•S debugs each statement
•/VAR.NAME displays the contents stored in the variable
•C to continue execution of program without debugging
•Q to Quit debugger

78
WORK SHOPS

79
WORK SHOP

Write a program to find the biggest number from the given three
numbers.
Based on the period for a given principal, calculate the interest as
follows:
• 3 months – 4.5 %
• 6 months – 5%
• 1 – 2 yrs – 5.5 %
• >2 yrs -6%

Using LOOP..REPEAT, accept customer no. and name for 5 members.


Write a program to convert the Julian date format into DD/MM/YYYY
format
Write a user defined function to calculate simple interest for given
principal amount, period and rate of interest.

80
FILE MANAGEMENT

81
FILE MANAGEMENT

Important File Management commands are


– OPEN
– READ
– WRITE
– DELETE
– CLOSE

82
OPEN

Used to open a File for reading or writing purposes.


SYNTAX:
OPEN file TO file.variable ON ERROR/THEN/ELSE statements

EXAMPLE :
– OPEN ‘FBNK.CUSTOMER’ TO CUSTOMER.FILE ELSE CRT
“Company File Cannot be opened “

83
READ

Used to read a file which is already opened using OPEN statement.


READ will not lock any record or file.
SYNTAX:
– READ var FROM file.var,rec.id ON ERROR statements THEN statements
ELSE statements
EXAMPLE :
READ R.CUS.REC FROM CUSTOMER.FILE,’100037’
THEN
CRT “Record Found “
END ELSE
CRT “Cannot find the Record “
END

84
WRITE

Used to write details on to a record in a file


SYNTAX :
– WRITE rec.var ON file.var,rec.id ONERROR {stat}

EXAMPLE :
R.CUS.REC<1> = ‘TESTWRITE’
WRITE R.CUS.REC ON CUSTOMER.FILE,’100037’ ON ERROR
CRT “cant write”

85
DELETE

Used to delete a record in a file.


SYNTAX :
– DELETE file.var, rec.id

86
CLOSE

Used to close a file.


SYNTAX :
– CLOSE file.var

Example :
OPEN CUSTOMER TO CUSTOMER.FILE
CLOSE CUSTOMER.FILE

87
USER DEFINED FUNCTIONS

88
DEFINING FUNCTIONS

Functions can also be defined in jBasic.


Functions can take in any number of parameters but returns
only one value.
RETURN is used to pass the result to the calling Program.

89
DEFINING FUNCTIONS - EXAMPLE

STEP 1:
– Define a Function that accepts two values and return the result
in a variable.

FUNCTION TEST.FUN(A,B)
C=A*B
RETURN(C)
END
STEP 2:
– Compile and Catalog the Function.

90
DEFINING FUNCTIONS - EXAMPLE

STEP 3:
– Write a Program that calls the Function(TEST.FUN) and Prints the
Result.
PROGRAM FUN.CALLING.PRG
A = 5 ; B =10
DEFFUN TEST.FUN(A,B)
RESULT = TEST.FUN(A,B)
PRINT “RESULT : “:RESULT
END
STEP 4:
– Compile and Catalog the Program
STEP 5:
– Run the Program
Result : RESULT : 50

91
SUBROUTINES WITH PARAMETERS

92
SUBROUTINES WITH PARAMETERS

Subroutines can take In Parameters and Return the values as


well.
Example: F.READ
– This Subroutine has five parameters out of which
– File name, record id and File Pointer are incoming parameters.
– Recordvar, Errorvar are Return values

93
SUBROUTINES WITH PARAMETERS-EXAMPLE

STEP 1:
Create a routine that accepts two values and returns the
multiplication of two values in variable.
SUBROUTINE TEST.CALLED.RTN(A,B,C)
C=A*B
RETURN
END

94
SUBROUTINES WITH PARAMETERS-EXAMPLE

STEP 2:
Create another routine that supplies the two values and prints the
result.
PROGRAM TEST.CALLING.RTN
A = 10 ; B =20
CALL TEST.CALLED.RTN(A,B,RESULT)
PRINT “RESULT : ”:RESULT
END
STEP 3:
Compile and catalog the Program and Subroutine.
STEP 4:
Run the Program
Result : RESULT : 200

95
CORE T24 SUBROUTINES

96
OPF

Used to open a File for reading or writing purposes.


It has two parameters passed.
SYNTAX :
– CALL OPF(File name,File pointer)
• Filename : Name of the File (Example : ‘FBNK.CUSTOMER’)
• File pointer : Path of the file

EXAMPLE :
FN.CUSTOMER = ‘FBNK.CUSTOMER’
F.CUSTOMER = ‘’
CALL OPF(FN.CUSTOMER,F.CUSTOMER)
NOTE:
File pointer is initialized with null value and at the time of execution it
will be assigned to the path of the file

97
F.READ

Used to read a record from a file which is already opened


using OPF.
For example, F.READ has five parameters.
SYNTAX:
– CALL
F.READ(Filename,record.id,dynamic.array,File.var,Error.var)
• Filename : File Name
• Record.id : ID of the record to be read
• Dynamic.array : Dynamic array that will hold the read record
• File.var : File Path
• Error.var : Error Variable

98
F.READ

EXAMPLE:
FN.CUSTOMER = ‘FBNK.CUSTOMER’
F.CUSTOMER = ‘’
R.CUSTOMER = ‘’
CALL OPF(FN.CUSTOMER,F.CUSTOMER)
CALL F.READ (FN.CUSTOMER,Y.CUSTOMER.ID,R.CUSTOMER,
F.CUSTOMER,Y.CUS.ERR)

99
F.WRITE

Used to write details on to a record in a file.


It has 3 parameters passed.
Before writing the values in a record, open the file and read
the record.
SYNTAX :
– CALL F.WRITE (Filename, Record.id, Dynamic array)
• Filename : file name
• Record.id : Record to be written
– Dynamic array : Array that holds the values to be written on a
record

100
F.WRITE

EXAMPLE
– <Initialize variables FN.CUSTOMER,F.CUSTOMER,….>
– <Open the file using OPF>
– <Read the record using F.READ>
– <Assign the value to the dynamic array which we are going to
write>
– R.CUSTOMER<EB.CUS.SHORT.NAME> = ‘ABC CORPORATION’
– CALL F.WRITE (FN.CUSTOMER,Y.CUSTOMER.ID,R.CUSTOMER)

101
EB.READLIST

To read a set of records from a file we use this core routine.


It has 5 parameters passed.
SYNTAX
– CALL EB.READLIST(1,2,3,4,5 )
• 1 : Select Query.
• 2 : List variable that contains only the ID of the selected records.
• 3 : Id of the SAVEDLISTS file (Optional)
• 4 : No of Records selected (Total Count)
• 5 : Return code

102
EB.READLIST

EXAMPLE
– <Initialise File name FN.CUSTOMER>
– SEL.CMD = “SELECT “:FN.CUSTOMER
– CALL
EB.READLIST(SEL.CMD,SEL.LIST,’’,NO.OF.RECORDS,RET.CODE)

103
REMOVE

REMOVE is the Function that is used to extract a value from a


dynamic array.
SYNTAX:
– REMOVE <var> FROM <array> SETTING <set var>
• Var : variable which holds the extracted string
• Array : Dynamic array from which the string is to be
extracted.
• Set var : Delimiter by which string is extracted from
array.
• (2 – FM, 3 – VM, 4 – SM, 0 – End of array)

104
JOURNAL.UPDATE

JOURNAL.UPDATE is a core routine that updates the


F.JOURNAL when a transaction happens.
When the system is in Online mode and if we are using
F.WRITE, then it will write the data on to the cache and not
to the disk. So a Call to Journal.Update is required after a
Write Statement.
When the system is in Batch mode, system takes care of
writing on to the disk. Hence call to Journal.Update is not
required.

105
EXAMPLES

106
EXAMPLE 1

Write a subroutine that will display the details (Id, Mnemonic


and Nationality) of a customer whose id is 100037

107
EXAMPLE 1 : ALGORITHM

Open the customer file


Read the customer file and extract the record with d 100037
From the extracted record obtain the mnemonic and
nationality
Display the customer id, mnemonic and nationality

108
EXAMPLE 1 : SOLUTION

SUBROUTINE CUST.READ
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INIT:
FN.CUS = "FBNK.CUSTOMER"
F.CUS = " "
Y.CUS.ID = '100037'
Y.NATIONALITY = " "
Y.MNEMONIC = " "
R.CUSTOMER = " "
Y.ERR = " "
RETURN

109
EXAMPLE 1 : SOLUTION

OPENFILES:
CALL OPF(FN.CUS,F.CUS)
RETURN
PROCESS:
CALL F.READ(FN.CUS, Y.CUS.ID , R.CUSTOMER , F.CUS, Y.ERR)
Y.NATIONALITY = R.CUSTOMER<EB.CUS.NATIONALITY>
Y.MNEMONIC = R.CUSTOMER<EB.CUS.MNEMONIC>
PRINT “CUSTOMER ID IS :”:Y.CUS.ID
PRINT "NATIONALITY IS :":Y.NATIONALITY
PRINT "MNENOMIC IS :":Y.MNEMONIC
RETURN
END

110
EXAMPLE 2

Write a subroutine that will changes the Account officer from 1


to 2 and display the details (Customer, Mnemonic, Old Acct
officer and New Acct officer) for all customers.

111
EXAMPLE 2 : ALGORITHM

Select all the customer records


Open the customer file
Read the Customer records one by one
Check the existing Account.Officer value and if it is ‘1’ then
assign the new value of Account Officer to ‘2’
Extract the required details to be printed from the record
Display the details

112
EXAMPLE 2 : SOLUTION

SUBROUTINE CUST.READ.WRITE
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
GOSUB INIT
GOSUB OPENFILES
GOSUB PROCESS
RETURN
INIT:
FN.CUS = "FBNK.CUSTOMER"
F.CUS = " "
Y.CUS.ID = ‘’
Y.NATIONALITY = " "
Y.MNEMONIC = " "
R.CUSTOMER = " "
Y.ERR = " "
RETURN

113
EXAMPLE 2 : SOLUTION

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 , Y.ERR)
Y.OLD.ACCT.OFFICER = R.CUSTOMER<EB.CUS.ACCOUNT.OFFICER>

114
EXAMPLE 2 : SOLUTION

IF Y.OLD.ACCT.OFFICER EQ ‘1’ THEN


Y.NEW.ACCT.OFFICER = ‘2’
R.CUSTOMER<EB.CUS.ACCOUNT.OFFICER> =
Y.NEW.ACCT.OFFICER
END
Y.DET = Y.CUS.ID:’ * ‘:Y.MNEMONIC:’ * ‘:Y.OLD.ACCT.OFFICER:’
* ‘: Y.NEW.ACCT.OFFICER
PRINT Y.DET
REPEAT
RETURN
END

115
SUMMARY

We have learnt jbasic features and types of programs


We discussed some important jbasic functions
We learnt some important T24 core subroutines

116

You might also like