Same Copybook

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
mainframesara
Member
Posts: 13
Joined: Mon Oct 26, 2009 12:00 pm

Same Copybook

Post by mainframesara » Mon Dec 07, 2009 10:36 am

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.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

COPY REPLACING in COBOL

Post by Natarajan » Mon Dec 07, 2009 11:35 am

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

Code: Select all


05  &#58;V1&#58;-EMPLOYEE. 
      10 &#58;V1&#58;-EMP-NO       PIC 9&#40;6&#41;.  
      10 &#58;V1&#58;-EMP-NAME PIC X&#40;30&#41;.



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 ==&#58;V1&#58;== BY ==INPUT==.

01 OUTPUT-FILE
     COPY CPYBK1  REPLACING ==&#58;V1&#58;== BY ==OUTPUT==.
Natarajan
Chennai

mainframesara
Member
Posts: 13
Joined: Mon Oct 26, 2009 12:00 pm

Post by mainframesara » Mon Dec 07, 2009 12:35 pm

Thanks Natarajan.

Post Reply

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



Other References
Mainframe Tools and others