Find and Replace string with current Date

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
jathampy
Member
Posts: 22
Joined: Sat Sep 26, 2009 4:02 pm
Location: software engineer

Find and Replace string with current Date

Post by jathampy » Fri Jul 23, 2010 3:43 am

My requirement is to replace the '########' string with current date in a SFTP control member.

Input
PWD
ls -l
get 'ETOLDAG_000003_########.csv' 'UGLXCD.EBAXMD.NETWORK.TEST'
rename 'ETOLDAG_000003_########.csv' 'ETOLDAG_000003_########.csv.taken'
quit

Output
PWD
ls -l
get 'ETOLDAG_000003_20100722.csv' 'UGLXCD.EBAXMD.NETWORK.TEST'
rename 'ETOLDAG_000003_20100722.csv' 'ETOLDAG_000003_20100722.csv.taken'
quit

I have coded the jcl given below to satisfy my current requirement. The same SFTP control card will be used in future to handle additional files. The current solution depends on the position of the string '########' and won't work if the filename character is increased

Can this be handled using FINDREP or any alternative solution to search the string at any position and replace with current date.?


/FTPCRE EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD PATH='/u/TST169/sftpinpa',PATHOPTS=ORDONLY,
// LRECL=80,RECFM=FB,FILEDATA=TEXT
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=(22,8,CH,EQ,C'########'),OVERLAY=(22:DATE1)),
IFTHEN=(WHEN=(25,8,CH,EQ,C'########'),OVERLAY=(25:DATE1)),
IFTHEN=(WHEN=(31,8,CH,EQ,C'########'),OVERLAY=(31:DATE1))
//*
//SORTOUT DD PATH='/u/TST169/sftpinpa',PATHOPTS=OWRONLY,
// LRECL=80,RECFM=FB,FILEDATA=TEXT

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Fri Jul 23, 2010 3:58 am

A DFSORT job like this should do it:

Code: Select all

/FTPCRE   EXEC  PGM=SORT
//SYMNAMES DD *
Mydate,S'&YR4.&MON.&DAY'
//SYSOUT   DD SYSOUT=*
//SORTIN     DD PATH='/u/TST169/sftpinpa',PATHOPTS=ORDONLY,
//       LRECL=80,RECFM=FB,FILEDATA=TEXT 
//SYSIN    DD *
  OPTION COPY
  OUTREC FINDREP=(IN=C'########',OUT=Mydate)
//*
//SORTOUT    DD PATH='/u/TST169/sftpinpa',PATHOPTS=OWRONLY,
//       LRECL=80,RECFM=FB,FILEDATA=TEXT
Last edited by Frank Yaeger on Mon Jul 26, 2010 8:30 pm, edited 1 time in total.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

jathampy
Member
Posts: 22
Joined: Sat Sep 26, 2009 4:02 pm
Location: software engineer

Post by jathampy » Fri Jul 23, 2010 9:15 pm

The solution provided by you worked. Thanks Frank fro your timely help.

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Sat Jul 24, 2010 3:30 pm

Hi Frank,

This example looks pretty different than what I've seen with SORT applications, what does

Code: Select all

//SORTIN     DD PATH='/u/TST169/sftpinpa',PATHOPTS=ORDONLY, 
//       LRECL=80,RECFM=FB,FILEDATA=TEXT 
//SYSIN    DD * 
in SORTIN tell the sort-program? May be I'm overlooking the obvious, however, please assist me to understand it.

Thanks for your time.
Regards,
Anuj

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Mon Jul 26, 2010 8:29 pm

It's a z/OS UNIX file. Here's an example in the DFSORT APG:

http://publibz.boulder.ibm.com/cgi-bin/ ... 0527161936

and here are some references:

http://publibz.boulder.ibm.com/cgi-bin/ ... 0527161936
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Tue Jul 27, 2010 12:25 pm

Thank you Frank - this helps.
Regards,
Anuj

jack98
Member
Posts: 1
Joined: Thu Mar 20, 2014 12:55 am

Post by jack98 » Thu Mar 20, 2014 1:07 am

Hi Mr Yaeyer.

About >>
OUTREC FINDREP=(IN=C'########',OUT=Mydate)
<<

Let's say that the search/replace-string is ALWAYS on the first line. How do we code to findrep ONLY on the 1st line ?
OUTREC IFTHEN=(WHEN ... FINDREP...)

Thank you.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Mar 20, 2014 3:13 am

If there is something in a fixed position with a value, or even an otherwise unique value to identify the first record, you can use that. If not, you can append/prepend a sequence number and test for a value of one,

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Thu Mar 20, 2014 9:57 pm

Welcome to the forum!

Fist of all, the name is Yaeger - it is important to use the correct name ahen a name is used.

Second - please do NOT address a question to a particular individual. In this case, Frank is no longer on the forum. He retired a year ago.

And last - it is best to start a new topic for your new question rather than posting a reply to a topic that has been dormant 3+ years. A link to the original topic may be included in ypour post if you want to refer to some other topic.

Good luck and enjoy the forum :)
Have a good one

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Jan 25, 2016 9:42 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others