I am new to programming with RPGLE I was trying to write a simple code to read data from a file and displaying it in the screen. While doing it I get errors:
RNF3438 30 000600 LIKE keyword is expected for field BNBIN1 but not found; definition is ignored. RNF7030 30 002200 The name or indicator DSPLY is not defined.
I have tired to figure it out but I have failed to do so....
This is pracfile.pf
A UNIQUE
A R RQOCBN
*
A BNBIN1 9B 0 TEXT('BINARY')
A BNBIN2 9S 2 TEXT('ZONED DECIMAL')
A BNBIN3 9P 2 TEXT('PACKED DECIMAL')
A BNBIN4 2F 2 TEXT('FLOATING POINT')
A BNBIN5 20A TEXT('ALPHANUMERIC DATA')
A BNBIN6 L TEXT('DATE DATA')
A BNBIN7 T TEXT('TIME DATA')
A BNBIN8 9H TEXT('HEXADECIMAL DATA')
A BNBIN9 Z TEXT('TIMESTAMP DATA')
A BNBIN10 95 TEXT('BINARY CHARACTER DATA')
*
A K BNBIN1
This is pracpgm.rpgle
**free
dcl-f PRACFILE disk Usage(*input:*output:*update:*delete);
// Declaring standalone for individual variables in a field
dcl-s BNBIN1 binary(9); //binary data
dcl-s BNBIN2 packed(9:2); //packed decimal data
dcl-s BNBIN3 zoned(9:2); //zoned decimal data
dcl-s BNBIN4 float(4); //float data
dcl-s BNBIN5 char(20); //alphanumeric data
dcl-s BNBIN6 date; //date data
dcl-s BNBIN7 time; //time data
dcl-s BNBIN8 char(9); //hexadecimal data
dcl-s BNBIN9 timestamp; //timestamp data
dcl-s BNBIN10 char(9); //binary character data
// Read the database file
read pracfile;
// Loop till the end of file and display character read from the file
dow not %eof
dsply ('Binary: ' + %char(BNBIN1));
dsply ('Packed decimal: ' + %char(BNBIN2));
dsply ('Zoned decimal: ' + %char(BNBIN3));
dsply ('Floating point: ' + %char(BNBIN4));
dsply ('Character: ' + BNBIN5);
dsply ('Date: ' + %char(BNBIN6));
dsply ('Time: ' + %char(BNBIN7));
dsply ('Hexadecimal: ' + BNBIN8);
dsply ('Timestamp: ' + %char(BNBIN9));
dsply ('Binary: ' + BNBIN10);
read PRACFILE;
enddo;
*inlr = *on; // Last record = ON
return; // End Program
I don't understand the error message completely why is LIKE keyword is expected for field BNBIN1? dsply is a command in rpgle why is the name or indicator DSPLY is not defined?
I tried finding the solutions in internet and reading the rpgle documentations but I was unable to find the soution to the problems.
The error about DSPLY
is because you are missing a ;
on the dow not %eof
line.
The error about BNBIN1 is because binary
is not the correct type in free-format; instead it is bindec
dcl-s BNBIN11 bindec(9);
However, never* use BINDEC
data type in RPG.
It's left over from before RPG supported actual integer data types.
The DDS binary
data type is an actual integer data type. So the 9B 0
is actually a 4 byte (aka 10 digit) integer supporting -2147483648 to 2147483647. You'd want integer(10)
in RPG. RPG's bindec(9)
only supports -999999999 to 999999999
Related note, make sure ctl-opt EXTBININT(*YES)
is specified.
Secondly, you don't need to declare the stand-a-lone variables at all. RPG pulls in the field names from the file. This should be all you need.
**free
ctl-opt EXTBININT(*YES)
dcl-f PRACFILE disk Usage(*input:*output:*update:*delete);
// Read the database file
read pracfile;
// Loop till the end of file and display character read from the file
// while the file name is not needed, I prefer to include it always.
dow not %eof(pracfile)
dsply ('Binary: ' + %char(BNBIN1));
dsply ('Packed decimal: ' + %char(BNBIN2));
dsply ('Zoned decimal: ' + %char(BNBIN3));
dsply ('Floating point: ' + %char(BNBIN4));
dsply ('Character: ' + BNBIN5);
dsply ('Date: ' + %char(BNBIN6));
dsply ('Time: ' + %char(BNBIN7));
dsply ('Hexadecimal: ' + BNBIN8);
dsply ('Timestamp: ' + %char(BNBIN9));
dsply ('Binary: ' + BNBIN10);
read PRACFILE;
enddo;
*inlr = *on; // Last record = ON
return;
*Ok almost never, if you had a PF field defined binary with decimal places, maybe RPG's BINARY would be useful.