Dbkey conversion when page range above 8 meg
search cancel

Dbkey conversion when page range above 8 meg

book

Article ID: 56995

calendar_today

Updated On:

Products

IDMS IDMS - Database

Issue/Introduction

The standard conversion algorithm in the Database Administration manual works fine for the standard dbkey format as long as the page number is 8,388,607 or less. However, the standard dbkey format allows for page numbers up to 16,777,215. Dbkeys with page numbers between these two values will be seen as a negative number and cobol programs will get invalid results using the standard algorithm.

 

Environment

Release: All supported releases.
Component: IDMS/DB

Cause

For these page numbers, the high-order bit of the internal representation of the dbkey value is on, thereby rendering the value negative when using PIC S9(8) COMP.

Resolution

What most clients 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, the cobol negative number problems can be avoided.

To convert a hexadecimal dbkey to displayable page number and line index:                        
  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).