Ü F SPEC
·
F is the alphabetic code used
for File Description specifications.
To prompt F SPEC
given the line command: IPF
Prompt type . . . F Sequence number . . . '''''''
File File End of File
Filename Type Designation File Addition Sequence
________ _ _ _ _ _
File Record Limits Length of Record
Format Length Processing Key Field Address Type
_ ____ _ ____ _
File
Organization Device Keywords
_ ______ __________________________
Comment
_______________
1.
File name: Mention
here name of the file that you are going to use in your program.
2.
File Type: Mention the
file type as I,O,U,C where I= INPUT, O=OUTPUT,U=UPDATE,C=COMBINED.
These are the modes in which we are going to use the file. C is used
for display file.
3.
File Designation:
Mention the File Designation as P,S,F
where P=PRIMARY,S=SECONDARY,F=FULL PROCEDURAL.
Primary File = Record will be processed in the order; from start to end by rpg
program cycle i.e. OPEN, READ, PROCESS, CLOSE. User can't change this order.
There can be only one primary file in the program.
Secondary Files = Secondary files apply to programs that do multifile processing. All
of the files involved in multifile processing, except the primary file, are
secondary files.
Full Procedural file = User can control any order by rpg program opcode. User can change
any order by rpg opcode. With full procedural files the programmer determines
which record or a block of records to be read by way of the value of the key
field used.
4.
File Addition: Mention
‘A’ if you want to add record to the DISK FILE. In update mode of file, use ‘A’
file designation.
5.
File Format: Mention
if the file is program described or externally described.
6.
Record Address Type: Mention this field entry as ‘K’ if the file is a
keyed file, blank if the file is a sequential access file or based on RRN.
7.
Device: Mention the
device as DISK, PRINTER or WORKSTN.
FCZGD02A0 IF E K DISK INCLUDE(CZTD02A2)
F PREFIX(D20:3)
Fcmgq08a0 if e k disk ignore(cmtq08a1:cmtq08a3)
FSSG043A0 IF A E K Disk RENAME(SSH04310:SSH04310A)
Ü F SPEC
continuation line
The prompt used for this is
IPFK in RPG-400
o
In order to refer the named
record format as a subfile record format in the program.
- In
order to rename the record format of a database file in a program.
- In
order to define a named data structure as a file information data
structure.
In RPGLE these keywords are defined in the
keywords option.
Ü F SPEC Keywords
o COMMIT{(rpg_name)}
The COMMIT
keyword allows the processing files under commitment control. By specifying the
optional parameter, you can control at run time whether to enable commitment
control. If the parameter contains a '1', the file will be opened with the
COMMIT indication on, otherwise the file will be opened without COMMIT.
o IGNORE(recformat{:recformat...})
The IGNORE keyword allows a record format from an externally
described file to be ignored. The external name of the record format to be
ignored is specified as the parameter recformat. One or more record formats can
be specified, separated by colons (:).
Example:
FACCLG01 IF E K DISK IGNORE(Rec_format_2: Rec_format_3)
Suppose ACCLG01 has 3 record formats Rec_format_1, Rec_format_2 and Rec_format_3.
Now if we need only Rec_format_1 in our program, then we can IGNORE rest
of the two record formats Rec_format_2 and Rec_format_3.
o INCLUDE(recformat{:recformat...})
The INCLUDE keyword specifies those record format names that are to
be included; all other record formats contained in the file will be ignored.
Example:
FACCLG01 IF E K DISK INCLUDE(Rec_format_1)
Suppose ACCLG01 has 3 record formats Rec_format_1, Rec_format_2 and Rec_format_3.
Now if we need only Rec_format_1 in our program, then we can INCLUDE
this record format and rest of the record formats will be ignored.
o PREFIX(prefix{:nbr_of_char_replaced})
The PREFIX keyword is used to partially rename the fields in an
externally described file. PREFIX(YE:3) would change the field name 'YTDTOTAL' to 'YETOTAL'.
Example:
FACCLG01 UF A E K Disk
F Prefix(A01:3)
FACCLG02 UF A E K Disk
F Prefix(A02:3)
Here above logical files ACCLOG1 and ACCLOG2 both are based on same
physical file and only difference is their key fields. But they do have same
field names. If we are using both file at the same time, we cannot distinguish
the field name of the two. Hence, to overcome this problem we use PREFIX that
partially renames the fields of the file.
Here ACCLG01 file will have its field’s first 3 character replaced
with A01 and ACCLG02 file will have its field’s first 3 character replaced with
A02.
o RENAME(Ext_format:Int_format)
The RENAME keyword allows you to rename record formats in an
externally described file.
Example:
FACCLG01 UF A E K Disk
F Rename(format1:format_xxx)
FACCLG02 UF A E K Disk
F Rename(format1:format_yyy)
Suppose we are using two files ACCLG01
and ACCLG02 both having the same record format name format1, In such a case to distinguish
the two files on the basis of their record format name, we can use the RENAME
keyword to rename the record format of one file to make it different than the
other one.
Here the new record format name for the two file will be format_xxx
and format_yyy.
o SFILE(recformat:rrnfield)
Type
the name of the record format and the field to contain the relative record
number for the entry field to be processed as a subfile. This keyword is valid only for externally
described files.
FSFLMSGDSP CF E WORKSTN SFILE(ACCSFL:RRN)
If we compile the program, we can see in
the compiler report that all the formats related to the subfile will get
included in the program by using subfile.
Compiler report
FSFLMSGDSP CF E WORKSTN SFILE(ACCSFL:RRN)
*---------------------------------------------------------------------
* RPG name External name
* File name. . . . . . . . . : SFLMSGDSP AMIT/SFLMSGDSP
* Record format(s) . . . . . : ACCSFL ACCSFL
* ACCCTL ACCCTL
* MSGSFL MSGSFL
* MSGCTL MSGCTL
*---------------------------------------------------------------------
o
USROPN
Specify this keyword to
indicate that the file must be explicitly opened with the OPEN operation and should be closed with CLOSE operation.
* The printer file is opened in the calculation specifications
FFILE1 O F 132 DISK USROPN
/FREE
// Open the file if it is not already open
if not %open (FILE1);
open FILE1;
endif;
/END-FREE
o EXTMBR('member name') EXTMBR('*ALL')
Using EXTMBR ('member name’), we can use the member that we want to
access of the file mentioned here in F-Spec.
If instead of any member name, we mention EXTMBR ('*ALL'), then all
the members are accessed one by one.
Example: Used in example of INFDS.
o INFDS(data structure name)
FILE INFORMATION DATASTRUCTURE
A file
information data structure (INFDS) can be defined for each file to make file
exception/error and file feedback information available to the program.
Example: Using INFDS & EXTMBR
>>>> To
read all members of a PF
Columns . . . : 1 71 Browse AMIT/QRPGLESRC
SEU==> MBR_READ
FMT FX .....FFilename++IPEASF.....L.....A.Device+.Keywords++++++++++++++++++++
*************** Beginning of data *************************************
0001.00 FCUST IF E DISK EXTMBR('*ALL')
0001.01 F INFDS(FILEDS)
0001.02 *
0001.03 DFILEDS DS
0001.04 DRECORD *RECORD
0001.05 DMEMBER 129 138
0001.06 DDB_RRN 397 400I 0
0001.07 *
0001.08 *
0001.09 DDATA1 DS
0001.10 DFLD1 10
0001.11 DFILLER1 2 INZ('--')
0001.12 DFLD2 10
0001.13 DFILLER2 2 INZ('--')
0001.14 DFLD3 4 0
0001.15 DFILLER3 2 INZ('--')
0001.16 *
0001.17 *
0001.18 DDATA2 DS
0001.19 DFLD4 6
0001.20 DFILLER4 2 INZ('--')
0001.21 DFLD5 10
0001.22 DFILLER5 2 INZ('--')
0001.23 DFLD6 5 0
0001.24 DFILLER6 2 INZ('--')
0001.25 DFLD7 10 0
0001.26 *
0001.27 *
0001.28 *
0002.00 C READ CUST
0003.00 C DOW NOT %EOF(CUST) AND *IN90=*OFF
0003.02 C EVAL FLD1=MEMBER
0003.03 C EVAL FLD2=RECORD
0003.04 C EVAL FLD3=DB_RRN
0003.05 C EVAL FLD4=CSNBR
0003.06 C EVAL FLD5=CSNAME
0003.07 C EVAL FLD6=CS#OPN
0003.08 C EVAL FLD7=CS$OPN
0003.09 C DATA1 DSPLY
0003.10 C DATA2 DSPLY
0003.11 C READ CUST
0004.00 C ENDDO
0005.00 C SETON LR
****************** End of data ****************************************
Work with Members Using PDM SYSTEM09
File . . . . . . CUST
Library . . . . AMIT Position to . . . . .
Type options, press Enter.
3=Copy 4=Delete 5=Display 7=Rename 8=Display description
9=Save 13=Change text 18=Change using DFU 25=Find string ...
Opt Member Date Text
CUST 07/27/12
MBR2 07/23/12
MBR3 07/23/12
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F6=Create
F9=Retrieve F10=Command entry F23=More options F24=More keys
File’s member Data
CUST data
CSNBR CSNAME CS#OPN CS$OPN
000001 000001 AMI 0 .00
000002 000002 upi 0 .00
000003 000003 KUM 0 .00
000004 000004 RAHIN 12,256 454,654.51
000005 000005 HARISH 980 798,789.00
MBR2 data
CSNBR CSNAME CS#OPN CS$OPN
000001 100002 upi 0 .00
000002 100003 KUM 0 .00
MBR3 data
CSNBR CSNAME CS#OPN CS$OPN
100003 KUM 0 .00
Output
Display Program Messages
CUST --CUSTR --0001--
000001--AMI --00000--0000000000
CUST --CUSTR --0002--
000002--upi --00000--0000000000
CUST --CUSTR --0003--
000003--KUM --00000--0000000000
CUST --CUSTR --0004--
000004--RAHIN --12256--0000454654
CUST --CUSTR --0005--
000005--HARISH --00980--0000798789
MBR2 --CUSTR --0001--
100002--upi --00000--0000000000
MBR2 --CUSTR --0002--
100003--KUM --00000--0000000000
MBR3 --CUSTR --0001--
100003--KUM --00000--0000000000
Example 2: INFDS using 369 position of display file to handle
PAGEUP, PAGEDOWN, ENTER KEY…
f MyScreen c f e workstn INFDS (ScnDS)
d ScnDS ds
* Attention Indicator Byte
d PressKey 369 369
d EnterKey c const(x'F1')
d RollUp c const(x'F5')
d RollDown c const(x'F4')
select;
when PressKey = EnterKey; // Enter Key pressed
- - - - - - - - - - // Do programming for Enter Key
when PressKey = RollUp;
- - - - - - - - - - // Do programming for RollUp
when PressKey = RollDown;
- - - - - - - - - - // Do programming for RollDown
Endsl;
Seton lr;
o INFSR(subroutine_name)
FILE ERROR SUBROUTINE
Type the name of the subroutine that will get
control when an exception/error condition occurs.
ü The file error subroutine can only be coded in the main source
section. You cannot code an INFSR for a file that is used in subprocedure.
ü Specifying INFSR (*PSSR) means that you
want the "standard" *PSSR subroutine to handle the file exception
which it would do by default - that's the reason why *PSSR is handling the
exceptions for your files.
ü If you only want exceptions handled for
the specific file then give the subroutine a name other than *PSSR, for example
"FileErrSr" and assign that with INFSR(FileErrSr).
However, you would still get the other file exceptions being handled by *PSSR
(unless you removed it). If you wanted to keep your *PSSR and not have it
handling errors for the other files then create an empty subroutine called
something like "IgnoreFileErr" and assign INFSR(IgnoreFileErr) to those files.
Example:
o OFLIND(indicator)
Indicator value from *INOA to
*INOG or *INOV, is used to
specify the overflow condition for the program
described printer files.
Indicator value from *IN01 to
*IN99 is used to specify the overflow condition for the externally described printer
files.
Example:
Externally described printer file PRINT4
Columns . . . : 1 80 Browse AMIT/QRPGLESRC
SEU==> PRINT4
FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
*************** Beginning of data ***********************************************************
0000.01 A*%%***********************************************************************
0000.02 A*%%TS RD 20 085008 ARUN REL-V5R4M0 5722-WDS
0000.03 A*%%FI+10660100000000000000000000000000000000000000000000000000
0000.04 A*%%FI 0000000000000000000000000000000000000000000000000
0000.05 A*%%***********************************************************************
0000.06 A R RCD001
0000.07 A*%%***********************************************************************
0000.08 A*%%RI 00000
0000.09 A*%%***********************************************************************
0000.10 A 80 2
0000.11 A 'PARTY ACCOUNT INFOR'
0000.12 A UNDERLINE
0000.13 A FLD001 2S 0O +2
0000.14 A EDTCDE(L)
0000.15 A UNDERLINE
0000.16 A*%%***********************************************************************
0000.17 A*%%SS
0000.18 A*%%***********************************************************************
0000.19 A R HEADER
0000.20 A*%%***********************************************************************
0000.21 A*%%RI 00000
0000.22 A*%%FS 001
0000.23 A*%%***********************************************************************
0000.24 A SPACEB(002)
0000.25 A 9
0000.26 A 'ORG'
0000.27 A HIGHLIGHT
0000.28 A +9
0000.29 A 'ACCOUNT NO'
0000.30 A +9
0000.31 A 'CCY'
0000.32 A +9
0000.33 A 'PARTY NO'
0000.34 A*%%***********************************************************************
0000.35 A*%%SS
0000.36 A*%%***********************************************************************
0000.37 A R DETAIL
0000.38 A*%%***********************************************************************
0000.39 A*%%RI 00005
0000.40 A*%%***********************************************************************
0000.41 A SPACEB(001)
0000.42 A ORG R O 9
0000.43 A REFFLD(REC1/ORG AMIT/MASTER)
0000.44 A ACC R O +8
0000.45 A REFFLD(REC1/ACC AMIT/MASTER)
0000.46 A CCY R O +8
0000.47 A REFFLD(REC1/CCY AMIT/MASTER)
0000.48 A PARTY R O +8
0000.49 A REFFLD(REC1/PARTY AMIT/MASTER)
0000.50 A*%%***********************************************************************
0000.51 A*%%SS
0000.52 A*%%SS
0000.53 A*%%SS
0000.54 A*%%SS
0000.55 A*%%SS
0000.56 A*%%SS
0000.57 A*%%***********************************************************************
0000.58 A R FOOTER
0000.59 A*%%***********************************************************************
0000.60 A*%%RI 00000
0000.61 A*%%FS 001
0000.62 A*%%***********************************************************************
0000.63 A SPACEB(002)
0000.64 A 13
0000.65 A 'TOTAL CUSTOMER FOUND = '
0000.66 A TOTAL 2S 0O +0
0000.67 A*%%***********************************************************************
0000.68 A*%%SS
0000.69 A*%%CP+999CRTPRTF
0000.70 A*%%CP+ FILE(AMIT/PRINT4)
0000.71 A*%%CP+ DEVTYPE(*SCS)
0000.72 A*%%CP PAGESIZE(*N 071 *N )
0000.73 A*%%CS+999CRTPRTF
0000.74 A*%%CS+ FILE(QTEMP/QPRDRPT )
0000.75 A*%%CS+ DEVTYPE(*SCS)
0000.76 A*%%CS PAGESIZE(*N 132 *N )
0000.77 A*%%***********************************************************************
****************** End of data ***************************************************
Print
program using OFLIND
Columns . . . : 6 80 Browse AMIT/QRPGLESRC
SEU==> PRINT4PGMC
FMT * *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
*************** Beginning of data *******************************************************
0001.00
0002.00 FMASTER IF E K DISK
0003.00 FPRINT4 O E PRINTER OFLIND(*IN99)
0004.00 C Z-ADD 0 COUNT 2 0
0005.00 C WRITE HEADER
0006.00 C READ REC1 80
0007.00 C *IN80 DOWEQ *OFF
0008.00 C 99 WRITE HEADER
0009.00 C WRITE DETAIL
0010.00 C ADD 1 COUNT
0011.00 C READ REC1 80
0012.00 C IF COUNT=5 >>>> Here overflow condition will occur after 5 are printed.
0013.00 C SETON 99
0014.00 C ELSE
0015.00 C SETOFF 99
0016.00 C ENDIF
0017.00 C ENDDO
0018.00 C MOVEL COUNT TOTAL
0019.00 C WRITE FOOTER
0020.00 C SETON LR
Output
ORG ACCOUNT NO CCY PARTY NO
190 A00000000001 EUR P00000000001
190 A00000000006 USD P00000000006
190 A00000000009 TRY P00000000009
191 A00000000002 USD P00000000002
191 A00000000004 EUR P00000000004
ORG ACCOUNT NO CCY PARTY NO
191 A00000000005 USD P00000000005
191 A00000000007 EUR P00000000007
191 A00000000008 USD P00000000008
TOTAL CUSTOMER FOUND = 08