|
View previous topic :: View next topic
|
| Author |
Message |
Badbeef
New User
Joined: 16 Oct 2006 Posts: 2
|
|
|
|
Hi there. Long time lurker first time poster (I think.. its been a while) So lets get to it
I have two requirements where I need to parse data from a file and then convert it to a different format with additional lines (yes it may be easier with Easytrieve but wondering if I can get away with it using sort).
I would like to show the first one for folks to see what I am going for then show the challenge I am stuck with
INPUT file - one record only
FILETEST101821.txt; otherstuff blah blah blah
My sample sort card - this works
| Code: |
SORT FIELDS=COPY
OUTFIL OUTREC=(C' SIGNON ESF=YES CASE=YES',80:X,/,
C' SUBMIT PROC=XXXXXXX -',80:X,/,
C' &STEP=STEP1 -',80:X,/,
C' &FROMDSN=HARD.CODED.FILE1 -',80:X,/,
C' &TOFILE=',X'7D',C'/hardcoded/directory1/',1,17,
X'7D',80:X,/,
C' SUBMIT PROC=XXXXXXX -',80:X,/,
C' &STEP=STEP2 -',80:X,/,
C' &FROMDSN=HARD.CODED.FILE2 -',80:X,/,
C' &TOFILE=',X'7D',C'/hardcoded/directory1/CK_',1,17,
X'7D',
C'-',80:X,/,
C' SIGNOFF',80:X)
|
Note: ---> the X'7D' is ( ' ) in Hexa
Output Results (more or less)
| Code: |
SIGNON ESF=YES CASE=YES
SUBMIT PROC=XXXXXXX -
&STEP=STEP1 -
&FROMDSN=HARD.CODED.FILE1 -
&TOFILE='/hardcoded/directory1/FILETEST101821.txt'
SUBMIT PROC=XXXXXXX -
&STEP=STEP2 -
&FROMDSN=HARD.CODED.FILE2 -
&TOFILE='/hardcoded/directory1/CK_FILETEST101821.txt'
SIGNOFF |
So I am able to just use that one record file and populate the file name in both &TOFILE lines
Challenge
So for the other requirement that I am stuck with:
I need to parse a 4 line record file that contains the source and destination file name for 2 files (the names change but the length of name is fixed) and turn it into the same format as the first challenge.
INPUT FILE2
| Code: |
PUT 'FILEA.SOURCE.PLACE' +
FILEA.DESTINATION.txt
PUT 'FILEB.SOURCE.PLACE' +
FILEB.DESTINATION.txt |
Target output
| Code: |
SIGNON ESF=YES CASE=YES
SUBMIT PROC=XXXXXXX -
&STEP=STEP1 -
&FROMDSN=FILEA.SOURCE.PLACE -
&TOFILE='/hardcoded/directory1/FILEA.DESTINATION.txt'
SUBMIT PROC=XXXXXXX -
&STEP=STEP2 -
&FROMDSN=FILEB.SOURCE.PLACE -
&TOFILE='/hardcoded/directory1/FILEB.DESTINATION.txt'
SIGNOFF
|
So for above I need to put the parsed text in the &FROMDSN and the &TOFILE IS it possible to extract the file names from INPUT FILE 2 and then put it in the format that I need with the additional lines in just one sort step (using multiple OUTREC ??) or do I need to split up into 4 files and then have another sort step do the merge?
Version of syncsort is 2.1.4.0R
Any help would be appreciated  |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Long-time lurker should know to use the code tags and that they are data sets not files! |
|
| Back to top |
|
 |
Badbeef
New User
Joined: 16 Oct 2006 Posts: 2
|
|
|
|
| Nic Clouston wrote: |
| Long-time lurker should know to use the code tags and that they are data sets not files! |
sadly as I have not had the chance to post never really got the chance to look at how to do the code tags. Could not find em in the Forum FAQ / User Guide section nor on any sticky. May I ask for a link that explains so please?
As for Datasets and not files, sorry force of habit. I keep talking to a bunch of Datastage/ETL folk over here and their definition of a Dataset is different from ours. Then when I talk to the Java /web folk their eyes glaze over when I say Dataset so I just say File  |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Use the full editor - it has buttons to add effects: highlight the text to apply the effect to and click the appropriate button. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Badbeef,
One thing you could do is to build a SYMNAMES data set by reading the 'file names data set', creating 4 symbols corresponding each name. Then use it in the next step. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2288 Location: USA
|
|
|
|
AFAIU a quite flexible approach is required, isn't it?
SYNCSORT is not the best tool for doing this, but it's not a rocket science anyway.
Stage 1: using PARSE, WHEN=GROUP, and BUILD convert the input file
| Code: |
PUT 'FILEA.SOURCE.PLACE' +
FILEA.DESTINATION.txt
PUT 'FILEB.SOURCE.PLACE' +
FILEB.DESTINATION.txt |
to its table-like equivalent:
| Code: |
FILEA.SOURCE.PLACE FILEA.DESTINATION.txt
FILEB.SOURCE.PLACE FILEB.DESTINATION.txt |
Stage 2: Use some kind of a template to define the desired output file structure:
| Code: |
SIGNON ESF=YES CASE=YES
SUBMIT PROC=XXXXXXX -
&STEP=STEP1 -
&FROMDSN=FILEA.SOURCE.PLACE -
&TOFILE='$$$PARAMETER$$$'
SUBMIT PROC=XXXXXXX -
&STEP=STEP2 -
&FROMDSN=FILEB.SOURCE.PLACE -
&TOFILE='$$$PARAMETER$$$'
SIGNOFF |
Stage 3: Using PARSE, WHEN=GROUP, and BUILD insert the required 'key markers' into a working version of the template:
| Code: |
SIGNON ESF=YES CASE=YES
SUBMIT PROC=XXXXXXX -
&STEP=STEP1 -
&FROMDSN=FILEA.SOURCE.PLACE - FILEA.SOURCE.PLACE
&TOFILE='$$$PARAMETER$$$' FILEA.SOURCE.PLACE
SUBMIT PROC=XXXXXXX -
&STEP=STEP2 -
&FROMDSN=FILEB.SOURCE.PLACE - FILEB.SOURCE.PLACE
&TOFILE='$$$PARAMETER$$$' FILEB.SOURCE.PLACE
SIGNOFF |
Stage 4: Using JOINKEYS, PARSE, IFTHEN, and BUILD combine the table-like input, and updated template - replacing $$$PARAMETERS$$$ parts with joined column 2 from table-like input.
| Code: |
SIGNON ESF=YES CASE=YES
SUBMIT PROC=XXXXXXX -
&STEP=STEP1 -
&FROMDSN=FILEA.SOURCE.PLACE -
&TOFILE='FILEA.DESTINATION.txt'
SUBMIT PROC=XXXXXXX -
&STEP=STEP2 -
&FROMDSN=FILEB.SOURCE.PLACE -
&TOFILE='FILEB.DESTINATION.txt'
SIGNOFF |
For details on using SORT statements, and parameters, please, RTFM or search this forum. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
| Code: |
PUT 'FILEA.SOURCE.PLACE' +
FILEA.DESTINATION.txt
PUT 'FILEB.SOURCE.PLACE' +
FILEB.DESTINATION.txt |
-Include only 1-4 = spaces
-Use RESIZE to place two records to each other
FILEA.DESTINATION.txt FILEB.DESTINATION.txt
Use JOINKEYS to Overlay, respective positions from DS1 to DS2. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|