Author |
Message
|
ManojNTT |
Posted: Fri Jan 08, 2016 3:35 am Post subject: FileName generation in ESQL |
|
|
Newbie
Joined: 03 Dec 2015 Posts: 6
|
Hi Guys
My flow is like below:
MQ INPUT -> Compute(For file name logic) -> File OUTPUT Node
I have a requirement that the file name should contain 0000000 for first file and it should increase for each next file along with some name as below
1st filename: ABC0000000
2nd fulname: ABC0000001
3rd filename: ABC0000002
.
.
.
I wrote esql code like this,
Declared shared variable FilePadding = 0000000;
SET FilePadding = FilePadding + 0000001 ;
SET OutputLocalEnvironment.Destination.File.Name = 'ABC'||CAST(FilePadding AS CHARACTER);
But I'm not getting the required output. Can anyone help me in this. |
|
Back to top |
|
 |
maurito |
Posted: Fri Jan 08, 2016 5:03 am Post subject: Re: FileName generation in ESQL |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
ManojNTT wrote: |
Hi Guys
My flow is like below:
MQ INPUT -> Compute(For file name logic) -> File OUTPUT Node
I have a requirement that the file name should contain 0000000 for first file and it should increase for each next file along with some name as below
1st filename: ABC0000000
2nd fulname: ABC0000001
3rd filename: ABC0000002
.
.
.
I wrote esql code like this,
Declared shared variable FilePadding = 0000000;
SET FilePadding = FilePadding + 0000001 ;
SET OutputLocalEnvironment.Destination.File.Name = 'ABC'||CAST(FilePadding AS CHARACTER);
But I'm not getting the required output. Can anyone help me in this. |
so why don't you tell us what you are getting ?...
probably not getting the leading '0', my guess is that you declared FilePadding as integer, so the leading 0 do not count and 0000001 will cast as character '1'.
Add the FORMAT clause to the CAST. that is in the docs. |
|
Back to top |
|
 |
ManojNTT |
Posted: Fri Jan 08, 2016 6:33 am Post subject: |
|
|
Newbie
Joined: 03 Dec 2015 Posts: 6
|
Yes Mauriro. I'm getting my output as 1.
How do I use FORMAT in this case?
If I use FORMAT it is fine upto first 9 files.
What about from 10th file(Since output reaches to 2 digits). Then how I can use FORMAT here? Plz suggest. |
|
Back to top |
|
 |
maurito |
Posted: Fri Jan 08, 2016 6:38 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
ManojNTT wrote: |
Yes Mauriro. I'm getting my output as 1.
How do I use FORMAT in this case?
If I use FORMAT it is fine upto first 9 files.
What about from 10th file(Since output reaches to 2 digits). Then how I can use FORMAT here? Plz suggest. |
Have you read the documentation as suggested ? what have you tried ? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jan 08, 2016 6:38 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ManojNTT wrote: |
If I use FORMAT it is fine upto first 9 files.
What about from 10th file(Since output reaches to 2 digits). Then how I can use FORMAT here? Plz suggest. |
I'd suggest you reread this and then use FORMAT correctly, rather than just using it to insert 6 '0' characters. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ManojNTT |
Posted: Fri Jan 08, 2016 7:18 am Post subject: |
|
|
Newbie
Joined: 03 Dec 2015 Posts: 6
|
Thanks Vitor and maurito
I got the result  |
|
Back to top |
|
 |
maurito |
Posted: Fri Jan 08, 2016 7:51 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
ManojNTT wrote: |
Thanks Vitor and maurito
I got the result  |
Do you realise that if for any reason the flow is restarted, you will start from 0 again ?. Have you questioned that to the whoever put the requirement to you ? would it not be easier to append a timestamp to the file ? |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Jan 08, 2016 9:39 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
maurito wrote: |
ManojNTT wrote: |
Thanks Vitor and maurito
I got the result  |
Do you realise that if for any reason the flow is restarted, you will start from 0 again ?. Have you questioned that to the whoever put the requirement to you ? would it not be easier to append a timestamp to the file ? |
The OP could put the sequence number into a DB table. A few years ago, I suggested this to one client in India who was addicted to files. They rejected the use of a DB table because it was unmaintainable.
Glad that contract was just for a month. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
maurito |
Posted: Fri Jan 08, 2016 9:56 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
smdavies99 wrote: |
maurito wrote: |
ManojNTT wrote: |
Thanks Vitor and maurito
I got the result  |
Do you realise that if for any reason the flow is restarted, you will start from 0 again ?. Have you questioned that to the whoever put the requirement to you ? would it not be easier to append a timestamp to the file ? |
The OP could put the sequence number into a DB table. A few years ago, I suggested this to one client in India who was addicted to files. They rejected the use of a DB table because it was unmaintainable.
Glad that contract was just for a month. |
to be honest with you, I would also reject the use of a db just for keeping a sequence, when that can easily be done by using a timestamp.
I am glad the client rejected that suggestion. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jan 08, 2016 10:45 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
maurito wrote: |
Do you realise that if for any reason the flow is restarted, you will start from 0 again ?. |
I'd bet no, the OP has not realized that.
maurito wrote: |
Have you questioned that to the whoever put the requirement to you ? |
Again I'll bet no, and would further bet that it'll be considered unacceptable when it's mentioned and/or it turns up in testing.
maurito wrote: |
would it not be easier to append a timestamp to the file ? |
That would be my choice, but my last bet is they'll stick with sequence numbers because they want to use sequence numbers, the reasoning being they want to use sequence numbers (i.e. no reasoning at all but a Pavlovian response) and the OP will be back asking about how to store the sequence number in a DB table, and how to deal with the issues when files arrive quickly.
Which of course isn't an issue with a timestamp unless the files arrive really, really quickly. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jan 08, 2016 10:59 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I wonder if there's some additional persistent storage method available in IIB v8 and later that doesn't require any additional software outside of IIB.
I wonder what happens if the "wrong" file gets the "wrong" sequence number - i.e. the 10th file that comes in is given sequence # 9. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
maurito |
Posted: Sat Jan 09, 2016 1:05 am Post subject: |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
mqjeff wrote: |
I wonder what happens if the "wrong" file gets the "wrong" sequence number - i.e. the 10th file that comes in is given sequence # 9. |
or even worse, if two files get the same sequence, as I have not seen the OP mentioning 'single thread' or 'atomic' when incrementing the sequence. |
|
Back to top |
|
 |
smdavies99 |
Posted: Sat Jan 09, 2016 4:19 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Oh what a tangled web we weave for something apparently so simple eh?
 _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jan 11, 2016 5:52 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I wonder if we can convince Dijkstra to write an article titled "Files considered Harmful". _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Jan 11, 2016 7:16 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
mqjeff wrote: |
I wonder if we can convince Dijkstra to write an article titled "Files considered Harmful". |
I'm sure the MQ Community would crowdfund it.  _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
|