use Formatter;
format FMT_HEADER= ************************************************** * FIRST PAGE OF REPORT * ************************************************** .
format FMT_TTITLE= ************************************************** * SOC : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< * $DEAZIEND ************************************************** PROG CDAZIEND CDDIPEND ---- -------- -------- .
format FMT_BODY= @<<< @<<< @<<<<< $FMT->line, $CDAZIEND,$CDDIPEND .
format FMT_CD1LVSTR= TOT]--> @<<<<<<< @<<<<<<< @<<<<<<< 111, 111, 111 . format FMT_BTITLE= -------------------------------------------------- @</@</@< P.@<<< $DAY,$MONTH,$YEAR, $FMT->page .
$BREAKS[0]="CDAZIEND"; $BREAKS[1]="CDDIPEND";
$FMT=new Formatter( 'DBI_DRIVER' => 'Oracle', 'DBI_DATABASE' => 'database', 'DBI_USERNAME' => 'dbusername', 'DBI_PASSWORD' => 'dbpassword', 'DBD_QUERY' => 'SELECT * FROM ANAGRA WHERE CLPERRIF=199901 ORDER BY CDAZIEND', 'BREAKS' => \@BREAKS, 'BREAKS_SKIP_PAGE' => { CD1LVSTR => 1, CDCCOSTO => 0 }, 'FORMAT_PAGESIZE' => 40, 'FORMAT_LINESIZE' => 50, 'FORMAT_FORMFEED' => "\f", 'FORMAT_HEADER' => *FMT_HEADER, 'FORMAT_TTITLE' => *FMT_TTITLE, 'FORMAT_BTITLE' => *FMT_BTITLE, 'FORMAT_BTITLE_HEIGHT' => 2, 'FORMAT_BODY' => *FMT_BODY, 'FORMAT_BREAKS' => { CD1LVSTR => *FMT_CD1LVSTR, }, 'EVENT_PREHEADER' => \&PREHEADER, 'EVENT_POSTHEADER' => \&POSTHEADER, 'EVENT_PRETTITLE' => \&PRETTITLE, 'EVENT_POSTTTITLE' => \&POSTTTITLE, 'EVENT_PREBODY' => \&PREBODY, 'EVENT_POSTBODY' => \&POSTBODY, 'EVENT_PREBTITLE' => \&PREBTITLE, 'EVENT_POSTBTITLE' => \&POSTBTITLE, 'EVENT_ALLBREAKS' => \&BREAKALL, 'EVENT_BREAKS' => { CDAZIEND => \&CDAZIEND, CDDIPEND => \&CDDIPEND } );
$FMT->generate();
sub PREHEADER {do something before header print out} sub POSTHEADER {do something after header print out} sub PRETTITLE {do something before top title print out} sub POSTTTITLE {do something after top title print out} sub PREBTITLE {do something before bottom title print out} sub POSTBTITLE {do something after bottom title print out} sub PREBODY {do something before body print out} sub POSTBODY {do something after body print out}
$FMT->ofmt("Print out a line during report generation",">");
Formatter module perform report generation based on DBI query.
* DBI_DRIVER => Specify wath driver you would use for connect to your database. (See DBD drivers for specific) * DBI_DATABASE => Specify database name (or instance). In union of last parameter it create connection string : dbi:DBI_DRIVER:DBI_DATABASE * DBI_USERNAME => Specify database username * DBI_PASSWORD => Specify database DBI_USERNAME password * DBD_QUERY => Point to a string where Sql Query are located * BREAKS => Point to an array containing fields that cause a break in the report * BREAKS_SKIP_PAGE => Point to an hash that specify if a new page are performed when the break FORMAT ar printed * FORMAT_PAGESIZE => Specify page height in character * FORMAT_LINESIZE => Specify line width in character (only for outf use) * FORMAT_FORMFEED => Specify formfeed sequence when a formfeed or newpage are requested * FORMAT_HEADER => Point to filehandle of the header definition for the report * FORMAT_TTITLE => Point to filehandle of the top title definition for the report * FORMAT_BODY => Point to filehandle of the body definition for the report * FORMAT_BTITLE => Point to filehandle of the bottom title definition for the report * FORMAT_BTITLE_HEIGHT => Height in lines of BTITLE * FORMAT_BREAKS => Point to an hash containig break fields related to its format filehandle definition * EVENT_PREHEDER => Point to the subroutine that is called before header generation * EVENT_POSTHEDER => Point to the subroutine that is called after header generation * EVENT_PRETTITLE => Point to the subroutine that is called before top title generation * EVENT_POSTTTITLE => Point to the subroutine that is called after top title generation * EVENT_PREBODY => Point to the subroutine that is called before body generation * EVENT_POSTBODY => Point to the subroutine that is called after body generation * EVENT_PREBTITLE => Point to the subroutine that is called before bottom title generation * EVENT_POSTBTITLE => Point to the subroutine that is called after bottom title generation * EVENT_BREAKS => Point to structure that contains break fields related to subroutine to execute when the break is berformed
Ex.
* Oracle (Oracle database) * CSV (Comma separated database) * Pg (PostgreSQL database) ... ecc.
For specific look at DBD::<Driver>
* ORACLE_SID for Oracle database * f_dir=/csv/data for CSV file specify directory location of text-file-table * dbname=your db name for PostgreSQL database * DSN for ADO db connection
* Example 1 (Direct via parameters) $FMT=new Formatter( 'DBI_DRIVER' => 'Oracle', 'DBI_DATABASE' => 'database', 'DBI_USERNAME' => 'dbusername', 'DBI_PASSWORD' => 'dbpassword', 'DBD_QUERY' => 'SELECT * FROM ANAGRA WHERE CLPERRIF=199901 ORDER BY CDAZIEND', ...
* Example 2 (Via variable) $query = qq { SELECT * FROM ANAGRA WHERE CLPERRIF=199901 AND CDAZIEND=345 ORDER BY CDAZIEND };
$FMT=new Formatter( 'DBI_DRIVER' => 'Oracle', 'DBI_DATABASE' => 'database', 'DBI_USERNAME' => 'dbusername', 'DBI_PASSWORD' => 'dbpassword', 'DBD_QUERY' => $query, ...
format FMT_DEPARTEMENT= TOTALS FOR DEPARTEMENT ARE ]--> @<<<<<<< @<<<<<<< @<<<<<<< 111, 111, 111 .
format FMT_SUBDEPARTEMENT ********************************* * @|||||||||||||||||||||||||||| * $SUBDEPARTEMENT ********************************* .
$BREAKS[0]="DEPARTEMENT"; $BREAKS[1]="SUBDEPARTEMENT";
$FMT=Formatter->new ( ... 'BREAKS' => \@BREAKS, 'BREAKS_SKIP_PAGE' => { DEPARTEMENT => 1, SUBDEPARTEMENT => 0 }, 'FORMAT_BREAKS' => { DEPARTEMENT => *FMT_DEPARTEMENT }, 'EVENT_BREAKS' => { SUBDEPARTEMENT => \&MySubDepartement }, ... );
sub MySubDepartement {$FMT->putformat(*FMT_SUBDEPARTEMENT)};
In this way a possible output is : ******************************************************* * REPORT BY SUBDEPARTMENT * ******************************************************* ********************************* * CHEMICALS * ********************************* 10 20 40 10 20 40 10 20 40 ********************************* * PHARMACIA * ********************************* 10 20 40 10 20 40 10 20 40
TOTALS FOR DEPARTEMENT ARE ]--> 111 111 111
Specify how many lines are printed for each piece of paper.
Specify how many character are counted by an outf function to perform alignement of text.
Specify the form feed sequence that are called whem a newpage or a formfeed function are called ( and alse a new page of report is required) Default value are CTRL-L (\f)
This parameter point to the format fileheader for HEADER page. Definition of format specific can be found in Perl documentation. Header page is printed only one time at beginning of the report and normally include general specification or purpose of report.
Example:
format MY_HEADER= ****************************************** * DATE : @</@</@<<< * $dd,$mm,$yyyy * PURPOSE : Statistique about user login * ****************************************** .
Identical to HEADER definition. TTITLE is printed on every change of page in the top of the report page
Identical to HEADER definition. BODY is printed on every change of value in fetch of query statament, values of query are passed and traslated to real variable in the main caller program.
Example : if query is SELECT NAME,SURNAME,ADDRESS FROM ADDRESSBOOK in yours format values $NAME,$SURNAME,$ADDRESS are created and updated on every fetch.
format MYBODY= @<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $NAME, $SURNAME $ADDRESS .
Identical to HEADER definition. BTITLE is printed on every change of page in the bottom of the report page
This parameter specify how many lines are printed by the FORMAT_BTITLE definition. I have put this parameter beacuse i don't know how to inform automatically my package in what lines is used by a format definition. If anyone know how to make it possible please contact me.
'EVENT_PRETTITLE' => \&MyBeforeTopTitle
Remember that all values created by the fetch statement are already updated when all events are generated
* Position character The position character specify the position in the line where the text are printed
* Print the bottom title in the current page * Send the form feed sequence * Print the top title in the new page
Vecchio Fabrizio <jacote@tiscalinet.it>