View previous topic :: View next topic
Author
Message
Jasand New User Joined: 23 Jan 2009Posts: 32 Location: Tamil nadu
Hi,
Please advise me on the below SORT to calculate the time diff in HH:SS
Input: FB/74
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
****************** REPORT START ******
XXXX 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51 20110407
YYY 17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05 20110407
****************** REPORT END ******
need to calculate the difference between the first and last time fields
eg: In first record(09:51 - 09:02) and populate the o/p in 64th field
The difficulty is that, the START and STOP timings may be both before midnight, after midnight , or one before midnight.
eg:
Code:
A1:A2 B1:B2
22:10 23:20
23:20 2:10
2:40 5:30
CALCULATE HOURS HH CALCULATE SECONDS SS
-------------------- ---------------------
IF THEN IF THEN
-------------------- ---------------------
B1>A1 B1-A1 B2>A2 B2-A2
B1<A1 (24-A1)+B1 B2<A2 A2-B2
B1=A1 00 B2=A2 00
OTHERS C'HH' OTHERS C'MM'
Code:
//STEP10 EXEC PGM=SYNCTOOL
//SYSOUT DD SYSOUT=*
//IN DD DSN=INPUT.Dataset,DISP=SHR
//MID DD DSN=MID.Dataset,
// DISP=(NEW,CATLG,DELETE),
// DCB=(RECFM=FB,BLKSIZE=0),
// UNIT=SYSDA,
// SPACE=(TRK,(100,50),RLSE)
//OUT DD DSN=OUT.Dataset,
// DISP=(NEW,CATLG,DELETE),
// DCB=(RECFM=FB),
// UNIT=SYSDA,
// SPACE=(TRK,(100,50),RLSE)
//TOOLMSG DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//TOOLIN DD *
SORT FROM(IN) TO(MID) USING(CTL1)
SELECT FROM(MID) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
* CALCULATE HOUR DIFFERENCE HH
SORT FIELDS=COPY
INCLUDE COND=(55,1,CH,EQ,C'2')
INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),
OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),
IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),
OVERLAY=(64:C'00:'))
/*
//CTL2CNTL DD *
* CALCULATE SECONDS DIFFERENCE SS
SORT FIELDS=COPY
INCLUDE COND=(55,1,CH,EQ,C'2')
INREC IFTHEN=(WHEN=(51,2,ZD,GT,9,2,ZD),
OVERLAY=(67:51,2,ZD,SUB,9,2,ZD,M11,LENGTH=2)),
IFTHEN=(WHEN=(51,2,ZD,LT,9,2,ZD),
OVERLAY=(67:9,2,ZD,SUB,51,2,ZD,M11,LENGTH=2)),
IFTHEN=(WHEN=(51,2,ZD,EQ,9,2,ZD),
OVERLAY=(64:C'00'))
/*
The CTL1 and CTL2 work good individually, but they dont work when put as above
I am getting only the HOUR diff in the MID file.
Also I am not able to handle the below conditions,
B1<A1 (24-A1)+B1 - in hour calculation
OTHERS C'HH' and OTHERS C'SS'
Appreciate your help on this.
Back to top
Jasand New User Joined: 23 Jan 2009Posts: 32 Location: Tamil nadu
Please find below the SYSOUT message that I get..
Code:
CTL1CNTL :
SORT FIELDS=COPY
INCLUDE COND=(55,1,CH,EQ,C'2')
INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),
OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),
IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),
OVERLAY=(64:C'00:'))
PARMLIST :
OPTION RESINV=0,ARESINV=0,MSGDDN=DFSMSG,SORTIN=IN,SORTOUT=MID,SORTDD=CTL1,DYNAL
OC
WER428I CALLER-PROVIDED IDENTIFIER IS "0001"
WER108I IN : RECFM=FB ; LRECL= 74; BLKSIZE= 27972
WER257I INREC RECORD LENGTH = 74
WER110I MID : RECFM=FB ; LRECL= 74; BLKSIZE= 27972
WER055I INSERT 0, DELETE 6
WER449I SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE
WER054I RCD IN 13, OUT 7
WER169I RELEASE 1.3 BATCH 0513 TPF LEVEL 2.2
WER052I END SYNCSORT - I072616N,STEP10,,DIAG=8A00,5140,A2AE,006E,C252,6CEB,22E
******************************* BOTTOM OF DATA ********************************
Let me know if I am not clear in stating the requirement.
Back to top
Jasand New User Joined: 23 Jan 2009Posts: 32 Location: Tamil nadu
Hi All,
Got the output partially with the below code,
Code:
//STEP0100 EXEC PGM=SYNCTOOL
//IN DD DSN=XXX.SAMPLE,DISP=SHR
//MID DD DSN=XXX.SAMPLE.MID,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(15,5),RLSE),
// DCB=(RECFM=FB)
//OUT DD DSN=XXX.SAMPLE.OUT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(15,5),RLSE),
// DCB=(RECFM=FB)
//TOOLMSG DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//TOOLIN DD *
SORT FROM(IN) TO(MID) USING(CTL1)
SORT FROM(MID) TO(OUT) USING(CTL2)
//CTL1CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(55,1,CH,GE,C'2')
* CALCULATE HOUR DIFFERENCE HH
INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),
OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),
IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),
OVERLAY=(64:C'00:'))
//CTL2CNTL DD *
SORT FIELDS=COPY
INCLUDE COND=(55,1,CH,GE,C'2')
* CALCULATE SECONDS DIFFERENCE SS
INREC IFTHEN=(WHEN=(51,2,ZD,GT,9,2,ZD),
OVERLAY=(67:51,2,ZD,SUB,9,2,ZD,M11,LENGTH=2)),
IFTHEN=(WHEN=(51,2,ZD,LT,9,2,ZD),
OVERLAY=(67:9,2,ZD,SUB,51,2,ZD,M11,LENGTH=2)),
IFTHEN=(WHEN=(51,2,ZD,EQ,9,2,ZD),
OVERLAY=(64:C'00'))
/*
Need to add one more condition int he HOUR calculation in CTL1
ie. (24-A1)+B1 when B1<A1 Can somebody help me out please..
Theo/p I get now is
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51 20110407 00:49
BBB 17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05 20110407 03:37
CCC 19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07 20110407 03:33
DDD 19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31 20110407 03:09
EEE 19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00 20110407 03:40
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05 20110407 05
GGG 23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26 20110407 10
Back to top
Arun Raj Moderator Joined: 17 Oct 2006Posts: 2481 Location: @my desk
Jasand,
Looks like the sample data is very familiar to me
Back to top
Arun Raj Moderator Joined: 17 Oct 2006Posts: 2481 Location: @my desk
Jasand,
You might want to re-visit your requirement.
Code:
BBB 17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05 20110407 03:37
The difference in time here should be 20:05 - 17:42 = 02:23 ie. 2 hrs 23 mins. But your expected output says 03:37.
Back to top
Akatsukami Global Moderator Joined: 03 Oct 2009Posts: 1788 Location: Bloomington, IL
It appears that he's:
Subtracting the rightmost quantity from the leftmost
Subtracting hours and minutes as if they were completely unrelated
Not using a needed sign in his answer
These errors are probably an indication of his lack of knowledge of SyncSort.
Back to top
Craq Giegerich Senior Member Joined: 19 May 2007Posts: 1512 Location: Virginia, USA
An easy to uderstand COBOL program would have take a lot less than 11 days to write.
Back to top
Jasand New User Joined: 23 Jan 2009Posts: 32 Location: Tamil nadu
@ All..
Sorry.. Its my stupidity with the logic 'Subtracting hours and minutes as if they were completely unrelated'
Yes Arun.. the same sample data and a different requirement
Back to top
Arun Raj Moderator Joined: 17 Oct 2006Posts: 2481 Location: @my desk
The below Syncsort job should give you what I assume you're trying to achieve. The input/output files were assumed to be of FB/LRECL=74.
Code:
//STEP01A EXEC PGM=SORT
//SORTIN DD DSN= Input file (FB/74)
//SYSOUT DD SYSOUT=*
//SORTOUT DD DSN= Output file (FB/74)
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:(06,2,ZD,MUL,+60),ADD,09,2,ZD,M11,LENGTH=4)),
IFTHEN=(WHEN=(48,2,ZD,LT,06,2,ZD),
OVERLAY=(85:((48,2,ZD,ADD,+24),MUL,+60),ADD,51,2,ZD,M11,LENGTH=4)),
IFTHEN=(WHEN=NONE,
OVERLAY=(85:(48,2,ZD,MUL,+60),ADD,51,2,ZD,M11,LENGTH=4))
OUTREC IFOUTLEN=74,IFTHEN=(WHEN=INIT,
OVERLAY=(89:85,4,ZD,SUB,81,4,ZD,M11,LENGTH=4,
64:89,4,ZD,DIV,+60,M11,LENGTH=2,C':',
89,4,ZD,MOD,+60,M11,LENGTH=2))
Input
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51 20110407
BBB 17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05 20110407
CCC 19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07 20110407
DDD 19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31 20110407
EEE 19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00 20110407
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05 20110407
GGG 23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26 20110407
SORTOUT had
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51 20110407 00:49
BBB 17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05 20110407 02:23
CCC 19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07 20110407 02:27
DDD 19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31 20110407 02:51
EEE 19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00 20110407 02:20
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05 20110407 02:05
GGG 23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26 20110407 01:10
PS. The above sort assumes that the time difference would always be less than 24 hours and hence might need changes if that does not hold true in your case.
Back to top
Jasand New User Joined: 23 Jan 2009Posts: 32 Location: Tamil nadu
Thank you Arun.. It works good.
the time difference would always be less than 24 hours and so it exactly matches for my requirement..
Back to top
Arun Raj Moderator Joined: 17 Oct 2006Posts: 2481 Location: @my desk
You're welcome. Glad that it helped.
Back to top
Please enable JavaScript!