C$PARAMSIZE

This routine returns the number of bytes actually passed by the caller for a particular parameter.

Usage

CALL "C$PARAMSIZE" 
    USING PARAM-NUM, 
    GIVING PARAM-SIZE

Parameters

PARAM-NUM numeric parameter This value is the ordinal position in the Procedure Division's USING phrase of the parameter whose size you want to know.
PARAM-SIZE any numeric data item This item receives the number of bytes in the data item actually passed by the caller.

Description

This routine returns the actual size (in bytes) of a data item passed to the current program by its caller. You pass the number (starting with 1) of the data item in the Procedure Division's USING phrase, and C$PARAMSIZE will return the size of the corresponding item that was actually passed. This can be useful for handling data items of unknown size.

For example, suppose that you wanted to write a routine that could convert any data item to upper-case, up to 10000 bytes in size. This routine could look like this:

IDENTIFICATION DIVISION.
PROGRAM-ID.  MAKE-UPPERCASE.

DATA DIVISION.
WORKING-STORAGE SECTION.
77  PARAM-SIZE    PIC 9(5).

LINKAGE SECTION.
77  PASSED-ITEM   PIC X(10000).

PROCEDURE DIVISION USING PASSED-ITEM.
MAIN-LOGIC.
   CALL "C$PARAMSIZE" USING 1, GIVING PARAM-SIZE
   INSPECT PASSED-ITEM( 1 : PARAM-SIZE ) 
      CONVERTING "abcdefghijklmnopqrstuvwxyz" 
      TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  EXIT PROGRAM.

In this example, if you do not use C$PARAMSIZE, you have to pass a full 10000 bytes to this routine or you get a memory usage error. By using C$PARAMSIZE and reference modification, only the memory actually passed is referenced, and there is no error. C$PARAMSIZE works only when the program is a called subroutine. It does not work with the "CALL RUN" form of the CALL verb.

If you pass a subitem of a linkage item in a CALL statement and the subprogram calls C$PARAMSIZE with requesting the size of the parameter, it will get the size as described in the linkage section of the calling program, unless that subitem is the first item of the linkage item. In that case, the size returned will be the size of the original item.