ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

String concatenation with "+"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • String concatenation with "+"

    We have a 5Mb varying length field that was being appended to by something similar to this:

    longField += %trim(field1) + ',' + %editc(amt: 'J') + ',' + %trim(field2) + ...

    This took quite a long time to complete.

    When we changed it to a single shorter varying length field and then appended it to the longer field performance increased by 5x. For example.

    shortField = %trim(field1) + ',' + %editc(amt: 'J') + ',' + %trim(field2) + ...
    longField += shortField;

    I know in other languages concatenation involves allocating new memory for the new field, copying contents of the old field, appending the new text, and releasing the old memory. This is not performant which is why there are dedicated libraries/classes specifically for string concatenation.

    I think I know the answer but hopefully Barbara will answer: How does the RPG compiler internally handle string concatentation?

    Mike
Working...
X