View previous topic :: View next topic
|
Author |
Message |
Shaheen Shaik
New User
Joined: 05 May 2016 Posts: 13 Location: India
|
|
|
|
Hi, I need to perform addition of a column in a file by selecting only for some records. for example
Code: |
empid salary location dept
12345 2900 Noida hr
12342 2348 Noida it
12398 1237 Mumbai cs
12378 12788 Mumbai it |
my output file should contain only one record with dept it and salary is the some of all it employes
output has to be
dept salary
[Please (added by moderator)] tell me basic way of doing this using sort card.
(Coded by moderator) |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Please present your data, code, JCL (anything you see on your screen really) using the code tags. This preserves spacing. Reading other posts on this forum you will have noticed this requirement. As it happens, you seem to have mangled your data: I have tried to align it as much as possible but I do not know if your salary field is left or right justified.
Also, do not demand an answer: the simple addition of the word "Please" is sufficient to keep people on your side.
Please provide the field (not column) start, length and data type. |
|
Back to top |
|
|
Shaheen Shaik
New User
Joined: 05 May 2016 Posts: 13 Location: India
|
|
|
|
Thank you Nic. |
|
Back to top |
|
|
Shaheen Shaik
New User
Joined: 05 May 2016 Posts: 13 Location: India
|
|
|
|
field lengths :
empid 1-6 (numeric) , salary 7-12(numeric), location 12-32(character), dept 33-35(character). |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Use an INCLUDE COND= for the department you want, and OUTFIL reporting features with REMOVECC,NODETAIL and TRAILER1 with a TOT/TOTAL. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Bill, He can also do a sum fields and in outfil include only what for dept=it, or reporting feature is better?
Code: |
//SORTIN DD *
A 12
A 20
B 10
B 40
B 40
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,1,CH,A)
SUM FIELDS=(3,2,ZD)
OPTION ZDPRINT
OUTFILE INCLUDE=(1,1,CH,EQ,C'A') |
|
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
(To add to what Nic said) You should also preview before posting i.e. Preview and Read what you are going to post so that you can correct any mistakes in your statements before posting. You'll only be able to edit your post within 10 mins of posting and Not after that. Now, read this what you have posted:
Quote: |
salary is the some of all it employes |
If you are specifying a department name then you should write 'IT' instead of 'it'. You are talking about 'SUM' and Not 'some' and it should be 'Employees' and Not 'employes'.
Please keep in mind to use Preview.
. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Welcome!
Are you aware of Beginners forum? if not then go to the home page and look at left side and redirect basic questions there as it is designed for that purpose. |
|
Back to top |
|
|
Abid Hasan
New User
Joined: 25 Mar 2013 Posts: 88 Location: India
|
|
|
|
To Rohit,
Bill's method is more efficient in the way that INCLUDE COND will remove the unwanted dept. records; which would reduce the load off the TOT.
Remaining OUTFIL functions are there to trim the data in the desired form.
SUM will definitely work, but it'll first work on the entire file first summing the fields considering each record, post which the OUTFIL INCLUDE will do trimming, which is a wastage of resource if the file is fairly large. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
yes I agree and my intention was checking upon sum fields vs tot function, but then we can do include first then sum fields and then use outrec fields as required. |
|
Back to top |
|
|
Abid Hasan
New User
Joined: 25 Mar 2013 Posts: 88 Location: India
|
|
|
|
Urmmm, fwiw, the trick lies somewhere else; by definition SUM requires the records to be sorted first on 'a key', fields of which are to be summed; whereas TOT doesn't have that limitation; meaning, it is similar to a COBOL program where one updates the summation buckets as and when the required field's criteria matches, without having to worry about where the record is occurring. Hence I feel TOT is still better.
But I'd still want to hear from Bill on this one. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Unless the data already requires SORTing, it is a waste of resources to use SUM. Even if you do that for a small amount of data, there can be someone (and it may be you) will copy those SORT control cards later.
Using the OUTFIL reporting features, there is no need to SORT. There are also many other things available than TOT and COUNT for when you need them. |
|
Back to top |
|
|
Shaheen Shaik
New User
Joined: 05 May 2016 Posts: 13 Location: India
|
|
|
|
Thank you all for your answers. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Bill, One question in this case does it require to do sort when we only deal with single category i.e. 'IT/it' records or DFSORT smart enough to know not to do sorting here after include? if not then , is there a way we let DFSORT know that to opt out for the sorting in such situations as there is only record all the time in SORTOUT? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you use a SORT statement, DFSORT is smart enough to do what it is told.
You may think it smarter that it "knows" there's only one type of record, from the INCLUDE/OMIT COND=, but it would have to do that "knowing" for each and every SORT step around the planet. The extra code to do something that may seem useful would rack up CPU (even if not much for any given step) when all you have to do to avoid it is not code the SORT unless you actually need to SORT. |
|
Back to top |
|
|
|