View previous topic :: View next topic
|
Author |
Message |
karthik3883
New User
Joined: 19 Oct 2007 Posts: 37 Location: chennai
|
|
|
|
Hi,
I require a help in arriving at a logic. my input file contains list like below and number of items is not fixed
BBRM
UB
UK
LCB
and i want to make this as ('BBRM','UB','UK','LCB") where condition.
I can able to do this in sort and i want to know how can we conclude it is a last record and finish with close paranthesis ')'
Regards
Karthik |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
You always want them as single record?
or is Multiple record ok for you ? |
|
Back to top |
|
|
karthik3883
New User
Joined: 19 Oct 2007 Posts: 37 Location: chennai
|
|
|
|
Hi I want them as a single record so that it can be used in where condition |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
ok on a regular basis how many records do you expect in Input file
What is the Maximum and minimum length of records?
FYI query also works if where clause is in multiple records
And sort product is? |
|
Back to top |
|
|
karthik3883
New User
Joined: 19 Oct 2007 Posts: 37 Location: chennai
|
|
|
|
the number of records is not fixed ,it may vary from month to month |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
karthik3883 wrote: |
I can able to do this in sort and i want to know how can we conclude it is a last record and finish with close paranthesis ')'
Regards
Karthik |
Karthik,
One way of doing it would be to have a dummy value using TRAILER1 at the end like this, which is never expected in the data.
Code: |
( --> HEADER1
'BBRM',
'UB',
'UK',
'LCB',
'dummy-end') --> TRAILER1 |
|
|
Back to top |
|
|
karthik3883
New User
Joined: 19 Oct 2007 Posts: 37 Location: chennai
|
|
|
|
Hi Arun,
Thank you ,
Actually we are doing a FTP from a file,normally a .txt which contains details like
aaaa
vvvv
ccccc
and wont contain trailer
i have to convert this to ('aaaa','vvv','ccccc);
please help me if there is any way to achieve this |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
karthik,
I would strictly suggest you to read the manuals so that you could understand Arun's hints or pointers |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
karthik3883,
If you are to use your output to build a "dynamic" SQL WHERE condition, it does not matter if you have the values in a single record or in multiple records. In fact it is pretty much easier to write it in multiple records.
My suggestion was to use the OUTFIL BUILD to format your data records which in turn will write the actual search values in your WHERE clause. And use the HEADER1 and TRAILER1 parameters in the OUTFIL to write the open and close parantheses respectively, but the last value in the WHERE should not have a comma suffixed to it and hence the trick with the TRAILER1 with dummy-end value. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi karthik3883,
You can achieve what Arun has suggested using this SORT job, assuming that you have DFSORT and maximum length of data is 10.
Code: |
//SORTIN DD *
AAAA
VVVV
CCCCC
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,BUILD=(C'''',2:1,10,
SQZ(SHIFT=LEFT,TRAIL=C''',')))
OUTFIL REMOVECC,HEADER1=('('),TRAILER1=('''DUMMY'');') |
Output:
Code: |
(
'AAAA',
'VVVV',
'CCCCC',
'DUMMY'); |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Need a help
may be the least useful subject posted in a long time . . .
Pretty much everyone who starts a topic is looking for some kind of help . . .
Please use meaningful topic/subject. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
As has been pointed out already, this is much more sensible to do over several lines.
Borrowing a Smart Trick, here is a DATASORT solution.
Yes, then does mean sorting the file, but since it is values for a WHERE clause, I'm assuming there aren't going to be hundreds of thousands of input records.
DATASORT allows you to specify "header records" (FIRST(n)) and "trailer records" (LAST(n)) which retain their original relative positions in the file whilst everything in between is sorted.
With DATASORT you get OPTION EQUALS for nothing. So the "data" can be sorted on the first byte (which by that time is always a single-quote) and the records even stay in the same order. The "non-trailer" records get a comma after the closing quote, the "trailer" record does not.
Code: |
//MKWHEN EXEC PGM=ICETOOL
//SYMNAMES DD *
DATA-AREA,1,71,CH
DATA-BYTE-ONE,1,1,CH
SINGLE-QUOTE,C''''
QUOTE-COMMA,C''','
OPENING-BRACKET,C'('
CLOSING-BRACKET,C')'
INDENT-BRACKETS,5
//SYMNOUT DD SYSOUT=*
//TOOLIN DD *
DATASORT FROM(IN) TO(OUT) LAST USING(WHEN)
//WHENCNTL DD *
INREC OVERLAY=(DATA-BYTE-ONE:DATA-AREA,
JFY=(SHIFT=LEFT,
LEAD=SINGLE-QUOTE,
TRAIL=QUOTE-COMMA))
SORT FIELDS=(DATA-BYTE-ONE,A)
OUTFIL FNAMES=OUT,REMOVECC,
HEADER1=(INDENT-BRACKETS:OPENING-BRACKET),
TRAILER1=(INDENT-BRACKETS:CLOSING-BRACKET),
IFTHEN=(WHEN=(DATA-BYTE-ONE,NE,SINGLE-QUOTE),
OVERLAY=(DATA-BYTE-ONE:DATA-AREA,
JFY=(SHIFT=LEFT,
LEAD=SINGLE-QUOTE,
TRAIL=SINGLE-QUOTE)))
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
BBRM
UB
UK
LCB
//OUT DD SYSOUT=* |
Output is:
Code: |
(
'BBRM',
'UB',
'UK',
'LCB'
) |
|
|
Back to top |
|
|
|