Export to incemental file name

Moderators: Phil Winkler, Graham Smith, Pete Tabord

Export to incemental file name

Postby David » Sat Mar 05, 2011 3:29 am

Hello.

I'm trying to create a normal "comma delimitted" export file. But what I want to achieve is to create an incremental file name.

eg
Export01.txt
Export02.txt

So it automatically knows which was the last created file, so the next time it runs it creates Export03.txt 04 05 and so on.

Do you know if this is something we could automate within de ff?

All the best
David
David
 
Posts: 32
Joined: Thu Sep 03, 2009 2:37 am
Has thanked: 0 time
Been thanked: 0 time
 

Re: Export to incemental file name

Postby JohnBaldwin » Sat Mar 05, 2011 10:41 am

The way I go about this is to have another table in the app, one with just one record, and which has a field, say SeqNo, which holds the next value (ie, 01 or 02, or whatever) to be used, and as a numeric string, and which can be looked up. Then the filename simply becomes

jointext("File",SeqNo)

When the file has been created then you will need to update the SeqNo accordingly.

Hope that's sufficiently clear.
John Baldwin (029 2055 4457)
JohnBaldwin
 
Posts: 221
Joined: Wed Sep 26, 2007 8:58 pm
Location: Cardiff, UK
Has thanked: 0 time
Been thanked: 0 time
 

Re: Export to incemental file name

Postby David » Sun Mar 06, 2011 4:38 am

Thanks John Much appreciated.

Although, this only creates half of the solution, your help has scored a direct hit. I wanted to create a file which would relate to a batch, and I thought the easiest way would be to increment the file name. But by referencing the batch header form, I have exactly what is required without any further maintenance.

Brilliant, thanks John
David
David
 
Posts: 32
Joined: Thu Sep 03, 2009 2:37 am
Has thanked: 0 time
Been thanked: 0 time
 

Re: Export to incemental file name

Postby Graham Smith » Wed Mar 09, 2011 2:01 pm

You don't say what database? If it's Ffenics, then you can do this a few different ways. Here's one:

Create a holder file that will just hold a single number.

Create a procedure that will get that number, increment it by one, and append the number to a file name that you store in a global variable. Like this:
Code: Select all
define global "gFileName" text 20 .
define "n" number .
for HolderForm ;
n := NextNbr .
gFileName := concat("c:\temp\export",n,".csv") .
modify records
  NextNbr := n + 1 .
end .


Now run the export and use the global as the file name. Like this:
Code: Select all
define global "gFileName" text 20 .
for FileName ;
list records
  FieldA .
end .

export to gFileName .
.items
@f[1,1]
.end
Graham Smith
DataSmith, Delaware
"For every expert there is an equal and opposite expert.", Arthur C. Clarke (1917 - 2008)
"X-Clacks-Overhead: GNU Terry Pratchett"
User avatar
Graham Smith
 
Posts: 2501
Joined: Fri Sep 07, 2007 11:31 am
Location: Delaware, USA
Has thanked: 0 time
Been thanked: 1 time
 

Re: Export to incemental file name

Postby KjetilUrne » Wed Mar 09, 2011 6:56 pm

Graham Smith wrote:define global "gFileName" text 20 .


How about being a little generous and extending this global so it will run smoothly beyond the 99th time?


(length of c:\temp\export100.csv = 21)
KjetilUrne
 
Posts: 602
Joined: Mon Oct 08, 2007 8:21 am
Location: Norway
Has thanked: 4 times
Been thanked: 1 time
 

Re: Export to incemental file name

Postby Graham Smith » Thu Mar 10, 2011 1:09 pm

KjetilUrne wrote:How about being a little generous and extending this global so it will run smoothly beyond the 99th time?

Hey, it was just an example and I was typing fast and not really thinking, gimma break will ya?. I think I generally use a 40 character global.
Graham Smith
DataSmith, Delaware
"For every expert there is an equal and opposite expert.", Arthur C. Clarke (1917 - 2008)
"X-Clacks-Overhead: GNU Terry Pratchett"
User avatar
Graham Smith
 
Posts: 2501
Joined: Fri Sep 07, 2007 11:31 am
Location: Delaware, USA
Has thanked: 0 time
Been thanked: 1 time
 
 

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron