PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Key function - Key Generate  (Read 484 times)


  • Diamond Member
  • *****
  • Posts: 124
    • View Profile
Key function - Key Generate
« on: December 05, 2022, 06:52:16 PM »
The really useful part of this functions Key Generate is not having to enumerate alternate keys for padding. 
But it does not return a complete key padded for trailing empty fields in external key files as shown below. 
I haven't checked it yet against the internal files as empty trailing fields are less likely by design.
So enumeration of keys or hard coding padding data may still be necessary.
Wondering if I am missing something here? 
I would expect and prefer to mid/stp the result if a partial key was wanted.
Still on Version 1410. 

01 OPEN (1)"OP9002" ! External Prime key file, Key 3 is 4 Fields, 33 bytes - 20:7:2:4
02 cmd$="key(1,key=""00190579172397"":""5850720"":""  "":""    "",kno=3)"
03 x$=EVS(cmd$)
04 PRINT HTA(x$)
05 PRINT LEN(x$)
06 cmd$="key(1,key=""00190579172397"":""5850720"":"""":"""",kno=3)"
07 x$=EVS(cmd$)
08 PRINT HTA(x$)
09 PRINT LEN(x$)
10 cmd$="key(1,key=""00190579172397"":""5850720"",kno=3)"
11 x$=EVS(cmd$)
12 PRINT HTA(x$)
13 PRINT LEN(x$)
14 CLOSE (1)
15 END


Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3770
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Key function - Key Generate
« Reply #1 on: December 06, 2022, 10:21:31 AM »
The reason the padding is not done in order to assure the key provided will position you to the first record that has the specified key. 

Padding will vary based on if the segment is descending or numeric and as such you need to provide the segment value if you want to get the key that can be used to position to that segment. 

You cannot safely use STP to strip trailing segments as the value for the first key could be $FFFF$ or $0000$ depending if the field is descending -- and for numeric segments the value should be a large negative value or large positive value if descending.


  • Diamond Member
  • *****
  • Posts: 124
    • View Profile
Re: Key function - Key Generate
« Reply #2 on: December 06, 2022, 12:34:40 PM »
Thank you Mike,
All good reasons to use the internally keyed files for new stuff.