Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

EZT prog to print duplicate records in an output file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CA Products
View previous topic :: :: View next topic  
Author Message
grayWolf

New User


Joined: 04 Oct 2010
Posts: 19
Location: Land of broken dreams

PostPosted: Wed Nov 02, 2011 12:38 pm    Post subject: EZT prog to print duplicate records in an output file
Reply with quote

Hi All,
We got a requirement to write all the duplicate records from the input file into an output file using Eztrieve.

Input file layout:

101001ABCDXYZQWERTY
102002GHJJRWQWEWTUY
102002ASDSGFHRJKNXZ
102002AGHHASDHHHJDF
103004BNVBNGNDDFGSF

First 3 bytes -> Department number
Second 3 bytes -> Stock number

If there are duplicates with respect to the Dept number/Stock number combination, we are supposed to write those records into an output file.
In the example above, since 102/002 is repeated 3 times, we must write these 3 records into an output file.

The logic that we followed is as follows:

1) Read the file
2) Move the file variables into Working storage variables
3) read the file
4) If the present record is equal to the previous record, write it into the output file.

So in my logic, only 1 record is written into the output file if there are TWO records as duplicates.

Please let me know what should be the logic that has to followed in case I need to write all the duplicates into the output file.
For example if there are 100 records as duplicates, all the 100 records should be in the Output file.


Thanks!
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Nov 02, 2011 12:56 pm    Post subject: Reply to: EZT prog to print duplicate records in an output f
Reply with quote

This is not really an Easytrieve question, it is "language independent" logic.

From what you have shown, I don't know why you don't get them all.


Code:
if it is the first time, store the keys for matching and continue as normal

normal: until end of file
if current keys equal to stored keys, write record, otherwise store keys
read a record

end of file:
this time, nothing else to do for this requirement


You could of course include counts of duplicates (in which case you'd have something in end of file for last set of duplicates as well as outputting the results), and would of course have the standard input/output counts (in Easytrieve, from Easytrieve!).
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Nov 02, 2011 12:57 pm    Post subject:
Reply with quote

answer not appropriate, deleted by DBZ
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Nov 02, 2011 2:23 pm    Post subject:
Reply with quote

maybe this:

dupped = ""
save_area = ""
save_key = ""

LOOP:

read record

if EOF
  • if dupped = "Y"
    • write save_area
    • END-OF-JOB

if save_key = record_key
  • write save_area
  • dupped = "Y"

if save_key not = record_key
  • if dupped = "Y"
    • write save_area
    • dupped = ""


move record to save_area
move record_key to save_key

GOTO LOOP
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Nov 02, 2011 3:07 pm    Post subject: Reply to: EZT prog to print duplicate records in an output f
Reply with quote

There's me wondering why dbz has all that stuff in, so I go back and look, and yes you need the record it is duplicating against as well. icon_redface.gif

So, all "one behind", store the whole record, and remember to check for the last stored one to write at the end of processing, or when encountering the first duplicate, write out the one that it duplicates, then the duplicate, then again no need for extra at end of file.
Back to top
View user's profile Send private message
grayWolf

New User


Joined: 04 Oct 2010
Posts: 19
Location: Land of broken dreams

PostPosted: Wed Nov 02, 2011 3:22 pm    Post subject: Re: Reply to: EZT prog to print duplicate records in an outp
Reply with quote

Bill Woodger wrote:
This is not really an Easytrieve question, it is "language independent" logic.


I had explicitly mentioned Easytrieve because I didn't want an answer with SORT icon_biggrin.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Nov 02, 2011 3:46 pm    Post subject:
Reply with quote

Quote:
So, all "one behind", store the whole record, and remember to check for the last stored one to write at the end of processing, or when encountering the first duplicate, write out the one that it duplicates, then the duplicate, then again no need for extra at end of file.


problem with that, if you have 3 dups for a key, you will write more than 3 records

Gray Wolf,

SORT is a Utility, not a programming language.
besides, Bill was saying, that it is not an solution isolated to Eztrieve.
complaining about that and your only comment being what it was,
causes me to refrain from posting anything helpful to your rookie questions in the future.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Wed Nov 02, 2011 3:54 pm    Post subject: Reply to: EZT prog to print duplicate records in an output f
Reply with quote

Quote:
I had explicitly mentioned Easytrieve because I didn't want an answer with SORT
horse manure

a <tool> should be chosen based on the available skills and competence.

if You do not have it, choose a different tool

anyway.. the logic about duplicates is usually learned at a very basic level of training
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Nov 02, 2011 4:01 pm    Post subject:
Reply with quote

dbzTHEdinosauer wrote:
Quote:
So, all "one behind", store the whole record, and remember to check for the last stored one to write at the end of processing, or when encountering the first duplicate, write out the one that it duplicates, then the duplicate, then again no need for extra at end of file.


problem with that, if you have 3 dups for a key, you will write more than 3 records

[...]


Yes, I'm making an unclear distinction between the "original" record and the "duplicates".

When you have one duplicate (ie itself and the original) you know to write out both (the original and the duplicate), in the correct order. On susequent duplicates for that key, you only need to write out the duplicate.

Mr Woolf, if you include "I don't want to do it with sort" in your question, like any other information, it makes the flow easier.

Despite my twice pigsearing it, it is really easy :-)

Maybe easier to code than describe.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 02, 2011 7:10 pm    Post subject:
Reply with quote

Chapter 12 of the EZT Reference Guide 6.2 describes : Single File Keyed Processing.

Using Synchronized File Processing on a single file enables you to compare the
contents of a key field or fields from one record to the next and use IF tests to
group records according to the key fields. The file name is coded on the JOB
INPUT statement as follows:
JOB INPUT (filename KEY (keyfield...))
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Nov 02, 2011 7:34 pm    Post subject: Reply to: EZT prog to print duplicate records in an output f
Reply with quote

Perfect, Peter.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Nov 02, 2011 7:58 pm    Post subject:
Reply with quote

Hello,

What is the maximum number of duplicates possible for "a key"?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Wed Nov 02, 2011 8:26 pm    Post subject: Reply to: EZT prog to print duplicate records in an output f
Reply with quote

Quote:
Please let me know what should be the logic that has to followed in case I need to write all the duplicates into the output file.
For example if there are 100 records as duplicates, all the 100 records should be in the Output file.


pretty simple ...
here is a rexx prototype
Code:
#!/usr/bin/rexx

Address HOSTEMU "EXECIO * DISKR 'zdata.txt' ( stem data. finis "

prev = data.1
pend = 0
do  i = 2 to data.0
    curr = data.i
    if  curr = prev then do
        pend = 1
        say prev
        prev = curr
    end
    else do
        if  pend = 1 then do
            pend = 0
            say prev
        end
        prev = curr
    end
end
if  pend = 1 then ,
    say prev
exit

::requires hostemu LIBRARY


input

Code:
a
b
b
c
c
c
d
e
e
f
f
f
g
h
i
j
j
k
k
k


result

Code:
[enrico@enrico-mbp ztests]$./zdupl.rx
b
b
c
c
c
e
e
f
f
f
j
j
k
k
k


the logic is pretty simple
the assigment of data.X to prev and curr is the equivalent> of a read

the simple script can be modified easily to be tested under TSO
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CA Products All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us