Hi,
Is it possible to use the same copybook for both the input and output files in the cobol program.
If so, can you please tell where to declare that copybook.
Thanks in advance.
Same Copybook
Moderators: dbzTHEdinosauer, Moderator Group
COPY REPLACING in COBOL
Option 1 - simple way of doing..
It is possible.... copybook can be included in the program using COPY statement.
once we include copy book in the program.. while reading data from input file use READ INTO.. copybook.. group item name....
and .. while writing into outputfile... use WRITE FROM.. copy book group item name...
Option 2 - using same copy book & replace the prefix, while copying the copy book
multiple times in the same program.
While using COPY <copybook name> .... make sure you use REPLACING option along with this...
Here is the example...
You copy book...
CPYBK1
In the program... you can use this copy book as many time you want.
But you need to replace :V1: with different name so that you wont get
compiler error saying... duplicate names defined.
ok.. since you want to define same copy book for input and output file...
do this.
copy the same copy book for input & output files as follows..
It is possible.... copybook can be included in the program using COPY statement.
once we include copy book in the program.. while reading data from input file use READ INTO.. copybook.. group item name....
and .. while writing into outputfile... use WRITE FROM.. copy book group item name...
Option 2 - using same copy book & replace the prefix, while copying the copy book
multiple times in the same program.
While using COPY <copybook name> .... make sure you use REPLACING option along with this...
Here is the example...
You copy book...
CPYBK1
Code: Select all
05 :V1:-EMPLOYEE.
10 :V1:-EMP-NO PIC 9(6).
10 :V1:-EMP-NAME PIC X(30).
In the program... you can use this copy book as many time you want.
But you need to replace :V1: with different name so that you wont get
compiler error saying... duplicate names defined.
ok.. since you want to define same copy book for input and output file...
do this.
copy the same copy book for input & output files as follows..
Code: Select all
01 INPUT-FILE
COPY CPYBK1 REPLACING ==:V1:== BY ==INPUT==.
01 OUTPUT-FILE
COPY CPYBK1 REPLACING ==:V1:== BY ==OUTPUT==.
Natarajan
Chennai
Chennai
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page