Tuesday, March 07, 2006

Cobol : Trimming a field

Cobol doesn't support a trim function but you can get by by using:

WORKING-STORAGE SECTION.

01 InputString Pic X(20).

01 TrimString Pic X(20).

01 TrimCount Pic 9(2).

PROCEDURE DIVISION.


move 'poiuytrewq ' to InputString

move zero to TrimCount
inspect function reverse (InputString) tallying TrimCount for leading space
compute TrimCount = (length of InputString) - TrimCount
move InputString (1:TrimCount) to TrimString


Enjoy!

No comments: