Page 1 of 1

Finding smallest value for a field in a file

Posted: Fri Sep 16, 2011 7:13 pm
by ickgeek23
Hi,
I have two input files
Input file1 like:

course name-------start date----- end date
course1-------------20110101----20111212
course2-------------20110501----20110512
course3-------------20091109----20111212
course4-------------20110508----20110815

Input file2:
student-----------------------date
student1--------------------20110101
student2--------------------20040101
student3--------------------20091109
student4--------------------20100101
student5--------------------20030101


My requirement is first i need to find the smallest value of the start date from the input file1 (in this case 20091109), then i need to select the records from input file2 which has the date greater than or equal to the smallest values found from the input file1-start date, and write in to the output file

So output file :

student1--------------------20110101
student3--------------------20091109
student4--------------------20100101


Can we do this without writing any cobol program...

Thanks in advance...
:)

Posted: Fri Sep 16, 2011 10:31 pm
by Frank Yaeger
You can use a DFSORT job like the following to do what you asked for:

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
COURSE1-------------20110101----20111212
COURSE2-------------20110501----20110512
COURSE3-------------20091109----20111212
COURSE4-------------20110508----20110815
//SORTOUT DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN DD *
  OPTION COPY
  OUTFIL REMOVECC,NODETAIL,
    BUILD=(80X),
    TRAILER1=('TARG,''',MIN=(21,8,ZD,TO=ZD,LENGTH=8),'''')
/*
//S2  EXEC  PGM=SORT
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
STUDENT1--------------------20110101
STUDENT2--------------------20040101
STUDENT3--------------------20091109
STUDENT4--------------------20100101
STUDENT5--------------------20030101
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INCLUDE COND=(29,8,CH,GE,TARG)
/*

Posted: Tue Sep 20, 2011 6:49 pm
by ickgeek23
Thanks Frank for the reply

My inputfile2 format has changed
like
Input file2:
student-----------------------date
student1--------------------2011-01-01
student2--------------------2004-01-01
student3--------------------2009-11-09
student4--------------------2010-01-01
student5--------------------2003-01-01
Inputfile1 is same
output is same as mentioned in the previous post.
Can you please help me in this how to solve

Posted: Tue Sep 20, 2011 9:54 pm
by Frank Yaeger
That's a simple change to the previous DFSORT job (you'll learn more if you try to figure these things out yourself):

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
COURSE1-------------20110101----20111212
COURSE2-------------20110501----20110512
COURSE3-------------20091109----20111212
COURSE4-------------20110508----20110815
//SORTOUT DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN DD *
  OPTION COPY
  OUTFIL REMOVECC,NODETAIL,
    BUILD=(80X),
    TRAILER1=('TARG,''',MIN=(21,8,ZD,EDIT=(TTTT-TT-TT)),'''')
/*
//S2  EXEC  PGM=SORT
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
STUDENT1--------------------2011-01-01
STUDENT2--------------------2004-01-01
STUDENT3--------------------2009-11-09
STUDENT4--------------------2010-01-01
STUDENT5--------------------2003-01-01
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INCLUDE COND=(29,8,CH,GE,TARG)
/*

Posted: Wed Sep 21, 2011 1:01 pm
by ickgeek23
Thanks Frank for the quick response:

When i ran the job it is giving an error as

SYSIN :
OPTION COPY
INCLUDE COND=(61,8,CH,GE,TARG)
*
WER268A INCLUDE STATEMENT : SYNTAX ERROR
WER211B SYNCSMF CALLED BY SYNCSORT; RC=0000
WER449I SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE


date filed in the inputfile2 is PIC X(10)
date field in input file1 (start date is) PIC X(8)


I am new to this programming language, can you please help me from where i can get these material so that it will be very helpful.

Thanks

Posted: Wed Sep 21, 2011 1:50 pm
by dbzTHEdinosauer
you need to check your SYNCSORT manuals, you are not using DFSORT.

Posted: Wed Sep 21, 2011 2:45 pm
by ickgeek23
I am using Syncsort

Posted: Wed Sep 21, 2011 2:50 pm
by ickgeek23
After executing the first step
with
OPTION COPY
OUTFIL REMOVECC,NODETAIL,
BUILD=(3000X),
TRAILER1=('TARG,''',MIN=(22,8,ZD,EDIT=(TTTT-TT-TT)),'''')

output file has the minimum date as
TARG,'2002-01-26'


when i use the sort in the next step
OPTION COPY
INCLUDE COND=(61,10,CH,GE,TARG)

Then i am getting the error as
SYSIN :
OPTION COPY
INCLUDE COND=(61,10,CH,GE,TARG)
*
WER268A INCLUDE STATEMENT : SYNTAX ERROR
WER211B SYNCSMF CALLED BY SYNCSORT; RC=0000
WER449I SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE

Thanks

Posted: Wed Sep 21, 2011 9:37 pm
by DikDude
I am new to this programming language, can you please help me from where i can get these material so that it will be very helpful.
If your organization is licensed to use the product, all of the material is available free from Syncsort support.

Posted: Wed Sep 21, 2011 10:21 pm
by Frank Yaeger
The job I gave you works fine with DFSORT. But you changed:

Code: Select all

    BUILD=(80X), 
to

Code: Select all

  BUILD=(3000X), 
which is incorrect. I don't know if fixing that will allow your job to run with Syncsort, but it is certainly necessary. You might want to check your complete job against my complete job to see if you messed up anything else.

At any rate, I'm a DFSORT developer. DFSORT and Syncsort are competitive products. I'm happy to answer questions on DFSORT and DFSORT's ICETOOL, but I don't answer questions on Syncsort.