Blogs Home
Wednesday, August 22, 2012 12:23 PM

Report Writing Tip: Dynamic Filenames from a scheduled NPR report (Client/Server or 6.x)

Written by Joe Cocuzzo, Senior VP of Report Writing Services - iatricSystems

NPR report writers at MAGIC sites probably know that you can write code anywhere in a MAGIC report to put a file name into /ZFTP.TITLE and if the report is scheduled to Auto FTP, the file name created by the report code will be used instead of the default file name based on the report title.

The Client/Server scheduler offers download file naming options: “Replace (using a hardcoded path),” “Append (using a hardcoded path)” or “Unique (adding a timestamp to a hardcoded path).” This is often not sufficiently flexible to suit dynamic file naming needs. There is a KB article (38192) that describes a method to imbed a program call in the title of a report to force it directly to download, but it is cumbersome, and in 5.6 and 6.0 you cannot imbed a local macro in a report that is to be run from a menu unless the macro is in Z or MIS. This is because when the M-AT front end displays the report screen, it does not open the application until after the title is displayed (so your call to a program in the title will crash).

This month we will show an easier way to include a macro with your scheduled report that will allow you to build a dynamic file name with code, rather than being restricted to the options provided by the scheduler.

All you need to do is add a macro (written as a program) called “” to your report, and in it set the path into @t.MIS.RPT.SCHED.share.file[@t.MIS.RPT.SCHED.mnemonic].

The code looks like this:

What makes this a program is that the last expression (last line) is terminated with a semicolon. There is nothing special about using the variable EXIT as the last expression, that is just a convention in MAGIC programming to show that the program returns nothing, since the variable EXIT is nil (since it is not defined anywhere in the macro).

You might be interested in how we figured out this easier way. The trick is to look at the MEDITECH source code for the Report Scheduler programs to see if there is a way to control the filename from code in the report being run by the scheduler.

I went into a report macro (any report will do) and used the F(5) “Get” key in a macro and looked through the MIS DPM’s to find “MIS.RPT.SCHED” and then poked around (view only) in the three bkg programs to find the one that set up the download path for a scheduled report. The procedure is: MIS.RPT.SCHED.bkg.start.

Looking at the top of that procedure, I saw the scheduler would obligingly run any macro attached to the report called “,” provided that macro is written as a program. This would happen after the data from the MIS.RPT.SCHED dictionary was transferred from permanent to temporary (slash) variables, but before the report itself was run.

Further down in the report I could tell that if I set up my report schedule to “overwrite,” I could be sure that the background job program would just use whatever path was sitting in @t.share.file. Because my macro “” will get called after the @t.share.file is fetched from the schedule dictionary, but before the file is opened for report output, I can write a new value to @t.share.file and have that path be used instead.

In the scheduler dictionary, I set my report up as follows:

After the scheduler runs my report, we can see in the destination folder that the macro named the file:

A sample report has been added to our C/S report library:

Search our report library for more Report Writing tips: (search for fishbone – only 1 hit per platform and likely to stay that way).

You can find additional Report Writing Tips on our website at, as well as information about our on-site Report Writer Training and Report Writing Services.

Read Joe's blog posts at MEDI-Talk.

Upcoming Report Writer Training Opportunities:

We are pleased to offer Report Writer training sessions at host sites. Details and a course description are available on our website at

Location Level Instructor Date Status
Salinas Valley Memorial HealthCare
Salinas, CA
Report Designer for 6.x: Beginner/Intermediate Philip Sherry September
5-7, 2012
Fee for Seat
Valley Presbyterian Hospital
Van Nuys,CA
C/S NPR Report Writer: Intermediate/Advanced Richard Serrano September
10-12, 2012
Fee for Seat

To subscribe for email notifications for new classes, please follow this link:

For more information or to reserve a seat, please contact our NPR report writing team at

(This article originally appeared in the August 2012 issue of Iatric Systems Updates! newsletter.)