Wednesday, May 22, 2013

Retrieving the relative record number in AS400 SQL

Sometimes, it can be useful to select all records from a physical file on the AS400, and to know what relative record number each one is.  For example, this came up for me because I needed to be able to use DSPPFM and view the raw data, because one of the fields was in hexidecimal format and I needed to display it in hex mode to view it easier.  This is how you do it:

SELECT RRN(A), A.*      
FROM FILE1 A

The above statements selects the relative record number of each record, and then selects all fields from the file.  This is by using the alias "A".  The 2nd line declares A as the alias for FILE1, so that the first instruction knows what file it is supposed to query.        

4 comments: