|
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
As an Amazon Associate we earn from qualifying purchases.
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.