Examples for OPNFCLF
Example 1: Opening a Keyed Database File
OpnFCLF FileID(VC2EMP) Usage(*Both) AccMth(*Key)
This example opens the file VC2EMP for both input and output operations. When reading from the file keys may be used for both random and sequential access.
By default LVLCHK is *YES. As the FILEDEFN parameter has not been specified (but is required for LVLCHK(*YES), this OPNFCLF command must be in CL source program that will be processed by a CLF precompiler. The precompiler will add the appropriate FILEDEFN parameter.
Example 2: Opening a File as Externally Described
/***********************************************/
/* This program takes one (required) */
/* parameter, the name of a member within the */
/* QCLSRC source file. */
/* */
/* The program will list the contents of the */
/* specified source member. Call this example */
/* from the command line in order to see the */
/* listing. */
/***********************************************/
Pgm Parm(&Member)
Dcl Var(&Member) Type(*Char) Len(10)
/***********************************************/
/* Declare our variables: */
/* The DCLFCLF will provide the external */
/* definition for QCLSRC */
/* The DCLINDCLF will provide the indicator */
/* to detect End of File (&EOF) */
/***********************************************/
DclFCLF FileID(QCLSRC)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Test to see if the &MEMBER parameter was */
/* passed (only needed for bound programs). */
/* If not, end with an error message. */
/***********************************************/
ChgVar Var(&Member) Value(&Member)
MonMsg MsgID(MCH3601) Exec(Do)
RmvMsg Clear(*All)
SndPgmMsg Msg( +
'Member name is a required parameter')
Return
EndDo
/***********************************************/
/* Open the file, this time with (by default) */
/* LVLCHK. */
/* */
/* Read the first record of the specified */
/* member. */
/* */
/* Enter a DoWhile loop conditioned by End of */
/* File (&EOF). So long as EOF is not */
/* detected: */
/* 1. Send the line of source read to the */
/* default (*PRV) call message queue */
/* 2. Read the next QCLSRC record and loop */
/***********************************************/
OpnFCLF FileID(QCLSRC) Mbr(&Member)
ReadRcdCLF FileID(QCLSRC) EOF(&EOF)
DoWhile Cond(*Not &EOF)
SndPgmMsg Msg(&SrcDta)
ReadRcdCLF FileID(QCLSRC) EOF(&EOF)
EndDo
/***********************************************/
/* When End of File is detected close the file */
/* and return. */
/***********************************************/
CloFCLF FileID(QCLSRC)
EndPgm
The source for this example can be found in member DEV_OPNF of source file VC2CLSRC in library VC2CLF.
To compile DEV_OPNF you use the CLF precompiler command Create Bound CLF Program (CRTBNDCLF) or Create CLF Program (CRTCLFPGM). To run the program you can use any of the following commands
Call Pgm(DEV_OPNF) Parm(DEV_OPNF) - list member DEV_OPNF
Call Pgm(DEV_OPNF) Parm(*First) - list the first member
Call Pgm(DEV_OPNF) Parm(*All) - list all members
Example 3: Opening a File as Program Described
/***********************************************/
/* This program takes one (required) */
/* parameter, the name of a member within the */
/* QCLSRC source file. */
/* */
/* The program will list the contents of the */
/* specified source member. Call this example */
/* from the command line in order to see the */
/* listing. */
/***********************************************/
Pgm Parm(&Member)
Dcl Var(&Member) Type(*Char) Len(10)
/***********************************************/
/* Declare our variables: */
/* &RCDDTA is a record from QCLSRC. QCLSRC */
/* should have been created with */
/* RCDLEN(92) */
/* &SRCDTA will hold the source data portion */
/* of a QCLSRC record */
/* &EOF is an indicator used to detect */
/* End of File for QCLSRC. This */
/* could have been defined with */
/* GENINDCLF. */
/***********************************************/
Dcl Var(&RcdDta) Type(*Char) Len(92)
Dcl Var(&SrcDta) Type(*Char) Len(80)
Dcl Var(&EOF) Type(*Lgl)
/***********************************************/
/* Test to see if the &MEMBER parameter was */
/* passed (only needed for bound programs). */
/* If not, end with an error message. */
/***********************************************/
ChgVar Var(&Member) Value(&Member)
MonMsg MsgID(MCH3601) Exec(Do)
RmvMsg Clear(*All)
SndPgmMsg Msg( +
'Member name is a required parameter')
Return
EndDo
/***********************************************/
/* Open the file without LVLCHK and with our */
/* own buffer. */
/* */
/* Read the first record of the specified */
/* member. */
/* */
/* Enter a DoWhile loop conditioned by End of */
/* File (&EOF). So long as EOF is not */
/* detected: */
/* 1. Send the line of source read to the */
/* default (*PRV) call message queue */
/* 2. Read the next QCLSRC record and loop */
/***********************************************/
OpnFCLF FileID(QCLSRC) Mbr(&Member) LvlChk(*No)
ReadRcdCLF FileID(QCLSRC) EOF(&EOF) RcdBuf(&RcdDta)
DoWhile Cond(*Not &EOF)
ChgVar Var(&SrcDta) +
Value(%sst(&RcdDta 13 80))
SndPgmMsg Msg(&SrcDta)
ReadRcdCLF FileID(QCLSRC) EOF(&EOF) +
RcdBuf(&RcdDta)
EndDo
/***********************************************/
/* When End of File is detected close the file */
/* and return. */
/***********************************************/
CloFCLF FileID(QCLSRC)
EndPgm
The source for the example can be found in member BAS_OPNF of source file VC2CLSRC in library VC2CLF.
To compile BAS_OPNF you can use the IBM provided commands CRTBNDCL or CRTCLPGM (in addition to the CLF precompiler commands). The precompiler is not necessary as the program is only using CLF runtime support.
To compile BAS_OPNF into QTEMP you can use the command
CrtBndCL Pgm(QTEMP/BAS_OPNF) SrcFile(VC2CLF/VC2CLSRC)
To run the program you can use any of the following commands
Call Pgm(BAS_OPNF) Parm(BAS_OPNF) - list member BAS_OPNF
Call Pgm(BAS_OPNF) Parm(*First) - list the first member
Call Pgm(BAS_OPNF) Parm(*All) - list all members
Example 4: Opening Database and Display Files with External Definitions
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP, */
/* display file VC2EMPDSP1, and indicators */
/* associated with CLF Input/Output commands */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclFCLF FileID(VC2EMPDSP1)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Declare the packed decimal field &RcdCnt */
/* that will be used to determine the current */
/* record count. If the file is empty */
/* (&RCDCNT = 0), prompt with how to load the */
/* VC2DPT file with sample data. */
/***********************************************/
Dcl Var(&RcdCnt) Type(*Dec) Len(10 0)
/***********************************************/
/* Open VC2EMP and verify that records have */
/* been loaded into the file. If not, tell */
/* the user how to load records. */
/***********************************************/
OpnFCLF FileID(VC2EMP) Usage(*Both) AccMth(*Key)
RtvFInfCLF FileID(VC2EMP) NbrRcds(&RcdCnt)
If Cond(&RcdCnt = 0) Then(Do)
OpnFCLF FileID(VC2FEMPTY) Usage(*Both) +
LvlChk(*No)
WrtReadCLF FileID(VC2FEMPTY) RcdFmt(EmpEmp)
CloFCLF FileID(VC2FEMPTY)
CloFCLF FileID(VC2EMP)
Return
EndDo
/***********************************************/
/* Having verified that records exist now open */
/* the display file for this program. */
/***********************************************/
OpnFCLF FileID(VC2EMPDSP1) Usage(*Both)
/***********************************************/
/* Enter a DOWHILE loop that is exited when */
/* command key 3 is pressed. */
/* */
/* Within the loop: */
/* 1 Write and read the VC2EMPDSP1 *DSPF */
/* record format PROMPT. PROMPT asks for */
/* employee number. A valid employee */
/* number would be 00001. The user can */
/* press ENTER or command key 3. */
/* 2 If command key 3 was pressed leave the */
/* DoWhile loop */
/* 3 Read the employee record for the */
/* employee number entered. */
/* 4 If no record is found (&RNF is '1') a */
/* message is displayed based on &IN50 */
/* 5 If a record is found record format CHANGE */
/* is written and read. */
/* CHANGE allows the user to maintain */
/* employee information (ENTER), delete the */
/* employee (F23), return to PROMPT without */
/* updating the employee record (F12), or */
/* exit the application (F3). */
/* 6 The user is then returned to the PROMPT */
/* display to enter the next employee */
/* number */
/***********************************************/
DoWhile Cond(*Not &IN03)
WrtReadCLF RcdFmt(PROMPT)
If Cond(&IN03) Then(Leave)
ReadRcdCLF FileID(VC2EMP) TYPE(*Key) +
RcdNotFnd(&RNF) KeyRel(*EQ) +
KeyList(&EmpNbr)
If Cond(&RNF) Then(Do)
ChgVar Var(&IN50) Value('1')
Iterate
EndDo
WrtReadCLF RcdFmt(CHANGE)
Select
When Cond(&IN03) Then(Leave)
When Cond(&IN12) Then(Do)
RlsRcdCLF VC2EMP
Iterate
EndDo
When Cond(&IN23) Then(DltRcdCLF VC2EMP)
OtherWise Cmd(UpdRcdCLF FileID(VC2EMP))
EndSelect
EndDo
/***********************************************/
/* When F3 is used to exit the DoWhile loop */
/* close the files and return */
/***********************************************/
CloFCLF FileID(VC2EMP)
CloFCLF FileID(VC2EMPDSP1)
EndPgm
This example opens the VC2EMP physical file for file maintenance. As the program allows a user to view, update, and delete records in the VC2EMP database the database file is opened for keyed IO and both read and write.
DEV_EMPU1, when initially called, verifies that there are records in the VC2EMP file. If not, the program displays a prompt to inform the caller that records need to be loaded prior to running the program. The display file used for this prompt, VC2FEMPTY, is not declared within the program using the DCLFCLF command. Because DCLFCLF was not used the developer needs to supply both the FILEID and the RCDFMT keywords when using the WRTREADCLF command with the record format EMPEMP. The developer does not have to specify both keywords when using the WRTREADCLF command with record formats of the VC2EMPDSP1 display file. In the case of VC2EMPDSP1 the developer used the DCLFCLF command and the precompiler is able to determine the FILEID to use based on only the RCDFMT keyword being provided by the developer.
The source for the example can be found in member DEV_EMPU1 of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF. The source for display file VC2EMPDSP1 can be found in member VC2EMPDSP1 of source file QDDSSRC in library VC2CLF. The source for display file VC2FEMPTY can be found in member VC2FEMPTY of source file QDDSSRC in library VC2CLF.
All objects referenced by DEV_EMPU1 should currently exist in library VC2CLF. To compile example DEV_EMPU1 into QTEMP you can use the commands
AddLibLE Lib(VC2CLF)
CrtBndCLF Pgm(QTEMP/DEV_EMPU1) SrcFile(VC2CLSRC)
To test the program you can use the command
Call Pgm(QTEMP/DEV_EMPU1)
From the prompt screen you can enter an employee number such as 52. After using the ENTER key you should see the details of employee 52's VC2EMP record. From this screen you can use command key 23 to delete the record, ENTER to update the record with any changes you may have keyed in, command key 12 to exit the screen without updating the record, and command key 3 to exit the program.
Example 5: Opening a Display File with a Separate Indicator Area
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP, */
/* display file VC2EMPDSP2 that is defined */
/* with INDARA specified, and indicators */
/* for both a separate indicator area and for */
/* CLF I/O related commands */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclFCLF FileID(VC2EMPDSP2)
DclIndCLF CLFInd(*Yes) IndAra(*Yes)
/***********************************************/
/* Open the two files. */
/* */
/* VC2EMPDSP2 is opened with a SEPINDARA(*YES) */
/***********************************************/
OpnFCLF FileID(VC2EMP) Usage(*Both) AccMth(*Key)
OpnFCLF FileID(VC2EMPDSP2) Usage(*Both) +
SepIndAra(*Yes)
/***********************************************/
/* Enter a DOWHILE loop that is exited when */
/* command key 3 is pressed. */
/* */
/* Within the loop: */
/* 1 Write and read the VC2EMPDSP2 *DSPF */
/* record format PROMPT. PROMPT asks for */
/* employee number. A valid employee */
/* number would be 00001. The user can */
/* press ENTER or command key 3. */
/* 2 If command key 3 was pressed leave the */
/* DoWhile loop */
/* 3 Read the employee record for the */
/* employee number entered. */
/* 4 If no record is found (&RNF is '1') a */
/* message is displayed based on &IN50 */
/* 5 If a record is found record format CHANGE */
/* is written and read. */
/* CHANGE allows the user to maintain */
/* employee information (ENTER), delete the */
/* employee (F23), return to PROMPT without */
/* updating the employee record (F12), or */
/* exit the application (F3). */
/* 6 The user is then returned to the PROMPT */
/* display to enter the next employee */
/* number */
/***********************************************/
DoWhile Cond(*Not &IN03)
WrtReadCLF RcdFmt(Prompt)
If Cond(&IN03) Then(Leave)
ReadRcdCLF FileID(VC2EMP) Type(*Key) +
RcdNotFnd(&RNF) KeyRel(*EQ) +
KeyList(&EmpNbr)
If Cond(&RNF) Then(Do)
ChgVar Var(&IN50) Value('1')
Iterate
EndDo
WrtReadCLF RcdFmt(Change)
Select
When Cond(&IN03) Then(Leave)
When Cond(&IN12) Then(Do)
RlsRcdCLF VC2EMP
Iterate
EndDo
When Cond(&IN23) Then(DltRcdCLF VC2EMP)
OtherWise Cmd(UpdRcdCLF FileID(VC2EMP))
EndSelect
EndDo
/***********************************************/
/* When F3 is used to exit the DoWhile loop */
/* close the files and return */
/***********************************************/
CloFCLF FileID(VC2EMP)
CloFCLF FileID(VC2EMPDSP2)
EndPgm
This example demonstrates the use of a separate indicator area when using a display file. The only significant changes from the DEV_EMPU1 sample program are:
- changing the display file from VC2EMPDSP1 to VC2EMPDSP2
- adding INDARA(*YES) to the DCLINDCLF command
- adding SEPINDARA(*YES) to the OPNFCLF command for display file VC2EMPDSP2
The source for the example can be found in member DEV_EMPUS of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF. The source for display file VC2EMPDSP2 can be found in member VC2EMPDSP2 of source file QDDSSRC in library VC2CLF.
The display file DC2EMPDSP2 should currently exist in library VC2CLF. To compile example DEV_EMPUS into QTEMP you can use the commands
AddLibLE Lib(VC2CLF)
CrtBndCLF Pgm(QTEMP/DEV_EMPUS) SrcFile(VC2CLSRC)
To test the program you can use the command
Call Pgm(QTEMP/DEV_EMPUS)
From the prompt screen you can enter an employee number such as 52. After using the ENTER key you should see the details of employee 52's VC2EMP record. From this screen you can use command key 23 to delete the record, ENTER to update the record with any changes you may have keyed in, command key 12 to exit the screen without updating the record, and command key 3 to exit the program.
Example 6: Opening Database and Printer Files with External Definitions
Pgm
/***********************************************/
/* This program creates a printed report */
/* listing employees in key sequence using */
/* the VC2EMPDPT access path (Dept/First name) */
/***********************************************/
/***********************************************/
/* Declare two working variables: */
/* &CURLIN - the current line number printed */
/* &PAGOVR - the overflow line number for a */
/* page */
/***********************************************/
Dcl Var(&CurLin) Type(*Dec) Len(3 0)
Dcl Var(&PagOvr) Type(*Dec) Len(3 0)
/***********************************************/
/* Declare our files and indicators */
/* VC2EMPDPT - Employees by department */
/* VC2POSPRT - External printer file */
/* CLF Indicators - &EOF used in program */
/***********************************************/
DclFCLF FileID(VC2EMPDPT)
DclFCLF FileID(VC2POSPRT)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Open the files */
/***********************************************/
OpnFCLF FileID(VC2EMPDPT) AccMth(*Key)
OpnFCLF FileID(VC2POSPRT) Usage(*Output)
/***********************************************/
/* Retrieve the page overflow line number */
/***********************************************/
RtvFInfCLF FileID(VC2POSPRT) PrtFOvrFlw(&PagOvr)
/***********************************************/
/* Write titles for report on first page */
/***********************************************/
WrtRcdCLF RcdFmt(HEADING)
/***********************************************/
/* Read the first record from VC2EMPDPT */
/***********************************************/
ReadRcdCLF FileID(VC2EMPDPT) EOF(&EOF)
DoWhile Cond(*Not &EOF)
/**********************************************/
/* While we have not reached End of File */
/* on VC2EMPDPT: */
/* 1 Retrieve the current print line number */
/* 2 If the current print line number is */
/* greater than or equal to the overflow */
/* line number then start a new page and */
/* re-write titles on the page */
/* 3 Write the detail employee print line */
/* 4 Read the next employee record */
/* 5 Continue in this loop until End of File */
/**********************************************/
RtvFInfCLF FileID(VC2POSPRT) CurPrtLine(&CurLin)
If Cond(&CurLin *GE &PagOvr) Then( +
WrtRcdCLF RcdFmt(HEADING))
WrtRcdCLF RcdFmt(DETAILS)
ReadRcdCLF FileID(VC2EMPDPT) EOF(&EOF)
EndDo
/***********************************************/
/* At End of File close the files and return */
/***********************************************/
CloFCLF VC2EMPDPT
CloFCLF VC2POSPRT
EndPgm
The example program opens the VC2EMPDPT logical file and creates a report using the external printer file VC2POSPRT. The report lists all employees in the CLF provided sample database. The VC2EMPDPT logical file is keyed by employee first name within department.
The source for the example can be found in member DEV_POSPRT of source file VC2CLSRC in library VC2CLF. The source for logical file VC2EMPDPT can be found in member VC2EMPDPT of source file QDDSSRC in library VC2CLF. The source for printer file VC2POSPRT can be found in member VC2POSPRT of source file QDDSSRC in library VC2CLF.
The logical file VC2EMPDPT and printer file VC2POSPRT should currently exist in library VC2CLF. To compile the DEV_POSPRT program into QTEMP you can use the commands
AddLibLE Lib(VC2CLF)
CrtBndCLF Pgm(QTEMP/DEV_POSPRT) SrcFile(VC2CLSRC)
To run the program you can call it using the command
Call Pgm(QTEMP/DEV_POSPRT)
Example 7: Opening a Database File Under Commitment Control
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP and */
/* indicators used with CLF I/O Commands */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Declare &ANSWER variable. This is used to */
/* control whether program commits or rolls */
/* back database changes */
/***********************************************/
Dcl Var(&Answer) Type(*Char) Len(1)
/***********************************************/
/* Setup logic that would not typically be */
/* in an application program. For */
/* 1 End journaling of VC2EMP if it is active */
/* (it should not be) */
/* 2 Delete journal CLFJRN in VC2CLF if it */
/* exists (it should not) */
/* 3 Delete journal receiver CLFJRNRCV in */
/* VC2CLF if it exists (it should not) */
/* 4 Create journal receiver CLFJRNRCV */
/* 5 Clears physical file VC2EMP and VC2DPT */
/* 6 Creates example program DEV_LOAD (that */
/* loads records into the VC2EMP and */
/* VC2DPT database files) into QTEMP */
/* 7 Calls DEV_LOAD */
/* 8 Starts journaling of VC2EMP */
/* 9 Starts commitment control */
/***********************************************/
EndJrnPF File(VC2CLF/VC2EMP)
MonMsg MsgID(CPF0000)
DltJrn Jrn(VC2CLF/CLFJRN)
MonMsg MsgID(CPF0000)
DltJrnRcv JrnRcv(VC2CLF/CLFJRNRCV) DltOpt(*IgnInqMsg)
MonMsg MsgID(CPF0000)
CrtJrnRcv JrnRcv(VC2CLF/CLFJRNRCV)
CrtJrn Jrn(VC2CLF/CLFJRN) JrnRcv(VC2CLF/CLFJRNRCV)
ClrPFM File(VC2CLF/VC2EMP)
ClrPFM File(VC2CLF/VC2DPT)
CrtBndCLF Pgm(QTEMP/DEV_LOAD) SrcFile(VC2CLF/VC2CLSRC)
Call Pgm(QTEMP/DEV_LOAD)
StrJrnPF File(VC2CLF/VC2EMP) Jrn(VC2CLF/CLFJRN) +
Images(*Both)
StrCmtCtl LckLvl(*Chg)
/***********************************************/
/* With setup done, the application program: */
/* 1 Opens the VC2EMP database file for both */
/* input and output, keyed access, and under */
/* commitment control */
/* 2 Reads by key the employee record for */
/* employee number 52 */
/* 3 If employee 52 is not found then the */
/* previous setup logic failed and the */
/* program displays an error message */
/* 4 If employee 52 is found the program: */
/* 4A Deletes the employee */
/* 4B Prompts the user to commit the */
/* deletion of employee 52 */
/* 4C If the user responds 'Y' the delete */
/* is committed */
/* If the user responds 'N' the delete */
/* is rolled back */
/* 5 Reads by key the employee record for */
/* employee number 52 */
/* 6 Displays a message to the user about */
/* whether or not the record was found */
/***********************************************/
OpnFCLF FileID(VC2EMP) Usage(*Both) AccMth(*Key) +
CmtCtl(*Yes)
ReadRcdCLF FileID(VC2EMP) Type(*Key) RcdNotFnd(&RNF) +
KeyRel(*EQ) KeyList(52)
If Cond(&RNF) Then(SndUsrMsg MsgID(VC25051) +
MsgF(VC2CLF/VC2MSG))
Else Cmd(Do)
DltRcdCLF FileID(VC2EMP)
SndUsrMsg Msg('Commit delete? Y or N') +
Values(Y N) MsgRpy(&Answer)
If Cond(&Answer *EQ Y) Then(Commit)
Else Cmd(RollBack)
ReadRcdCLF FileID(VC2EMP) Type(*Key) +
RcdNotFnd(&RNF) KeyRel(*EQ) KeyList(52)
If Cond(&RNF) Then(SndUsrMsg +
MsgID(VC25052) MsgF(VC2CLF/VC2MSG))
Else Cmd(SndUsrMsg MsgID(VC25053) +
MsgF(VC2CLF/VC2MSG))
EndDo
/***********************************************/
/* Having completed the transaction the */
/* program now: */
/* 1 Closes the VC2EMP database file */
/* 2 Ends commitment control */
/* 3 Ends journaling of VC2EMP */
/* 4 Deletes the journal CLFJRN */
/* 5 Deletes the journal receiver CLFJRNRCV */
/* 6 Returns */
/***********************************************/
CloFCLF FileID(VC2EMP)
EndCmtCtl
EndJrnPF File(VC2CLF/VC2EMP)
DltJrn Jrn(VC2CLF/CLFJRN)
DltJrnRcv JrnRcv(VC2CLF/CLFJRNRCV) DltOpt(*IgnInqMsg)
EndPgm
The source for the example can be found in member DEV_CMTCTL of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.
To compile DEV_CMTCTL into QTEMP you can use the command
CrtBndCLF Pgm(QTEMP/DEV_CMTCTL) SrcFile(VC2CLF/VC2CLSRC)
To run the program you can use the command
Call Pgm(QTEMP/DEV_CMTCTL)
Example 8: Sharing a FILEID Across Programs
This example includes two programs. The first program, DEV_SHROPN, opens the VC2EMP database file for input processing and reads one record. The second program, DEV_SHRCLO, reads one record from the open FILEID of DEV_SHROPN and then closes the file. The record read by DEV_SHRCLO is actually the second record of the VC2EMP file as it's position in the file is determined by the last user of the shared FILEID. In this case the program DEV_SHROPN.
This is the source for the DEV_SHROPN program.
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP and */
/* indicators used with CLF I/O Commands */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Open the Employee master file VC2EMP in */
/* arrival sequence */
/* Read the first record in the file */
/* Send a message showing what record was read */
/***********************************************/
OpnFCLF FileID(VC2EMP) ERR(&ERR)
If Cond(&ERR) Then(Do)
SndPgmMsg Msg( +
'Error doing shared open from DEV_SHROPN')
Return
EndDo
ReadRcdCLF FileID(VC2EMP)
SndPgmMsg Msg('DEV_SHROPN found' *BCat &EmpFName)
/***********************************************/
/* Call the DEV_SHRCLO example program. */
/* */
/* DEV_SHRCLO will use the open of VC2EMP */
/* performed in this program and, after */
/* reading one record, close VC2EMP */
/***********************************************/
Call Pgm(DEV_SHRCLO)
/***********************************************/
/* Upon return from DEV_SHRCLO attempt to read */
/* the next record from the VC2EMP file. */
/* */
/* An error should be returned from READRCDCLF */
/* as VC2EMP has been closed. */
/* The program will send a message based on */
/* the &ERR indicator returned by READRCDCLF */
/***********************************************/
ReadRcdCLF FileID(VC2EMP) ERR(&ERR)
If Cond(*Not &ERR) Then(SndPgmMsg +
msg('DEV_SHRCLO did not close VC2EMP'))
Else Cmd(SndPgmMsg Msg( +
'The file was closed by DEV_SHRCLO'))
/***********************************************/
/* The program now returns. */
/* */
/* DEV_SHROPN could use the CLOFCLF command */
/* to close the file even though it is not */
/* open. Closing a file that is not open */
/* will result in a diagnostic message, but */
/* not a severe error. */
/***********************************************/
EndPgm
The source for this example can be found in member DEV_SHROPN of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.
To compile this example you can use the command
CrtBndCLF Pgm(VC2CLF/DEV_SHROPN) SrcFile(VC2CLF/DEV_SHROPN)
This example program does need to be compiled into the VC2CLF library as that library name is hardcoded in program DEV_SHRCLO for the OPNPGM keyword of several CLF commands.
This is the source for the DEV_SHRCLO program.
Pgm
/***********************************************/
/* Declare the Employee master file VC2EMP and */
/* CLF-related indicators */
/***********************************************/
DclFCLF FileID(VC2EMP)
DclIndCLF CLFInd(*Yes)
/***********************************************/
/* Open the VC2EMP file using the open */
/* done in VC2CLF/SHROPN */
/***********************************************/
OpnFCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN) +
ERR(&ERR)
If Cond(&ERR) Then(Do)
SndPgmMsg Msg( +
'Error doing shared open from DEV_SHRCLO')
Return
EndDo
/***********************************************/
/* Read the next record from VC2EMP. */
/* */
/* As DEV_SHROPN read one record (Rebecca) */
/* this read should be the second record */
/* in arrival sequence (Bruce) */
/* The program sends a message showing what */
/* record was read */
/***********************************************/
ReadRcdCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
SndPgmMsg Msg('DEV_SHRCLO found' *BCat &EmpFName)
/***********************************************/
/* DEV_SHRCLO now closes the file initially */
/* opened by VC2CLF/SHROPN. This also */
/* closes the file for VC2CLF/SHROPN */
/***********************************************/
CloFCLF FileID(VC2EMP) OpnPgm(VC2CLF/DEV_SHROPN)
EndPgm
The source for this example can be found in member DEV_SHRCLO of source file VC2CLSRC in library VC2CLF. The source for physical file VC2EMP can be found in member VC2EMP of source file QDDSSRC in library VC2CLF.
To compile this example you can use the command
CrtBndCLF Pgm(VC2CLF/DEV_SHRCLO) SrcFile(VC2CLF/VC2CLSRC)
After creating both DEV_SHROPN and DEV_SHRCLO you can call the sample programs with the command
Call Pgm(VC2CLF/DEV_SHROPN)