A good question would be: Why is the DBKey defined as S9(8) comp? There really is no reason why it could not be X(4), or rather:
01 DBKEY.
03 DBKEY-PAGE PIC X(3).
03 DBKEY-LINE PIC X(1).
It would of course work only when you use the default 1 byte line index that supports 255 records per page.
Anyway, the first 3 bytes is the page number and the last byte is the line index so in addition to the above DBKEY field, I define the following structure:
01 DBKEY-CONV.
03 DBKEY-CONV-PAGE PIC S9(8) COMP.
03 FILLER REDEFINES DBKEY-CONV-PAGE
05 FILLER PIC X(1)
05 DBKEY-CONV-PAGE-X PIC X(3).
03 DBKEY-CONV-LINE PIC S9(8) COMP.
03 FILLER REDEFINES DBKEY-CONV-LINE.
05 FILLER PIC X(3).
05 DBKEY-CONV-LINE-X PIC X(1).
And the code to convert it to page number and line index should be:
MOVE LOW-VALUES TO DBKEY-CONV.
MOVE DBKEY-PAGE TO DBKEY-CONV-PAGE- X.
MOVE DBKEY-LINE TO DBKEY-CONV-LINE-X.
MOVE DBKEY-CONV-PAGE TO DBKEY-PAGE-DISPLAY.
MOVE DBKEY-CONV-LINE TO DBKEY-LINE-DISPLAY.
If you need to go the other way..
MOVE LOW-VALUES TO DBKEY-CONV.
MOVE DBKEY-PAGE-DISPLAY TO DBKEY-CONV-PAGE.
MOVE DBKEY-LINE-DISPLAY TO DBKEY-CONV-LINE.
MOVE DBKEY-CONV-PAGE-X TO DBKEY-PAGE.
MOVE DBKEY-CONV-LINE-X TO DBKEY-LINE.
There really isn’t an easy way if you want to be able to go both ways.