IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help in arriving at a logic


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Jun 19, 2013 9:05 am
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Jun 19, 2013 9:23 am
Reply with quote

You always want them as single record?

or is Multiple record ok for you ?
Back to top
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Jun 19, 2013 9:47 am
Reply with quote

Hi I want them as a single record so that it can be used in where condition
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Jun 19, 2013 10:05 am
Reply with quote

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
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Jun 19, 2013 11:22 am
Reply with quote

the number of records is not fixed ,it may vary from month to month
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jun 19, 2013 11:53 am
Reply with quote

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
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Jun 19, 2013 12:30 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Jun 19, 2013 12:52 pm
Reply with quote

karthik,

I would strictly suggest you to read the manuals so that you could understand Arun's hints or pointers
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jun 19, 2013 2:36 pm
Reply with quote

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
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Jun 19, 2013 5:47 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 19, 2013 7:03 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Jun 20, 2013 4:19 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Finding faulty logic Subscript out of... COBOL Programming 5
This topic is locked: you cannot edit posts or make replies. Need assistance in job scheduling logic. Mainframe Interview Questions 2
No new posts Rexx Logic error while adding seperat... CLIST & REXX 3
No new posts PL/1 Callback address logic in z/OS C... PL/I & Assembler 1
No new posts Sync logic between VSAM files and DB2... COBOL Programming 9
Search our Forums:

Back to Top