Sorting alphanumeric field with hexadecimal values

135 pts.
Tags:
AS/400
CL
RPG
We have a task where we have to convert key numeric field (8,0) to alphanumeric field (8A) with hexadecimal values ('00000000' - 'FFFFFFFF'). The problem in sorting with alphanumeric is the alphabet is less than the numeric value (A-Z < 0-9). Is there a way, by LF or any AS400 utility, that can sort hexadecimal data in alphanumeric field? Thanks!
ASKED: March 5, 2012  4:17 PM
UPDATED: March 23, 2012  6:48 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes,By assuming Keyword ALTSEQ(QSYS/QASCII) in LF can only solve the sort sequence problem,How to value the KEYID,I think Tom’s say is a right way.
So others about the sequence like these:
1: The table which you use is decided by your pratical applications.
This table QASCII is tranfer the EBCDIC code to ASCII code,because the char&numeric sort sequence is reversely,so the table QASCII was choosed.
2: If some of the keylist don’t want to change the sort sequnce, the keyword NOALTSEQ(a key field-level keyword) is assumed to the specific fields.
Jackli

Discuss This Question: 14  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • CharlieBrowne
    You numeric values will always be after the alpha values. I do not understand the converting that you describe. If you have a 8 position signed numeric field, that 1st position will always be a digit. If the field is packed numeric that is different.
    39,815 pointsBadges:
    report
  • BigKat
    let me see if I understand the question: you want to convert a numeric value to hexadecimal (15 => 0000000F), then store that value in a 8A field but you still want it to sort as if it was the value 15 and not a character string of '0000000F'
    7,565 pointsBadges:
    report
  • TomLiotta
    Please provide these details:
    1. The database definition of the current "numeric field",
    2. The database definition of the new "alphanumeric field"
    3. A few examples of values that exist now, and
    4. The new converted values that you want to create.
    It might also be useful if you explain why the collating sequence is a problem. What is it a problem for? Do you want to create programming that doesn't have a problem with the collating sequence? Tom
    125,585 pointsBadges:
    report
  • Vsevilod
    Hi everyone! I apologize for the late reply. We have project where the client needs to increase the limit of key record number (8,0) in a file. The problem with the numeric field (8,0). It can only handle maximum of 99999999 records. They don't purge these records so they are having problems now the number of records is reaching its limit. A maintenance program increments the record number every time a new record is created. First we suggested increasing the length of the numeric field (10,0 or bigger). But our project manager decided against it because a huge number of files and programs will be affected and we are on a very tight schedule. So we suggested to change the numeric field to a alphanumeric field which would contain hexadecimal values. This would greatly increase the number of records (00000000 - FFFFFFFF). In reports and display/maintenance programs, these records should be arranged in its hexadecimal manner. (00000000 -> FFFFFFFF). With the current sequencing of the LF, character values are less than the numeric values (A-Z < 0-9). Example ABCD1234 FFFFFFFF 00000000 1234ABCD 99999999 Where it should be displayed/printed as 00000000 1234ABCD 99999999 ABCD1234 FFFFFFFF Is there a way where this sorting can be accomplished? Many thanks!
    135 pointsBadges:
    report
  • TomLiotta
    Is there a way where this sorting can be accomplished? Yes, but two questions still need to be answered:
    • The database definition of the current “numeric field”,
    • The database definition of the new “alphanumeric field”
    The task is clearly complicated "because a huge number of files and programs will be affected". Without knowing exactly what is being manipulated, many can go wrong. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    00000000 1234ABCD 99999999 ABCD1234 FFFFFFFF The way you describe it, you're not actually using "hex" values. You're just using characters instead of numerics, and you're allowing new characters to be used. I think that has introduced some confusion. (It did for me.) But that's okay. It actually might make it much easier. Tom
    125,585 pointsBadges:
    report
  • Vsevilod
    The database definition of the numeric field is 8S0 (current situation) The database definition of the alphanumeric field is 8A (suggested change) I hope I answered your question. Yes. A large number of display/printer files, programs will be affected by this change. But the changes will be easier to implement. Programmers will just have to change the data format from 8,0 to 8A in DSPF/PRTF/PF/PGM, modify numeric operations to alphanumeric operations in PGMS, and add validations for the record field (8A with hex value). Sorry if you got confused with my explanation. Thanks again!
    135 pointsBadges:
    report
  • TomLiotta
    ...the numeric field is 8S0... Is that from DDS? Or is it a RPG program definition? If it's actual DDS, then we can guess the database definition without needing to see it. (You can use DSPFFD over the database file to see the database definition of a field. DDS should map to a database definition, but RPG may have misleading differences.) If the database field is actually ZONED 8 0, then you might easily be able to alter it to be CHAR 8. And by assigning your desired alternate collating sequence to it, you should be able to sort it as if it is a character representation of hex digits. Tom
    125,585 pointsBadges:
    report
  • Vsevilod
    Yes, you are correct. All objects (PF, DSPF, PRTF, CL/LE, and RPG/LE) have the data defined as zoned 8 0. And the developers will change it to 8 alphanumeric. The question is, how to sort the the 8 alphanumeric in "hexadecimal" sorting using LF or other AS400 operations? Or can this be done in RPG/LE only? Thanks!
    135 pointsBadges:
    report
  • jackli
    You can do like this: Create(or change) a LF by add file level keyword: ALTSEQ(QSYS/QASCII),so the LF will sort by the all key field ascii code sequence not by the ebcdic code sequence.This keyword only change the key field sequence but not change the field data.I think the table QASCII must be existed,If no,you can CRTTBL to create a user defined table. jackli
    95 pointsBadges:
    report
  • TomLiotta
    ALTSEQ(QSYS/QASCII) I haven't actually looked at using that table for alternate sequencing, but it's definitely the right idea. As for any applications using this scheme, there may be some logic issues involved when assigning/creating new IDs unless they're always assigned by a programmed function. If assigned by program, I would probably use actual 32-bit unsigned (4-byte, 8 hex digits) values and simply convert the hex digits back and forth with the cvtch() and cvthc() functions. I'd do any incrementing on the 32-bit integer and then just convert the 4-bytes to hex characters. Tom
    125,585 pointsBadges:
    report
  • Vsevilod
    Yes it works! Thank you everyone!
    135 pointsBadges:
    report
  • akurmala
    hi, I have to convert the alphanumeric values into HEX decimal using sort card. if my input having value as 'SKUD 00726000' then outpu should be with HEX Decimal SKUD 00726000 EDEC4FFFFFFFF 2244000726000 Could any one please help on this.
    10 pointsBadges:
    report
  • TomLiotta
    ...using sort card.   What is a "sort card"? Can you be a little more detailed in what you need to do?   Is this a program problem? What language do you need? Are you trying to display or print the hex output on two separate lines?   Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following