I have a need to find the length of a text string - i.e. how long is the string before the start of the trailing spaces.
The code I've written does the job, but unfortunately the program, when executed, spends 40% of it's time with this section of code, and I want to make it perform more efficiently, if possible.
The program needs to evaluate several text fields of varying lengths. In order to do so, a working storage area called Text-Field PIC X(32760) is defined, with each text field to be evaluated moved there prior to the length check. Also known is the length of each field to be tested.
The code I'm using is below:
Compute WS-Pos = WS-Field-Length
Perform Varying WS-Pos from WS-Pos by -1
Until WS-Pos < 0
Or Text-Field(WS-Pos:1) Not = Space
End-Perform
The result I need will then be found in WS-Pos, which will be equal to the length of the data in the field, minus any trailing spaces.
I will note that before entering this code, the entire field is checked to see if it is equal to Spaces, so this code will not be executed if the field is all Spaces.
Another attempt at this used the Function Reverse to move the data into a separate string and then tally leading spaces to arrive at the number of spaces to subtract from the possible field length, but this proved less efficient that the code above.
Any suggestions would be appreciated!
The code I've written does the job, but unfortunately the program, when executed, spends 40% of it's time with this section of code, and I want to make it perform more efficiently, if possible.
The program needs to evaluate several text fields of varying lengths. In order to do so, a working storage area called Text-Field PIC X(32760) is defined, with each text field to be evaluated moved there prior to the length check. Also known is the length of each field to be tested.
The code I'm using is below:
Compute WS-Pos = WS-Field-Length
Perform Varying WS-Pos from WS-Pos by -1
Until WS-Pos < 0
Or Text-Field(WS-Pos:1) Not = Space
End-Perform
The result I need will then be found in WS-Pos, which will be equal to the length of the data in the field, minus any trailing spaces.
I will note that before entering this code, the entire field is checked to see if it is equal to Spaces, so this code will not be executed if the field is all Spaces.
Another attempt at this used the Function Reverse to move the data into a separate string and then tally leading spaces to arrive at the number of spaces to subtract from the possible field length, but this proved less efficient that the code above.
Any suggestions would be appreciated!