Previous Topic: $RECLENGTH FunctionNext Topic: $REMAINDER Function


$RECSEGMENT Function

This function is used with variable‑segment VSAM records to specify which record type (which variable segment) to write. Although the function is primarily intended for use in the FOR NEW construct, you can also use it in a FOR EACH or FOR FIRST construct to change a record to a new record type.

This function has the following format:

$REC‑SEGMENT(dataview‑name) 
dataview‑name

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

You can only use the $REC‑SEGMENT function as the target of a SET statement, with the source (the value on the right of the equal sign) being the name of a level‑2 field that is one of the variable segments defined in the dataview. Since the field name, not the field content, is the value set, the field name must be enclosed in single or double quotes (' or “).

Examples

The following statement causes CA Ideal to write a record in the VSAM dataview named MASTER‑SUMMARY using the variable segment named TYPE1. TYPE1 is the name of a level‑2 group field defined in the MASTER‑SUMMARY dataview. Another variable segment, named TYPE2, redefines the TYPE1 group field.

FOR NEW MASTER‑SUMMARY
    …
    .
    .
    SET $REC‑SEGMENT(MASTER‑SUMMARY) = 'TYPE1'
ENDFOR

The next example shows how the $REC‑SEGMENT function changes the record type in a FOR EACH statement.

FOR EACH MASTER‑SUMMARY
   IF REC‑TYPE = 1
     THEN
       SET REC‑TYPE = 2
       SET $REC‑SEGMENT(MASTER‑SUMMARY) = 'TYPE2'
       statements             statements changing the record
    ENDIF
ENDFOR

The field named REC‑TYPE is tested first to determine which type of record was read. Then the record is changed, and finally, the $REC‑SEGMENT function changes the record type to the one that includes the variable segment named TYPE2. When the record is written at the ENDFOR statement, the record type is changed from 1 to 2, and the variable segment TYPE2 is written.