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

Suppress Zeros with SPACES in DFSORT


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

New User


Joined: 01 Oct 2010
Posts: 43
Location: Bangalore

PostPosted: Mon Jun 27, 2011 10:54 am
Reply with quote

Hi

I have an input file like the one given below

Code:

12345678901234567890
TOM     + 30  IBM     
SREE    + 40  CTS
TOM     - 10  IBM

And the output should be like

Code:

12345678901234567890
TOM     + 20  IBM   
SREE    + 40  CTS

It shouldn't be +20. spaces should be there b/w sign and number

Now i am using one code which will suppress Zeros with blank not with spaces.... See the code below... Is there any way to suppress Zero with spaces???
Please find the code which i am using

Code:
INREC OVERLAY=(9:9,4,SFF,TO=ZD,LENGTH=4) 
SORT   FIELDS=(1,6,CH,A,15,3,CH,A)                                   
SUM    FIELDS=(9,4,ZD)                                       
OUTREC OVERLAY=(9:9,4,ZD,EDIT=(SIIT),SIGNS=(+,-))
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Mon Jun 27, 2011 5:09 pm
Reply with quote

swathykrishnan,
Can you have signs at different positions for the same person? For example from your sample input, Tom record in input has a sign at 9th position but the last Tom record has sign at 11th position. Is it possible? If yes where do you want sign in your expected output?

What is the LRECL/RECFM of the input file?

Also please use code tags when providing sample data to keep formatting as is.

Thanks,
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 27, 2011 6:44 pm
Reply with quote

You will have to do Your own sign demangling and positioning along the lines of

Code:
 000017   INREC  OVERLAY=(81:9,4,SFF,TO=ZD,LENGTH=4)                           
 000018   SORT   FIELDS=(1,6,CH,A,15,3,CH,A)                                   
 000019   SUM    FIELDS=(81,4,ZD)                                               
 000020   OUTREC IFTHEN=(WHEN=(81,4,ZD,GE,0),                                   
 000021          BUILD=(1,6,C'  +',81,4,ZD,EDIT=(IIT),C'  ',15,3)),             
 000022          IFTHEN=(WHEN=NONE,                                             
 000023          BUILD=(1,6,C'  -',81,4,ZD,EDIT=(IIT),C'  ',15,3))             


quick and dirty just reproduced the record layout , no provision for greater that 3 digits numbers

modify accordingly, tested for an 80 byte record

I reformatted things using the code tags according to the sort statements
You must have been looking at the topic before
( yes the formatting was very poor also with a fixed font )
Back to top
View user's profile Send private message
swathykrishnan

New User


Joined: 01 Oct 2010
Posts: 43
Location: Bangalore

PostPosted: Mon Jun 27, 2011 7:04 pm
Reply with quote

First of thanks a lot for your quick response Enrico and sqlcode...
@Enrico: thanks man.. your logic is superb...... that will do whatever i want....
@sqlcode: The position of the sign will be always fixed in Input file and RECFM=FB....
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 27, 2011 7:26 pm
Reply with quote

I am no sort expert, Frank and/or Kolusu might certainly come out with a smarter/better solution

small correction to have 80 bytes record with spaces rather than binary 0s
Code:
 000018   INREC  OVERLAY=(81:9,4,SFF,TO=ZD,LENGTH=4)                           
 000019   SORT   FIELDS=(1,6,CH,A,15,3,CH,A)                                   
 000020   SUM    FIELDS=(81,4,ZD)                                               
 000021   OUTREC IFTHEN=(WHEN=(81,4,ZD,GE,0),                                   
 000022          BUILD=(1,6,C'  +',81,4,ZD,EDIT=(IIT),C'  ',15,3,80:X)),       
 000023          IFTHEN=(WHEN=NONE,                                             
 000024          BUILD=(1,6,C'  -',81,4,ZD,EDIT=(IIT),C'  ',15,3,80:X))         
 

note the 80:X added
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Jun 27, 2011 10:43 pm
Reply with quote

skrockzz,

Well, I'm not really sure what you want the output to look like for various cases, such as with three non-zero digits or one non-zero digit, but be aware that you can include embedded blanks in the EDIT mask by enclosing the pattern in apostrophes. For example:

Code:

EDIT=('S IIT')


If you used that in the code in your first post, SORTOUT would have:

Code:

SREE     + 40 CTS       
TOM      + 20 IBM       
Back to top
View user's profile Send private message
swathykrishnan

New User


Joined: 01 Oct 2010
Posts: 43
Location: Bangalore

PostPosted: Mon Jun 27, 2011 11:17 pm
Reply with quote

Hi Frank...Thanks for your valuable input...
Let me explain my requirement....
i have to find sum of one field which have a fixed length including sign, say 5. Here the sign will be always in 1st column. and the numbers will be right aligned. When i add these numbers using the code posted by me its will keep sign just to the left of number.... but i have to keep sign in exact position as its in the input file... see the example below..

INput
Code:

MEERA +  2 IBM
MANJU + 24 CGI
MEERA + 98 IBM
MANJU - 22 CGI
SWATH + 23 IBM


Output should be
Code:

MEERA +100 IBM
MANJU +  2 CGI
SWATH + 23 IBM


I think your code will always embed one space in the output
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Jun 27, 2011 11:36 pm
Reply with quote

Quote:
have to find sum of one field which have a fixed length including sign, say 5.


Your input example actually has a fixed length of 4 for the sum field. Assuming that you really do have a fixed length of 5, you can use a DFSORT job like the following to do what you asked for:

Code:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
MEERA +   2 IBM
MANJU +  24 CGI
MEERA +  98 IBM
MANJU -  22 CGI
SWATH +  23 IBM
AAAAA -  25 IBM
AAAAA - 125 IBM
BBBBB -1002 IBM
CCCCC +1002 IBM
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  INREC OVERLAY=(81:7,5,SFF,TO=ZD,LENGTH=4)
  SORT   FIELDS=(1,5,CH,A,13,3,CH,A)
  SUM    FIELDS=(81,4,ZD)
  OUTREC IFOUTLEN=80,
   IFTHEN=(WHEN=(81,4,ZD,LT,0),
    OVERLAY=(7:C'-',81,4,ZD,EDIT=(IIIT))),
   IFTHEN=(WHEN=NONE,
    OVERLAY=(7:C'+',81,4,ZD,EDIT=(IIIT)))
/*


SORTOUT would have:

Code:

AAAAA - 150 IBM       
BBBBB -1002 IBM       
CCCCC +1002 IBM       
MANJU +   2 CGI       
MEERA + 100 IBM       
SWATH +  23 IBM       
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 27, 2011 11:47 pm
Reply with quote

Hi Frank!

I wonder why it is so difficult to extract from people such simple info ...
position/column where to stick the sign
position/column and length of the edited numeric thing

my attempt was simply decoding the initial info
column 9 for the sign 3 positions for the numeric thing

cheers and good luck !
enrico
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Mon Jun 27, 2011 11:49 pm
Reply with quote

swathykrishnan,

Alternatively you can use the following control cards
Code:

//SYSIN    DD *                                       
  SORT FIELDS=(1,5,CH,A,13,3,CH,A)                     
  OUTFIL REMOVECC,NODETAIL,                           
  SECTIONS=(1,5,13,3,                                 
  TRAILER3=(1,6,TOT=(7,5,SFF,EDIT=(S),SIGNS=(+,-)),   
            TOT=(7,5,SFF,EDIT=(IIIT)),12,69))         
//*
Back to top
View user's profile Send private message
swathykrishnan

New User


Joined: 01 Oct 2010
Posts: 43
Location: Bangalore

PostPosted: Tue Jun 28, 2011 12:12 am
Reply with quote

thank you Frank.... that logic is good one.....
@Kolusu.. your code(Section,Trailer) is completely new to me... anyway i will try that also and will let you know....
@Enrico: your understanding was also correct... that code also will work

This is my first post in this forum.... thanks for your overwhelming support..... i didn't expect such talented quick responses from a public forum.... but this one is really superb..... thanks a lot..... is this owned by IBM?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Jun 28, 2011 1:19 am
Reply with quote

This Help Board is NOT owned or endorsed by IBM. But Kolusu and I are IBM DFSORT developers who participate in it.

BTW, Kolusu's solution is a clever one. Note that the separate SIGNS trick could be used with the SUM solution as well eliminating the need for the IFTHENs.

DFSORT has so many ways to do things that it's difficult to always think of the easiest one, even for me and I invented a lot of the functions.
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 Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
Search our Forums:

Back to Top