|
Steve Richter wrote:
what's the story, does the cat opcode have a problem with varying strings? d sMsg s 80a varying d sMsg2 s 256a varying c eval sMsg = 'abc' c sMsg cat 'def':1 sMsg2 the resulting value in sMsg2 is blanks. I want it to be 'abc def'. I was hoping that the CAT opcode would work best when appending to a string: d sWord s 80a varying d sSentence s 2000a varying ** using CAT c cat sWord:1 sSentence ** is more efficient than using "+" ? c eval sSentence = sSentence + ' ' + sWord will the v5r2 += operator be more efficient than + ? sSentence += sWord ; sSentence = sSentence + sWord ;
If you want to work with varying length character variables, you should really be using expressions, and not the old-style fixed form calcs. I discussed the reason in another thread. Basically, because of the weird semantics of character operands in fixed form calcs, we defined the functionality such that a varying length character variable would work exactly the same as a fixed length variable defined with the same length as the current length of the varying variable. Defining the functionality this way avoided the need for complex rules with lots of special cases. (By default, when you code a fixed length character variable as a result of a fixed-form calc, the left-most or right-most characters might not be changed depending on the lengths of the operands.) In your example, variable SMSG2 starts out with a value of ''. Coding it as the result of the CAT operation is equivalent to coding a fixed length character variable defined with a length of zero. And so, yes, the + operator is preferred over CAT when dealing with varying length character. Not because it's necessarily faster, but rather, it works as you would expect with varying length character variables. Is += more efficient? It could be if the evaluation of the target involves a compute-intensive operation. For example, let's say you code "ARR(PROC())+=STR;", and PROC() takes some time. Clearly, that would be faster than coding "ARR(PROC())=ARR(PROC())+STR;", but only because the procedure is called one less time. Otherwise, "A+=B;" is exactly equivalent to "A=A+B;". (Oh yeah, note that "A+=B;" is not allowed where A is a fixed length character variable. If it were allowed, it would effectively be a NO-OP anyways.) Cheers! Hans
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.