Sei sulla pagina 1di 12

Work with File Handling

Day 26
CL Programming:
Overview:
This module enables the student to understand the concept of File Handling in CL.

Outline:
Topics covered,
File Handling
TFCTL
Objective:
!y the end of this module, the student should be able to"
File Handling
TFCTL
# Du$e%tar Technologies &vt. Ltd.
'('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26

File Handling:
T)o types of *les are supported in CL programs, display *les and database *les. +ou can
send data to a )or$station and receive input from the )or$station and receive input from
the )or$station for use in the program, or you can read from a database *le in the
program.
The following statements al! onl! to database "les used with CL rograms:
, CL program may use only database *les )ith a single record format.
The *le may be either a physical of or logical *le, and a logical *le may be de*ned
over multiple physical *le members.
-nly input operations, )ith the C.F command, are allo)ed. The %/DF, %/DC.F
commands are not allo)ed for database *les.
DD% is not re0uired to create a physical *le, )hich is referred to in a CL program.
1f DD% is not used to create a physical *le, the *le has a record format )ith the
same name as the *le, and there is one *eld in the record format )ith the same
name as the *le, and )ith the same length as the record length of the *le
2CDL3/ parameter of the CT&F command4.
The *le need not have a member )hen it is created for the program. 1t must,
ho)ever, have a member )hen the program processes the *le.
The *le is opened for input only )hen the *rst C.F command is processed. The
*le must e5ist and have a member at that time.
The *le remains open until the program returns or )hen the end of *le is reached.
6hen end of *le is reached, message C&F7869 is sent to the CL program, and
additional operations are not allo)ed for the *le. The program should monitor for
this message and ta$e appropriate action )hen end of *le is reached.
The database *le is read in arrival se0uence.
6e can )rite a 0uery on database *le in CL &rogram using command -&/:+F.
The following statements al! onl! to disla! "les used with CL rograms:
Display *les may have up to ;; record formats.
,ll data manipulation commands 2%/DF, %/DC.F, C.F4 are allo)ed for display
*les.
The display *le must be de*ned )ith the DD%.
The display *le is opened for both input and output )hen the *rst %/DF,
%/DC.F, or C.F command is processed. The *le remains open until the
program returns.
/ote" The open does not occur for both types of *les until the *rst send or receive
occurs.
Oening and Closing Files in a CL Procedure
6hen you use CL support, you can refer to only one *le in a program. The *le referred to
is implicitly opened )hen you do your *rst send, receive, or send(receive operation. ,n
opened display *le remains open until the program in )hich it )as opened returns or
transfers control. ,n opened database *le is closed )hen end of *le is reached, or )hen
the program in )hich it )as opened returns or transfers control. -nce a database *le has
been closed, it cannot be opened again during the same call of program.
6hen a display *le is opened in a CL programs, it is al)ays opened for both input and
output. 6hen a database *le is opened in a CL program, it is opened for input only.
#eferring to Files in a CL Procedure
Files are accessed during compiling of DCLF commands )hen CL program is created. 1f
you have 0uali*ed the name of the *le at compile time, the *le must be in a library at
# Du$e%tar Technologies &vt. Ltd.
2('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
run time. 1f you have used the library list at compile time, the *le must be in a library on
the library list at run time.
$eclaring a File
The Declare File 2DCLF4 command is used to declare a display or database *le to your CL
procedure or program. The DCLF command cannot be used to declare *les such as tape,
dis$ette, printer, and mi5ed *les. -nly one DCLF command id allo)ed in a CL program.
The $CLF command has the following arameters:
o DCLF F1L3 2library<name(*le<name4
o CDF=T 2record<format<names4
/ote that the *le must e5ist before the program is compiled. 1f you are using a *le in
your program you may have to specify input(output *elds in your DD%. These *elds are
handled as variables in the program. 6hen a DCLF command is used, the CL compiler
declares CL variables for each *eld and option indicator in each record format in the *le.
For a *eld, the CL variable name is the indicator preceded by > 1/.
For e5ample, if a *eld named 1/&?T and indicator '7 are de*ned in DD%, the DCLF
command automatically declares them as >1/&?T and >1/ '7. This declaration is
performed )hen the CL module or program is compiled. ?p to @7 record format names
can be speci*ed on one command, !ut none can be variables. -nly one record format
may be speci*ed for a database *le.
1f the follo)ing DD% )ere used to create display *le C/TLD%& in library =CA,//"
Three variables viB. >1/7', >T3CT and >3%&-/%3 )ould be available from the display
*le. 1n a CL procedure referring to this display *le, you )ould enter only the DCLF source
statement"
$CLF P%&'(&')*CLP'
The compiler )ill e5pand this statement to individually declare all display *le variables.
The e5panded declaration in the compiler list loo$s li$e"
)ending and #eceiving $ata with a $isla! File
The only commands you can use )ith a display *le to send or receive data in CL
programs are the %/DF, C.F and %/DC.F commands.
6hen you run an %/DF command the content of the variables associated )ith the output
or out(input *elds in the record format you specify is formatted by system and sent to
the display device. %imilarly, )hen you run an C.F command, the values of the *elds
associated )ith input or output (input *elds in the record format on the display are
placed in the corresponding CL variables.
The %/DC.F command sends the contents of the CL variables to the display and then
performs the e0uivalent of an C.F command to obtain the updated *elds from the
display.
Lab )ession:
1n follo)ing e5ample )e )ill see ho) to use )or$station *le in CL program. This is simple
calculation program"
Follo)ing is the DD% )here )e use calculations"
# Du$e%tar Technologies &vt. Ltd.
D('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Columns . . . : 1 71 Edit PB01U01D/MYDDS
SEU==> DSPCAL
*************** Beinnin o! d"t" *************************************
0000.10 A*##$S SD %00&0'1% 170110 PB01U01 (EL)*&(%M0 &7%%)+DS
0000.%0 A*##EC
0000.'0 A DSPS,-.%/ 00 *DS'1
0000./0 A ( (EC1
0000.&0 A*##$S SD %00&0'1% 170110 PB01U01 (EL)*&(%M0 &7%%)+DS
0000.20 A C30'.0' 4e5it41
0000.70 A C30/.0/ 46"t41
0000.00 A C30&.0&1
0000.70 A C302.021
0001.00 A ' %&4CA$ 89:"te:s4
0001.10 A 7 1/43i:st ;o :4
0001.%0 A 10 1/4Se6ond ;o :4
0001.'0 A 1' 1/4(esult :4
0001./0 A 17 1&43':E5it4
0001.&0 A 3;8 &S 0B 7 '0
0001.20 A S;8 &S 0B 10 '0
0001.70 A (ES 7S 0B 1' '0
0001.00 A 0 /'4896 :4
0001.70 A 8P$ 1A B 0 &0
****************** End o! d"t" ****************************************

/o) 1n CL program ho) to declare *le using DCLF as discussed above<
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> CALC,
*************** Beinnin o! d"t" *************************************
0001.00 /*P(8<(AM : SE$MYL,BL*/
000%.00 P<M
000%.01 /* DECLA(E $=E +8(>S$A$,8; 3,LE */
4444444 DCL3
****************** End o! d"t" ****************************************

















&ress F9 ,/D )rite Filename, Library name, ecord format name as given belo),
# Du$e%tar Technologies &vt. Ltd.
9('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
&ress
F9
Work with File Handling
Day 26
De6l":e 3ile .DCL31

$?9e 6@oi6esA 9:ess Ente:.

L"Bel . . . . . . . . . . . . .
3ile . . . . . . . . . . . . . . DSPCAL ;"me
LiB:":? . . . . . . . . . . . PB01U018 ;"meA *L,BLA *CU(L,B
(e6o:d !o:m"t . . . . . . . . . (EC1 ;"meA *ALL
C !o: mo:e D"lues
AlloE D":i"Ble lent@ !ields . . *;8 *;8A *YES
AlloE !ield D"lue o! null . . . *;8 *;8A *YES
AlloE :"9@i6 !ields . . . . . . *;8 *;8A *YES
Comment . . . . . . . . . . . .







Bottom
3'=E5it 3/=P:om9t 3&=(e!:es@ 31%=C"n6el 31'==oE to use t@is dis9l"?
3%/=Mo:e Fe?s

&ress enter,
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> CALC,
*************** Beinnin o! d"t" *************************************
0001.00 /*P(8<(AM : SE$MYL,BL*/
000%.00 P<M
000%.01 /* DECLA(E $=E +8(>S$A$,8; 3,LE */
000'.00 DCL3 3,LE.PB01U018/DSPCAL1 (CD3M$.(EC11
4444444
****************** End o! d"t" ****************************************
















# Du$e%tar Technologies &vt. Ltd.
@('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> CALC,
*************** Beinnin o! d"t" *************************************
0001.00 /*P(8<(AM : SE$MYL,BL*/
000%.00 P<M
000%.01 /* DECLA(E $=E +8(>S$A$,8; 3,LE */
000'.00 DCL3 3,LE.PB01U018/DSPCAL1 (CD3M$.(EC11
000/.00 /* EGECU$E $=E (EC8(D 38(MA$ 83 D,SPLAY SC(EE; */
4444444 S;D(C*3M$
****************** End o! d"t" ****************************************














&ress F9 and enter the 3C-D format name
Send/(e6eiDe 3ile .S;D(C*31

$?9e 6@oi6esA 9:ess Ente:.

L"Bel . . . . . . . . . . . . . A
Dis9l"? deDi6e . . . . . . . . . *3,LE ;"meA *3,LE
(e6o:d !o:m"t . . . . . . . . . REC1 ;"meA *3,LE
+"it . . . . . . . . . . . . . . *YES *YESA *;8
Comment . . . . . . . . . . . .











Bottom
3'=E5it 3/=P:om9t 3&=(e!:es@ 31%=C"n6el 31'==oE to use t@is dis9l"?
3%/=Mo:e Fe?s

Hit enter,
# Du$e%tar Technologies &vt. Ltd.
6('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
&ress
F9
Work with File Handling
Day 26
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> CALC,
*************** Beinnin o! d"t" *************************************
0001.00 /*P(8<(AM : CALC, */
000%.00 P<M
000%.01 /* DECLA(E $=E +8(>S$A$,8; 3,LE */
000'.00 DCL3 3,LE.PB01U018/DSPCAL1 (CD3M$.(EC11
000/.00 /* EGECU$E $=E (EC8(D 38(MA$ 83 D,SPLAY SC(EE; */
000&.00 A: S;D(C*3 (CD3M$.(EC11
****************** End o! d"t" ****************************************














,nd do the follo)ing coding as sho)n belo)"
# Du$e%tar Technologies &vt. Ltd.
E('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> CALC,
*************** Beinnin o! d"t" *************************************
0001.00 /*P(8<(AM : CALC,*/
000%.00 P<M
000%.01 /* DECLA(E $=E +8(>S$A$,8; 3,LE */
000'.00 DCL3 3,LE.PB01U018/DSPCAL1 (CD3M$.(EC11
000/.00 /* EGECU$E $=E (EC8(D 38(MA$ 83 D,SPLAY SC(EE; */
000&.00 A: S;D(C*3 (CD3M$.(EC11
0002.00 ,3 C8;D.H,;0' = 4141 $=E;.<8$8 CMDLBL.B11
0007.00 ELSE CMD.,3 C8;D.H8P$ = 4C41 $=E;.C=<*A( C
0000.00 *A(.H(ES1 *ALUE.H3;8 C HS;8111
0007.00 ELSE CMD.,3 C8;D.H8P$ = 4)41 $=E;.C=<*A( C
0010.00 *A(.H(ES1 *ALUE.H3;8 ) HS;8111
0011.00 ELSE CMD.,3 C8;D.H8P$ = 4*41 $=E;.C=<*A( C
001%.00 *A(.H(ES1 *ALUE.H3;8 * HS;8111
001'.00 ELSE CMD.,3 C8;D.H8P$ = 4/41 $=E;.C=<*A( C
001/.00 *A(.H(ES1 *ALUE.H3;8 / HS;8111
001&.01 ELSE CMD.C=<*A( *A(.H(ES1 *ALUE.011
0012.00 <8$8 CMDLBL.A1
0017.00 B: E;DP<M
****************** End o! d"t" ****************************************




1n this )ay *le handling is done in CL. -nly one *le can be handle at a time either
)or$station *le or database *e.
Transfer Control:
The Transfer Control 2TFCTL4 command calls the program speci*ed on the command,
passes control to it, and removes the transferring program from the call stac$. educing
the number of programs on the call stac$ can have a performance bene*t. 6hen a C+LL
command is used, the program called returns control to the program containing the
C+LL command. 6hen a TF#CTL command is used, control returns to the *rst program
in the call stac$. The *rst program then initiates the ne5t se0uential instruction follo)ing
the C,LL command. The TFCTL command is not valid in 1L3 CL" procedures. The
TF#CTL command can be used to pass parameters to the program being called in the
same )ay the C+LL command passes parameters, but )ith these restrictions"
o The parameters passed must be CL variables.
o The CL variables passed by the transferring program must have been
received as parameters by that program.
o This command is valid only )ithin -&= CL programs.
Following e,amle contains the transfer control e,amle-
%teps '" This step contain TF' )here )e call TF2 and chec$s the control of program"
# Du$e%tar Technologies &vt. Ltd.
8('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> $3(%
*************** Beinnin o! d"t" *************************************
0001.00 P<M
000%.00 DCL *A(.HC,$Y1 $YPE.*C=A(1 LE;.101 *ALUE.MUMBA,1
000'.00 S;DUS(MS< MS<.4oBIe6t e5ist)))))41
000/.00 CALL P<M.PB01U01S/ $3(%1 PA(M.HC,$Y1
000&.00 S;DUS(MS< MS<.46ont:ol B"6F)))) 4 *6"t .HC,$Y11
0002.00 E;DP<M
****************** End o! d"t" ****************************************













CALL & RETURN Commands:
+ou can use the C,LL and 3T?/ commands to pass control bac$ and forth bet)een
programs. 1nformation may be passed to called programs as parameters )hen control is
passed. The C,LL command calls a program named on the command, and passes control
to it. 6hen the called program *nishes running, control returns to the ne5t command in
the calling program. The se0uence of C,LL commands in a set of programs calling each
other is the call stac$. , ma5imum of 97 parameters can be passed to the called
program.
!ecause parameters are passed by position, not name , the position of the value passed
in the C,LL command must be the same as its position on the receiving &A= command.
1n addition to the position of the parameters, +ou must pay careful attention to their
length and type, &arameters listed in the receiving procedure of program must be
declared as the same length and type as they are in the calling procedure or program.
eferring to locally de*ned variables incurs fe)er overheads than referring to passed
variables. Therefore, if the called procedure or program fre0uently refers to passed
variables and referring to the locally de*ned value rather than the passed value. The
names of the variables passed do not have to be same as the names on the receiving
parameter list. The names of the variables receiving the values in the called program
must be declared to the called program, but the order of the declare commands is not
important. 6hen a variable is passed, the called program can change the value of the
variable, and the change is reFected in the calling program. The ne) value does not
have to be returned to the calling program. The ne) value does not have to be returned
to the calling program for later useG it is already there. Thus no special coding is needed
for a variable that is to be returned to the calling program.
&arameters can be passed and received as follo)s"
Character string constants of D2 bytes or less are al)ays passed )ith a length of
D2 bytes 2padded on the right )ith blan$s4. 1f a character constant is longer than
D2 bytes, the entire length of the constant is passed.
Decimal constants are al)ays passed in a pac$ed form )ith a length of '@ )ith @
decimal places.
# Du$e%tar Technologies &vt. Ltd.
;('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Logical constants are passed )ith a length of D2 bytes. The logical value 7 or ' is in the
*rst byte, and the remaining bytes are blan$.
# Du$e%tar Technologies &vt. Ltd.
'7('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
%tep 2" )e )ill transfer control in to third program TFD
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> $3(%
*************** Beinnin o! d"t" *************************************
0001.00 P<M PA(M.HP(M11
000%.00 DCL *A(.HP(M11 $YPE.*C=A(1 LE;.101
000'.00 DCL *A(.H*A(11 $YPE.*C=A(1 LE;.101 *ALUE.PU;E1
000/.00 S;DUS(MS< MS<.46ont:ol in se6ond 9:o:"mJJJJJ4 *6"t HP(M11
000&.00 C=<*A( *A(.HP(M11 *ALUE.H*A(11
0002.00 $3(C$L P<M.PB01U01S/ $3('1 PA(M.HP(M11
0007.00 E;DP<M
****************** End o! d"t" ****************************************












%tep D"
Columns . . . : 1 71 Edit PB01U01S/MYCLP
SEU==> $3('
*************** Beinnin o! d"t" *************************************
0001.00 P<M PA(M.HP(M11
000%.00 DCL *A(.HP(M11 $YPE.*C=A(1 LE;.101
000'.00 DCL *A(.H*A(11 $YPE.*C=A(1 LE;.101 *ALUE.PU;E11
000/.00 S;DUS(MS< MS<.46ont:ol in $=,(D 9:o:"mJJJJJ4 *6"t HP(M11
0002.00 C=<*A( HP(M1 H*A(1
0007.00 (E$U(;
0000.00 E;DP<M
****************** End o! d"t" ****************************************













Compile above program see the output call TF' )hich call the program TF2 and TF2
sends the control 1n third program TFD. The output of above program is given belo)
)hich sho)s you ho) the control moves bet)een programs.
# Du$e%tar Technologies &vt. Ltd.
''('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.
Work with File Handling
Day 26
Dis9l"? P:o:"m Mess"es

KoB 0070/1/PB01U0'/ABC st":ted on 0//0//0& "t 10://:'7 in suBs?stem L,;$E( i
control in second program_____MUMBAI
*;
control in THIRD program_____PUNE
*;
control bac!!!! PUNE1










$?9e :e9l?A 9:ess Ente:.
(e9l? . . .


3'=E5it 31%=C"n6el

# Du$e%tar Technologies &vt. Ltd.
'2('2
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies
Pvt. Ltd.

Potrebbero piacerti anche