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

EZT prog to print duplicate records in an output file


IBM Mainframe Forums -> CA Products
Post new topic   Reply to topic
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 02, 2011 12:56 pm
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
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 02, 2011 3:07 pm
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
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Nov 02, 2011 3:54 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 02, 2011 4:01 pm
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: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 02, 2011 7:10 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 02, 2011 7:34 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Wed Nov 02, 2011 7:58 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Nov 02, 2011 8:26 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CA Products

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top