Troubleshooting
Problem
Resolving The Problem
|
Disclaimer: This document contains code made available by IBM® Corporation on an as is basis. Anyone receiving this document is considered to be licensed under IBM copyrights to use the IBM-provided source code in any way he or she deems fit, including copying it, compiling it, modifying it, and redistributing it, with or without modifications. No license under any IBM patents or patent applications is to be implied from this copyright license. |
The sample DDS-PF and IBM® RPG/400® program demonstrate how to use Relative Record Number (RRN) in processing a file.
Library yourlib file QDDSSRC member RRNPF type PF:
A R FMT1
A FLD1 10A
A FLD2 10A
A FLD3 5P 0
After compiling that member, run the following CL command:
INZPFM FILE(yourlib/RRNPF) MBR(RRNPF) TOTRCDS(101)
Library yourlib file QRPGSRC member RRNEXMPL type RPG:
H* DDS FOR RRNPF
H* R FMT1
H* FLD1 10A
H* FLD2 10A
H* FLD3 5P 0
H*
H* ADDED 101 RECORDS TO THE FILE USING INZPFM
H* INZPFM FILE(yourlib/RRNPF) MBR(RRNPF) TOTRCDS(101)
H*
H* THIS PROGRAM CHAINS TO THE FIRST 100 RECORDS BY
H* RELATIVE RECORD NUMBER AND UPDATES THE RECORD WITH
H* FLD3 CONTAINING THE RELATIVE RECORD NUMBER FOR THAT
H* RECORD.
H*
H 1
FRRNPF UF E DISK KRECNO RNUM A
C Z-ADD0 RNUM 70
C DO 100 RECN 70
C 101 SUB RECN RNUM
C RECN CHAINRRNPF 10
C N10 Z-ADDRNUM FLD3
C N10 UPDATFMT1
C ENDDO
* THE NEXT FEW LINES DEMONSTRATE THE USE OF DELETE AND WRITE
* NOTE: TO WRITE A RECORD TO THE FILE A DELETED RECORD MUST
* EXIST.
C Z-ADD101 RNUM
C MOVE *ALL'A' FLD1
C MOVE *ALL'B' FLD2
C Z-ADDRNUM FLD3
C RECN DELETFMT1 10
C N10 WRITEFMT1
C MOVE *ON *INLR
After compiling the program, you can call it. After it is completed, if you were to run a query against it, you would see that records 1 through 100 would have FLD1 and FLD2 blank, and FLD3 would contain the Relative Record Number. In record 101, FLD1 would be all A's and FLD2 would be all B's.
// DDS FOR RRNPF
// R FMT1
// FLD1 10A
// FLD2 10A
// FLD3 5P 0
//
// ADDED 101 RECORDS TO THE FILE USING INZPFM
// INZPFM FILE(YOURLIB/RRNPF) MBR(RRNPF) TOTRCDS(101)
//
// THIS PROGRAM CHAINS TO THE FIRST 100 RECORDS BY
// RELATIVE RECORD NUMBER AND UPDATES THE RECORD WITH
// FLD3 CONTAINING THE RELATIVE RECORD NUMBER FOR THAT
// RECORD.
//
Ctl-Opt DEBUG;
Dcl-F RRNPF Usage(*Update:*Delete:*Output) RECNO(RNUM);
Dcl-S RNUM Packed(7:0);
Dcl-S RECN Packed(7:0);
RNUM = 0;
For RECN = 1 To 100;
RNUM = 101 - RECN;
Chain RECN RRNPF;
*IN10 = not %Found;
If not *In10;
FLD3 = RNUM;
Endif;
If not *In10;
Update FMT1;
Endif;
EndFor;
// THE NEXT FEW LINES DEMONSTRATE THE USE OF DELETE AND WRITE
// NOTE: TO WRITE A RECORD TO THE FILE A DELETED RECORD MUST
// EXIST.
RNUM = 101;
EvalR FLD1 = *ALL'A';
EvalR FLD2 = *ALL'B';
FLD3 = RNUM;
Delete RECN FMT1;
*IN10 = not %Found;
If not *In10;
Write FMT1;
Endif;
*INLR = *ON;
Historical Number
15120711
Was this topic helpful?
Document Information
Modified date:
13 December 2024
UID
nas8N1018133