COBOL VSAM Return Code: Here’s Example How to Define it

how to define vsam return codes
[how to define vsam return codes]

Many of the times COBOL file status code is different from VSAM file status code. Some times this question asked in interviews also.

How to define File status code for ESDS

In the ENVIRONMENT Division

For an ESDS:

SELECT file-name
 ASSIGN TO UT-AS-ddname
 ORGANIZATION IS SEQUENTIAL
 ACCESS MODE IS SEQUENTIAL
 FILE-STATUS IS data-name-1 data-name-2.
 Notes:

Notes:

The ORGANIZATION and ACCESS clauses are optional as the default is SEQUENTIAL

The PASSWORD clause is not used within Boots.

The FILE STATUS clause monitors the execution of each input-output request for the file. This clause is optional but when it is specified, the system moves a value into data-name-1 after each input-output request that explicitly or implicitly refers to this file. This field is defined in the Data Division (although not on the File Section) as a two-byte alphanumeric item and must not be the object of an OCCURS DEPENDING ON clause.

Data-name-2 can be coded in VS COBOL II programs to access native VSAM return code information to the COBOL program. This field must be defined as a group item of 6 bytes in the Working-Storage Section or Linkage Section of the Data Division. The first 2 bytes of data-name-2 contain the VSAM return code in binary notation. It can take a value of 0, 8, or 12. The next 2 bytes contain the VSAM function code in binary notation. The value for this code is defined as 1, 2, 3, 4, or 5.
The last 2 bytes of data-name-2 contain the VSAM feedback code again in binary. The code value is 0 through to 255.

The Function Code and Feedback Code are set only if the Return Code is set to non-zero. If they are set when the Return Code is zero, the contents of the fields are not reliable.

Example
SELECT VSAM-MASTER ASSIGN TO UT-AS-VSMAST
FILE STATUS IS STATUS-CODE VSAM-RETURN-CODE.

WORKING-STORAGE SECTION.
01 STATUS-CODE PIC XX.
01 VSAM-RETURN-CODE.
   05 VSAM-R15-RETURN-CODE PIC S99 COMP.
   05 VSAM-FUNCTION-CODE   PIC S9 COMP.
   05 VSAM-FEEDBACK-CODE   PIC S999 COMP

Also Read:

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.