You are on page 1of 23

PROGRAMMING IN INFOBASIC

1.1 Introduction
As you would be aware by now, Globus uses uniVerse/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
ery simple yet powerful programming language. !ith its english like statements, it makes
programming ery simple. A salient feature of Infobasic is that it does not support data types. All
ariables in Infobasic are treated as "ynamic Arrays#$efer %.& Arrays'. (ince Infobasic does not
support data types, the need to declare ariables does not arise.
2.1 Arrays
Before we understand the arious commands and the way to write programs in
Infobasic, it is ery essential to understand the concept of arrays.
)ery ariable that we use occupies a portion of the memory. *sually character
ariables occupy & byte of memory, which hae the capacity to store just one character. Incase a
series of characters #string' like +G,-B*(. has to be stored, then a character ariable would not
suffice. /here comes the need for arrays. !e now need 0 bytes of continuous memory blocks in order
to store the string. (e1uential storage of characters that form a string will make storage and retrieal
easier and faster. 2oreoer all the 0 bytes should hae the same name. /his is e3actly the functionality
of an array.
/o sum it up, an array is nothing but continuos memory allocation, where in
all the bytes hae the same name as that of the array and can be distinguished with the help of a
subscript which always starts with a +4..
Figure 1.1 Structure Of An Array

Array 1
G L O B U S
0 1 2 3 4 5
5ote 6
Incase you wish to access +G. in +G,-B*(. then specify Array&748
2.1.1 Types Of Arrays
/here are two different types of arrays that are supported by Infobasic. /hey are
I. "ynamic Arrays
II. "imensioned Arrays
I. yna!ic Arrays
"ynamic arrays are, as the name implies, dynamic in both the number,
dimensions and their e3tents. "ynamic arrays are especially useful in proiding the ability to
manipulate ariable length records with a ariable length of fields and/or alues within fields etc. A
dynamic array is just a string of characters that contain one or more delimiter characters. /he delimiter
characters are 6
A(9II "ecimal "escription
%:; <ield 2arker
%:= Value 2arker
%:% (ub>Value 2arker
)ach field is separated by a field marker and a field may contain more than one alue separated by a
alue marker. Any alue may hae more than one sub>alue separated by a sub>alue marker.
Figure 2.1 Structure Of A Dynamic Array
I. i!ensioned Arrays
"imensioned array proide more efficient means of creating and manipulating tables
of data elements where the number of dimensions and the e3tent #number of elements' of each
dimension is known and is not likely to change. "imensioned arrays hae to be declared using the
"I2)5(I-5 statement.

Filed1FMField2FM Value1VMValue2VMValue3VMValue4
MField4FMSubValue1SMSubValue2FMField5
)3ample6
/o declare a dimensioned array use "I2)5(I-5 Array%7:,=8
: > ? $efers to the number of rows
= > ? $efers to the number of columns
A customer record is a dimensioned array. All the fields that form the customer record are
dynamic arrays.
Note :
All ariables in Infobasic are treated as dynamic arrays. "ynamic arrays do not need any
e3plicit declaration. Initialisation would suffice.
A$$A@ A +.  A dynamic array being initialised. Incase the array needs to store a numeric
alue
".1 Structure Of An Info#asic Pro$ra!
/here are two different types of programs that we can write in Infobasic. -ne is
+B$-G$A2. itself and the other is +(*B$-*/I5)..
Any program that is e3ecuted from the uniVerse prompt is termed as a +B$-G$A2.
and a program that is e3ecuted from within Globus is termed as a subroutine.
Figure 3.1 Structure of a program and subroutine
*sually, any program or subroutine deeloped by the user is stored under a
directory named BB and the core Globus programs or subroutines are stored under G,-B*(.BB.
5eer store user written programs/subroutines in the G,-B*(.BB directory.
%.1 Co!pi&in$ And Cata&o$uin$ Info#asic Pro$ra!s And Su#routines
Cust like programs written in any programming language need to be compiled,
Infobasic programs also need to be compiled. 9ompilation is the process of conerting the code into
assembly language that the machine can understand. -nce programs/subroutines are compiled, object
codes get produced. /hese object codes get stored in specific directories.
If the source#program/subroutine' is in BB then the object code gets stored in BB.-. If
the source is in G,-B*(.BB then the object code gets stored in G,-B*(.BB.-. Apart from compiling
Infobasic programs, we also need to catalogue them. As you would be aware by now, V-9 is the back
bone of our database uniVerse. 9ataloguing is the process of making an entry in the V-9. !hen a
program or a subroutine is catalogued, a V-9 entry with a type +V. gets created.
*Comments *Comments
PROGRAM ProgramName SUBROU!N" S#$ro#t%neName
Statement1 Statement1
Statement 2 Statement 2
Statement 3 Statement 3
R"URN
"N& "N&
5ote 6
In jBase V-9 entries do not get created for programs and subroutines. In
CBase, when a subroutine is compiled, an object code gets created and is stored under the current
directory. 9ataloguing subroutines in jBase is the process of making the object code a part of a
library file under the path specified by the jBase global ariable CB9")VD,IB. /his library file
under the lib directory gets created automatically inorder to store object codes produced as a
result of compiling subroutines. /he siEe and the name of the library files is determined by the
configuration file j,ib"efinition under the jBase +config. directory.
Incase of a program, when catalogued, the object code is placed under the
directory pointed by the jBase global ariable CB9")VDBI5. *sually this ariable points to the +bin.
directory, which is under the +run. directory. *nlike subroutines, library files do not get created
here. /he object files get stored straight away under the path specified by CB9")VDBI5.
'.1 (ritin$ Info#asic Pro$ra!s
)*a!p&e 1
Pro$ra! to disp&ay +,e&&o (or&d-
Step 1
!rite a program to display the string FG),,- !-$,"H and store it under the BB directory.
Conso&idated So&ution 1
>ED BP HELLO
New record.
---- !
"""1# P$O%$&' HELLO
"""2# ($) *HELLO +O$LD*
"""3# END
"""4#
Bo,,o- a, li.e 3.
---- F!
*HELLO* /led i. /le *BP*.
)" is the editor used by Infobasic. Blease refer to +*sing )" )ditor. notes that has been attached to
this course material.
Step 2.
9ompile the program
B&S!( BP HELLO
(o-0ili.1Source#2BP3HELLO24
Ob5ec, # 2BP.O3HELLO2
(o-0ila,io. (o-0le,e.
BA(I9 is the command used by Infobasic to compile programs/subroutines. It conerts the code into
assembly language and creates the object file.5ote that the object code has been placed under the
directory BB.- automatically.
Step ".
9atalogue the program
>(&)&LO% BP HELLO
*6-bde-o.ru.6HELLO* ca,alo1ed.
9A/A,-G*) is the command in Infobasic that makes an entry in the V-9 for a compiled
program/subroutine.
VOC Entry for the program
() VO( HELLO
HELLO
"""1 V
"""2 6-bde-o.ru.6HELLO
"""3 B
"""4 BN
Step %.
)3ecute the program by typing the following statement at the uniVerse prompt'
>$7N HELLO
HELLO +O$LD -utput of the program
/.1 Contro& Structures In Info#asic
Cust like any other programming language, Infobasic also supports a number of control
structures namely
I. If /hen )lse
II. Begin 9ase )nd 9ase
III. <or ,oop
IV. -pen ,oop
I. If T0en )&se
/he If clause is used to determine the operations to be run following to be run
following either the true or false #successful or unsuccessful' result of the statement. If the statement
ealuates to a +true. then the statements following the /G)5 clause will get e3ecuted. If the statement
ealuates to a +false. then the set of statements following the +),(). clause would get e3ecuted. In
most cases, either the /G)5 or the ),() must be specifiedI optionally both may be. In certain
specific cases the ),() clause only is aailable.
<or each of these statements the format of the /G)5 and ),() clauses is the same.
If the /G)5 or ),() clause is restricted to one statement, on the same line as the test statement, the
/G)5 or ),() can be specified in the simple format.
If the /G)5 or ),() 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 )5".
Note :
Instead of using BA(I9 to compile and 9A/A,-G to catalogue programs/subroutines
we can use )B.9-2BI,) to compile and catalogue programs/subroutines. /his command can be
used in jBase as well to compile and catalogue programs/subroutines.
"(am)*e :
!F &%E 8# 19 )HEN
P$!N) :&%E !S LESSE$ )H&N O$ E;7&L )O 19<
P$!N) :'!NO$<
END
ELSE
P$!N) :'&=O$<
END
II. Be$in Case )nd Case
*se the 9A() statement to alter the se1uence of instruction e3ecution based on the
alue of one or more e3pressions. If e3pression in the first 9A() statement is true, the following
statements up to the ne3t 9A() statement are e3ecuted. )3ecution continues with the statement
following the )5" 9A() statement. If the e3pression in a 9A() statement is false, e3ecution
continues by testing the e3pression in the ne3t 9A() statement. If it is true, the statements
following the 9A() statement up to the ne3t 9A() or )5" 9A() statement are e3ecuted.
)3ecution continues with the statement following the )5" 9A() statement. If more than one 9A()
statement contains a true e3pression, only the statements following the first such 9A() statement
are e3ecuted. If no 9A() statements are true, none of the statements between the B)GI5 9A()
and )5" 9A() statements are e3ecuted.

III. For 1oop
*se the <or ,oop to e3ecute a set of statements repeatedly until a specific condition is
met or for specific number of times. /he counted loop uses a ariable to hold the iteration count. /his
commences at the start alue for the loop is automatically incremented by a step alue at each
iteration. -nce it has passed the end alue, the loop terminates.
I2. Open 1oop
/he open loop specifies a more powerful loop construction which will continue to
iterate until a condition is met to terminate this. /he condition is held in the !GI,) clause. /he
$)B)A/ statement takes the control back to the first line after the ,--B statement.

"(am)*e:
7SE$N&'E # >LO%N&'E
BE%!N (&SE
(&SE 7SE$N&'E # :)O'<
DEP&$)'EN) # :H$<
(&SE 7SE$N&'E # :D!(?<
DEP&$)'EN) # :&D'!N<
(&SE 1 i@ .o.e o@ ,Ae (aBe B,a,e-e.,B -a,cA ,Ae.
,AiB B,a,e-e., would 1e, eCecu,ed
:DEP&$)'EN) NO) FO7ND<
"(am)*e :
FO$ (O7N)E$ # 1 )O 1"
($) :)E'ENOS %LOB7S< )Ae B,ri.1 )E'ENOS %LOB7S will
1e,
NED) (O7N)E$ printed &4 times
"(am)*e :
LOOP
($) :!.0u, 2 Nu-berB<
!NP7) E.N7'1
!NP7) E.N7'2
+H!LE E.N7'1E.N7'2 5ote that a condition is being checked using the !hile
clause. +6. is the concatenation operator in Infobasic. /he
!hile statement specified here checks if @.5*2& and
@.5*2% contain alues.
($) :)o,al : E.N7'1 F E.N7'2
$EPE&)
3.1 Bui&t In Info#asic Functions
Infobasic has a number of built in functions that help in rapid code deelopment. (ome
of the commonly used build in functions are listed below.
I. ,en
II. 9ount
III. "count
IV. *p9ase
V. "own9ase
VI. 9hange
VII. Icon
VIII. -con
I. 1en
*se the ,)5 function to return the number of characters in string.
II. Count
7Be ,Ae (O7N) @u.c,io. ,o re,ur. ,Ae .u-ber o@ ,i-eB a BubB,ri.1 iB
re0ea,ed i. a B,ri.1 Galue.
No,e
Followi.1 are ,Ae boolea. o0era,orB uBed i. !.@obaBic
#E; EHuali,I
J8>NE !.eHuali,I
>%) %rea,er )Aa.
>#%E %rea,er )Aa.3EHual
8#L) LeBB )Aa.
8#LE LeBB )Aa.3EHual
'&)(HES Pa,,er. 'a,cA
"(am)*e :
Var1 # Le.K:)E'ENOS<L
Var1 = 8
"(am)*e :
Var1 # :abc4de@41Ai<
Var2 # (O7N)KVar14<4<L /he 9-*5/ function here is used to count the
number of F,H in the string held in the ariable ar&
Var2 = 3
III. count
*se the "9-*5/ function to return the number of delimited fields in a data string.
I2. 4pCase
*se the *p9ase function to conert the passes string to *BB)$ 9A().
2. o5nCase
*se the "own9ase function to conert the passed string to lower case
2I. C0an$e
*se the 9GA5G) function to replace a substring in e3pression with another
substring. If you do not specify occurrence, each occurrence of the substring is replaced.
Icon 6
2II. Icon6
*se the I9-5V function to conert string to a specified internal storage format.
string is an e3pression that ealuates to the string to be conerted. If the string ealuates to a null
alue, null is returned.
"(am)*e :
Var1 # :abc4de@41Ai<
Var2 # D(O7N)KVar14<4<L )he "9-*5/ function here is used to count the
number of fields delimited by the delimiter F,H in the
string held in the ariable ar&
Var2 = 4
Note :
&COUN $as%+a**y +o#nts t,e n#m$er o- .e*%m%ters an. a..s one to t,e res#*t an.
.%s)*ays' /,en t,e n#m$er o- .e*%m%ters nee. to $e o$ta%ne.0 #se t,e COUN -#n+t%on'
/,en t,e a+t#a* n#m$er o- 1a*#es nee. to $e o$ta%ne.0 #se t,e &COUN -#n+t%on'
"(am)*e :
Var1 # 7P(&SEK:,e-e.oB<L
Var1 = TEMENOS
"(am)*e :
Var1 # DO+N(&SEK:)E'ENOS<L
Var1 = temenos
"(am)*e :
Var1 # (H&N%EK:)E'ENOOS<4<OO<4<O<L
Var1 = TEMENOS
"(am)*e :
2III. Ocon6
*se the -9-5V function to conert string to a specified format for e3ternal output.
/he result is always a string e3pression.
7.1 (ritin$ Su#routines In Info#asic
@ou would be aware by now that Infobasic allows us to create programs as well as
subroutines, which are to be e3ecuted from within Globus.
Figure 4.1 Structure Of A Subroutine
All subroutines hae to compulsorily begin with the line (*B$-*/I5)
(ubroutine5ame and end with $)/*$5 and )5". /he subroutine name and the name of the file
where the subroutine is to be stored need not hae the same name. But as a conention, inorder to
aiod unnecessary confusion the subroutine name and the file name are kept the same.
Insert files are similar to +Include. files that you might hae used in +9. and +9JJ.
programs. /here are number of insert files aailable. )ach one of them contain some inbuilt
functionality which can be used in our programs/subroutines. /his enables re>usability of code.
ID9-22-5 and ID)K*A/) are two main insert files aailable in Globus.
ID9-22-5 defines all common global ariables that can be used across subroutines and the file
ID)K*A/) initialiEes those common ariables. It is a good practice to include these files in eery
subroutine we write irrespectie of whether we are to use common global ariables or not. /hese insert
files are aailable under the directory G,-B*(.BB.
Example 2
!rite a subroutine that will display the details#Id, 2nemonic and 5ationality'of a customer whose id is
&4440L
So&ution 2
Step 1
A&$orit0!.
(tep &. -pen the 9ustomer <ile
"(am)*e :
D&)E#O(ONVK2M1NN24*D2*L  3 Feb M3
(*B$-/*I5) (ubroutine5ame
MI5()$/ ID9-22-5 Insert <iles
MI5()$/ ID)K*A/)
Actual (tatements
Actual (tatements
$)/*$5
)5"
(tep %. $ead the 9ustomer file and e3tract the record with id &4440L
(tep =. <rom the e3tracted record obtain the mnemonic and nationality
(tep ;. "isplay the customer id, mnemonic and nationality.
Step 1 .
Inorder to open the 9ustomer file we can use the Infobasic command -B)5.
OPEN FBN?.(7S)O'E$ OOOOOOO.
!hen we use the *niVerse command -B)5 to open a file, we need to supply the
e3act file name#along with the prefi3'. If programs are written using -B)5 statements , they do not
become portable across branches of a bank as each branch will hae a different mnemonic to indentify
itself uni1uely.
<or Instance
Bank N@N
In Branch&
In a subroutine we open the customer file by using *niVerse -B)5 statement
OPEN FB$1.(7S)O'E$
In Branch%
If the aboe subroutine with the -B)5 statement were to be e3ecuted in this branch,
the subroutine would return a fatal error saying that it cannot open the file. /he name
of the customer file in this branch is <B$%.9*(/-2)$.
Inorder to oercome this problem or program portability, we need to use the core
Globus subroutine -B< instead of -pen.
OPF .
-B< is a core Globus subroutine that is used to open files.
Synta* .
(&LL OPFKPara-e,er14Para-e,er2L
Barameter &  /he name of the file to be opened prefi3ed with a <.
Barameter % >? Bath of the file to be opened. /his is usually specified as + +
)*a!p&e .
FN.(7S # PF.(7S)O'E$Q
F.(7S # PQ
(&LL OPFKFN.(7S4F.(7SL 9ode to open the 9ustomer file
(or8in$ Of OPF .
/he core Globus subroutine -B< is to be used. It takes in % parameters6
& > /he name of the file to be opened
% > Bath of the file
Both the aboe mentioned parameters are to be stored in ariables and then passed to the
-B< subroutine.
FN.(7S # PF.(7S)O'E$Q
/he name of the ariable that is to store the file name has to begin with F<5.H followed
by a string that denotes the file that is to be opened. Cust supply the alue F<.H followed by the name of
the file to open like aboe to the ariable <5.9*(.
!hen the -B< subroutine gets e3ecuted, the 9-2BA5@ file is read inorder to obtain
the mnemonic of the bank. /hen the <I,).9-5/$-, record of the file is read to find out the type of
file#I5/,9*( or <I5'. -nce the file type is e3tracted, the +<.. in the file name gets replaced with
F<Bank2nemonicH > <B5O thus making subroutines portable across branches.
F.(7S # PQ
/he name of the ariable that will hold the path of the file has to begin with a +<..
followed by a string that denotes the file that is to be opened. /his string has to be the same as that of
the file name#<5' ariable. /his ariable should be e1uated to a null#+.'.
!hen -B< gets e3ecuted, the V-9 entry for the file is read and the path of the data file gets populated
in this ariable.
Step 2 .
Inorder to read the 9ustomer file the Infobasic command $)A" can be used
$E&D FBN?.(7S)O'E$ OOOOO..
But this will result in the same problem as the -B)5 statement did P Bortability of
programs across branches of a Bank.
Inorder to oercome this problem, we use the core Globsu subroutine <.$)A".
Synta* .
<.$)A"#<ile5ame,Id of the record to be read,"ynamic array that will hold the read record,<ilepath,)rror ariable'
)*a!p&e .
E.(7S!D # :1"""NM<
(&LL F.$E&DKFN.(7S4E.(7S!D4$.(7S)O'E$4F.(7S4(7S.E$$1L
5ote $.9*(/-2)$ is a dynamic array that will hold the e3tracted customer record. It
does not re1uire declaration, but initialiEing it to a +. would be a good programming practice. /he error
ariable 9*(.)$$& will hold +null. if the read is successful else will hold a numeric alue. 5ote that the
id of the record has been supplied using a ariable.
(tep = 6
In order to obtain the mnemonic and the nationality of the customer, we need to
access the dynamic array $.9*(/-2)$. /o e3tract alues from a dynamic array, angular brackets
FQ ?H need to be used.#*se +#'. for dimensioned arrays'
!e can e3tract data from the dynamic array by specifying field positions as follows
Contents Of R.CSTOMER
No,e ,Aa, ,Ae GalueB o@ /eldB AaGe bee. deli-i,ed uBi.1 a /eld -arRerK' a.d -ul,i GalueB AaGe
bee. deli-i,ed uBi.1 ,Ae Galue -arRerK!L. )Aere are.Q, a.I Bub GalueB i. ,AiB cuB,o-er record.
D&OHEN%B?D&O HEN% B&N? !N(D&O HEN% B&N? !N(11M &S!&N '&NS!ON 2"M DEL& $OS& S
)LE%&SP! V!LL&%E '&?&)! (!)E '&N PH1111M"S1""MMMPH4PH2""""1"12
""""1"1111ST$!(?B&N&)1U2ST&ND$E&B&$NES1"""N121"421ST$!(?B
&N&)17S""1"""11
E.'NE'ON!( # $.(7S)O'E$81>
or by specifying the actual name of the field.It is a&5ays ad6isa#&e to use fie&d na!es 9co: fie&d
positions cou&d c0an$e fro! one re&ease of G&o#us to anot0er. Gere & is the field position of the
field mnemonic in the 9*(/-2)$ file.
Gow does one know the field numbers and the field namesR
2ost of the files in Globus hae insert files which begin with +ID<.. followed by the name
of the file. /hey will be aailable under G,-B*(.BB./hese files hold the names and the field positions
of the arious fields. /hese fields could hae prefi3es/suffi3es.
<or the customer insert file
Brefi3 used is 6 )B.9*(
(uffi3 used is 6 5I,
/herefore to e3tract the mnemonic and nationality of the customer we need to use the
following code
E.'NE'ON!( # $.(7S)O'E$8EB.(7S.'NE'ON!(>
E.N&)!ON&L!)E # $.(7S)O'E$8EB.(7S.N&)!ON&L!)E?
Step % .
/o display the Id, 2nemonic and 5ationality alues e3tracted we could use the
Infobasic command 9$/.
Synta* .
($) VariableNa-e3<S,ri.1<
)*a!p&e .
($) :(uB,o-er !d :E.(7S!D
!23'CUSOM"R 3%*e 4 !nsert 3%*e 3or ,e C#stomer A))*%+at%on
5ote the field
number and the
field name
($) :(uB,o-er '.e-o.ic :E.'NE'ON!(
($) :(uB,o-er Na,io.ali,I :E.N&)!ON&L!)E
Conso&idated So&ution 2
6Subrou,i.e ,o diB0laI ,Ae de,ailB o@ cuB,o-er 1"""NM
S7B$O7)!NE (7S.D!SPL&E.DE)&!LS
V!NSE$) !T(O''ON
V!NSE$) !TE;7&)E
V!NSE$) !TF.(7S)O'E$
%OS7B !N!)
%OS7B OPENF!LES
%OS7B P$O(ESS
$E)7$N
!N!)
FN.(7S # PF.(7S)O'E$Q
F.(7S # PQ
E.(7S.!D # 1"""NM
E.'NE'ON!( # PQ
E.N&)!ON&L!)E # PQ
$.(7S)O'E$ # PQ
(7S.E$$1 # PQ
$E)7$N
OPENF!LES
(&LL OPFKFN.(7S4F.(7SL
$E)7$N
P$O(ESS
(&LL F.$E&DKFN.(7S4E.(7S.!D4$.(7S)O'E$4F.(7S4(7S.E$$1L
E.'NE'ON!( # $.(7S)O'E$8EB.(7S.'NE'ON!(>
E.N&)!ON&L!)E # $.(7S)O'E$4EB.(7S.N&)!ON&L!)E>
($) :(uB,o-er !d :E.(7S.!D
($) :(uB,o-er '.e-o.ic :E.'NE'ON!(
($) P(uB,o-er Na,io.ali,I :E.N&)!ON&L!)E
$E)7$N
END
5ote
Note :
!n t,e a$o1e s#$ro#t%ne0 t,e +o.e ,as $een s)*%t an. ma.e )art o- 3 .%--erent
)aragra),s' !n or.er to a+,%e1e mo.#*ar%ty an. to ma5e ma%ntenan+e o- +o.e eas%er0 %t %s
a.1%sa$*e to ma5e #se o- )aragra),s' "1ery )aragra), ,as to ,a1e a name an. ,as to en. 6%t, a
R"URN statement'A GOSUB ParagraphName statement ta5es t,e +ontro* to t,at s)e+%-%+
)aragra),' On+e t,e statements %ns%.e t,e )aragra), get e(e+#te.0 t,e RETURN statement ta5es
t,e +ontro* $a+5 to t,e *%ne a-ter t,e GOSUB statement t,at a+t#a**y %n1o5e. t,%s )aragra),'
,%s ty)e o- mo.#*ar )rogramm%ng nee.s to $e #se. -or a *engt,y s#$ro#t%ne' !n+ase t,e
n#m$er o- *%nes t,at +onst%t#te t,e s#$ro#t%ne %s 1ery *ess0 t,e )rogrammer +o#*. +,oose to
6r%te +o.e #s%ng t,e o) &o6n a))roa+, o- )rogramm%ng 6,ere t,ere 6%** $e no )aragra),s at
a**'
Note :
/e nee. to +om)%*e an. +ata*og#e t,%s s#$ro#t%ne no6' Use
EB.(O'P!LE BP (7S.D!SPL&E.DE)&!LS
Com)%*e an. +ata*og#e'
,o5 o (e )*ecute T0is Su#routine Fro! G&o#us;
As you would be aware by now, anything that needs to be e3ecuted from the +Awaiting
Application. prompt in Globus needs to hae an entry in the BG2.<I,). Inorder to e3ecute out
subroutine from within Globus, we need to make an entry in the BG2.<I,). )nsure that you set the
type in the BG2.<I,) to +2. #2ainline program'. /he I" of the BG2.<I,) entry should be the name of
the file which stores the subroutine.
e#u$ State!ent
/he ")B*G statement shows the e3ecution of a subroutine line by line
,et us add the ")B*G statement to the subroutine and see the display #Add it just
after the insert files'
S7B$O7)!NE (7S).D!SPL&E.DE)&!LS
V!NSE$) !T(O''ON
V!NSE$) !TE;7&)E
V!NSE$) !TF.(7S)O'E$
"E#$
%OS7B !N!)
)nsure that you compile and catalogue after making any changes to the subroutine.
)*ecute T0e Su#routine
/ype the name of the subroutine in the +Awaiting Application. prompt and see the e3ecution of
the program line by line.
Note :
!- 6e ty)e CUS'&!SPLA7'&"A!LS %n t,e A6a%t%ng A))*%+at%on )rom)t 6e 6o#*. see no
o#t)#t'
/,at ,a))ene.8 No res#*ts9999999 &on:t )an%+'
)*a!p&e "
2odify e3ample & to display theid, mnemonic and nationality of all customers.
So&ution "
Note :
Some &"BUGger +omman.s
( > /o e3ecute the line
Variablename/ > /o see the contents of a ariable
K > Kuit out of the subroutine and return to the *niVerse prompt.
Press Ctrl + C to abort te subroutine.
!rea"# Option $A%C%&%'%(%)* + Coose A. ,ill return to te -ni.erse prompt
A&$orit0!
(tep &. -pen the 9ustomer <ile
(tep %. (elect all the customer ids
(tep =. $emoe one customer id from the selected list
(tep ;. <or the e3tracted customer id e3tract the corresponding record from the customer file
(tep :. <rom the e3tracted record e3tract the mnemonic and nationality
(tep 0. "isplay the customer id, mnemonic and the nationality
$epeat (teps = to 0 for all customers
Step 1
@ou would be aware by now that we need to use -B< to open any file in Globus.
FN.(7S # PF.(7S)O'E$Q
F.(7S # PQ
(&LL OPFKFN.(7S4F.(7SL
Step 2
!e need to select all the customer ids from the 9ustomer file. In order to achiee this
we need to e3ecute a (elect statement that will pick up all the 9ustomer ids. (elect statements can be
e3ecuted within subroutines. In order to e3ecute select statements within a subroutine, we need to first
assign the select statement to a ariable and then e3ecute the contents of the ariable using the core
Globus subroutine )B.$)A",I(/. P&ease note t0at a Se&ect state!ent e*ecuted fro! 5it0in a
su#routine can on&y return t0e ids fro! t0e fi&e on 50ic0 t0e Se&ect state!ent is #ased.
)B.R)A1IST
)B.$)A",I(/ is a core Globus subroutine that is used to e3ecute a (elect statement within a
subroutine
Synta* .
)B.$)A",I(/ takes in : parameters.

& > /he select statement to be e3ecuted. Gie the name of the ariable that holds the select statement
here.
% > /he name of a dynamic array that will hold the result of the select statement. Blease note that a
select statement here can only select ids from the respectie file. /herefore this dynamic arrays will
only hold the ids of the records that hae been selected. All the ids will be delimited by a field
marker#<2'.
= > /his is an optional parameter. /his is the name of a file in the hard disk that can hold the result of
the select statement. *sually this is set to 5*,, #+.'
; > A ariable that will hold the number of records selected.
: > A ariable to hold the return code. !ill contain null if the select statement was successful else will
contain & or %.
SEL.('D # :SELE() :FN.(7S
5ote the space. If this space is not gien then
(),.92" will contain F(),)9/<B5O.9*(/-2)$H
thus resulting in an error in )B.$)A",I(/
(&LL EB.$E&DL!S)KSEL.('D4SEL.L!S)4QQ4NO.OF.$E(4(7S.E$$L
Step " And %
*se ,--B and $)2-V)#"iscussed )arlier' to repeat (teps = to 0
Conso&idated So&ution "
S(ubroutine to display the mnemonic and nationality of all customers
S7B$O7)!NE (7S.D!SPL&E.DE)&!LS
V!NSE$) !T(O''ON
V!NSE$) !TE;7&)E
V!NSE$) !TF.(7S)O'E$
DEB7%
%OS7B !N!)
%OS7B OPENF!LES
%OS7B P$O(ESS
$E)7$N
!N!)
FN.(7S # 2F.(7S)O'E$2
F.(7S # 22
E.(7S.!D # 22
$.(7S)O'E$ # 22
(7S.E$$1 # 22
E.'NE'ON!( # 22
E.N&)!ON&L!)E # 22
SEL.('D # 22
SEL.L!S) # 22
NO.OF.$E( # "
$E).(ODE # 22
$E)7$N
OPENF!LES
(&LL OPFKFN.(7S4F.(7SL
$E)7$N
P$O(ESS
SE%.CM" = &SE%ECT &'FN.CS
C(%% E#.RE("%)ST*SE%.CM"+SE%.%)ST+,,+NO.OF.REC+RET.CO"E-
%OO.
REMOVE /.CS.)" FROM SE%.%)ST SETT)N$ .OS
01)%E /.CS.)"'.OS
(&LL F.$E&DKFN.(7S4E.(7S.!D4$.(7S)O'E$4F.(7S4(7S.E$$1L
E.'NE'ON!( # $.(7S)O'E$8EB.(7S.'NE'ON!(>
E.N&)!ON&L!)E # $.(7S)O'E$8EB.(7S.N&)!ON&L!)E>
($) *(uB,o-er !d *E.(7S.!D
($) *(uB,o-er '.e-o.ic *E.'NE'ON!(
($) *(uB,o-er Na,io.ali,I *E.N&)!ON&L!)E
RE.E(T
$E)7$N
END

)*a!p&e %
2odify )3ample % to store the e3tracted mnemonic and nationality of all customers in an
array#do not display them' delimited by a +S.. /he array should contain data as follows
Note :
Use t,e R"MO;" statement to s#++ess%1e*y e(tra+t .ynam%+ array
e*ements t,at are se)arate. $y system .e*%m%ters' /,en a system .e*%m%ter %s
en+o#ntere.0 t,e e(tra+te. e*ement %s ass%gne. to 1ar%a$*e'
!n or.er to e(e+#te t,e a$o1e s#$ro#t%ne0 6e nee. to +om)%*e an.
+ata*og#e %t' An entry %n t,e PGM'3!L" ,as to $e ma.e to e(e+#te %t -rom 6%t,%n G*o$#s'
!n or.er to see t,e e(e+#t%on o- t,e s#$ro#t%ne *%ne $y *%ne0 6e nee. to a.. t,e &"BUG
statement'
CusId<Mne!onic<Nationa&ityFMCusId<Mne!oic<Nationa&ity
So&ution %
A&$orit0! .
(tep &. -pen the 9ustomer <ile
(tep %. (elect all the customer ids
(tep =. $emoe one customer id from the selected list
(tep ;. <or the e3tracted customer id e3tract the corresponding record from the customer file
(tep :. <rom the e3tracted record e3tract the mnemonic and nationality
(tep 0. (tore the customer id, mnemonic and the nationality in a dynamic array
$epeat (teps = to 0 for all customers
Step 1= 2 =" =% And '
As discussed earlier we could go ahead and use -B<, <.$)A", ,--B, $)2-V)
and $)B)A/ to accomplish the aboe mentioned steps.
Step /
In order to append the e3tracted alues into an array we could use the following
method.
&rraINa-e8-1> # Value
In our case, once we e3tract the mnemonic and the nationality of the customer
we could concatenate the id, mnemonic and the nationality of the customer delimited with a +S. and then
store it in a dynamic array.
)ery time a new alue comes in, the e3isting alues get pushed down by one
position. /his is achieed by the +>&. that we specify along with the array name. All alues get
appended, delimited by a field marker +<2..
'&!N&$$&E8-1> # E.(7S!DQ6QE.'EN'ON!(Q6QE.N&)!ON&L!)E
/he array will look like this after all alues hae been concatenated
11111*AAA*INFM22222*BBB*INFM 33333*CCC*INFM 44444*DDD*IN
Conso&idated So&ution %
6Subrou,i.e ,o B,ore ,Ae id4 -.e-o.ic a.d .a,io.ali,I o@ all
6cuB,o-erB i. a. arraI
S7B$O7)!NE (7S.D!SPL&E.DE)&!LS
V!NSE$) !T(O''ON
V!NSE$) !TE;7&)E
V!NSE$) !TF.(7S)O'E$
5ote >
/o hae alues in an array delimited by alue markers use
Array5ameQ1=>1? A Value&6.S.6Vale%6.S.6Value=6.S.6Value;
/o hae alues in an array delimited by sub alue markers use
Array5ameQ1=1=>1? A Value&6.S.6Vale%6.S.6Value=6.S.6Value;
%OS7B !N!)
%OS7B OPENF!LES
%OS7B P$O(ESS
$E)7$N
!N!)
FN.(7S # 2F.(7S)O'E$2
F.(7S # 22
E.(7S.!D # 22
$.(7S)O'E$ # 22
(7S.E$$1 # 22
E.'NE'ON!( # 22
E.N&)!ON&L!)E # 22
SEL.('D # 22
SEL.L!S) # 22
NO.OF.$E( # "
$E).(ODE # 22
(7S.DE)&!LS.&$$&E # 22
$E)7$N
OPENF!LES
(&LL OPFKFN.(7S4F.(7SL
$E)7$N
P$O(ESS
SEL.('D # *SELE() *FN.(7S
(&LL EB.$E&DL!S)KSEL.('D4SEL.L!S)4224NO.OF.$E(4$E).(ODEL
LOOP
$E'OVE E.(7S.!D F$O' SEL.L!S) SE))!N% POS
+H!LE E.(7S.!DPOS
(&LL F.$E&DKFN.(7S4E.(7S.!D4$.(7S)O'E$4F.(7S4(7S.E$$1L
E.'NE'ON!( # $.(7S)O'E$8EB.(7S.'NE'ON!(>
E.N&)!ON&L!)E # $.(7S)O'E$8EB.(7S.N&)!ON&L!)E>
CS."ET()%S.(RR(/2314 = /.CS.)"',5,'/.MNEMON)C',5,'/.N(T)ON(%)T/
$EPE&)
$E)7$N
END
Note :
!n or.er to e(e+#te t,e a$o1e s#$ro#t%ne0 6e nee. to +om)%*e an. +ata*og#e %t' An
entry %n t,e PGM'3!L" ,as to $e ma.e to e(e+#te %t -rom 6%t,%n G*o$#s' !n or.er to see
t,e e(e+#t%on o- t,e s#$ro#t%ne *%ne $y *%ne0 6e nee. to a.. t,e &"BUG statement'
Additiona& Infor!ation .
F.(RIT)
F.(RIT) is a core Globus subrotutine that is used to write a record on to a file.
Synta*.
F.+$!)EKFileNa-e4!d o@ ,Ae record ,o be wri,,e.4&c,ual record ,o be wri,,e.L
(&LL F.+$!)EKFN.(7S4E.(7S.!D4$.(7S)O'E$L
F.)1)T)
<."),)/) is also a core Globus subroutine that is used to delete a record from a file.
Synta* .
F.DELE)EKFileNa-e4!d o@ ,Ae record ,o be dele,edL
(&LL F.DELE)EKFN.(7S4E.(7S!DL
?.1 Info#asic Co!!ands
Infobasic has a number of built in commands as well that enable rapid code
deelopment. <ind below some ery commonly used Infobasic commands,
I. -B)5()K
II. $)A"()K
III. !$I/)()K
IV. 9,-()()K
V. 2A/$)A"
VI. 2A/!$I/)
VII. ,-9A/)
I. OP)NS)@
-B)5()K is used open a se1uential file. If the file that you are trying to open does
not e3ist, and you wish to create it you could create it by specifying 9$)A/) statement in the ),()
clause, -B)5()K has the capability to do it#Achieed by the ),() clause'
Synta*
OP)NS)@ +pat0 of t0e fi&e and t0e fi&e na!e- TO fi&e6aria#&e ON )RROR
STOP +!essa$e-
)N )1S)
CR)AT) fi&e6aria#&e )1S) STOP +!essa$e-
)N
)*a!p&e
-B)5()K F/globus/temenos.t3tH /- /)2& -5 )$$-$
(/-B F*nable to open temenos.t3tH
)5" ),()
9$)A/) /)2& ),() (/-B F*nable to create temenos.t3tH
)5"
II. R)AS)@
$)A"()K is used to read data from a se1uential file. !hile reading data from a afile,
$)A"()K uses the new line character 9GA$#&4' as the delimiter. -nce the end of the file is reached
the ),() clause statements are e3ecuted.
Synta*
$)A"()K ariable <$-2 file.ariable
/G)5 statements ),() statements
)*a!p&e
$)A"()K data& <$-2 /)2&
/G)5 9$/ F$ead operation completeH ),() 9$/ F9annot read from file temenos.t3tH
III. (RIT)S)@
!$I/)()K is used to write to a se1uential file. It writes the e3pression as the ne3t
line to the file opened to file.ariable using a new line character 9GA$#&4' as the delimiter.
Synta*
!$I/)()K e3pression /- file.ariable
-5 )$$-$ statements
/G)5 statements
),() statements
)*a!p&e
!$I/)()K F/emenos GlobusH /- /)2&
/G)5 9$/ F"ata !rittenH ),() 9$/ F*nable to write data into temenos.t3tH
I2. C1OS)S)@
9,-()()K is used to write an end>of>file mark and to make the file aailable to other
users. It is ery important that you use 9,-()()K on any file opened with -B)5()K, because
9,-()()K releases the $)A"* lock that was taken by the -B)5()K statement.
Synta*
9,-()()K file.ariable
-5 )$$-$ statements
)*a!p&e
9,-()()K /)2&
-5 )$$-$ 9$/ F*nable to write an end>of>file mark on temenos.t3tH
2. 1OCAT)
,-9A/) statement is used to locate the position of a string or determine the position
to insert in to maintain a specific se1uence.
Synta*
,-9A/) e3pr I5 dynamic.arrayQ<I),",VA,*)?,(/A$/B-(
B@ sort.e3pr ()//I5G ariable
/G)5 statements ),() statements
Additiona& Infor!ation
(ort.)3pr 6
A, Ascending left#Alpha sort'
A$ Ascending right#5umeric sort'
", "escending left#Gigh>low alpha sort'
"$ "escending right#Gigh>low numeric sort'
)*a!p&e
"A@( A F2-56H<26H/*)H6<26H!)"H6<26H/G*H6<26H<$IH
,-9A/) F!)"H I5 "A@( ()//I5G <-*5" ),() <-*5" A 4
9$/ FBosition of !)" in "A@( dynamic array 6H6<-*5"
,-9A/) F(A/H I5 "A@( B@ FA,H ()//I5G B-( ),()
I5( F(A/H B)<-$) "A@(QB-(?
)5"
9$/ FBosition where (A/ has been inserted 6H6B-(
9$/ F"ays dynamic array after inserting (A/ 6H6"A@(
Output
Bosition of !)" in "A@( dynamic array 6 =
Bosition where (A/ has been inserted 6 %
"ays dynamic array after inserting (A/ 6 2-5(A//*)!)"/G*<$I
2I. MATR)A
2A/$)A" is a command that is used to read the contents of a
dimensioned/dynamic array. @ou can specify the id of the record to be picked up from the array. Incase
the read is successful, then the statements following the +/G)5. statements are e3ecuted else the
statements following the +),(). statement are e3ecuted.
Synta*
2A/$)A" array <$-2 file.ariable, record.I" /G)5 statements ),() statements
)*a!p&e
2A/$)" Array& from <.$)GI(/)$.")/AI,(,I"& /G)5 T.. ),() T..
/he aboe statement will search for a record with id specified in the ariable I"&, if found, it will
transfer the record to the array Array&.
2II. MAT(RIT)
2A/!$I/) is used to build a dynamic array from a specified dimensioned array and
write it to the file opened to file.ariable using a key of record.id.
Synta*
2A/!$I/) matri3 -5 file.ariable,O)@
)*a!p&e
"I2 A$$A@&#:'
2A/$)A" A$$A@& <$-2 /)2&,&4&),()
2A/ A$$A@& A +.
)5"
2A/!$I/) A$$A@& -5 /)2&,&44
5ote 6
*se G),B BA(I9 functionname/commandname at the uniVerse prompt to get help
on any of the Infobasic commands or functions.