Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to count the number of times key changed using DFSORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
vnktrrd

New User


Joined: 12 Jan 2010
Posts: 34
Location: New York

PostPosted: Thu Nov 15, 2018 9:19 pm    Post subject: How to count the number of times key changed using DFSORT
Reply with quote

Hi,

Thanks in advance for your support. Here is my requirement :

I have a file like below with first 4 characters as key.
AAAA
AAAA
BBBB
BBBB
BBBB
CCCC
AAAA
BBBB
BBBB
CCCC
CCCC
DDDD
DDDD
DDDD

I want a count of number of times the key changed. Count for above example is 6.

Please let me know how to do this in DFSORT.

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

Arun Raj

Moderator


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

PostPosted: Thu Nov 15, 2018 10:32 pm    Post subject:
Reply with quote

vnktrrd,

If you have DFSORT, post your queries in the DFSORT forum.

One way to achieve this is, use WHEN=GROUP and KEYBEGIN, to add group IDs, then in the output write the last record using OUTFIL TRAILER1. This record will have the number of groups - 7 as per your example.
This can be tweaked to arrive at the result - 6. Good luck
Back to top
View user's profile Send private message
vnktrrd

New User


Joined: 12 Jan 2010
Posts: 34
Location: New York

PostPosted: Thu Nov 15, 2018 11:53 pm    Post subject:
Reply with quote

Hi Arun,

Would you please elaborate ?

Thanks.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Fri Nov 16, 2018 12:12 am    Post subject:
Reply with quote

Assign group-id for each group as below.
Code:
AAAA 00000001
AAAA 00000001

BBBB 00000002
BBBB 00000002
BBBB 00000002

CCCC 00000003

AAAA 00000004

BBBB 00000005
BBBB 00000005

CCCC 00000006
CCCC 00000006

DDDD 00000007
DDDD 00000007
DDDD 00000007
Subtract 1 from each group-id and write the last record to output.

Or assign a sequence number and restart when the key changes as below.
Code:
AAAA 00000001
AAAA 00000002

BBBB 00000001
BBBB 00000002
BBBB 00000003

CCCC 00000001

AAAA 00000001

BBBB 00000001
BBBB 00000002

CCCC 00000001
CCCC 00000002

DDDD 00000001
DDDD 00000002
DDDD 00000003
Write the sum/count of 1's - 1 to output.
Back to top
View user's profile Send private message
sergeyken

Active User


Joined: 29 Apr 2008
Posts: 388
Location: Maryland

PostPosted: Fri Nov 16, 2018 1:21 am    Post subject:
Reply with quote

The TS wanna get the ready-to-use code, to copy-paste it into his project.
The task is equivalent to an exercise for a first year student.
Nowadays too many people don't want to read and understand the manuals. I'm not sure if they can read, at all?
Back to top
View user's profile Send private message
expat

Global Moderator


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

PostPosted: Fri Nov 16, 2018 12:34 pm    Post subject:
Reply with quote

To be honest, I'm a bit lost by the whole question.

There is no real explanation as to what is required, and there is no example of the expected output.

Just some advice, please learn quickly to explain what you need, in detail, giving examples of input / output where possible. You might understand exactly what it is that you need, but as I have said above. It took me two or three reads to finally work it out.

You also need to show what YOU have tried yourself, and the results given and the results expected. From your example above what did you expect out of the exercise.
You will almost certainly always be asked to provide what you have tried yourself.

Another important thing to remember is that there are such things called code tags - learn about them, and use them !!! After 33 posts I'm sure that you must have used them before, if at least not seen them used.

As sergeyken intimates, it seems that you want the ready to run code rather than make any effort yourself. Unfortunately a lot of us supposedly experts have a pretty accurate idea of when this is the case.

So, just some friendly advice >>> keep us happy, and ultimately ....... you happy.
Back to top
View user's profile Send private message
vnktrrd

New User


Joined: 12 Jan 2010
Posts: 34
Location: New York

PostPosted: Fri Nov 16, 2018 7:00 pm    Post subject:
Reply with quote

Hi All,

So many quick conclusions by the time I respond. Happy to see someone out there to help.

The output I expect out of the exercise is 6 which I gave in the first post and Arun seems to have understood it correct and have responded with what options of the Sort to use. Since I have very less experience working with the DFSORT, I requested him to elaborate the solution and not to post the code.

Finally, I understood what I have to do and will post the code as soon as I complete. Thanks again for all your support.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Fri Nov 16, 2018 9:23 pm    Post subject: Reply to: How to count the number of times key changed using DFSORT
Reply with quote

I tried to build Arun's first solution but I can't subtract 1 from last record.

Here is the code:
Code:

OPTION COPY                                           
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,4),PUSH=(6:ID=3))
OUTFIL REMOVECC,NODETAIL,                             
 TRAILER1=(6,3)                   



output is:
Code:
007


Does trailer not allow subtraction.

I get syntax error.
Code:
 TRAILER1=(6,3,SUB,+1)
                  £   
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Fri Nov 16, 2018 10:51 pm    Post subject:
Reply with quote

Quote:
subtract 1 from last record
I mentioned about subtracting 1 from each record and then write only the last one. Or you could try the other approach if that is easier.

SUB in TRAILER1 stands for subtotal and not subtraction, refer to the manual for more details on that.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Mon Nov 19, 2018 8:18 pm    Post subject:
Reply with quote

Thanks Arun. I have upgraded code to subtract 1 from each record.

Code:
OPTION COPY                                           
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,4),PUSH=(6:ID=3)),
IFTHEN=(WHEN=INIT,OVERLAY=(6,3,ZD,SUB,+1))
OUTFIL REMOVECC,NODETAIL,
 TRAILER1=(6,3)


It's not giving expected result because of OVERLAY line.

WHEN=INIT OVERLAY produces:
Code:
---+----1----+-
***************
              0
              0
              1
              1
              1
              2
              3
              4
              4
              5
              5
              6
              6
              6


I do not understand why is subtracted value shifting to 16th position, and also why is key part is cleared down. I understand OVERLAY only edits targeted column not entire record. Thanks.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Mon Nov 19, 2018 8:46 pm    Post subject:
Reply with quote

zh_lad wrote:
I do not understand why is subtracted value shifting to 16th position, and also why is key part is cleared down. I understand OVERLAY only edits targeted column not entire record
Your input field is just 4 bytes, but the result from arithmetic operation, in this case is 15 bytes with leading spaces by default, unless you use an EDIT. So the result is consistent with what you have provided in your control statements.

Please go through the DFSORT application programming guide for more details.
DFSORT Application Programming Guide wrote:
An arithmetic expression produces a signed, 31-digit zoned decimal (ZD) result to be edited as specified.
If an Mn, EDIT, or EDxy parameter is not specified, the result is edited using the M0 edit mask.
The default number of digits (d) used for editing is 15 if every term in the expression is one of the following:
v a 1-4 byte BI or FI field
v a 1-8 byte PD field
v a 1-15 byte ZD, FS, CSF, UFF or SFF field
v a decimal constant with 1-15 significant digits.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Mon Nov 19, 2018 9:07 pm    Post subject:
Reply with quote

Thanks Arun. I have changed my sort statement and used mask. This produces expected result.

Code:
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,4),PUSH=(6:ID=3))
SORT FIELDS=(6,3,ZD,D)                               
OUTFIL ENDREC=1,BUILD=(6,3,ZD,SUB,+1,M10,LENGTH=3)   



Code:
---
***
  6


Any suggestion, welcome. Thanks
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Mon Nov 19, 2018 9:16 pm    Post subject:
Reply with quote

Code:
SORT FIELDS=(6,3,ZD,D)
Sorting is not recommended when it is really not needed.
Back to top
View user's profile Send private message
zh_lad

Active User


Joined: 06 Jun 2009
Posts: 113
Location: UK

PostPosted: Tue Nov 20, 2018 5:11 pm    Post subject: Reply to: How to count the number of times key changed using DFSORT
Reply with quote

Fine. I have gone back to TRAILER1 option, added Mask and it work as expected.
Code:

OPTION COPY                                                   
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,4),PUSH=(6:ID=3)),       
      IFTHEN=(WHEN=INIT,BUILD=(1,5,6,3,ZD,SUB,+1,M10,LENGTH=3))
OUTFIL REMOVECC,NODETAIL,                                     
      TRAILER1=(6,3)                                           

Code:

---
***
  6


only doubt I have on order of IFTHEN statements. I thought WHEN=INIT won't give desired result (subtraction) as it will take precedence over GROUP.

Here is the text from SORT PDF:
IFTHEN clauses are processed in the following order:
- WHEN=INIT clauses and WHEN=GROUP clauses
- WHEN=(logexp) clauses and WHEN=ANY clauses
- WHEN=NONE clauses
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Tue Nov 20, 2018 9:16 pm    Post subject:
Reply with quote

zh_lad,

Thanks for posting.
Quote:
I thought WHEN=INIT won't give desired result (subtraction) as it will take precedence over GROUP
As you see, they are at the same level of precedence and you can have combinations of WHEN=GROUP and WHEN=INIT in any order.
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 -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To get the count of PDS data sets whi... Vignesh Sid JCL & VSAM 4 Fri Nov 30, 2018 8:38 pm
No new posts Need advise in calling DFSORT from REXX ajithajt CLIST & REXX 9 Thu Nov 29, 2018 10:50 am
No new posts How to handle different file length b... javen777 DFSORT/ICETOOL 15 Mon Nov 26, 2018 12:13 pm
No new posts Accessing control blocks to retrieve ... menonkiran COBOL Programming 5 Wed Nov 14, 2018 9:08 pm
This topic is locked: you cannot edit posts or make replies. DFSORT output in CSV for data spans i... hiravibk DFSORT/ICETOOL 3 Tue Nov 13, 2018 7:55 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us