Modifying Variable-Length OCCURS Segments in VSAM

The VSAM Write Data Adapter supports both types of variable length records (e.g., OCCURS=fieldname and OCCURS=VARIABLE). You can issue INCLUDE, UPDATE, and DELETE statements in MODIFY procedures against these segments using standard MATCH and NEXT logic.

If you specify OCCURS=fieldname, FOCUS automatically updates that field each time occurrences are added or deleted. Do not include logic in your procedure for maintaining this field, or include a counter field as part of the transaction data.

Response may be better using the OCCURS=VARIABLE segment attribute because VSAM controls most of the processing. However, only one segment per data source can be defined this way and that must be the last segment in the Master File to ensure that FOCUS interprets the data correctly.

For some applications, OCCURS=fieldname may be more beneficial, because the counter is maintained by the MODIFY processing and you have flexibility for using more than one OCCURS segment.

You could use the following procedure to INCLUDE, UPDATE, OR DELETE data in variable-length records. It refers to the file VSAM3.

MODIFY FILE VSAM3
COMPUTE
IDTEMP/A9=;
LNTEMP/A15=;
CRTFORM LINE 1
"***************************************************"
"* RIVERDALE JUNIOR HIGH *"
"* STUDENT GRADES MAINTENANCE *"
"* *"
"* PLEASE ENTER THE FOLLOWING INFORMATION: *"
"* *"
"* STUDENT ID:<IDTEMP/09 *"
"* LAST NAME:<LNTEMP/15 *"
"* *"
"* ENTER=CONTINUE PFl=EXIT *"
"***************************************************"
COMPUTE
STUDENT=IDTEMP;
LAST_NAME=LNTEMP;
REPOSITION STUDENT
MATCH STUDENT
ON NOMATCH TYPE " NEW STUDENT: <STUDENT "
ON NOMATCH INCLUDE
ON NOMATCH GOTO NEWREC
ON MATCH TYPE " UPDATING STUDENT: <STUDENT "
ON MATCH GOTO OLDREC

The next section determines if the input is for a new or existing STUDENT. It displays a message and then branches to the appropriate case.

CASE NEWREC
COMPUTE
STUDENT=IDTEMP;
LAST_NAME=LNTEMP;
MATCH STUDENT
ON NOMATCH TYPE "IMPROPER CONDITION IN NEWREC"
ON NOMATCH REJECT
ON MATCH CRTFORM LINE 1 TYPE 3

The following CRTFORM displays students' last names and identification numbers. It then enables you to enter up to five occurrences of COURSE, GRADE, and QTR TAKEN data. The VSAM3 file is defined with a variable number of child segments.

"****************************************************"
"* RIVERDALE JUNIOR HIGH *"
"* *"
"* *"
"* LAST NAME:<D.ID FIRST NAME:D.FN <69 *"
"* *"
"* COURSE <25 GRADE <50 QUARTER_TAKEN <69 *"
"* ------ <25 ----- <50 ------------- <69 *"
"* <CN(00l) <25 <GRADE(00l) <50 <QTR_TAKEN(00l) <69 *"
"* <CN(002) <25 <GRADE(002) <50 <QTR_TAKEN(002) <69 *"
"* <CN(003) <25 <GRADE(003) <50 <QTR_TAKEN(003) <69 *"
"* <CN(004) <25 <GRADE(004) <50 <QTR_TAKEN(004) <69 *"
"* <CN(005) <25 <GRADE(005) <50 <QTR_TAKEN(005) <69 *"
"* *"
"* *"
"* ENTER=UPDATE PFl=EXIT PF2=HOME *"
"****************************************************"

A MATCH is done on the COURSE field. If there is no COURSE information, the occurrence is loaded with the new data, updating the existing course data.

ON MATCH UPDATE FN
ON MATCH REPEAT 5 TIMES
GETHOLD
ACTIVATE COURSE GRADE QTR_TAKEN
IF COURSE EQ ' ' THEN GOTO EXITREPEAT;
MATCH COURSE
ON MATCH UPDATE GRADE QTR_TAKEN
ON MATCH GOTO ENDREPEAT
ON NOMATCH INCLUDE
ON NOMATCH GOTO ENDREPEAT
ENDREPEAT
GOTO TOP
ENDCASE

If the student is in the file, processing continues with the OLDREC case, where we hold existing COURSE data in the Scratch Pad Area. The procedure can be repeated up to five times because a variable number of segment occurrences are anticipated.

CASE OLDREC
COMPUTE
DELT/Al=' ';
MATCH STUDENT LAST NAME
ON NOMATCH TYPE "IMPROPER CONDITION IN OLDREC"
ON NOMATCH REJECT
ON MATCH REPEAT 5 TIMES
NEXT COURSE
ON NEXT HOLD COURSE GRADE QTR_TAKEN DELT
ON NEXT GOTO ENDREPEAT
ON NONEXT GOTO EXITREPEAT
ENDREPEAT

To delete a course, type a D in the field DELT on the CRTFORM.

"****************************************************"
"* RIVERDALE JUNIOR HIGH *"
"* *"
"* *"
"* LAST NAME:<D.ID FIRST NAME:D.FN <69 *"
"* *"
"* COURSE <25 GRADE <50 QUARTER_TAKEN <66D <69 *"
"* ------ <25 ----- <50 ------------- <66- <69 *"
"* <T.CN(00l) <25 <T.GRADE(00l) <50 <T.QTR_TAKEN(00l)<66 <T.DELT(001*"
"* <T.CN(002) <25 <T.GRADE(002) <50 <T.QTR_TAKEN(002)<66 <T.DELT(002*"
"* <T.CN(003) <25 <T.GRADE(003) <50 <T.QTR_TAKEN(003)<66 <T.DELT(003*"
"* <T.CN(004) <25 <T.GRADE(004) <50 <T.QTR_TAKEN(004)<66 <T.DELT(004*"
"* <T.CN(005) <25 <T.GRADE(005) <50 <T.QTR_TAKEN(005)<66 <T.DELT(005*"
"* *"
"* ENTER=UPDATE PFl=EXIT PF2=HOME *"
"****************************************************"

This section updates the segment if data is marked for deletion and then branches to case DELCASE.

ON MATCH UPDATE FN
ON MATCH REPEAT 5 TIMES
GETHOLD
ACTIVATE COURSE GRADE QTR_TAKEN
IF COURSE EQ ' ' THEN GOTO EXITREPEAT;
MATCH COURSE
ON MATCH UPDATE GRADE QTR_TAKEN
ON MATCH IF DELT EQ 'D' THEN PERFORM DELCASE;
ON MATCH GOTO ENDREPEAT
ON NOMATCH INCLUDE
ON NOMATCH GOTO ENDREPEAT
ENDREPEAT
GOTO TOP
ENDCASE

This section deletes a child segment.

CASE DELCASE
ACTIVATE COURSE GRADE QTR_TAKEN
MATCH COURSE
ON MATCH DELETE
ON MATCH TYPE " COURSE: <COURSE DELETED "
ON NOMATCH REJECT
ENDCASE
DATA VIA FIDEL
END

Information Builders