SORT AND COPY ONLY IF COUNT MORE THAN 250



Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

SORT AND COPY ONLY IF COUNT MORE THAN 250

Postby bsaishankar » Sat Jan 09, 2010 7:26 am

How to use SYNCSORT to Create a new file only if the original file has records more or equal to 250 records. I see that the COUNT can be used but not sure if that can be used staraight in the comparsions .

This has to be done for 2 siutations.

Situation 1 file records:
Original file size is 500 bytes VBA format
There is 1 record/account.
No sorting of records is needed.
Sampling of records will be as below
1 SZ1 AC#1 AAA..........
1 SZ1 AC#2 BBB...........
1 SZ1 AC#3 CCC....
1 SZ1 AC#4 DDD......


Situation 2 file records:
Original file size is 500 bytes VBA format
No sorting of records is needed.
Each account will have 5 records.
There are 5 record/account, when counting they have to be grouped or if COUNT can be used,will have to divide by 5 with total count.

Sampling of records will be as below
1 SZ1 AC#1 AAA..........
1 SZ2 AC#1 ABA...........
1 SZ3 AC#1 ACA..........
1 SZ4 AC#1 ADA......
1 SZ5 AC#1 AEA.........
1 SZ1 AC#2 CCC....
1 SZ2 AC#2 CBC....
1 SZ3 AC#2 CCC....
1 SZ4 AC#2 CDC....
1 SZ5 AC#2 CEC....
1 SZ1 AC#3 DDD......
1 SZ2 AC#3 DDD......
1 SZ3 AC#3 DDD......
1 SZ4 AC#3 DDD......
1 SZ5 AC#3 DDD......


Any help is appreciated.

Thank You.
bsaishankar
 
Posts: 2
Joined: Sat Jan 09, 2010 6:52 am
Has thanked: 0 time
Been thanked: 0 time

Re: SORT AND COPY ONLY IF COUNT MORE THAN 250

Postby Thampy » Sat Jan 23, 2010 12:28 am

Hi baishankar,

You can set return code based on the count and then do an IDCAMS repro to copy the file. There will be other better ways of doing it.

Method 1 Use Idcams
//STEP010 EXEC PGM=IDCAMS
//IN01 DD DSN=Your-Input-File,DISP=SHR
//OUT01 DD DSN=Your-Output-File,DISP=(,CATLG,DELETE),
// LIKE=Your-Input-File
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
PRINT INFILE(IN01) COUNT(251)
IF LASTCC=0 THEN REPRO INFILE(IN01) OUTFILE(OUT01)
/*
Note : If the record count is less than 251, then print statement produce the return code 4, Otherwise all the input records are copied to Out01. However an empty output file will be created. You can code an Else statement listed below to delete the output file created, if you need so.
IF LASTCC=0 THEN REPRO INFILE(IN01) OUTFILE(OUT01)
ELSE DELETE 'Your-Output-file'

For your second requirement, since you have mentioned that there will be always five records per account, you can use the same Idcams jcl by modifying the COUNT to 1251.

Method 2 Use SORT and IDCAMS

//STEP010 EXEC PGM=SORT
//SORTIN DD DSN=Your-Input-File,DISP=SHR
//SYSOUT DD SYSOUT=*
//SORTOUT DD DUMMY
//SYSIN DD *
OPTION COPY,NULLOUT=RC4
INREC OVERLAY=(501:SEQNUM,4,ZD)
OUTFIL INCLUDE=(501,4,ZD,GT,250)
/*
//IF010 IF (STEP010.RC = 0) THEN
//STEP020 EXEC PGM=IDCAMS
//IN01 DD DSN=Your-Input-File,DISP=SHR
//OUT01 DD DSN=Your-Output-File,DISP=(,CATLG,DELETE),
// LIKE=Your-Input-File
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
REPRO INFILE(IN01) OUTFILE(OUT01)
/*
//ENDIF010 ENDIF

For the second requirement, you can replace the SORT JCL with the one given below or change the include condition of the first SORT JCL to 1250
OPTION COPY,NULLOUT=RC4
INREC IFTHEN=(WHEN=GROUP,RECORDS=5,PUSH=(501:ID=4))
OUTFIL INCLUDE=(501,4,ZD,GT,250)

Method 3 Use SYNCTOOL and IDCAMS

//STEP010 EXEC PGM=SYNCTOOL
//IN01 DD DSN=Your-Input-File,DISP=SHR
//TOOLMSG DD SYSOUT=*
//SSMSG DD SYSOUT=*
//OUT01 DD DUMMY
//TOOLIN DD *
COUNT FROM(IN01) LOWER(251) RC4
/*
//IF010 IF (STEP010.RC = 0) THEN
//STEP020 EXEC PGM=IDCAMS
//IN01 DD DSN=Your-Input-File,DISP=SHR
//OUT01 DD DSN=Your-Output-File,DISP=(,CATLG,DELETE),
// LIKE=Your-Input-File
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
REPRO INFILE(IN01) OUTFILE(OUT01)
/*
//ENDIF010 ENDIF

For the second requirement, change LOWER(251) to LOWER(1251)

Hope this will help to resolve your problem

Thanks & Regards
Thampy
Thampy
 
Posts: 36
Joined: Sat Sep 26, 2009 2:27 pm
Has thanked: 0 time
Been thanked: 3 times

Re: SORT AND COPY ONLY IF COUNT MORE THAN 250

Postby bsaishankar » Wed Jan 27, 2010 11:13 am

Thank You Thampy. This is a great insight to me. I will try them out. Once thanks again for the solutions.
bsaishankar
 
Posts: 2
Joined: Sat Jan 09, 2010 6:52 am
Has thanked: 0 time
Been thanked: 0 time

Re: SORT AND COPY ONLY IF COUNT MORE THAN 250

Postby Alissa Margulies » Sat Jan 30, 2010 3:24 am

Here is another variation of Thampy's solution that may help. It is a simple two-step solution using SyncSort for z/OS.

What the solution entails is as follows:

STEP01:
- Pass the parameter 'NULLOUT=RC4'.
What NULLOUT=RC4 does is instruct SyncSort to issue a return code of 4 if the output file contains no records. If records are present in the output, a return code of 0 will be issued.
- Use INREC to add a SEQNUM to the beginning of the data portion of each variable-length record.
Since this step is only used to determine whether the number of records is equal to or greater than 250, I also use INREC to get rid of all but the RDW of each record.
- SORT on the field containing the sequence number (Ascending order).
- Use OUTFIL INCLUDE to filter out only records with a sequence number of 250 or greater.
If there are records present with a sequence number of 250 or greater, a return code of 0 will be issued;
if there are no records with a sequence number of 250 or greater the output file will be empty and the step will get a return code of 4.

STEP02:
- Whether this COPY step will run is based upon COND codes.
Execute STEP02 if STEP01 gets a RC=0 (there are 250 or more records);
do not execute if STEP01 gets a RC=4 (there are less than 250 records in the STEP01 output).

Example coding:
//STEP01 EXEC PGM=SORT,PARM='NULLOUT=RC4'
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SORTIN   DD DSN=your.input.data.set,DISP=SHR
//SYSIN    DD *
  INREC FIELDS=(1:1,4,5:SEQNUM,4,ZD)
  SORT FIELDS=(5,4,ZD,A)
  OUTFIL FILES=OUT,
   INCLUDE=(5,4,ZD,GE,0250)
/*
//STEP02 EXEC PGM=SORT,COND=(4,EQ)
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD DSN=your.output.data.set
//SORTIN   DD DSN=your.input.data.set,DISP=SHR
//SYSIN    DD *
   SORT FIELDS=COPY
/*


I used a 4-byte sequence number. You may need to increase the size of this field if there is the potential for more than 9999 records in the input file (such as what you describe in your "Situation 2").

You will want to be careful about specifying the COND parameter in STEP02 since there are return codes other than 0 or 4 that can occur. For example, you do not want STEP02 to execuce if STEP01 fails (RC 16) for some reason. Consult IBM JCL documentation for more information on using the COND parameter.

Set the INCLUDE value higher as appropriate for your "Situation 2".
Alissa Margulies
Syncsort Mainframe Product Services
201-930-8260
zos_tech@syncsort.com
Alissa Margulies
Global moderator
 
Posts: 369
Joined: Tue Feb 26, 2008 11:15 pm
Location: USA
Has thanked: 1 time
Been thanked: 3 times


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post