Troubleshooting
Problem
This document provides a sample CL program to determine the number of records currently in a single-member data file.
Resolving The Problem
This sample program determines the number of records currently in a single-member data file. The source code can be modified to retrieve other file attributes. The program uses the DSPFD command with a template output file (QAFDMBR) located in QSYS.
Example
Example
/************************************************************************/
/* */
/* Program NUMREC. */
/* */
/* This program returns the number of records in a single-member data file. */
/* Program parameters are as follows: */
/* &FILEVAR Name of file to process */
/* &LIBVAR Name of library containing the file */
/* &OUTFILEVAR Name of outfile to receive information from DSPFD */
/* */
/* The program may be called from the command line, e.g. */
/* */
/* CALL PGM(NUMREC) PARM('FILE1' 'QGPL' 'OUTFILE1') */
/* NOTE: You will want to have FILE1 in QGPL exist with records in it. */
/* For the OUTFILE1 you create this by doing a CRTDUPOBJ of the file QAFDMBR */
/* before calling the program. */
/************************************************************************/
PGM PARM(&FILEVAR &LIBVAR &OUTFILEVAR)
DCL VAR(&FILEVAR) TYPE(*CHAR) LEN(10)
DCL VAR(&LIBVAR) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTFILEVAR) TYPE(*CHAR) LEN(10)
DCL VAR(&VAR1) TYPE(*CHAR) LEN(70)
DCL VAR(&VAR2) TYPE(*CHAR) LEN(10)
/* Declare template file for DSPFD outfile. QAFDMBR is used when */
/* compiling the program because QAFDBMR already exists. With this */
/* approach, it is not necessary to create the outfile before compiling */
/* this CL source code. */
DCLF FILE(QAFDMBR)
/* Redirect output from QAFDMBR template to user-declared outfile. */
OVRDBF FILE(QAFDMBR) TOFILE(&OUTFILEVAR)
/* Write file information into outfile. */
DSPFD FILE(&LIBVAR/&FILEVAR) TYPE(*MBR) +
OUTPUT(*OUTFILE) OUTFILE(&OUTFILEVAR)
/* Read information from outfile. */
RCVF RCDFMT(QWHFDMBR)
/* Convert number of records field to char form. */
CHGVAR VAR(&VAR2) VALUE(&MBNRCD)
/* Build display string. */
CHGVAR VAR(&VAR1) VALUE('CURRENT NUMBER OF +
RECORDS: ' *CAT &VAR2)
/* Display current number of records. */
SNDPGMMSG MSG(&VAR1)
ENDPGM
CRTBNDCL PGM(<YOURLIB>/NUMREC) SRCFILE(<YOURLIB>/QCLLESRC) SRCMBR(NUMREC)
> CRTDUPOBJ OBJ(QAFDMBR) FROMLIB(QSYS) OBJTYPE(*FILE) TOLIB(<YOURLIB>) NEWOBJ(OUTFILE1)
Object OUTFILE1 in <YOURLIB> type *FILE created.
1 objects duplicated.
Object OUTFILE1 in <YOURLIB> type *FILE created.
1 objects duplicated.
> CALL PGM(<YOURLIB>/NUMREC) PARM(('QCUSTCDT') ('QIWS') ('OUTFILE1'))
Member OUTFILE1 added to output file OUTFILE1 in library <YOURLIB>.
1 records added to member OUTFILE1 in file OUTFILE1 in <YOURLIB>.
CURRENT NUMBER OF RECORDS: 0000000012
Member OUTFILE1 added to output file OUTFILE1 in library <YOURLIB>.
1 records added to member OUTFILE1 in file OUTFILE1 in <YOURLIB>.
CURRENT NUMBER OF RECORDS: 0000000012
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
25831216
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
CL
Software version:
All Versions
Operating system(s):
IBM i
Document number:
640673
Modified date:
13 November 2024
UID
nas8N1017101
Manage My Notification Subscriptions