× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Ken,

I agree, that the compiler works as designed regarding to the documentation. But it works different from the other compilers that I know. Fields whose contents have a different lengths cannot be equal. Whether or not the content are spaces, does not matter.

I do not agree, that people need to move there varying fields to fix-length fields when they do not want to care about the length. The question is not whether they care for the length, but whether they care for trailing spaces. If I do not care about trailing spaces, then I have to trim my fields according to my needs. That is what people have to do for almost every programming language.

Just see the following example that uses trailing 'a's instead of spaces. Nobody would say, that the following fields are equal:

Field 'string1' = 20a varying
Field 'string2' = 30a varying

string1 = 'Helloaaa';
string2 = 'Helloaaaaaa';
If (string1 = string2);
// not reached in this example
endif;

But of course they are equal, when the trailing 'a's haven been removed by %trimr():

string1 = 'Helloaaa';
string2 = 'Helloaaaaaa';
If (%trimr(string1: 'a') = %trimr(string2: 'a'));
// not the strings compare to equal
endif;

So what is the difference between a space and an 'a'? For sure you do not want the compiler to remove your trailing spaces when concatenating string, do you?

The different maximum length of the strings (20 and 30) does not affect the comparison, because of the 'varying' keyword. So there is no need for using fix-length fields, just for the comparison.

Regards,

Thomas.

-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Ken Sims
Gesendet: Freitag, 27. März 2015 14:07
An: rpg400-l@xxxxxxxxxxxx
Betreff: Re: RPG String Compare - Bug or not?

Hi Thomas -

On Fri, 27 Mar 2015 10:19:23 +0000, Thomas Raddatz <thomas.raddatz@xxxxxx> wrote:

"If character, graphic, or UCS-2 fields are compared, fields of unequal length are aligned to their leftmost character. The shorter field is filled with blanks to equal the length of the longer field so that the field lengths are equal for comparison."

It does not explicitly mention varying fields and I completely agree for fix-length fields. But for varying fields, for example, a field with length = 0 is different from a field with one or more spaces.

What is your opinion about that?

My opinion is that it is working as designed.

If the values are equal after the field with the shorter varying length is padded with spaces to be the same length as the field with the longer varying length, then the fields are equal per the documentation.

If you want to require that the varying lengths be equal, you need to check that also:

if (%len(FieldA) = %len(FieldB)) and (FieldA = FieldB) ;

Also ... If the compiler was coded so that varying fields had to be the same length to be considered equal, then people who didn't care about the length being equal would have to move the varying fields to fixed length fields to do a comparison. The way it is now is more programmer-friendly.

Ken
Opinions expressed are my own and do not necessarily represent the views of my employer or anyone in their right mind.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.

--
IMPORTANT NOTICE:
This email is confidential, may be legally privileged, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone else is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.