View previous topic :: View next topic
|
Author |
Message |
santhunaveen
New User
Joined: 22 Sep 2006 Posts: 33
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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........ |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
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 |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
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.... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Feed backs is welcomed
|
it is either:
Feed back is welcomed
or
Feed backs are welcomed |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Dick,
Quote: |
Feed backs are welcomed |
Oops, its Typo dick ........ |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
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 |
|
|
Baundra
New User
Joined: 06 Jul 2008 Posts: 1 Location: Mumbai
|
|
|
|
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 |
|
|
Joshna K
New User
Joined: 03 Aug 2007 Posts: 2 Location: Pune, India
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Anuj...
Is the concept specific to UNIX or the same will work in mainframes also ?? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Joshna K
New User
Joined: 03 Aug 2007 Posts: 2 Location: Pune, India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|