dbkey conversion when page range above 8 meg

Document ID : KB000056995
Last Modified Date : 14/02/2018
Show Technical Document Details

The standard conversion algorithm in DB Admin manual works fine for standard dbkey format as long as the page number is 8,388,607 or less, but standard dbkey format allows page numbers up to 16,777,215.  Dbkeys with page numbers between these 2 values will be seen as a negative number and cobol pgms will get invalid results using the standard algorithm.                      
*                                                                           
What most people have done is to define a dbkey work field that simply has "more room".                                                            
*                                                                           
  01  WORK-STUFF.                                                           
    02 BIG-DBKEY PIC S9(18) COMP.                                           
    02 BIG-DBKEY-PARTS REDEFINES BIG-DBKEY.                                 
      03 FILLER PIC X(4).                                                   
      03 LITTLE-DBKEY  PIC S9(8) COMP.                                      
    02 DISP-PAGE PIC 9(10).                                                 
    02 DISP-LINE PIC 999.                                                   
*                                                                           
 With these work fields you can avoid the Cobol negative number problems.   
*                                                                           
  TO convert a hex dbkey to displayable page & line:                        
  1)  First get the dbkey into LITTLE-DBKEY                                 
       (After a FIND/OBTAIN just "MOVE DBKEY to BIG-DBKEY"                  
         or                                                                 
       "ACCEPT LITTLE-DBKEY FROM ...")                                      
  2) "DIVIDE BIG-DBKEY BY 256 GIVING DISP-PAGE REMAINDER DISP-LINE."        
*                                                                           
To read decimal page number/line number from an input and turn them into hex dbkey that can be used to obtain by dbkey or can be put into DIRECT-DBKEY for storing direct records:                                    
  MOVE DISP-PAGE to BIG-DBKEY.                                              
  MULTIPLY BIG-PAGE BY 256.                                                 
  ADD DISP-LINE TO BIG-PAGE.                                                
  MOVE LITTLE-DBKEY TO DIRECT-DBKEY (or your dbkey field defined S9(8) COMP).