IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to declare copybook having layout for 2 files in FD sect


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
santhunaveen

New User


Joined: 22 Sep 2006
Posts: 33

PostPosted: Mon Sep 15, 2008 12:23 pm
Reply with quote

Hi,

one copybook is having layout for record....

in my program i want to use same copybook for 2 files...in FD file section..how can i declare copybook for 2 files...copybook should not be declared 2 times in program...can anyone tell how can I achieve this....
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Sep 15, 2008 12:55 pm
Reply with quote

Hi,

This
Quote:
copybook should not be declared 2 times in program
needs clarification, copybook is invoked in COBOL by the COPY statement, which has two forms:

COPY text-name.
COPY text-name REPLACING item-1 BY item-2.

aren't these what you want to use..? If not please provide some more details..
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Mon Sep 15, 2008 12:57 pm
Reply with quote

Hi,

As you know, you cann't use copybook twice in a program because compiler will throw error..right!!!!

ONE WAYS IS
----------------

So use same copybook by replacing Working storage variable with different name

Consider a layout

01 WS-EMP-DETAILS.
02 WS-EMP-ID PIC X(05).
02 WS-EMP-NAME PIC X(20).
02 WS-EMP-SAL PIC S9(05)V99.

NOW REPLACE WS-EMP BY EMP FOR ANOTHER FILE LAYOUT AND HANDLE IT IN PROGRAMTICALLY...

BY FALLOWING VERB

COPY <EMP COPYBOOK> REPLACING ==WS-EMP== BY ==EMP==.

Hope this helps
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Sep 15, 2008 5:56 pm
Reply with quote

Revel,

what cobol are you using?

COBOL 2 and COBOL 3 on the mainframe will not replace as you said.

I believe you suggestion is not true.


santhunaveen,

I would suggest using copy REPLACING WS-EMP-DETAIL by WS-EMP-FILE-1
and in the second FD
REPLACING WS-EMP-DETAIL by WS-EMP-FILE-2

and then use reference qualification to access the elementary item:
e.g.
WS-EMP-ID IN WS-EMP-FILE-1
and
WS-EMP-ID IN WS-EMP-FILE-2.

I would further suggest you use the work-area option and not reference the FD data areas;
the copybooks would then be in WORKING-STORAGE and not in the FILE SECTION.
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Mon Sep 15, 2008 6:33 pm
Reply with quote

Hi DICK,

I have used that VERB in application, It works fine for me...

What you said is another way of doing; you are only changing group data item by another data item; the problem with this approach is use of elementary data item in application program

ie to use WS-EMP-ID in application pgm we need verb like

Code:
WS-EMP-ID IN WS-EMP-FILE-1
               or
WS-EMP-ID OF WS-EMP-FILE-1



Code:
01 WS-EMP-DETAILS.               -----    group data item.
    02 WS-EMP-ID            PIC X(05).
    02 WS-EMP-NAME       PIC X(20).
    02 WS-EMP-SAL          PIC S9(05)V99.


Instead of replacing only one data item ie GROUP DATA ITEM

i suggest him to replace part of data item with another ward so that he can make use of layout for 2 file easily.

ie WS-EMP to EMP
===============================================
one more suggestion

You are replacing only group item in a copybook;

instead exclude GROUP Item in a copybook and have it in Application pgm

ie in a COPYBOOK

Code:
    02 WS-EMP-ID            PIC X(05).
    02 WS-EMP-NAME       PIC X(20).
    02 WS-EMP-SAL          PIC S9(05)V99.


In application pgm

For 1 FD; Have like
01 EMP-DETAILS-1.
COPY <copybook>

FOR 2 FD; Have like
01 EMP-DETAILS-2.
COPY <copybook>

Hope i am on right path........ icon_smile.gif
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Mon Sep 15, 2008 7:01 pm
Reply with quote

Hi,

Please find link which is having details about COPY Verb

publib.boulder.ibm.com/infocenter/ratdevz/v7r1m1/index.jsp?topic=/com.ibm.etools.cbl.win.doc/topics/tppor03.htm
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Mon Sep 15, 2008 7:24 pm
Reply with quote

Revel,
Generally copybooks are built to cater needs of more thn one program.
Changing copybooks to serve a single program is not advisable and should not be practiced.

Moreover most of the copybooks are built in a way to get easily used by programs.
So, they generally don’t start with 01 variable.

Santhunaveen, you can try this if the group variable in copybook is not starting with 01 level.

FD EMPFL1.

01 FD-EMP1.
COPY EMPSTMT REPLACING ==ws-emp== BY ==EMP1==.

FD EMPFL2.

01 FD-EMP2.
COPY EMPSTMT REPLACING ==ws-emp== BY ==EMP2==.

Or as dick has suggested ,use the work area to copy them.
In the FD section u can define entry as
01 FD-EMP1 pic x(length of the copybook).
01 FD-EMP2 pic x(length of the copybook).

And move the values "to or from" the working storage while writing or reading from the files, as per ur coding standards.

Cris
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Tue Sep 16, 2008 12:45 pm
Reply with quote

Cris,

Quote:
Generally copybooks are built to cater needs of more thn one program.
Changing copybooks to serve a single program is not advisable and should not be practiced.


I disagree with above statement, I come across handling this situation in my previous company ie there were 2 files which is having same type of layout so instead of creating 2 copybooks for 2 files; its better to replace part of data items with meaning full name so that that can handled it in application pgm very easily

More over we are not changing copybook physically right, we are doing it programatically so there is no question of ambiguity in application pgm.

Its not good coding practice to have different copybook for different files which as of same structure.

Example; Consider a 50 Files of same kind of Structure; Instead of having 50 copybooks its better to have 1 copybook and replace part of dataitems with meaning full name it in pgm and use it, we don't need to code 50 copybook right

Feed backs is welcomed.... icon_wink.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 16, 2008 2:12 pm
Reply with quote

Quote:

Feed backs is welcomed


it is either:

Feed back is welcomed

or

Feed backs are welcomed
Back to top
View user's profile Send private message
revel

Active User


Joined: 05 Apr 2005
Posts: 135
Location: Bangalore/Chennai-INDIA

PostPosted: Tue Sep 16, 2008 2:51 pm
Reply with quote

Dick,

Quote:
Feed backs are welcomed


Oops, its Typo dick ........ icon_wink.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 16, 2008 3:49 pm
Reply with quote

Attention to Detail!

that's why there is a 'PREVIEW' option in addition to the 'SUBMIT' option.

Sorry to pick on you, but I can't get a sub-portion of a reference name changed with the COPY REPLACING unless the sub-portion is TAGGED.
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Tue Sep 16, 2008 5:42 pm
Reply with quote

Revel,

At times we completely misunderstand the context when we are not communicating properly.
Quote:
Revel,
Generally copybooks are built to cater needs of more thn one program.
here i suggested the practice of using same copybook for different application programs/files.
Quote:
instead exclude GROUP Item in a copybook and have it in Application pgm

Possibly I miss understood it this time.
Quote:
Its not good coding practice to have different copybook for different files which as of same structure.

I never suggested that, moreover i have not seen this happening either.

Cris
Back to top
View user's profile Send private message
Baundra

New User


Joined: 06 Jul 2008
Posts: 1
Location: Mumbai

PostPosted: Tue Sep 23, 2008 5:01 pm
Reply with quote

As answered by Cris if the copybook is declared with 01 level then also we can use the replacement

Santhunaveen, you can try this if the group variable in copybook is starting with 01 level.

FD EMPFL1.

01 FD-EMP1.
COPY EMPSTMT REPLACING ==01 ws-emp== BY ==03 EMP1==.

FD EMPFL2.

01 FD-EMP2.
COPY EMPSTMT REPLACING ==01 ws-emp== BY ==03 EMP2==.

In the FD section u can define entry as
01 FD-EMP1 pic x(length of the copybook).
01 FD-EMP2 pic x(length of the copybook).

And move the values "to or from" the working storage while writing or reading from the files, as per ur coding standards.

Gaurav
Back to top
View user's profile Send private message
Joshna K

New User


Joined: 03 Aug 2007
Posts: 2
Location: Pune, India

PostPosted: Thu Jul 02, 2009 11:56 am
Reply with quote

I am facing a similar problem as to defining 2 copybooks in a single program.

EMPLOYEE COPYBOOK
--------------------------
03 EMP-NO PIC 9(10).
03 EMP-NAME PIC X(50).
03 EMP-DESIGNATIONS PIC X(30).


This is defined in LINKAGE SECTION.
02 EMP-DETAILS.
COPY EMPLOYEE.

This is defined in WORKING-STORAGE SECTION.
01 WA-EMP-DETAILS.
COPY EMPLOYEE REPLACING ==EMP== BY ==WA-EMP==.

After compilation, I got error as
EMP-NO not unique
EMP-NAME not unique
EMP-DESIGNATION not unique

FYI, this program is run on unix.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Jul 02, 2009 12:11 pm
Reply with quote

Change your copy book to
Code:
03 :TAG:-EMP-NO PIC 9(10).
03 :TAG:-EMP-NAME PIC X(50).
03 :TAG:-EMP-DESIGNATIONS PIC X(30).

and in WORKING-STORAGE SECTION use
Code:
01 WA-EMP-DETAILS.
COPY EMPLOYEE REPLACING ==:TAG:== BY ==WA==.

Try with above and check if it works.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Jul 02, 2009 12:29 pm
Reply with quote

Hi Anuj...

Is the concept specific to UNIX or the same will work in mainframes also ??
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Jul 02, 2009 1:46 pm
Reply with quote

Binop,

If by UNIX you are referring to MFCOBOL then 'am not sure -- I do not have experience with that.

It works with Enterprise COBOL. For other compilers, please have a look in Manulas.
Back to top
View user's profile Send private message
Joshna K

New User


Joined: 03 Aug 2007
Posts: 2
Location: Pune, India

PostPosted: Thu Jul 02, 2009 2:30 pm
Reply with quote

Hi,
Thanks for the reply.
I will not be able to change the copy book as it is being used by many programs.
Can you please suggest something that can be done in the program itself to resolve the issue.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 02, 2009 5:20 pm
Reply with quote

Have you looked up what the NOT UNIQUE message means? Hint: section 1.8.1.1 on Qualification in the COBOL Language Reference (manuals link at the top of the page) gives you what you need to know.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top