View previous topic :: View next topic
|
Author |
Message |
Giri Bangalore
New User
Joined: 09 Mar 2014 Posts: 2 Location: India
|
|
|
|
Hi,
I have a requirement to add a new field at the end of each record. The requirement is as follows
input file
empid |name |city |dob |firstname
00001 |mark.tracey |New York |01-01-2001 |
00002 |carm.shaw.vander |Boston |07-03-2000 |
00003 |rebekah |Boston |06-01-2000 |
00004 |debby |st.lucas |05-08-1999 |
00005 |.tim.moody |stamford |06-06-2002 |
Output file
empid |name |city |dob |firstname
00001 |mark.tracey |New York |01-01-2001 |tracey
00002 |carm.shaw.vander |Boston |07-03-2000 |shaw
00003 |rebekah varsell |Boston |06-01-2000 |rebeka
00004 |debby |st.lucas |05-08-1999 |debby
00005 |.tim.moody |stamford |06-06-2002 |tim
Please note that the first name can be a max of 20 characters but only the first 6 characters should be part of the new field. The criteria is to get the string after the first dot if present, the full name should be considered if there are no dots at all in the name field.
I tried it with a simple inrec parse with the dot '.' as the delimiter, but am getting the city name when there is no "." in the name field. Is it possible to have it done in dfsort.
Thanks in advance, |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
most probably a double parse might do it ...
parse all the | separated fields
and parse again the first one |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Untested
Try SQZ=(SHIFT=LEFT) |
|
Back to top |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
Giri Bangalore,
Your input does NOT match the output shown. for ex:
Input :
Code: |
00003 |rebekah |Boston |06-01-2000 |
|
Output :
Code: |
00003 |rebekah varsell |Boston |06-01-2000 |rebeka |
1. How did you end up with extra name? Is that a typo?
2.Do you really have the header ? or did you include it to just show us the contents? Do you need it in the output?
Code: |
empid |name |city |dob | |
3. What is the LRECL and RECFM of the input file?
4. Does all the records have a delimiter "|" at the end ? or do we need to populate it along with the extracted first name?
Enrico was on the right track that you need to parse the name field twice as you have mixed bag of strings.
Pandora , You need PARSE to extract the first name and then use SQZ , but you also need to remember that it will eliminate the embedded blanks in between too. so you need to use MID and FINDREP to variably attach the first name at the end of each record. |
|
Back to top |
|
|
Giri Bangalore
New User
Joined: 09 Mar 2014 Posts: 2 Location: India
|
|
|
|
Thanks everybody for all the suggestions.
Hi Skolusu, here are my responses
1. Yes, it was a typo. The record in the input file also should have the name rebekah varsell.
2. The headers are actually present in the input file. It is an existing report that we send to business.
3. The LRECL is 100 and the Record format is FB.
4. Yes, all the records have the delimiter | at the end.
I will try Enrico's suggestion today and let you know if I am successfull.
Regards,
Giri Bangalore |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Though this is does not answer your question, why pass the entire file creating another when the needed output might be created as the "input" file is created? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Quote: |
Pandora , You need PARSE to extract the first name and then use SQZ , but you also need to remember that it will eliminate the embedded blanks in between too. so you need to use MID and FINDREP to variably attach the first name at the end of each record. |
Yes Kolusu I was aware SQZ will eliminate the space inbetween but he could try if he won't have space looking at coded data looks he wont need the SQZ. |
|
Back to top |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
Giri Bangalore,
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
EMPID |NAME |CITY |DOB |
00001 |MARK.TRACEY |NEW YORK |01-01-2001 |
00002 |CARM.SHAW.VANDER |BOSTON |07-03-2000 |
00003 |REBEKAH VARSELL |BOSTON |06-01-2000 |
00004 |DEBBY |ST.LUCAS |05-08-1999 |
00005 |.TIM.MOODY |STAMFORD |06-06-2002 |
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ABSPOS=8,FIXLEN=20,ENDBEFR=C'|',ENDBEFR=C' ')),
OVERLAY=(101:C'@',%01)),
IFTHEN=(WHEN=(102,20,SS,EQ,C'.'),
PARSE=(%02=(ABSPOS=102,FIXLEN=20,STARTAFT=C'.',ENDBEFR=C'.')),
OVERLAY=(101:C'@',%02))
OUTREC IFTHEN=(WHEN=INIT,
BUILD=(1,121,SQZ=(SHIFT=LEFT,MID=C' ',LENGTH=120))),
IFTHEN=(WHEN=INIT,
FINDREP=(INOUT=(C'| @NAME',C'|FIRSTNAME',C'| @',C'|')))
//* |
Output from the above
Code: |
EMPID |NAME |CITY |DOB |FIRSTNAME
00001 |MARK.TRACEY |NEW YORK |01-01-2001 |TRACEY
00002 |CARM.SHAW.VANDER |BOSTON |07-03-2000 |SHAW
00003 |REBEKAH VARSELL |BOSTON |06-01-2000 |REBEKAH
00004 |DEBBY |ST.LUCAS |05-08-1999 |DEBBY
00005 |.TIM.MOODY |STAMFORD |06-06-2002 |TIM |
|
|
Back to top |
|
|
|