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

Requirement to copy records from input file to output file


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

New User


Joined: 01 Apr 2009
Posts: 7
Location: India

PostPosted: Thu Apr 02, 2009 8:35 pm
Reply with quote

Hi,

My requirement is to copy records from input file to output file, if the job is running on a particular day and time(Ex: Wednesday after 7.00 PM) and it needs to be done through JCL directly(not through Cobol or some other Programming language).

I am planning to implement it as follows:

1. Write a SQL step as below to get the current day and time
//DSNTIAUL EXEC DSNTIAUL,DBSID=...,PARAM='SQL'
//SYSPUNCH DD DSN=...
// DISP=(,CATLG,DELETE)
//SYSREC00 DD DSN=...
// DISP=(,CATLG,DELETE),
// SPACE=(1,(2000,500)),AVGREC=M
//SYSIN DD *
SELECT dayofweek(current date), current time from sysibm.sysdummy1;
/*


2. Write a SORT step with include condition with the given days and time, so that output is 1 record or 0 records
3. Write IDCAMS step as below so that it returns either return code 0(if 1 record) or 4(if 0 records)

//STEP0001 EXEC PGM=IDCAMS
//IN DD DSN=..., DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSIN DD DATA
PRINT INFILE(IN) COUNT(1)
/*

4. write SORT step to copy depending on this return code above


But, Is there a better way, instead of using steps 2 , 3 and 4 above? is it possible to copy records from input file2 to Output file, if the record in input file1(it contains only 1 record) contains a particular value?
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: Thu Apr 02, 2009 8:48 pm
Reply with quote

Quote:
is it possible to copy records from input file2 to Output file, if the record in input file1(it contains only 1 record) contains a particular value?


See the "Set RC=12 or RC=4 if file is empty, has more than n records, etc" Smart DFSORT Trick at:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
smudunuru

New User


Joined: 01 Apr 2009
Posts: 7
Location: India

PostPosted: Thu Apr 02, 2009 9:23 pm
Reply with quote

Hi Frank,

Thanks for your suggestion. I have mentioned, I can use IDCAMS to get a return code of 0 or 4 based on file is empty or not. But my aactual question is as follows:

Suppose, there are two input files in which file1 contains only 1 record(ex: date) and file2 contains hundred records. Is it possible to use a SORT to copy all records from file2 to output file, if date in file1 matches a particular value.

Best Regards
Srihari
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Thu Apr 02, 2009 11:28 pm
Reply with quote

smudunuru,

Your requirement can be achieved in a single DFSORT step. I need the following details

1. LRECL and RECFM of your input file
2. Position and format of the DAY field in your input file
3. position and format of the TIME field in your input file
4. Show me a sample input and desired output
Back to top
View user's profile Send private message
smudunuru

New User


Joined: 01 Apr 2009
Posts: 7
Location: India

PostPosted: Fri Apr 03, 2009 3:15 pm
Reply with quote

Hi Skolusu,

Here are the details.

1. file1(contains day and time): LRECL= 80, RECFM=FB
Code:
          6  11.27.42

file2(actual data): LRECL= 200, RECFM=FB
Outfile: LRECL=200, RECFM=FB
2&3. Day: position 1, length 1
Time: position 11, length 8

4. If the day in file1 is 5 and time is greater than 19.00.00, then outfile should contain the same data as file2, otherwise outfile should not contain any records

Best Regards
Srihari
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Fri Apr 03, 2009 9:32 pm
Reply with quote

smudunuru,

I don't see a reason as to why you need to check the first file, if your intention is to copy the records based on the hard coded values.It is just a simple include condition . if your input has any records that satisfy that condition they will be written to the output or else you will have an empty file.

Code:

//STEP0100 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DSN=your 200 byte actual file,
//            DISP=SHR             
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                         
  SORT FIELDS=COPY                                       
  INCLUDE COND=(1,1,CH,EQ,C'5',AND,11,8,CH,GT,C'19.00.00') 
/*                                                       


Even if you wanted to pick the current day values you don't need the other file. The system symbol LWDAY gives you the day of the week in 3 letter form. MON, TUE, WED,THU...
We pad this at the end of every record i.e pos 201.

Dayofweek function in DB2 returns an integer in the range of 1 to 7 that represents the day of the week where 1 is Sunday and 7 is Saturday. using a Bunch of IFTHEN's we convert the day of the week we got from system symbol to a numeric value and use it on the include condition on OUTFIL. since today is day 6 (FRI) , I only pick one value from the sample output.

Code:

//STEP0100 EXEC PGM=SORT                                 
//SYMNAMES DD *                                           
PICKDAY,S'&LWDAY'                                         
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD *   
----+----1----+----2----+----3----+----4----+----5
1         10.42.52   - DROPPED                           
2         10.42.52   - DROPPED                           
3         10.42.52   - DROPPED                           
4         10.42.52   - DROPPED                           
5         19.42.52   - DROPPED
5         18.42.52   - DROPPED                           
6         20.42.52   - SHOULD BE PICKED                   
7         10.42.52   - DROPPED                           
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                           
  SORT FIELDS=COPY                                       
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(201:PICKDAY)),         
  IFTHEN=(WHEN=(201,3,CH,EQ,C'SUN'),OVERLAY=(201:C'1')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'MON'),OVERLAY=(201:C'2')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'TUE'),OVERLAY=(201:C'3')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'WED'),OVERLAY=(201:C'4')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'THU'),OVERLAY=(201:C'5')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'FRI'),OVERLAY=(201:C'6')), 
  IFTHEN=(WHEN=(201,3,CH,EQ,C'SAT'),OVERLAY=(201:C'7'))   
                                                         
  OUTFIL BUILD=(1,200),                                   
  INCLUDE=(1,1,CH,EQ,201,1,CH,AND,11,8,CH,GT,C'19.00.00')
/*
Back to top
View user's profile Send private message
smudunuru

New User


Joined: 01 Apr 2009
Posts: 7
Location: India

PostPosted: Fri Apr 03, 2009 10:52 pm
Reply with quote

skolusu,

Thank you very much. It solves my problem using LWDAY.


Best Regards
Srihari
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Sat Apr 04, 2009 3:11 am
Reply with quote

It is nice to have the solution posted. If your solution is much different than this please post it.
Code:
//STEP010 EXEC PGM=SORT
//SYMNAMES DD *
PICKDAY,S'&LWDAY'
/*
//SYSIN    DD *
  SORT FIELDS=COPY
  INREC OVERLAY=(201:PICKDAY,204:&TIME1)
  OUTFIL INCLUDE=(201,3,CH,EQ,C'WED',AND,204,2,CH,GE,C'19')
/*
//SORTIN   DD DSN=...,DISP=SHR
//SORTOUT   DD DSN=...LRECL=200...
Back to top
View user's profile Send private message
smudunuru

New User


Joined: 01 Apr 2009
Posts: 7
Location: India

PostPosted: Sun Apr 05, 2009 2:25 am
Reply with quote

Douglas Wilder,

It is exactly the same thing that worked for me as you posted.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
Search our Forums:

Back to Top