Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SUM FIELDS - To add a byte if sign field is there

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Fri Jul 16, 2010 12:26 am    Post subject: SUM FIELDS - To add a byte if sign field is there
Reply with quote

Hi,

I have an input file of 160 bytes (Fixed Byte) and I need to sum the amount field for same Type code field
Type code - X(5) - starting at 42nd byte, length - 5 bytes
Amount field S9(4)V99 - starting at 77th byte, length - 6 bytes

When I did SUM FIELDS, it seems the data got overflow and got incorrect results.

Code:
SORT FIELDS=(42,5,CH,A)
SUM FIELDS=(77,6,ZD)


I thought of using INREC to pad zeroes before 77th byte however since sign is there, I am not sure how to add additional 2 bytes and then do SUM

Please help.

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

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jul 16, 2010 12:45 am    Post subject:
Reply with quote

Hello,

Post some sample input records and the output you want from these input records.

Mention the dsorg and lrecl of the files. Post any "rules" for getting form the input to the output.

Post the jcl and sort control statements ysed and the informational output from this run (including the message id's).
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Fri Jul 16, 2010 12:54 am    Post subject:
Reply with quote

Hi,

Please find the sample input and output and JCL used.

Type Code is at 42nd byte X(5).
Amount is at 77th byte - S9(4)V99

Input data
Code:
Type Cd   Amount   
10000    +200.01
10000    -100.01
10000     +50.02
20000    +1500.50
20000    -2000.50
Output
Code:
10000     +150.02
20000     -500


Code:
//STEP01  EXEC PGM=SORT                                     
//SYSOUT    DD SYSOUT=*                                     
//SYSPRINT  DD SYSOUT=*                                     
//SORTIN    DD DSN=<Input file>,DISP=SHR   
//SORTOUT   DD DSN=<Output file>,     
//             DISP=(,CATLG,DELETE),                       
//             UNIT=DISK,                                   
//             SPACE=(CYL,(1,1),RLSE),                   
//             DCB=(RECFM=FB,LRECL=160,BLKSIZE=0)           
//SYSIN     DD *                                           
   SORT FIELDS=(42,5,CH,A)   
   SUM FIELDS=(77,6,ZD)
/* 


Thanks
Vinu
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Fri Jul 16, 2010 1:12 am    Post subject:
Reply with quote

Since you need to convert the signed numeric to a valid ZD format, you will need an INREC converting the CSF/SFF to ZD before summing.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Fri Jul 16, 2010 1:18 am    Post subject:
Reply with quote

Hi CICS guy,

Is it mandatory to convert the signed field to ZD before doing summing ?

Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Jul 16, 2010 1:21 am    Post subject:
Reply with quote

Vinu,

That amount is NOT a ZD value - it's an SFF value. SFF cannot be used in SUM. Here's a DFSORT job that will do what you asked for. I assumed the amount was actually in positions 77-84 (8 bytes), and that you only wanted the Type code and amount in the output records as shown in your example.

Code:

//S1 EXEC PGM=SORT                                         
//SYSOUT DD SYSOUT=*                                       
//SORTIN DD DSN=...  input file                       
//SORTOUT DD DSN=...  output file                               
//SYSIN DD *                                               
  SORT FIELDS=(42,5,CH,A)                                 
  OUTFIL REMOVECC,NODETAIL,                               
    SECTIONS=(42,5,                                       
      TRAILER3=(42:42,5,                                   
        77:TOT=(77,8,SFF,EDIT=(SIIIT.TT),SIGNS=(+,-))))   
/*
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Fri Jul 16, 2010 1:34 am    Post subject:
Reply with quote

Hi Frank,

Thanks for the code.
My Amount field is S9(4)V99 - 6 bytes.

So I have changed EDIT=(SIIIT.TT) to EDIT=(SIT.TT)
This truncated the output values.

Another example where the output can go past 6 bytes
For ex
Code:
Input
11111   +9000.99
11111   +8000.99

Output
11111   +17001.98


Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Jul 16, 2010 2:05 am    Post subject:
Reply with quote

Hmm ... I think we're getting a bit mixed up here with the internal representation of the value vs the external representation. Based on your example, and this statement:

Quote:
I thought of using INREC to pad zeroes before 77th byte however since sign is there, I am not sure how to add additional 2 bytes and then do SUM


I assumed your values looked like this in the input records.

sdddd.dd

But if they're really 6-byte ZD values, then the sign is in the last byte, not in the first byte. That is, the ZD values look like this in hex:

FdFdFdFdFdsd

where s is the sign.

So you can pad with zeros (F0) on the left and not affect the sign.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Fri Jul 16, 2010 2:12 am    Post subject:
Reply with quote

Hi Frank,

My values look like those mentioned in input records.

Amt can be +100.00, +2000.99 ie., it is S9(4)V99. (6 bytes).
While summing it overflows the 4 bytes. As you have mentioned, we can't do summing if Signed byte is there.
The code you have mentioned worked fine. Only problem is the length of bytes in it. Here ZD is not there.
My reqt is just to have the sum of amount for the similar Type codes.

Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Jul 16, 2010 3:15 am    Post subject:
Reply with quote

You are absolutely making NO SENSE. You keep contradicting yourself as to what the values look like and how many bytes they occupy.

+2000.99 (X'4EF2F0F0F04BF9F9') would occupy 8 bytes and would be SFF format. 200099 (X'F2F0F0F0F9F9') would occupy 6 bytes and would be ZD format.

Then you say "it overflows the 4 bytes". 4, 6, 8? Eeeek.

I can't figure out what your data really looks like or what you want to do since you keep making confusing statements about it.

Please show what the +100.00 and +2000.99 values look like in HEXADECIMAL ... that will clear up once and for all what type of values you have.

Quote:
Only problem is the length of bytes in it. Here ZD is not there.


I have NO IDEA what you mean by this.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Jul 16, 2010 3:42 am    Post subject:
Reply with quote

Quote:
My Amount field is S9(4)V99 - 6 bytes.

So I have changed EDIT=(SIIIT.TT) to EDIT=(SIT.TT)

This truncated the output values.


If S9(4)V99 is 6 bytes, it's ZD with 6 digits, so if you change the EDIT mask to have 4 digits (IT.TT) instead of 6 digits (IIIT.TT), of course it will truncate the digits. You need SIIIT.TT for 6 digits. You would need SIIIIIT.TT to add two leading zeros to prevent overflow.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Sat Jul 17, 2010 2:58 am    Post subject:
Reply with quote

Hi Frank,

Thanks for the information.
Eventhough with IT.TT itself, it didnt give the desired results.
I have the Type code 1000C,1012A, 1012D, 1115A etc in input however it gave me the truncated result for 1012D,1115A. Not sure whether it combines all other Type codes.

When I tried using IIIT.TT, got error stating that the Input and Output LRECL is mismatching.

Thanks
Chidam
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Sat Jul 17, 2010 3:38 am    Post subject:
Reply with quote

We were talking about the amount field. So why are you saying what the Type Code field looks like? What does the amount field look like? Isn't the amount field the field you're trying to add?

Quote:
Eventhough with IT.TT itself, it didnt give the desired results.


No, it wouldn't as I explained in my previous post.

Quote:
When I tried using IIIT.TT, got error stating that the Input and Output LRECL is mismatching.


Well, that means you tried to increase the length of the output records, but your output data set has a different LRECL. Remove the LRECL for the output data set if you're specifying it. If you're using an OLD data set that already has an LRECL, switch to using a new data set without an LRECL, so sort can set the correct LRECL.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Tue Jul 20, 2010 2:09 am    Post subject:
Reply with quote

Thanks Frank.
I was trying to increase the Amount field. I tried increasing IIIT and it worked fine.

Thanks
Vinu
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 -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 1 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us