|
Special files are a means by which RPG programs can handle file
types that are not native to the language.When any file operation is performed on a file
defined as special', such as open,close, read, write, etc,control is passed to a
named program to perform the operation. The following code is a sample how a special file
might be used to provide non-standard editing functions to show on a display file.
The RPG "F" spec for a Special file looks like the
following:
FSPECIAL O F 20 SPECIAL EDITCL
F KPLIST PLEDIT
|
The file type is SPECIAL and the extension is the name of the
program that will process the file requests, (Open, Close, Read, Write, Update and Delete)
The File Extension spec is used to define the name of the Parameter
List (PLIST) used to call the program. The program parameter list has some required
parameters and you need only specify on the PLIST those parameters that are need over and
above these.
The required parameters are:
Parm. Len. Description
------ ---- -----------------------------------------------------------------
Option A(1) where O=Open, C=Close, R=Read, W=Write, D=Delete and U=Update
Status A(1) where 0=Normal, 1=Input EOF and 2=Error
Error N(5,0) Error number placed in *RECORD of INFDS
Area A(rcd-len) field defined with the same length as record length asspecified on the
"F" spec. |
In the example "F" spec above the record length was 20.
The PLIST definition below uses one extra field the same length as the record length. So
the PLIST would be specified as follows:
C PLEDIT PLIST
C PARM AMTDSP 20
|
The following "C" and "O" specs serve as an
example of how you would write to a special file:
OSPECIAL E EDIT
O AMT J 20
|
The RPG code fragments are part of a program that will return to
the program a character field DSPAMT which is the fully edited representation of the
numeric field AMT.
In this example, RPG is doing most of the work and the Special File
Processing Program EDITCL actually recieves the fully edited amount, therefore the CL
program needs only to copy the input parameter to the return parametr, Viz:
QCLSRC source: EDITCL (Sample Special file handling program)
/* ***************************************************************** */
/* * This program handles I/O to RPG Special Files * */
/* * * */
/* * Author: Trevor D. Seeney, SENTINEX Inc. * */
/* ***************************************************************** */
PGM PARM(&OPTION &STATUS &ERROR &AREA &RETURN)
DCL VAR(&OPTION) TYPE(*CHAR) LEN(1)
DCL VAR(&STATUS) TYPE(*CHAR) LEN(1)
DCL VAR(&ERROR) TYPE(*DEC) LEN(5 0)
DCL VAR(&AREA) TYPE(*CHAR) LEN(20)
DCL VAR(&RETURN) TYPE(*CHAR) LEN(20)
/* * Receive inut buffer * */
CHGVAR VAR(&RETURN) VALUE(&AREA)
RETURN
ENDPGM
|
Although this is a very simple example it does enable a programmer
to bring to the display screen the editing options that are available in printed form.
With a slight modification to the CL program it is possible to change the color of the
displayed amount by testing the sign of the amount and prefixing the return variable with
a display attribute (for example, red for negative and dark blue for positive amounts).
Another good use for this technique is to unpacked numeric data found in character
strings.
I would like to give credit to Steve Ames for
showing me this technique.
The complete RPG program and the CL program that inserts the color
attributes is available on request by E-Mail or FAX.
|