You are on page 1of 9

LM QUEN VI JBASE V NG DNG TRONG ENQUIRY

Mc ch:
- Hiu c bn v cch lp trnh bng nfobasic
- Tng bc d doc subroutine dn gin bng nfobasic
- Cc bc cn thit d tao subroutine cho 1 Enquiry
( K hiu: * - Xem thm ti liu nu quan tm)
Reference: nfobasicProgramming-jBase, PROGRAMMNG N NFOBASC
1. V !"#! !"$ I!%&'()*c
- nfobasic khng h tro kiu d liu, nn dng bin khng cn khai bo trc
- Moi bin trong nfobasic du l array.
- C 2 loai array *
. Dynamic Arrays
. Dimensioned Arrays
+. ,-. /01c c2( 1 I!%&'()*c 30&"0(4
- Program thuc thi t database prompt goi l '3ROGRAM5
- Program thuc thi bn trong Globus goi l "SUBROUTINE.
Note:
*Comments *Comments
PROGRAM ProgramName SUBROUTNE SubroutineName
Statement1 Statement1
Statement 2 Statement 2
Statement 3 Statement 3
RETURN
END END
Lu vi SUBROUTNE:
n order to achieve modularity and to make maintenance of code easier, it is
advisable to make use of paragraphs. Every paragraph has to have a name and has to
end with a RETURN statement
SUBROUTNE subroutine-name( )
GOSUB paragraph-name
GOSUB paragraph-name
RETURN
Paragraph-name:
Statement
Statement
Statement
RETURN
Paragraph-name:
Statement
Statement
Statement
RETURN
END
6. B*7! 89ch :; /h<c /h*
Quy c:
- Ta lu cc chng trnh vo th muc BANK
- Lu : tn ca file lu chng trnh phi trng vi tn ca subroutine/ program
khai bo trong d
bin dch v thc thi, vo Database prompt :
- Chay run > cmd
- Chay lnh: telnet [ip-server]
Login: [user]
Password: [password]
START GLOBUS Y/N = N
Note :
S dung --> HELP BASC functionname/commandname t database prompt d tra
cu v nfobasic commands hay functions.
1. 30&"0(4)
Vi program HELLO
- Bin djch:
-- > EB.COMPLE BANK HELLO
- Chay:
-- > HELLO
+. S.'0&./*!=)
Vi subroutine HELLO
- Bin djch:
-- > EB.COMPLE BANK HELLO
- Mun SUBROUTNE thuc thi doc trong Globus ta cn khai bo trong file
PGM.FLE (* GlobusDirectoryStructureAndmportantFilesnGlobus.doc ) nh
sau:
+ T Globus, g PGM.FLE, COMMAND
+ t trng type trong PGM.FLE l 'M' (Mainline program).
+ TrngD trong PGM.FLE din tn ca file lu subroutine
- Chay DEBUG 1 subroutine:
t dng lnh: DEBUG trong subroutine ni bt du mun DEBUG
-- > EBS.LOGN
Ln lot g account v password ca ban doc cp trong Globus
-- >HELLO
Note:
Mt s DEBUG commands
S - To execute the line
V variable name - To see the contents of a variable
Q or QUT- Quit out of the subroutine and return to the Database prompt.
Press Ctrl + C to abort the subroutine.
Break: Option (AC!"#$% & Choose A. 'ill return to the #atabase prompt
>. V 81: ?0&"0(4 @ELLO
PROGRAM HELLO
CRT "HELLO WORLD"
END
- Lu vo file BANK/HELLO
Bin djch:
EB.COMPLE BANK HELLO
Chay:
HELLO
HELLO WORLD Output of the program
A. V 8 +: SUBROUTINE ,UST.DIS3LAY.DETAILS
Vit subroutine hin thj thng tin (d, Mnemonic and Nationality) ca khch hng (bng
CUSTOMER) c D l 100069
AB"&0*/h4:
Step 1. M File Customer
Step 2. oc file Customer , trch ly record c id l 100069
Step 3 T record, ly thng tin v mnemonic v nationality
Step 4. Hin thj customer id, mnemonic , nationality.
S/=?1
m file CUSTOMER, ta dng core Globus subroutine l OPF
SC!/(D :
CALL OPF(Parameter1,Parameter2)
Parameter 1 The name of the file to be opened prefixed with a F.
Parameter 2 -> Path of the file to be opened. This is usually specified as ' '
ED(4?B= :
FN.CUS = F.CUSTOMER!
F.CUS = !
CALL OPF(FN.CUS,F.CUS) Code to open the Customer file
Note:
FN.CUS = F.CUSTOMER!
- Tn bin cha tn file nn doc bt du bng "FN.
- Chi chp nhn gi trj "F. theo sau l tn file doc m d gn cho bin FN.CUS.
L do:
Khi OPF thuc thi: Bn ghi trong FLE.CONTROL ca file CUSTOMER doc doc d
tm ra type of file (NT, CUS or FN).
Khi xc djnh doc loai ca file, k tu 'F.' trong file name doc thay th bi
"FBankMnemonic - FBNK do d dm bo subroutines kh chuyn (cch m file bng
cu lnh thng thng ca nfobasic l OPEN khng dm bo diu ny-* )
S/=? + :
oc bn ghi t file, dng F.READ
SC!/(D :
F.READ(FileName,d of the record to be read,Dynamic array that will hold the read
record,Filepath,Error variable)
ED(4?B= :
".CUS#D = $1%%%&'(
CALL F.READ(FN.CUS,".CUS#D,R.CUSTOMER,F.CUS,CUS.ERR1)
Note:
- Mc d bin trong nfobasic khng cn khai bo trc, nhng nn khi tao a good
programming practice (vd: R.CUSTOMER = ")
- CUS.ERR1 tr v NULL nu thnh cng, nu khng s l 1 gi trj numeric
- id ca record phi doc truyn vo thng qua bin (".CUS#D)
S/=? 6:
Ly 1 gi trj t Dynamic array , s dung arrayname<field number or field name>
( dng '( )' di v dimensioned array)
VD: ".MNEMON#C = R.CUSTOMER)1* -->dng field number
Hoc
".MNEMON#C = R.CUSTOMER)E+.CUS.MNEMON#C* -->dng field name
Note:
(. !)* th+ng tin ,- .ield number ,/ the .ield name 0 12u$
- Mi file trong Globus du c 1 file goi l 3nsert 4ile, tn file ny bt du bng EIFG.'
theo sau l tn file.
Tm cc file _F ny th muc : H?(cI("=+HJ:=0)*&! &% T+>KH'!IHGLOBUS.B3
Cc file ny cha tn v vj tr ca cc trng ta cn tm
5. Ch6 7:
.. I/ *) (BL(C) (8:*)('B= /& .)= %*=B8 !(4=) '=c(.)= %*=B8 ?&)*/*&!) c&.B8 ch(!"=
%0&4 &!= 0=B=()= &% GB&'.) /& (!&/h=0
8. 9: d;: 3<4.C=>?O@AB 4ile
Code hon chnh:
,S-.r/-t01e t/ 20345a6 t7e 2eta053 /8 9-3t/mer 1%%%&'
SU+ROUT#NE CUS.D#SPLA".DETA#LS
:#NSERT #;COMMON
:#NSERT #;E<UATE
:#NSERT #;F.CUSTOMER
GOSU+ #N#T
GOSU+ OPENF#LES
GOSU+ PROCESS
RETURN
#N#T=
FN.CUS = F.CUSTOMER!
F.CUS = !
".CUS.#D = 1%%%&'
".MNEMON#C = !
".NAT#ONAL#T" = !
R.CUSTOMER = !
CUS.ERR1 = !
RETURN
OPENF#LES=
CALL OPF(FN.CUS,F.CUS)
RETURN
PROCESS=
CALL F.READ(FN.CUS,".CUS.#D,R.CUSTOMER,F.CUS,CUS.ERR1)
".MNEMON#C = R.CUSTOMER)E+.CUS.MNEMON#C*
".NAT#ONAL#T" = R.CUSTOMER)E+.CUS.NAT#ONAL#T"*
CRT $C-3t/mer #2= $=".CUS.#D
CRT $C-3t/mer M1em/109= $=".MNEMON#C
CRT $C-3t/mer Nat0/1a50t6= $=".NAT#ONAL#T"
RETURN
END
Note:
(. NCu th+ng tin ,- .ield ta muDn l)* kh+ng tEm th)* trong 3<4 .ile thE sao$
- Mt s field ca CUSTOMER khng tm thy thng tin c trong _F file, d l cc
trng doc djnh ngha thm v dt trong LOCAL.REF.TABLE.
(vd: TELEPHONE ca khch hng)
C th xem LOCAL.REF.TABLE t Globus nh sau:
- G lnh LOCAL.REF.TABLE
- G tn bng cn tm thng tin mn hnh LOCAL.REF.TABLE nput
5. CFGh l)* giF trH .ield tI !OCA!.BA4.?AB!A $
CALL E+.LOCAL.LOCREF(>CUSTOMER>,>TELEPHONE>,REF.CUS.TELEPHONE)
".CUS.TELEPHONE = R.CUSTOMER)E+.CUS.LOCAL.REF,REF.CUS.TELEPHONE*
M. SUBROUTINE ch& ENQUIRY
Cng tng tu nh trn
Tuy nhin yu cu ca SUBROUTNE cho ENQURY l phi tr v mng lu d liu
VD:
Vit SUBROUTNE ly thng tin mnemonic, nationality ca tt c CUSTOMER
SU+ROUT#NE CUS.D#SPLA".DETA#LS (CUS.DETAILS.ARRAY)
:#NSERT #;COMMON
?
CUS.DETAILS.ARRAY<-1> = Y.CUS.ID:'*':Y.MNEMONIC:'*':Y.NATIONALITY
RETURN
END
Note :
- To have values in an array delimited by value markers use
ArrayName<1NO1> = Value1:'*':Vale2:'*':Value3:'*':Value4
- To have values in an array delimited by sub value markers use
ArrayName<1N1NO1> = Value1:'*':Vale2:'*':Value3:'*':Value4
*
2. ly doc tt c customer id t Customer file, ta chay Select statement
SEL.CMD = $SELECT $=FN.CUS
Note the space. f this space is not given
then SEL.CMD will contain
"SELECTFBNK.CUSTOMER thus resulting
in an error in EB.READLST
CALL E+.READL#ST(SEL.CMD,SEL.L#ST,!!,NO.OF.REC,CUS.ERR)
Note
S=B=c/ )/(/=4=!/ /h<c /h* /P '7! /0&!" 1 ).'0&./*!= chQ cR /hS /0T : *8) /P %*B= 4; S=B=c/
)/(/=4=!/ chU!.
EB.READLIST
EB.READLST l core Globus subroutine dng d thuc thi 1 Select statement
bn trong 1 subroutine
SC!/(D :
EB.READLST c 5 parameters.

1 - Bin lu Select statement cn thuc thi.
2 Tn ca 1 dynamic array s lu tr kt qu ca select statement.
3 - L 1 optional parameter. L tn ca file trong hard disk c th lu kt qu ca select
statement. Thng d l NULL ('')
4 - Bin lu s long records selected.
5 - Bin lu the return code. null nu select statement thuc thi thnh cng, ngoc lai s
l 1 hoc 2.
3. Dng REMOVE statement d trch ra tng thnh phn t dynamic array doc phn
cch bng du phn cch ca h thng ( *)
*---------------------------------------------------------------------------------------------
,S-.r/-t01e t/ 3t/re t7e 02, m1em/109 a12 1at0/1a50t6 /8 a55
,9-3t/mer3 01 a1 arra6
SU+ROUT#NE CUS.D#SPLA".DETA#LS
:#NSERT #;COMMON
:#NSERT #;E<UATE
:#NSERT #;F.CUSTOMER
GOSU+ #N#T
GOSU+ OPENF#LES
GOSU+ PROCESS
RETURN
#N#T=
FN.CUS = >F.CUSTOMER>
F.CUS = >>
".CUS.#D = >>
R.CUSTOMER = >>
CUS.ERR1 = >>
".MNEMON#C = >>
".NAT#ONAL#T" = >>
SEL.CMD = >>
SEL.L#ST = >>
NO.OF.REC = %
RET.CODE = >>
CUS.DETA#LS.ARRA" = >>
RETURN
OPENF#LES=
CALL OPF(FN.CUS,F.CUS)
RETURN
PROCESS=
SEL.CMD = "SELECT "=FN.CUS
CALL E+.READL#ST(SEL.CMD,SEL.L#ST,>>,NO.OF.REC,RET.CODE)
LOOP REMO@E ".CUS.#D FROM SEL.L#ST SETT#NG POS
WH#LE ".CUS.#D=POS
CALL F.READ(FN.CUS,".CUS.#D,R.CUSTOMER,F.CUS,CUS.ERR1)
".MNEMON#C = R.CUSTOMER)E+.CUS.MNEMON#C*
".NAT#ONAL#T" = R.CUSTOMER)E+.CUS.NAT#ONAL#T"*
CUS.DETAILS.ARRAY<-1> = Y.CUS.ID:'*':Y.MNEMONIC:'*':Y.NATIONALITY
REPEAT
RETURN
END

You might also like