*TRIM function on Dynamic fields

I’m trying to code a utility program that will read in a variable length, pipe delimited file with variable length fields (the data fields for different files can be different lengths) but am having problems with using too much CPU. I have tried it as below as well as using very large fixed length fields for the #SEPARATION-FILE fields (A500) but both blow with S322 abends. Is there a better way to code this scenario so that it won’t suck up so much CPU?

The basic layout of my code is below:
DEFINE DATA LOCAL
1 #INPUT-FILE (A) DYNAMIC

1 #SEPARATION-FILE
2 #SEPARATION-FIELD1 (A) DYNAMIC
2 #SEPARATION-FIELD2 (A) DYNAMIC

  • 72 MORE FIELDS ALL DEFINED THE SAME AS ABOVE

1 #OUTPUT-FILE
2 #OUT-FIELD1 (A10)
2 #OUT-FIELD2 (A100)

  • 72 MORE FIELDS ALL DEFINED TO VARIOUS LENGTHS

END-DEFINE

READ WORK FILE 1 #INPUT-FILE
SEPARATE #INPUT-FILE LEFT JUSTIFIED INTO
#SEPARATION-FIELD1
#SEPARATION-FIELD2 …and so forth matching layout of #SEPARATION-FILE
IGNORE WITH DELIMITERS ‘|’

MOVE *TRIM(#SEPARATION-FIELD1) TO #OUT-FIELD1
MOVE *TRIM(#SEPARATION-FIELD2) TO #OUT-FIELD2 …and so forth for all fields

WRITE WORK FILE 2 #OUTPUT-FILE
RESET #SEPARATION-FILE #OUT-FILE
END-WORK
END

Thanks,
Rosie

I have no experience using newer features like *TRIM, but if your variables are all alphanumeric, is that function required? Unless you get a Natural error moving an alpha dynamic to alpha fixed length, it should work the same as if they were bounded alpha variables (with truncation possible either way).

I am also wondering if you need the LEFT JUSTIFIED clause, or do you know that you could get some values in your input record have leading spaces?

Your use of *TRIM is not necessary, and consuming too much CPU time.

*TRIM, all by itself, removes both leading and trailing blanks (see options LEADING and TRAILING).

You are already removing leading blanks with the use of LEFT JUSTIFIED.

Removing trailing blanks, with fixed length target variables, does not do anything. There will be trailing blanks anyway.

So, run the program without the MOVE statements that use *TRIM. The output should be what you want, and the CPU usage should be about half (or less) what you used with *TRIM.

I was using *TRIM to truncate the dynamic length field into a potentially shorter length field. However, based on your responses I just did a quick little test program intentionally moving a longer dynamic field into a shorter fixed field and that handily truncated things for me without abending, as I had thought it would do. Thanks so much for the guidance!

I don’t know for sure that there wouldn’t be a performance impact, but wouldn’t the following be easier to code/read, instead of coding for 72 different variable names?


1 #SEPARATION-FIELDS (A/72) DYNAMIC
...
SEPARATE #INPUT-FILE LEFT JUSTIFIED INTO #SEPARATION-FIELDS (*) IGNORE WITH DELIMITERS '|'

Maybe I’m missing something because the example was made generic for posting the question.