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
 

 

Requirement to copy records from input file to output file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Requirement to copy records from input file to output file
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 Moderator


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

PostPosted: Thu Apr 02, 2009 8:48 pm    Post subject:
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:

www.ibm.com/systems/support/storage/software/sort/mvs/tricks/
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Requirement to copy records from input file to out
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Requirement to copy records from input file to out
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SSH - known_hosts file configuration vasanthz All Other Mainframe Topics 1 Wed Jul 26, 2017 2:10 am
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm


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