Sie sind auf Seite 1von 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.

<iled&FM<ield%FM Value&"MValue%"MValue="MValue;
M<ield;FM(ubValue&SM(ubValue%FM<ield:
)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.
----: I
0001= PROGRAM HELLO
0002= CRT "HELLO ORLD"
000!= END
000"=
Bo##o$ %# &'(e !.
----: )I
"HELLO" *'&ed '( *'&e "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
BA(I9 BB G),,-
9ompiling6(ourceAIBB/G),,-I,
-bject A IBB.-/G),,-I
9ompilation 9omplete.
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
?9A/A,-G BB G),,-
JKmbdemo.runKG),,-J cataloged.
9A/A,-G*) is the command in Infobasic that makes an entry in the V-9 for a compiled
program/subroutine.
"OC *ntry for t0e pro%ra!
9/ V-9 G),,-
G),,-
444& "
444% Kmbdemo.runKG),,-
444= B
444; B5
Step &/
)3ecute the program by typing the following statement at the uniVerse prompt'
?$*5 G),,-
G),,- !-$," -utput of the program
1.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 specifiedL 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 :
I) AGE += 1, THEN
PRINT -AGE I. LE..ER THAN OR E/0AL TO 1,1
PRINT -MINOR1
END
EL.E
PRINT -MA2OR1
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 2oop
*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.
I". Open 2oop
/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:
0.ERNAME = 3LOGNAME
BEGIN CA.E
CA.E 0.ERNAME = -TOM1
DEPARTMENT = -HR1
CA.E 0.ERNAME = -DIC41
DEPARTMENT = -ADMIN1
CA.E 1 '* (o(e o* #5e C%6e 6#%#e$e(#6 $%#c5
#5e( #5'6 6#%#e$e(# wo7&d 8e#
e9ec7#ed
-DEPARTMENT NOT )O0ND1
END CA.E
"(am)*e :
)OR CO0NTER = 1 TO 10
CRT -TEMENO. GLOB0.1 T5e 6#r'(8 TEMENO. GLOB0. w'&&
8e#
NE:T CO0NTER printed &4 times
"(am)*e :
LOOP
CRT -I(;7# 2 N7$<er61
INP0T =.N0M1
INP0T =.N0M2
HILE =.N0M1:=.N0M2 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.
CRT -To#%& - : =.N0M1 > =.N0M2
REPEAT
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. 2en
*se the ,)5 function to return the number of characters in string.
II. Count
*se the 9-*5/ function to return the number of times a substring is repeated in
a string alue.
III. count
5ote 6
<ollowing are the boolean operators used in Infobasic
A)M )1uality
NO?5) Ine1uality
?G/ Greater /han
?AG) Greater /han/)1ual
OA,/ ,ess /han
OA,) ,ess /han/)1ual
2A/9G)( Battern 2atch
"(am)*e :
?%r1 = Le(@-TEMENO.1A
Var1 = 8
"(am)*e :
?%r1 = -%<cBde*B85'1
?%r2 = CO0NT@?%r1B1B1A /he 9-*5/ function here is used to count the
number of F,H in the string held in the ariable ar&
Var2 = 3
*se the "9-*5/ function to return the number of delimited fields in a data string.
I". 4pCase
*se the *p9ase function to conert the passes string to *BB)$ 9A().
". o5nCase
*se the "own9ase function to conert the passed string to lower case
"I. 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
"II. 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 :
?%r1 = -%<cBde*B85'1
?%r2 = DCO0NT@?%r1B1B1A The "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 :
?%r1 = 0PCA.E@-#e$e(o61A
Var1 = TEMENOS
"(am)*e :
?%r1 = DONCA.E@-TEMENO.1A
Var1 = temenos
"(am)*e :
?%r1 = CHANGE@-TEMENOO.1B1OO1B1O1A
Var1 = TEMENOS
"(am)*e :
"III. 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 +9PP.
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)M*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)M*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
&4440Q
So'ution 2
Step 1
A'%orit0!/
(tep &. -pen the 9ustomer <ile
(tep %. $ead the 9ustomer file and e3tract the record with id &4440Q
"(am)*e :
DATE=OCON?@CD1EECB"D2"A ! )e< D!
(*B$-/*I5) (ubroutine5ame
RI5()$/ ID9-22-5 Insert <iles
RI5()$/ ID)M*A/)
Actual (tatements
Actual (tatements
$)/*$5
)5"
(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 )BN4.C0.TOMER FFFFFFF.
!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 S@S
In Branch&
In a subroutine we open the customer file by using *niVerse -B)5 statement
OPEN )BR1.C0.TOMER
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+ /
CALL OP)@P%r%$e#er1BP%r%$e#er2A
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 /
)N.C0. = G).C0.TOMERH
).C0. = GH
CALL OP)@)N.C0.B).C0.A 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.
)N.C0. = G).C0.TOMERH
/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 > <B5T thus making subroutines portable across branches.
).C0. = GH
/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
READ )BN4.C0.TOMER FFFFF..
But this will result in the same problem as the -B)5 statement did U 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 /
=.C0.ID = -1000ED1
CALL ).READ@)N.C0.B=.C0.IDBR.C0.TOMERB).C0.BC0..ERR1A
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
FO ?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.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 an" sub
values in this #ustomer re#ord.
$%O&EN'()$%O &EN' (%N) *NC$%O &EN' (%N) *NC++, %S*%N M%NS*ON -., $E/% ROS% S
T/E'%S0* 1*//%'E M%)%T* C*T2 M%N
0&++++,.3+..,,,0&40&-....+.+-
....+.++++35R*C)(%N%T+-35%N$RE%(%RNES+...6+-+.4-+3
=.MNEMONIC = R.C0.TOMER+1>
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 namesV
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
=.MNEMONIC = R.C0.TOMER+EB.C0..MNEMONIC>
=.NATIONALIT= = R.C0.TOMER+EB.C0..NATIONALIT=?
Step & /
/o display the Id, 2nemonic and 5ationality alues e3tracted we could use the
Infobasic command 9$/.
Synta+ /
CRT ?%r'%<&eN%$eI1.#r'(81
*+a!p'e /
CRT -C76#o$er Id : -:=.C0.ID
!23'CUSOM"R 3%*e 4 !nsert 3%*e 3or ,e C#stomer A))*%+at%on
5ote the field
number and the
field name
CRT -C76#o$er M(e$o('c : -:=.MNEMONIC
CRT -C76#o$er N%#'o(%&'#J : -:=.NATIONALIT=
Conso'idated So'ution 2
K.7<ro7#'(e #o d'6;&%J #5e de#%'&6 o* c76#o$er 1000ED
.0BRO0TINE C0..DI.PLA=.DETAIL.
LIN.ERT IMCOMMON
LIN.ERT IME/0ATE
LIN.ERT IM).C0.TOMER
GO.0B INIT
GO.0B OPEN)ILE.
GO.0B PROCE..
RET0RN
INIT:
)N.C0. = G).C0.TOMERH
).C0. = GH
=.C0..ID = 1000ED
=.MNEMONIC = GH
=.NATIONALIT= = GH
R.C0.TOMER = GH
C0..ERR1 = GH
RET0RN
OPEN)ILE.:
CALL OP)@)N.C0.B).C0.A
RET0RN
PROCE..:
CALL ).READ@)N.C0.B=.C0..IDBR.C0.TOMERB).C0.BC0..ERR1A
=.MNEMONIC = R.C0.TOMER+EB.C0..MNEMONIC>
=.NATIONALIT= = R.C0.TOMERBEB.C0..NATIONALIT=>
CRT -C76#o$er Id: -:=.C0..ID
CRT -C76#o$er M(e$o('c: -:=.MNEMONIC
CRT GC76#o$er N%#'o(%&'#J: -:=.NATIONALIT=
RET0RN
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.COMPILE BP C0..DI.PLA=.DETAIL.
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'
.0BRO0TINE C0.T.DI.PLA=.DETAIL.
LIN.ERT IMCOMMON
LIN.ERT IME/0ATE
LIN.ERT IM).C0.TOMER
DEBUG
GO.0B INIT
)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 #
A'%orit0!
Note :
Some &"BUGger +omman.s
( > /o e3ecute the line
Variablename/ > /o see the contents of a ariable
M > Muit 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
(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.
)N.C0. = G).C0.TOMERH
).C0. = GH
CALL OP)@)N.C0.B).C0.A
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*A2IST
)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 %.
.EL.CMD = -.ELECT -:)N.C0.
5ote the space. If this space is not gien then
(),.92" will contain F(),)9/<B5T.9*(/-2)$H
thus resulting in an error in )B.$)A",I(/
CALL EB.READLI.T@.EL.CMDB.EL.LI.TBHHBNO.O).RECBC0..ERRA
Step # And &
*se ,--B and $)2-V)#"iscussed )arlier' to repeat (teps = to 0
Conso'idated So'ution #
CusId<Mne!onic<Nationa'ityFMCusId<Mne!oic<Nationa'ity
K(ubroutine to display the mnemonic and nationality of all customers
.0BRO0TINE C0..DI.PLA=.DETAIL.
LIN.ERT IMCOMMON
LIN.ERT IME/0ATE
LIN.ERT IM).C0.TOMER
DEB0G
GO.0B INIT
GO.0B OPEN)ILE.
GO.0B PROCE..
RET0RN
INIT:
)N.C0. = C).C0.TOMERC
).C0. = CC
=.C0..ID = CC
R.C0.TOMER = CC
C0..ERR1 = CC
=.MNEMONIC = CC
=.NATIONALIT= = CC
.EL.CMD = CC
.EL.LI.T = CC
NO.O).REC = 0
RET.CODE = CC
RET0RN
OPEN)ILE.:
CALL OP)@)N.C0.B).C0.A
RET0RN
PROCE..:
SEL.CMD = "SELECT ":N.CUS
C!LL EB."E!DL#ST$SEL.CMD%SEL.L#ST%&&%NO.O."EC%"ET.CODE'
LOO(
"EMOVE ).CUS.#D "OM SEL.L#ST SETT#NG (OS
*+#LE ).CUS.#D:(OS
CALL ).READ@)N.C0.B=.C0..IDBR.C0.TOMERB).C0.BC0..ERR1A
=.MNEMONIC = R.C0.TOMER+EB.C0..MNEMONIC>
=.NATIONALIT= = R.C0.TOMER+EB.C0..NATIONALIT=>
CRT "C76#o$er Id: ":=.C0..ID
CRT "C76#o$er M(e$o('c: ":=.MNEMONIC
CRT "C76#o$er N%#'o(%&'#J: ":=.NATIONALIT=
"E(E!T
RET0RN
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 +K.. /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'
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 1
In order to append the e3tracted alues into an array we could use the following
method.
Arr%JN%$e+-1> = ?%&7e
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 +K. 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..
MAINARRA=+-1> = =.C0.ID:HKH:=.MENMONIC:HKH:=.NATIONALIT=
/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 &
K.7<ro7#'(e #o 6#ore #5e 'dB $(e$o('c %(d (%#'o(%&'#J o* %&&
Kc76#o$er6 '( %( %rr%J
.0BRO0TINE C0..DI.PLA=.DETAIL.
LIN.ERT IMCOMMON
LIN.ERT IME/0ATE
LIN.ERT IM).C0.TOMER
GO.0B INIT
GO.0B OPEN)ILE.
GO.0B PROCE..
5ote >
/o hae alues in an array delimited by alue markers use
Array5ameO1=>1? A Value&6.K.6Vale%6.K.6Value=6.K.6Value;
/o hae alues in an array delimited by sub alue markers use
Array5ameO1=1=>1? A Value&6.K.6Vale%6.K.6Value=6.K.6Value;
RET0RN
INIT:
)N.C0. = C).C0.TOMERC
).C0. = CC
=.C0..ID = CC
R.C0.TOMER = CC
C0..ERR1 = CC
=.MNEMONIC = CC
=.NATIONALIT= = CC
.EL.CMD = CC
.EL.LI.T = CC
NO.O).REC = 0
RET.CODE = CC
C0..DETAIL..ARRA= = CC
RET0RN
OPEN)ILE.:
CALL OP)@)N.C0.B).C0.A
RET0RN
PROCE..:
.EL.CMD = ".ELECT ":)N.C0.
CALL EB.READLI.T@.EL.CMDB.EL.LI.TBCCBNO.O).RECBRET.CODEA
LOOP
REMO?E =.C0..ID )ROM .EL.LI.T .ETTING PO.
HILE =.C0..ID:PO.
CALL ).READ@)N.C0.B=.C0..IDBR.C0.TOMERB).C0.BC0..ERR1A
=.MNEMONIC = R.C0.TOMER+EB.C0..MNEMONIC>
=.NATIONALIT= = R.C0.TOMER+EB.C0..NATIONALIT=>
CUS.DET!#LS.!""!),-1. = ).CUS.#D:&/&:).MNEMON#C:&/&:).N!T#ON!L#T)
REPEAT
RET0RN
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+/
).RITE@)'&eN%$eBId o* #5e record #o <e wr'##e(BAc#7%& record #o <e
wr'##e(A
CALL ).RITE@)N.C0.B=.C0..IDBR.C0.TOMERA
F.*2*T*
<."),)/) is also a core Globus subroutine that is used to delete a record from a file.
Synta+ /
).DELETE@)'&eN%$eBId o* #5e record #o <e de&e#edA
CALL ).DELETE@)N.C0.B=.C0.IDA
?.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()M
II. $)A"()M
III. !$I/)()M
IV. 9,-()()M
V. 2A/$)A"
VI. 2A/!$I/)
VII. ,-9A/)
I. OP*NS*@
-B)5()M 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()M 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 *2S*
CR*AT* fi'e6aria$'e *2S* STOP ,!essa%e.
*N
*+a!p'e
-B)5()M 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"()M is used to read data from a se1uential file. !hile reading data from a afile,
$)A"()M 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"()M ariable <$-2 file.ariable
/G)5 statements ),() statements
*+a!p'e
$)A"()M data& <$-2 /)2&
/G)5 9$/ F$ead operation completeH ),() 9$/ F9annot read from file temenos.t3tH
III. )RIT*S*@
!$I/)()M 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/)()M e3pression /- file.ariable
-5 )$$-$ statements
/G)5 statements
),() statements
*+a!p'e
!$I/)()M F/emenos GlobusH /- /)2&
/G)5 9$/ F"ata !rittenH ),() 9$/ F*nable to write data into temenos.t3tH
I". C2OS*S*@
9,-()()M 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,-()()M on any file opened with -B)5()M, because
9,-()()M releases the $)A"* lock that was taken by the -B)5()M statement.
Synta+
9,-()()M file.ariable
-5 )$$-$ statements
*+a!p'e
9,-()()M /)2&
-5 )$$-$ 9$/ F*nable to write an end>of>file mark on temenos.t3tH
". 2OCAT*
,-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.arrayO<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@(OB-(?
)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
"I. 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 W.. ),() W..
/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&.
"II. 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,T)@
*+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.

Das könnte Ihnen auch gefallen