FW: Simultaneous report running - different users

John Esak john at valar.com
Sun Feb 20 11:10:41 PST 2005


(I put this up last night but it never made it to the list. Here is is
again.)
-----Original Message-----
From: John Esak [mailto:john at valar.com]
Sent: Sunday, February 20, 2005 3:18 AM
To: filePro mailing list
Cc: Don Coleman
Subject: Simultaneous report running - different users



Hi Don,

Here is the code I was talking about for running the same report
simultaneously by different users. The problem you noted is very much a
problem found everywhere in a multi-user situation. One user starts up a
report which needs temporary files made, while it is running another user
starts the same report. Usually, the first action of a report that uses
temporary spin-off files is to clear these files as the firs line of the
script which runs the report, something like this:

  ddir tempfile -k
  dreport file -f mk_tempfile_spin_off ...
  dreport tempfile -f runstuff ...

Yow! The second instance of running this report clobbers the data the first
user is putting into those temp files.  There are lots of ways to work
around this. Sometimes with unique keys, extra fields, and lots of code to
get you to those specific keys for that day, that minute, that user. This is
like what Jose was suggesting.  I find this little bit of code and
methodology to work much better than his method. It relies on the username
and qualifiers.

First, let me say that I am describing this procedure for a Unix system with
a Unix script, filenames, etc. Windows people can work it out as well making
the proper substitutions and adjustments for their system.

I will describe one of our uses for this username-qualifier solution. Near
the end of the day, many of our people have to see the orders that came in
that day... those orders and those orders only... and they have to run a
special input process on these orders which lets them generate reports, so
it is not just a matter of using a selection set or demand index in the
order file.  I spin off the desired records from this file to a temproary
file and then give the user access to Inquire, Update and Add in this
tempfile. This gives them maximum flexibility to use indexes, and  selection
sets to work with these records. You probably are generating a tempfile and
running reports on it with dreport... same thing. The idea of basing the
rpoert on the user's unique id let's it happen without conflicts.

My code asks them which day they want the orders for... then generates a
qualifier based on their user name. It then populates that qualifier with
the desired records only. When this is done, it puts them into clerk in that
qualifier so they can view this data as they need, and generate reports as
they need from only these selected records. It is run out of our order file,
"npio". (nexus plastics, inc. - orders).

Essentially, this process need only be added to your existing -v table, and
run with a 3 line output table that copies the records to the spin-off file.
Then, you run your desired report as normal.

Here is what our running script looks like.

  rreport npio -fp mk_daily -v mk_qual_file -a -u
  ddir npio -k -m $LOGNAME
  rclerk npio -s1 -m ${LOGNAME} -z daily_userqual -xi -b daily

The "mk_qual_file" process is what you would use to ask the user what
criteria to use for selecting the records. This can be anything of course,
your choice of input questions, etc. We just select orders with a creation
date equal to today's date, but for purposes of this discussion, I'll just
show that we are selecting every record. I ripped all the extra npi-related
stuff out of this code and made it as generic as possible for you. The only
thing you will have to alter are the last lines which generate the indexes
in the newly made qualified file. Put in your -rf fields, lengths, and
sorts. I have it building 3 indexes A,B,C with our lenghts and sorts. You
change these to suit _your_ requirements.

So basically, we are going to build a new qualifier key and its indexes
on-the-fly and base it on the user's @id. If the user has run this process
before, the qualifier does not need to be made again, it will be there
already.

I'll put the colon-delimited prc's at the end of this file.

I have spread the code out onto many lines to make it more readable. You
could shrink this down to about 10 lines probably, but why bother? I like my
code to be spread out, clear and well commented.  Unfortunately, I've been
writing filePro code for so long now,that it all looks self-explanatory to
me. If there is something you want further explained, just ask.

   Sort/Slect Table: mk_qual_file

         If: 'create a username-qualifier for this file if it doesn't exist
    1  Then: 'then select records for this report
         If: made_qual ne "done"
    2  Then: gosub mk_qual
    3  Then: '
    4  Then: 'do your criteria for selection questions here...
         If: '
    5  Then:
sel      If: 'sel
    6  Then:
         If: 'record matches my criteria
    7  Then: select
    8  Then: end
mk_qual  If: 'mk_qual
    9  Then:
   10  Then: declare made_qual(4,,g);  made_qual="done"
   11  Then: declare key_file(256), data_file(256)
   12  Then: key_file="/u/appl/filepro/" { @fi { "/key" { @id
   13  Then: data_file="/u/appl/filepro/" { @fi { "/data" { @id
         If: exists(key_file) eq "1"
   14  Then: return
   15  Then: declare h_c(8,.0)
   16  Then: h_c=create(key_file,"rw")
         If: h_c le "-1"
   17  Then: show "@bad key_file creation...";  exit "66"
   18  Then: h_c=create(data_file,"rw")
         If: h_c le "-1"
   19  Then: show "@bad data_file creation...";  exit "67"
   20  Then: declare SysCmd
   21  Then: SysCmd="dxmaint" < @fi < "-m" < @id < "-oA -rf 2,4,a -e"
   22  Then: SysCmd=SysCmd { ";dxmaint" < @fi < "-m" < @id < "-oB -rf
2,5,a -
             e"
   23  Then: SysCmd=SysCmd { ";dxmaint" < @fi < "-m" < @id < "-oC -rf
3,3,a -
             e"
   24  Then: system SysCmd
   25  Then: return

The output table just copies the selected records to the spun-off qualifier
file.


   Output Table: mk_file

    1  Then: declare qual_file(39,,g);  qual_file=@fi { "@" { @id
    2  Then: lookup tempfile=(qual_file) r=free
    3  Then: copy tempfile;  write tempfile;  end

So, to reiterate, you run the following 3 line script...

1. rreport npio -fp mk_daily -v mk_qual_file -a -u
2. ddir npio -k -m $LOGNAME
3. <rclerk npio -s1 -m ${LOGNAME} -z daily_userqual -xi -b daily>
   <or>
   <dreport npio -f somereportname -a -m $LOGNAME -u>
   --your report or rclerk stuff replaces this third line appropriately--

Have fun, hope this helps.
John Esak

Colon-delimited files for cut-and-paste to your system.

prc.mk_qual_file
:'create a username-qualifier for this file if it doesn't exist:'then se
ords for this report:
:made_qual eq "":gosub mk_qual:
sel:'sel::
::'do your criteria for selection questions here...:
::select:
::end:
mk_qual:'mk_qual::
::declare made_qual(4,,g);  made_qual="done":
::declare key_file(256), data_file(256):
::key_file="/u/appl/filepro/" { @fi { "/key" { @id:
::data_file="/u/appl/filepro/" { @fi { "/data" { @id:
:exists(key_file) eq "1":return:
::declare h_c(8,.0):
::h_c=create(key_file,"rw"):
:h_c le "-1":show "@bad key_file creation...";  exit "66":
::h_c=create(data_file,"rw"):
:h_c le "-1":show "@bad data_file creation...";  exit "67":
::declare SysCmd:
::SysCmd="dxmaint" < @fi < "-m" < @id < "-oA -rf 2,4,a -e":
::SysCmd=SysCmd { ";dxmaint" < @fi < "-m" < @id < "-oB -rf 2,5,a -e":
::SysCmd=SysCmd { ";dxmaint" < @fi < "-m" < @id < "-oC -rf 3,3,a -e":
::system SysCmd:
::return:

prc.mk_file
::declare qual_file(39,,g);  qual_file=@fi { "@" { @id:
::lookup tempfile=(qual_file) r=free:
::copy tempfile;  write tempfile;  end:



More information about the Filepro-list mailing list