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

Position (count) of a record


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Tue Aug 28, 2012 10:27 pm
Reply with quote

Hi,

Is it possible to get the position of a particular record using syncsort or any utility?


E.G,

Code:


a
b
c
d
e
f


Position of d in the above file is 4. 'D' is the fourth record, 'e' is the fifth record.

Sorry, if this is a silly question. I tried sum fields but i am able to the number of occurences of a particular record.

Can you help?
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: Tue Aug 28, 2012 10:41 pm
Reply with quote

You want to know the particular "record number" of a selected record?

COPY operations.
INREC with WHEN=INIT, OVERLAY at end of record, for fixed, or BUILD at begining, for variable, a sequence number big enough for all the records on the file. Identify those records NOT the one you want (WHEN=(logexp), and OVERLAY the sequence number to zero.

OUTFIL OMIT those which are zero. The only one left is the record you want, with the its sequence number.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Tue Aug 28, 2012 11:49 pm
Reply with quote

Thanks Bill. I got the idea but didn't get hold on the syntax. I have not used most of these.

I will try to test this and post it in forum.
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 Aug 29, 2012 12:03 am
Reply with quote

This one can give you a start.

Leads to something like this.

Code:
 SORT FIELDS=COPY                                             
 INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,7,ZD)),           
       IFTHEN=(WHEN=(pos,len,type,NE,C'your criteria'),OVERLAY=(81:C'0000000')
 OUTFIL OMIT=(81,7,ZD,EQ,0)


I've knocked that up quickly, and it is not tested, but around about what you are after. Gives you a chance to consult the manual and understand anything you don't already know how to use.

This is for a fixed-length 80-byte record. For a different fixed-length, change appropriately.

For variable, change first OVERLAY to BUILD=(1,4,SEQNUM,7,ZD,5) and change the 81's in the other OVERLAY and OMIT to 5.

The 7 in the SEQNUM allows for just under 10m records. Adjust appropriately to your file.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Wed Aug 29, 2012 10:23 pm
Reply with quote

Awesome, It is working. Thanks Bill.
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 Aug 29, 2012 11:06 pm
Reply with quote

No problem. Perhaps you can post the working code, as it can then help someone with a similar problem in the future.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Thu Aug 30, 2012 12:21 am
Reply with quote

Below is the sort card that worked.

Code:

SORT FIELDS=COPY                                             
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,7,ZD)),           
      IFTHEN=(WHEN=(1,3,CH,NE,C'555'),OVERLAY=(81:C'0000000'))
OUTFIL OMIT=(81,7,ZD,EQ,0)                                   


My file is LRECL = 80,FB and the data in the file is given below,

Code:

111
222
333
444
555
666
777
888
999


Output is given after the job execution is given below,
Code:

555                                                                      0000005


Note: 555 is the fifth record in the file and the sequence number in the output is 5.

Complete job below,


Code:

//JOBTEST JOB ('4935-000000-00-A-00000000000'),               
// 'TEST',CLASS=V,MSGCLASS=A,MSGLEVEL=1,NOTIFY=&SYSUID   
//*                                                             
//COPY EXEC PGM=SYNCSORT                                       
//SORTIN DD DSN=FILSM.TEST.FILE,DISP=SHR                       
//SORTOUT DD SYSOUT=*                                           
//SYSPRINT DD SYSOUT=*                                         
//SYSOUT   DD SYSOUT=*                                         
//SYSDUMP DD SYSOUT=*                                           
//SYSIN DD *                                                   
  SORT FIELDS=COPY                                             
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,7,ZD)),           
        IFTHEN=(WHEN=(1,3,CH,NE,C'555'),OVERLAY=(81:C'0000000'))
  OUTFIL OMIT=(81,7,ZD,EQ,0)                                   
/*                                                             
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: Thu Aug 30, 2012 4:26 am
Reply with quote

Just got a friendly kicking. There is a better way.

Code:
  SORT FIELDS=COPY                   
  INREC OVERLAY=(81:SEQNUM,7,ZD)     
  OUTFIL INCLUDE=(1,3,CH,EQ,C'555')


This is also easier if you need more flexibility, like more than one "key value" to search for.

Note you can use SS if you want to find a string somewhere.

You could also use it to exclude a selected record(s) from a file, with another OUTFIL with SAVE for all the other stuff on the original file, with a little reassurance of knowing the record number(s) dropped.
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts To get the count of rows for every 1 ... DB2 3
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top