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

Remove duplicate record with condition


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Wed Jul 11, 2018 3:55 pm
Reply with quote

Hello All,
I have an input file of fixed length 300 characters, my activity is focused on two fields Order number and status code.

Code:
Order number                                    status code
(Position 25, length 7 characters)       (Position 102, length 3 characters)
Order1                                              020
Order1                                              025
Order2                                              020
Order3                                              025
Order4                                              020
Order4                                              025


If there are two records with same order number then I want to remove the record having status code “025”.So the output file should look like the below

Code:
Order number                                    status code
(Position 25, length 7 characters)        (Position 102, length 3 characters)
Order1                                              020
Order2                                              020
Order3                                              025
Order4                                              020


Note the input file is pre-sorted on order number and status code.
I tried few Sort options, but it was removing the first record which is associated with status code “020”.Any help is appreciated.

Regards,
Rajiv R

CODED
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

PostPosted: Wed Jul 11, 2018 3:59 pm
Reply with quote

Please show the code that you have used and did not give the required results.

Will there only ever be two records for each order, or more
Back to top
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Wed Jul 11, 2018 4:38 pm
Reply with quote

Yes your correct there can be only maximum two records with same order number, one with status code 020 and other with status code 025,of which the record with status code 025 needs to be removed.


Sorry i was testing with the presorted file,that's the reason it was deleting the record with status code 020.
I tried using sorted file and gives desired result.

The below are options i used

1) Option 1
Code:

//S2      EXEC PGM=ICEMAN
//SYSOUT  DD   SYSOUT=*
//SORTIN  DD   DSN=racfid.TEST.FCAST.UNSOLVD,DISP=SHR
//SORTOUT DD   DSN=racfid.TEST.FCAST.UNSOLVD.SORTED.ICEMAN,
//             DISP=(,CATLG),
//             SPACE=(CYL,(500,500),RLSE),
//             RECFM=FB,
//             LRECL=300
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(301:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(102,3,CH,EQ,C'025'),OVERLAY=(301:8C'0'))
  SORT FIELDS=(25,7,CH,A)
  SUM FIELDS=NONE
  OUTREC FIELDS=(1,300)
/*

2)Option 2:
Code:

//S3      EXEC PGM=SORT
//SYSOUT  DD   SYSOUT=*
//SORTIN  DD   DSN=racfid.TEST.FCAST.UNSOLVD.SORTED,DISP=SHR
//SORTOUT DD   DSN=racfid.TEST.FCAST.UNSOLVD.SORTED.SORT,
//             DISP=(,CATLG),
//             SPACE=(CYL,(500,500),RLSE),
//             RECFM=FB,
//             LRECL=300
//SYSIN    DD    *
  SORT FIELDS=(25,7,CH,A)
  SUM FIELDS=NONE
/*


3) Option 3:
Code:

//S4    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN      DD DSN=racfid.TEST.FCAST.UNSOLVD.SORTED,DISP=SHR
//FIRST   DD DSN=racfid.TEST.FCAST.UNSOLVD.SORTED.NODUP,
//         DISP=(,CATLG),
//         SPACE=(CYL,(500,500),RLSE),
//         RECFM=FB,
//         LRECL=300
//REST    DD DSN=racfid.TEST.FCAST.UNSOLVD.SORTED.DUP,
//         DISP=(,CATLG),
//         SPACE=(CYL,(500,500),RLSE),
//         RECFM=FB,
//         LRECL=300
//TOOLIN DD *
SELECT FROM(IN) TO(FIRST) ON(25,7,CH) FIRST DISCARD(REST)
/*

In all three options it worked fine,only i was using the presorted input file.
Thank you so much for intention to help.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

PostPosted: Wed Jul 11, 2018 5:12 pm
Reply with quote

Here's a quick snippet of code that may help you, NOT tailored to your needs because I'm busy right now, but may help you out

Use EXCLUDE instead of INCLUDE, also might work in conjunction with your writing 8 x 0 at pos 301
Code:

  OPTION  VLSHRT VLSCMP
  SORT    FIELDS=(29,44,A),FORMAT=CH
  OUTFIL  INCLUDE=(9,2,CH,EQ,C'M ',AND,
                29,44,SS,EQ,C'AB.L00T304A.LABEL'),
          OUTREC=(1,4,29,44,1X,233,6)


Good luck
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jul 11, 2018 10:10 pm
Reply with quote

If the file is already sorted on the 2 fields, you may not need to sort it again.

You could use a COPY override in your Option3. Or something like this in your Options1/2. [UNTESTED]
Code:
//SYSIN    DD *
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(25,7),
        PUSH=(301:SEQ=1))
  SORT FIELDS=COPY
  OUTFIL INCLUDE=(301,1,ZD,EQ,1),BUILD=(1,301)
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Record count of RECFM=U tape file DFSORT/ICETOOL 17
No new posts Revoke on DB2 to remove an user DB2 4
No new posts REMOVE DUPLICATE RECORDS BASED ON A S... DFSORT/ICETOOL 4
No new posts Checking the total counts inside a re... JCL & VSAM 5
This topic is locked: you cannot edit posts or make replies. Splice JCL into one record for DD sta... SYNCSORT 2
Search our Forums:

Back to Top