working with database files in cl procedures
TRANSCRIPT
-
7/21/2019 Working With Database Files in CL Procedures
1/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
DCLF (Declare File) Command Description
DCLF FILE(library-name/file-name)RCDFMT(record-forma-!ame"#
Purpose
The Declare File (DCLF) command declares one file (by name) to a control language (CL)
program !nly one DCLF command is allo"ed in a CL program The command specifies the
name of the file and the record formats to be used in the program #fter the file is declared$ the
program can contain the data manipulation command %C&F for database files that reference the
file This enables the program to interact "ith its user by sending data to and recei'ing data from
a "or station or database file Database files can be used for input processing only
hen the CL program is compiled$ a CL 'ariable is automatically declared for each field in each
record format used in the program If the file is a non-field le'el database file$ the record format
contains one field "ith the name of that record format The field name becomes the 'ariable
name prefi*ed "ith an ampersand (+) The attributes of each declared field are the same as the
attributes of the fields in the file Fields defined in the record format as numeric are defined as
decimal 'ariables #lso$ indicators used in the referenced file are declared as logical 'ariables in
the form +I,nn$ in "hich nn is the indicator number
&ariables automatically declared by the DCLF command can be used in the program the same as
the 'ariables declared by a DCL command For e*ample$ indicators can be used in e*pressions
and IF statements because they are declared as logical 'ariables
The content of the 'ariables$ not the 'ariable names$ are seen by the user the display sho"s one$
some$ or all of the fields in the record format that can be filled in by the user DD. determines
the display format
FROM THE DESK OF N$K$ ELURUPa%e &
-
7/21/2019 Working With Database Files in CL Procedures
2/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
Restrictions:
This command is 'alid only "ithin CL programs #ll declare commands (C!01%I23T$
Declare CL &ariable (DCL) and Declare File (DCLF)) must follo" the 0rogram (024)
command and precede any other command The three types of declare commands can be
placed in any order
5 The file must either be a database file "ith only one record format or be a display file
6 The file cannot be a mi*ed file$ e'en if only display de'ices are defined for that mi*ed
file
7 The database file can be either physical or logical$ and can be either field-le'el or non-field le'el
8 # file must e*ist before the program is created
9ecause CL 'ariables are automatically declared for each field in a referenced file:s record
formats$ the follo"ing restrictions apply;
If the file is changed (and the file description specifies that le'el checing is to be
performed)$ the CL program must be recompiled to match the ne" file description
If any field name is defined in more than one record format of the display file$ the
attributes in each record format for the commonly named field must match
#ny CL 'ariable declared in the program by a DCL command "ith the same name as an
automatically declared CL 'ariable (for a referenced field) must also ha'e the same
attributes specified in DD. for the referenced field
The 'ariables used in the file must ha'e data types supported for CL 'ariables 3o"e'er$
fields defined as paced decimal format$
-
7/21/2019 Working With Database Files in CL Procedures
3/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
positions For 'ariables "ith more than 8 digits$ CL "ill declare a character 'ariable that
is the number of digits$ di'ided by 5$ plus (n/ 5 > ) in length # C0I?6?@ message "ill
be issued stating that the con'ersion has taen place$ "hich can be seen in the program
listing For character 'ariables$ the limit is ==== characters
Examples for DCLF
Example 1: Declaring Fields of All Record Formats as Variales
DCLF FILE(#9LE)
This command specifies that the file named #9LE is used by the CL program to pass data
bet"een the user and the program 9ecause no library "as specified$ the library list is used to
locate the file %CDF4T "as not specified therefore$ all the fields and indicators in all the
record formats are automatically declared as 'ariables$ and data from any field in any record
format (up through the first ==) in the file can be passed bet"een the program and the user ,o
de'ice file routing data is recei'ed by the program
Additional Considerations
File processing is handled differently in CL programs$ depending on "hether the file specified in
the DCLF command is a display file or a database file
The follo"ing statements apply if the file is a database file at compile time;
The file must be a database file "ith a single record format at run time
The program may contain only %C&F commands .,DF$ .,D%C&F$ E,D%C&$ and
#IT commands are not allo"ed
The file is opened for input only
The file is opened by the %C&F command$ not the !0,D9F command
Recei!ing Data from a Dataase File
FROM THE DESK OF N$K$ ELURUPa%e
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c415721402.htm#ToC_179http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c415721402.htm#ToC_179 -
7/21/2019 Working With Database Files in CL Procedures
4/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
The only command you can use to recei'e data from a database file is the %C&F command
hen you run a %C&F command$ the ne*t record on the file:s access path is read$ and the 'alues
of the fields defined in the database record format are placed in the corresponding CL 'ariables
,ote that CL does not support
-
7/21/2019 Working With Database Files in CL Procedures
5/7
-
7/21/2019 Working With Database Files in CL Procedures
6/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
FROM THE DESK OF N$K$ ELURUPa%e 7
-
7/21/2019 Working With Database Files in CL Procedures
7/7
WORKING WITH DATABASE FILES IN CL PROCEDURES
FROM THE DESK OF N$K$ ELURUPa%e 8