docfxh0m

Upload: ramatarak

Post on 03-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 docFxh0m

    1/23

    PROGRAMMING IN INFOBASIC

    1.1 Introduction

    As you would be aware by now, Globus uses uniVerse/jBase as the bank end to storeits data. All programs that make up Globus are written in a language called Infobasic. Infobasic is aery simple yet powerful programming language. !ith its english like statements, it makesprogramming ery simple. A salient feature of Infobasic is that it does not support data types. Allariables in Infobasic are treated as "ynamic Arrays#$efer %.& Arrays'. (ince Infobasic does notsupport 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 inInfobasic, it is ery essential to understand the concept of arrays.

    )ery ariable that we use occupies a portion of the memory. *sually characterariables occupy & byte of memory, which hae the capacity to store just one character. Incase aseries of characters #string' like +G-B*( has to be stored, then a character ariable would notsuffice. here comes the need for arrays. !e now need 0 bytes of continuous memory blocks in orderto store the string. (e1uential storage of characters that form a string will make storage and retriealeasier and faster. 2oreoer all the 0 bytes should hae the same name. his is e3actly the functionalityof an array.

    o sum it up, an array is nothing but continuos memory allocation, where inall the bytes hae the same name as that of the array and can be distinguished with the help of asubscript which always starts with a +4.

    Figure 1.1 Structure Of An Array

    Array 1G L O B U S

    0 1 2 3 4 5

    5ote 6Incase you wish to access +G in +G-B*( then specify Array&748

  • 8/12/2019 docFxh0m

    2/23

    2.1.1 Types Of Arrays

    here are two different types of arrays that are supported by Infobasic. hey are

    I. "ynamic ArraysII. "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 tomanipulate ariable length records with a ariable length of fields and/or alues within fields etc. Adynamic array is just a string of characters that contain one or more delimiter characters. he delimitercharacters are 6

    A(9II "ecimal "escription

    %:; Value 2arker

    )ach field is separated by a field marker and a field may contain more than one alue separated by aalue 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 tablesof data elements where the number of dimensions and the e3tent #number of elements' of eachdimension is known and is not likely to change. "imensioned arrays hae to be declared using the"I2)5(I-5 statement.

    ? $efers to the number of rows= > ? $efers to the number of columnsA customer record is a dimensioned array. All the fields that form the customer record aredynamic 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 dynamic array being initialised. Incase the array needs to store a numeric

  • 8/12/2019 docFxh0m

    3/23

    #.1 Structure Of An Info$asic Pro%ra!

    here are two different types of programs that we can write in Infobasic. -ne is+$-G$A2 itself and the other is +(*B$-*I5).

    Any program that is e3ecuted from the uniVerse prompt is termed as a +$-G$A2and 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 adirectory named B and the core Globus programs or subroutines are stored under G-B*(.B.5eer store user written programs/subroutines in the G-B*(.B 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 intoassembly language that the machine can understand. -nce programs/subroutines are compiled, objectcodes get produced. hese object codes get stored in specific directories.

    If the source#program/subroutine' is in B then the object code gets stored in B.-. Ifthe source is in G-B*(.B then the object code gets stored in G-B*(.B.-. Apart from compilingInfobasic programs, we also need to catalogue them. As you would be aware by now, V-9 is the backbone of our database uniVerse. 9ataloguing is the process of making an entry in the V-9. !hen aprogram 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 6In 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 currentdirectory. 9ataloguing subroutines in jBase is the process of making the object code a part of alibrary file under the path specified by the jBase global ariable CB9")VDIB. his library file

    under the lib directory gets created automatically inorder to store object codes produced as aresult of compiling subroutines. he siEe and the name of the library files is determined by theconfiguration file jib"efinition under the jBase +config directory.

    Incase of a program, when catalogued, the object code is placed under thedirectory pointed by the jBase global ariable CB9")VDBI5. *sually this ariable points to the +bindirectory, which is under the +run directory. *nlike subroutines, library files do not get createdhere. he object files get stored straight away under the path specified by CB9")VDBI5.

  • 8/12/2019 docFxh0m

    4/23

    (.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 F)- !-$"H and store it under the B directory.

    Conso'idated So'ution 1

    >ED BP HELLONew record.

    ----: I0001= PROGRAM HELLO0002= CRT "HELLO ORLD"

    000!= END000=Bo##o$ %# &'(e !.----: )I"HELLO" *'&ed '( *'&e "BP".

    )" is the editor used by Infobasic. lease refer to +*sing )" )ditor notes that has been attached tothis course material.

    Step 2/

    9ompile the program

    BA(I9 B )-9ompiling6(ourceB/)-,-bject B.-/)-9ompilation 9omplete.

    BA(I9 is the command used by Infobasic to compile programs/subroutines. It conerts the code intoassembly language and creates the object file.5ote that the object code has been placed under thedirectory B.- automatically.

    Step #/

    9atalogue the program

    ?9AA-G B )-JKmbdemo.runK)-J cataloged.

    9AA-G*) is the command in Infobasic that makes an entry in the V-9 for a compiledprogram/subroutine.

    "OC *ntry for t0e pro%ra!

    9 V-9 )-)-

    444& "444% Kmbdemo.runK)-

    444= B444; B5

  • 8/12/2019 docFxh0m

    5/23

    Step &/

    )3ecute the program by typing the following statement at the uniVerse prompt '

    ?$*5 )-

    )- !-$" -utput of the program

    .1 Contro' Structures In Info$asic

    Cust like any other programming language, Infobasic also supports a number of controlstructures namely

    I. If hen )lseII. Begin 9ase )nd 9aseIII.

  • 8/12/2019 docFxh0m

    6/23

    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 followingstatements up to the ne3t 9A() statement are e3ecuted. )3ecution continues with the statementfollowing the )5" 9A() statement. If the e3pression in a 9A() statement is false, e3ecutioncontinues by testing the e3pression in the ne3t 9A() statement. If it is true, the statementsfollowing 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() statementare e3ecuted. If no 9A() statements are true, none of the statements between the B)GI5 9A()and )5" 9A() statements are e3ecuted.

    III. For oop

    *se the

  • 8/12/2019 docFxh0m

    7/23

    3.1 Bui't In Info$asic Functions

    Infobasic has a number of built in functions that help in rapid code deelopment. (omeof the commonly used build in functions are listed below.

    I. enII. 9ountIII. "countIV. *p9aseV. "own9aseVI. 9hangeVII. Icon

    VIII. -con

    I. en

    *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 ina string alue.

    III. count

    5ote 6

  • 8/12/2019 docFxh0m

    8/23

    *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 *)$ 9A().

    ". o5nCase

    *se the "own9ase function to conert the passed string to lower case

    "I. C0an%e

    *se the 9A5G) function to replace a substring in e3pression with anothersubstring. 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 nullalue, null is returned.

    "(am)e :

    ?%r1 = %

  • 8/12/2019 docFxh0m

    9/23

    "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 assubroutines, 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 filewhere the subroutine is to be stored need not hae the same name. But as a conention, inorder toaiod 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 +9PPprograms. here are number of insert files aailable. )ach one of them contain some inbuiltfunctionality 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 fileID)M*A) initialiEes those common ariables. It is a good practice to include these files in eerysubroutine we write irrespectie of whether we are to use common global ariables or not. hese insertfiles are aailable under the directory G-B*(.B.

    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

  • 8/12/2019 docFxh0m

    10/23

    (tep =.

  • 8/12/2019 docFxh0m

    11/23

    !hen the -< subroutine gets e3ecuted, the 9-2A5@ file is read inorder to obtainthe mnemonic of the bank. hen the

  • 8/12/2019 docFxh0m

    12/23

    .MNEMONIC = R.CTOMER+1>

    or by specifying the actual name of the field.It is a'5ays ad6isa$'e to use fie'd na!es 9co: fie'dpositions cou'd c0an%e fro! one re'ease of G'o$us to anot0er. ere & is the field position of thefield mnemonic in the 9*(-2)$ file.

    ow does one know the field numbers and the field names

    2ost of the files in Globus hae insert files which begin with +ID

  • 8/12/2019 docFxh0m

    13/23

    CRT C76#o$er M(e$o('c : :.MNEMONICCRT C76#o$er N%#'o(%&'#J : :.NATIONALIT

    Conso'idated So'ution 2

    K7

  • 8/12/2019 docFxh0m

    14/23

    -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 +AwaitingApplication prompt in Globus needs to hae an entry in the G2.

  • 8/12/2019 docFxh0m

    15/23

  • 8/12/2019 docFxh0m

    16/23

    (tep &. -pen the 9ustomer his is an optional parameter. his is the name of a file in the hard disk that can hold the result ofthe 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 willcontain & or %.

    EL.CMD = ELECT :)N.C

    5ote the space. If this space is not gien then().92" will contain F())9

  • 8/12/2019 docFxh0m

    17/23

    CusId

  • 8/12/2019 docFxh0m

    18/23

    So'ution &

    A'%orit0! /

    (tep &. -pen the 9ustomer

  • 8/12/2019 docFxh0m

    19/23

    RETRN

    INIT: )N.C = ).CTOMER ).C = .C.ID =

    R.CTOMER = C.ERR1 = .MNEMONIC = .NATIONALIT = EL.CMD = EL.LIT = NO.O).REC = 0 RET.CODE = C.DETAIL.ARRA = RETRN

    OPEN)ILE: CALL OP)@)N.C).C

    RETRNPROCE: EL.CMD = "ELECT ":)N.CCALL [email protected]).RECRET.CODE LOOP REMO?E .C.ID )ROM EL.LIT ETTING PO HILE .C.ID:PO CALL ).READ@)N.C.C.IDR.CTOMER).CC.ERR1 .MNEMONIC = R.CTOMER+EB.C.MNEMONIC> .NATIONALIT = R.CTOMER+EB.C.NATIONALIT> CUS.DET!#LS.!!),-1 = ).CUS.#D:&/&:).MNEMON#C:&/&:).N!T#ON!L#T)

    REPEAT RETRN

    END

    Note :

    !n or.er to e(e+#te t,e a$oe s#$ro#t%ne 6e nee. to +om)%e an. +ataog#e %t' An

    entry %n t,e PGM'!L" ,as to $e ma.e to e(e+#te %t -rom 6%t,%n Go$#s' !n or.er to see

    t,e e(e+#t%on o- t,e s#$ro#t%ne %ne $y %ne 6e nee. to a.. t,e &"BUG statement'

  • 8/12/2019 docFxh0m

    20/23

    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%$eId o* #5e record #o

  • 8/12/2019 docFxh0m

    21/23

    Synta+

    OP*NS*@ ,pat0 of t0e fi'e and t0e fi'e na!e TO fi'e6aria$'e ON *RRORSTOP ,!essa%e

    *N *S*

    CR*AT* fi'e6aria$'e *S* STOP ,!essa%e*N

    *+a!p'e

    -)5()M F/globus/temenos.t3tH - )2& -5 )$$-$(- F*nable to open temenos.t3tH

    )5" )()9$)A) )2& )() (- 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 9A$#&4' as the delimiter. -nce the end of the file is reachedthe )() clause statements are e3ecuted.

    Synta+

    $)A"()M ariable

  • 8/12/2019 docFxh0m

    22/23

    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

    ". OCAT*

    -9A) statement is used to locate the position of a string or determine the positionto insert in to maintain a specific se1uence.

    Synta+

    -9A) e3pr I5 dynamic.arrayO

  • 8/12/2019 docFxh0m

    23/23

    2A$)" Array& from