Previous Topic: $RECEIVED FunctionNext Topic: $RECSEGMENT Function


$RECLENGTH Function

This function is used with VSAM records to determine the length of the current record. You can use the $REC‑LENGTH function as the source of data in any statement, provided that a record was read before the statement is encountered.

This function has the following format:

$REC‑LENGTH(dataview‑name)
dataview‑name

The name of a VSAM dataview. The dataview name is required for this function.

In the scope of a FOR EACH or FOR FIRST statement, the value of the $REC‑LENGTH function is the length of the current record. If $REC‑SEGMENT (see the $REC‑SEGMENT function that follows) is reset in the FOR statement, the value of $REC‑LENGTH changes to the length of the record with the new variable segment. When used with an OCCURS DEPENDING ON clause, the value of $REC‑LENGTH actually changes after the ENDFOR when the record was written.

In the scope of a FOR NEW statement, the value of the $REC‑LENGTH function is the maximum length of the record until a new length is set by changing the value of the $REC‑SEGMENT function or when the ENDFOR is reached.

You can only use the $REC‑LENGTH function as the source of data in a CA Ideal statement. You cannot use it as the left operand in a WHERE clause of a FOR statement.

You can use the $REC‑LENGTH function whenever the fields in a dataview can be used. The function has no value before a record is read, after a record is deleted, and if a WHEN DUPLICATE or WHEN NONE condition is encountered. An attempt to access the function in these circumstances causes a run‑time error.

When updating an ESDS data set, you cannot actually change the length of an existing record; however, the $REC‑LENGTH function returns the value that is correct for the $REC‑SEGMENT used to write the record. When the new length is shorter than the original record length, the unused part of the record is filled with binary zeroes. If the new length is longer than the original length, a run‑time error occurs.

Example

The following example shows how you can use $REC‑LENGTH to determine the record type of a variable‑segment ESDS record that does not include a fixed‑length segment. A SELECT construct tests the length of each input record and executes the appropriate procedure for that record type.

FOR EACH PSS‑MASTER
    SELECT FIRST ACTION
      WHEN $REC‑LENGTH(PSS‑MASTER) = 110
        DO PROCESS‑UPGRADE
      WHEN $REC‑LENGTH(PSS‑MASTER) = 72
        DO PROCESS‑LOAN
      WHEN $REC‑LENGTH(PSS‑MASTER) = 95
        DO PROCESS‑CHECK
      WHEN ANY
        DO PROCESS‑SUMMARY
      WHEN NONE
        DO PROCESS‑ERRORS
    ENDSELECT
ENDFOR