Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025

 


Article

4GL. How to convert a ROWID to a RECID and Vice Versa

« Go Back

Information

 
Article Number000001594
EnvironmentProduct: Progress
Version: 9.x
Product: OpenEdge
Version: 10.x, 11.x
OS: All supported platforms
Question/Problem Description
4GL. How to convert a ROWID to a RECID and Vice Versa
Sample methods to convert a ROWID variable to a RECID variable.
Sample methods to convert a RECID variable to a ROWID variable.
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
There is no native 4GL function that converts ROWID variables to RECID variables or visa versa.  One must exercise caution when trying to convert a RECID variable to a ROWID variable as the ROWID variable may not always be a unique identifier of the current database record.
  • A ROWID is a unique internal identifier of the current database record.  
  • A ROWID variable may be converted to a character string representation using the STRING function.
  • A ROWID value converts to a hexadecimal string of the form "0xhexdigits," where hexdigits is any number of characters "0" through "9" and "A" through "F"
  • The TO-ROWID Function converts a string representation of a valid ROWID variable to a valid ROWID value.  Although TO-ROWID converts a properly formatted string to a ROWID value, there is no guarantee that this value corresponds to an existing record in your database.
 
  • A RECID  is a unique internal identifier of the current database record, which is supported mainly for backward compatibility.
  • For most applications, Progress recommends the use of ROWID instead.  A RECID variable has a default INTEGER type representation.
  • With the implementation of Table Partitioning in OpenEdge 11.4 RECID can no longer be used to uniquely reference data in a partitioned table as they do not contain a partition-Id component and always pertain to partition 0.
  • The exitsting ROWID information plus the table number is no longer sufficient to uniquely identify a specific record in the database.  
  • Uniqueness is obtained by also including the partition id associated with the record.  The internal format of a ROWID has been extended to include the partition information.  The information associated with a RECID only contains the encoded block and record within block information. For further information refer to Article: 

A.  Code example converts a ROWID variable to a RECID variable using the following algorithm:
  1.     Get the ROWID variable.
  2.     Get the hexadecimal string representation.
  3.     Get the integer representation of the RECID.
/*  Convert ROWID to RECID   */

DEFINE VARIABLE iRecId AS INTEGER NO-UNDO.
DEFINE VARIABLE cRowId AS CHARACTER NO-UNDO.
DEFINE VARIABLE rRowID AS ROWID NO-UNDO.

FIND FIRST customer.
cRowId = STRING(ROWID(customer)).

MESSAGE NAME cRowID
   VIEW-AS ALERT-BOX INFO BUTTONS OK.

cRowId = SUBSTRING(cRowId, 3, LENGTH(cRowId)).
RUN HexToInt(INPUT cRowId , OUTPUT iRecId).
FIND FIRST Customer WHERE RECID(Customer) = iRecId.

MESSAGE NAME iRecId
   VIEW-AS ALERT-BOX INFO BUTTONS OK.


PROCEDURE HexToInt:
  DEFINE INPUT PARAMETER c AS CHARACTER NO-UNDO.
  DEFINE OUTPUT PARAMETER i AS INTEGER NO-UNDO INITIAL 0.
  DEFINE VARIABLE j AS INTEGER NO-UNDO.
  
  c = CAPS(c).
  DO j = 1 TO LENGTH(c):
     IF CAN-DO("0,1,2,3,4,5,6,7,8,9", (SUBSTRING(c, j, 1))) THEN
        i = i + INT(SUBSTRING(c, j, 1)) *
                exp(16, (LENGTH(c) - j)).
     ELSE
        i = i + (KEYCODE(SUBSTRING(c, j, 1)) -
                KEYCODE("A") + 10) * EXP(16, (LENGTH(c) - j)).
  END.
END PROCEDURE.
 
B.  Code example converts a RECID variable to a ROWID variable using the following algorithm:
  1.      Get the RECID variable integer representation.
  2.      Get its equivalent hexadecimal string representation.
  3.      Get the equivalent ROWID variable.
/* Convert RECID to ROWID */ 
DEFINE VARIABLE iRecId AS INTEGER NO-UNDO.
DEFINE VARIABLE cRowId AS CHARACTER NO-UNDO.
DEFINE VARIABLE rRowID AS ROWID NO-UNDO.

FIND FIRST customer.
iRecId = RECID(customer).

MESSAGE NAME iRecId
   VIEW-AS ALERT-BOX INFO BUTTONS OK.

RUN IntToHex(INPUT iRecId , OUTPUT cRowId).
rRowId = TO-ROWID(cRowId).
FIND customer WHERE ROWID(Customer) = rRowId.

MESSAGE NAME cRowId
   VIEW-AS ALERT-BOX INFO BUTTONS OK.

PROCEDURE IntToHex.
  DEFINE INPUT PARAMETER i AS INTEGER NO-UNDO.
  DEFINE OUTPUT PARAMETER c AS CHARACTER NO-UNDO.
  
  DEFINE VARIABLE j AS INTEGER  NO-UNDO.

  DO WHILE TRUE:
     j = i MODULO 16.
     c = (IF j < 10 THEN STRING(j) ELSE CHR(ASC("A") + j - 10)) + c.
     IF i < 16 THEN LEAVE.
     i = (i - j) / 16.
  END.
  
  j = 8 - LENGTH(c).
  DO i = 1 TO j:
      c = "0" + c.
  END.
  c = "0x" + c.
END PROCEDURE.

 
Workaround
Notes
Attachment 
Last Modified Date11/9/2018 9:04 AM