× 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.



Hey Scott,
Would this give the desired result then for a fixed len field?

     D String1         s             10A   inz('TEST')
      /free
        %Trimr(String1) += 'QQQ';

String1 would equal 'TESTQQQ   ' then wouldn't it?


Ron Power
Programmer
Information Services
City Of St. John's, NL
P.O. Box 908
St. John's, NL
A1C 5M2
Tel: 709-576-8132
Email: rpower@xxxxxxxxxx
Website: http://www.stjohns.ca/
___________________________________________________________________________
Success is going from failure to failure without a loss of enthusiasm. - 
Sir Winston Churchill




Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> 
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
20/07/2004 08:49 PM
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: Standalone Alpha vs. Varying Length Alpha Q






Hi Tony,

> I can't seem to find anywhere in the documentation that states you can't 
use
> the += on two fixed-length alpha fields.  Am I missing something, or is 
this
> only possible with varying length fields?

Hmmm... by "standalone" do you really mean "fixed-length"?  The term
"standalone" means that a field is not part of a data structure -- and
that doesn't seem to have any bearing on your questions.

Your question appears to be "why does += work on a varying field and not
on a fixed-length field?"  Is that correct, or am I confused?

Why doesn't this code work?

     D String1         s             10A   inz('TEST')
      /free
        String1 += 'QQQ';

To explain, I'll break it into two steps.  Adding "QQQ" to the end of
String1 in a temporary variable, then assigning that temporary variable
back to String1:

     D String1         s             10A   inz('TEST')
     D Temp            s             13A

      /free
        Temp = String1 + 'QQQ';
        String1 = Temp;

After the first line, Temp will contain 'TEST      QQQ'  Why?  Because it
originally contained 'TEST      ' and you added 'QQQ' to the end of it.

After the second line, String1 will contain 'TEST      '.  Why doesn't the
QQQ show up?  Because the variable is only 10 characters long, and it
didn't fit.

Now, go back to the first example, and think, is there ever a time that I
could add a string to the end of a fixed-length string?  The answer is no.
A fixed-length string, by definition, always has every byte in use.  You
can't add data to the end of it because there's never any space left to
put it in!

With VARYING, on the other hand, you have control of how much of the
string is in use.  For example

     D String1         s             10A   varying inz('TEST')
     D Temp            s             13A   varying
      /free
        Temp = String1 + 'QQQ';
        String1 = Temp;

After the first line of code, Temp will contain "TESTQQQ".  Why?  Because
there were no trailing blanks -- I was using only the first 4 bytes of
of String1.

Now, since the result is less than 10 characters I can store it back in
String1.

Therefore, if String1 is varying, the following example also works fine:

     D String1         s             10A   varying inz('TEST')
      /free
        String1 += 'QQQ';

The key to working with VARYING is simply to remember that the trailing
blanks in a character string ARE REALLY THERE, even though they're not
printable characters :)

---
Scott Klement  http://www.scottklement.com
--
This is the RPG programming on the AS400 / 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.




This OutBound email has been scanned for Viruses

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.