Comparing Strings with Numeric Comparison Operators in RPG

2900 pts.
Tags:
RPG
Strings
Hi all,
I wonder how Numeric comparison operators work for strings; like 'IFGT' and 'IFLT' for comparing two string values. How two strings are compared like this.
Thanks,
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 6  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.
  • CharlieBrowne
    By saying string comparisons, I assume you mean both fields are defined as alpha. If that is the case, what are the contents of the strings. Do they have a decimal point in them? how are negative numbers stored? Are both strings the same length and justified the same way?
    62,385 pointsBadges:
    report
  • aceofdelts
    It does work (in RPG)  ... testing less than or greater than for two character fields. Pretty much according to sort sequence going left to right. I try to avoid using digits or special characters if I can since I don't remember if they are first or last or ??? in the sort sequence.
    2,550 pointsBadges:
    report
  • azohawk

    The comparison is based on the hexdecimal value of the characters. Consequently  'a '  is different than 'A '  and 'aa'. 

    Create a small sample file, the use a query sort to view the file if you want to see the specific sequence.

    Since the system sees the hex value for doing the compare-it percieves it as a numeric comparison.

    3,990 pointsBadges:
    report
  • hunshabbir7
    Thanks for your response but I did not get it yet. Two strings are pure strings like "aBX-672-MMM" and "NhF-666-TRE" and these are compared with IFGT and IFLT operations. How this operation works?
    2,900 pointsBadges:
    report
  • philpl1jb

    It compares the EBCDIC values of the first characters of each string

    A small 'a' is EBCDIC 129 a large 'N' is 213. 

    So the first string starts with 129 and the second with a larger value 213. 

    If the first characters of each sting are equal then the second characters are compared.  And the process is repeated.

    54,090 pointsBadges:
    report
  • TheRealRaven
    First, IFGT and IFLT are not "numeric" operators. They are just comparison operators. It doesn't matter if the program is comparing two numbers or two strings or two dates; the comparisons determine which is greater and which is lesser. "Numeric" has nothing to do with the operators.

    Second, character string comparisons are based in the job's 'collating sequence'. In general, you only need to think of the order two items would be placed in an alphabetic list. Whichever one comes first alphabetically, that one is the lesser and the other string is the greater.

    If you want to see which string is greater, it is easier to code a RPG program with maybe six lines of code and run it. You'll have an answer much faster than posting to a forum and waiting for possibly incorrect answers.
    32,290 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.

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

Following

Share this item with your network: