Focal Point
Dynamic file name from RC

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3311027182

April 24, 2008, 03:41 PM
Trina
Dynamic file name from RC
Hi there!

Is there any way of getting dynamic file name each time a task generated from Report Caster? Explanation below-

File Name : HR-yyyymmdd-nnnnn.txt

Exp 1:
HR-20080422-00001.txt
This is the name I want when the task run first time from RC on April 22nd.

Exp 2:
HR-20080423-00002.txt
This is the name I want when the task run second time from RC on April 23rd.

Exp 3:
HR-20080424-00003.txt
This is the name I want when the task run 3rd time from RC on April 24th.

Thanks!


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
April 25, 2008, 02:52 AM
Tony A
Trina,

What you are asking makes no difference whether executed from within RC, MRE or APPs, the principle is the same. All you have to think about is how you want to control to last portion of the file name - then "nnnnn".

One way to do it would be to have a file or table somewhere that you hold the sequence number in. Then each time the process is run you can read the file, increment it, use the value and write the new number back to your file.

Then use DM to build the filename, something like this -
FILEDEF SEQ_NO DISK [full file path relative to the reporting server]
-RUN
-READ SEQ_NO &Seq_No.A6
-IF &IORETURN NE 0 THEN [go to error report DM code];
-SET &Seq_No = EDIT(&Seq_No) + 1;
-SET &SN_Len = &Seq_No.LENGTH + 5;
-SET &Seq_No = SUBSTR(&SN_Len, '00000&Seq_No.EVAL', &SN_Len - 5, &SN_Len, 6, 'A6');
-RUN
FILEDEF SEQ_NO DISK [full file path relative to the reporting server]
-RUN
-WRITE SEQ_NO &Seq_No
-SET &FileName = 'HR-'||&YYMD||'-'||&Seq_No||'.txt';
-TYPE &FileName

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
April 28, 2008, 04:18 PM
Trina
Thanks a lot Tony.

One more question - how would RC know the the value of the parameter &FileName?


Trina


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
April 28, 2008, 05:42 PM
Tony A
Because of this line within your code
quote:
-SET &FileName = 'HR-'||&YYMD||'-'||&Seq_No||'.txt';
T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
April 29, 2008, 10:49 AM
Trina
Sorry Tony, I'm still not getting it. I do have that code in my .fex procedure. But in the "Report Distribution Information" section of the RC what would I write for "Save Report AS"?

Trina


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
April 29, 2008, 11:30 AM
Prarie
Are you talking about the Task Section...where is says Save report as? That is saving the report.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Yes, you are correct Prarie!


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
quote:
what would I write for "Save Report AS"?

Anything you like as the saving of the file will be controlled by your fex (because of the code) and not RC which normally expects the "report" to finish with ON TABLE PCHOLD FORMAT &WFFMT or the like.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
I've the following code in my .fex

-SET &FILENAME = 'HR-ATFI-EPIC'||&YYMD||'-'||'.txt';

I wrote "HR" in the "Save Report As" section and ran. RC send me the report as email attachment with name "HR" only.


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
What do you have in the ON TABLE PCHOLD part?


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
If I use ON TABLE PCHOLD FORMAT &FILENAME, it
gives me the following error. That's why I used
ON TABLE PCHOLD FORMAT EXL2K

BTP1010 Task error: THE OPTION AFTER THE WORD FORMAT IS INVALID:


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
My success with FTP dynamic filenames (date) stemmed from these two techniques. Hope it works for you as well.
http://techsupport.informationbuilders.com/sps/10962092.html
http://techsupport.informationbuilders.com/sps/22162080.html


I understand this will handle only the filename portion as a dynamic variable, but I am sure you can expand it similarly to handle extension with a sequence with what Tony A already mentioned here. Probably having to place it in a pre-process fex to finding the next sequence number. Hope this is of help. Ira

AIX 533 wf 5.3.7 dev
7.6.1 test
533 prod

Ira


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
Trina,

Create another variable called for example, &DDNAME.

-SET &DDNAME='HR-ATFI-EPIC';

Then,

APP FI &DDNAME DISK &FILENAME
-RUN
Then your table request including this line:
ON TABLE PCHOLD AS &DDNAME

Try that.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
As per Ginny, you need to FILEDEF the file you want to create but then HOLD (not PCHOLD) that file.

The error you got using ON TABLE PCHOLD FORMAT &FILENAME is because the &FILENAME isn't a valid format so you needed to use ON TABLE HOLD AS &FILENAME FORMAT EXL2K.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
quote:
-SET &FILENAME = 'HR-ATFI-EPIC'||&YYMD||'-'||'.txt';


She's got a .txt in &FILENAME and I don't think that will work either. She's got to hold as ddname and use &FILENAME in her filedef.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
Actually, the ".txt" really doesn't matter that much as it will still work. However, you should have the file FILEDEF'd and reference the ddname in the HOLD statement -
-SET &FILENAME = 'HR-ATFI-EPIC'||&YYMD||'-'||'.txt';
FILEDEF &FILENAME DISK C:\ibi\apps\tonya\&FILENAME
....
ON TABLE HOLD AS &FILENAME FORMAT ALPHA

... and of course for EXL2K output you'd want the file extension of ".xls".

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
Thanks Ginny and Tony!

I tired-

-SET &FILENAME = 'HR-ATFI-EPIC'||&YYMD||'-'||'.xls';
-SET &DDNAME='HR-ATFI-EPIC';
APP FI &DDNAME DISK &FILENAME
-RUN
Then
ON TABLE PCHOLD AS &DDNAME
as well as
ON TABLE HOLD AS &DDNAME (according to Tony)

But unfortunately none of these works.


WebFOCUS 7.6.10
Windows/XP
Database: Oracle
Output: Excel
ON TABLE HOLD AS &DDNAME FORMAT EXL2K


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Trina,

When you say that it doesn't work, I guess you mean that you can't locate the file or that the file is not named correctly when you cast it to the recipient email address?

Let's take a step back and explain a few things.

When you run a report through RC and want RC to cast the output, then the file name will be what you have set in the relevant input text box via RC.

If you want to control the file name then you generally have to resort to forcing your fex to do the hard graft and use HOLD AS filename within your code. As you have discovered you will have to filedef the ddname etc. but you still have to understand how WF functions in regard to filedefs.

If you filedef the full and complete path within your filedef then the file will end up in the directory specified relative to the reporting server. e.g FILEDEF DDNAME DISK C:\ibi\apps\ibisamp\rcoutput.xls used with ON TABLE HOLD AS DDNAME FORMAT EXL2K will place the "Excel" file on your reporting server in the folder etc. if the folder exists (the filename is created so it obviously doesn't have to exist).

If you do not specify the full path with the filedef then the file will end up in the temprary folder for the agent number that is used to run the fex. (see other posts on getting the temp folder name). This is not normally good because the folder is emptied when the agent finishes running your report. So FILEDEF DDNAME DISK rcoutput.xls with ON TABLE HOLD AS DDNAME FORMAT EXL2K will end up somewhere like C:\ibi\webfocus76\wfs\edatemp\ts000001\rcoutput.xls - albeit very briefly before WF cleans up the folder!! You can cathc this file and copy it to a location that you wish by using a system command such as CMD COPY rcoutput.xls C:\etc. etc. etc. You could also copy it to a share on another machine via CMD COPY rcoutput.xls \\[machine name]\[share name]\etc. etc. etc.

Next you have to understand the difference between PCHOLD and HOLD. PCHOLD will return the file to the client browser when the fex is run interactively (i.e not through RC. HOLD will place the file on the reporting server, location depandant upon whether you have used FILEDEF or not.

So using your filedef and PCHOLD, RC would have ignored the PCHOLD and placed the output into a file named as per the dialog within RC when the scheduled task was created and sent that file to the spcified recipient.

Using your filedef with HOLD would have placed the file into the edatemp folder on your reporting server mometarily before delaeting it! Frowner

However, before you get too despondant, there is a method you could use, and that would be to have a pre process to set the file name in the RC dialog - which is actually held in one of the RC tables - to something you want. Not straight forward for a beginner but it is possible.

I hope that this has explained a few things without causing more confusion Confused and good luck

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
Wow...that was quite a mouth full...Tony..shouldn't you be sleeping? Wink


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
I thought I was having a nightmare!! Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
You ARE!!!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe