Search code examples
cobol

Manipulating input data to function in LINKAGE SECTION instead of Working Storage


IN COBOL (regardless of the implementation or platform), is it bad to do something like this in a user defined function?

IDENTIFICATION DIVISION.
       FUNCTION-ID. FF.    
LINKAGE SECTION.
    01   TXT     PIC X(100).
    01   RESULTS PIC X(100).
    PROCEDURE DIVISION
                               USING          TXT
                               RETURNING      RESULTS.
                  MOVE FUNCTION TRIM(TXT)  TO TXT.

While this code works (at least where i tested it), I am not sure that modifying the input data is a good idea. For example one could create a Working-Storage field and use it instead but this would add more size to the executing program specially if many such fields exist. Of course the manipulated data in the input will not be communicated back to the caller. It is only for logical operations within the function.

Your suggestion is appreciated.


Solution

  • This completely depends on how your function is defined and documented, and is not very specific to COBOL.

    It also applies to the "common" CALL's (but in this case the programmer can explicit request BY CONTENT to ensure that the data passed is a copy and therefore not changed in the calller).