PPWIZARD Manual
[Bottom][Contents][Search][Prev]: Importing fields into 3 HTML documents[Next]: Resource Validation - Local

Importing Fields, Each Record To It's Own File

I wrote this example for someone who wanted to do pretty much what you see here, each record of a CSV file creates it's own html page. The name of the file is determined by the record number.

You should also have a look at the other multiple import example. The example on this page is similar but does things in a completely different way.

;----------------------------------------------------------------------------
;    MODULE NAME:   IMPORT.IT
;
;    DESCRIPTION:   Example file of import of a comma delimited file where
;                   each record goes into its own file. The line number is
;                   used to name the file.
;
;
;                   Imported file looks like:
;                   ~~~~~~~~~~~~~~~~~~~~~~~~~
;                   Dennis,Bareis,Programmer
;                   Wendy,Buxton,Librarian
;                   Fred,Nerk,Idiot
;
;----------------------------------------------------------------------------


;--- Start and end main HTML file -------------------------------------------
<HTML>
<HEAD>
   <TITLE>MAIN FILE</TITLE>
</HEAD>
<BODY>
<H1>MAIN FILE</H1>
<P>This is a fairly basic example kept simple on purpose to hopefully
make things easier to understand.
Basically we imported a comma delimited
file (could have been fixed or other format) and generate the record into a
new html page whose name depends on the line Number.


;--- Initialize a line count ------------------------------------------------
#RexxVar RecordLineCount = 0


;--- Define HTML to start the import data files -----------------------------
#define StartsImportFiles                           \
        ;--- Open the record's file ------------   -\
        #output 'file_{$LineNum}.htm' ASIS         -\
                                                   -\
        ;--- Output Start of HTML page ---------   -\
        <HTML>                                     %\
        <HEAD>                                     %\
           <TITLE>IMPORTED: {$Desc}</TITLE>        %\
           <?PpwizardGeneratorMetaTags>            %\
        </HEAD>                                    %\
        <BODY>                                     %\
        <H1>IMPORTED: {$Desc}</H1>

;--- Define HTML to end the import data files -------------------------------
#define EndsImportFiles                             \
        ;--- Output end of html page -----------   -\
        </BODY></HTML>                             -\
                                                   -\
        ;--- Close this HTML file --------------   -\
        #output


;--- Prepare for import -----------------------------------------------------
#evaluate ''  'NL = d2c(10)'                        ;;NL = Newline Code
#define     IMPORT_PROTECT_START                    ;;We don't want imported data "protected" or #output etc won't get executed
#define     IMPORT_PROTECT_END
#define     IMPORT_HEADER                           ;;We will output our own headers
#define     IMPORT_BEFORE
#define     IMPORT_AFTER                            ;;We will output our own trailers
#DefineRexx IMPORT_RECORD_FILTER
        ;--- Which output file should contain this record? ---
        RecordLineCount = RecordLineCount + 1;

        ;--- Make sure output will go to correct file --------
        Codes =          '<' || '$StartsImportFiles LineNum="' || RecordLineCount || '" Desc="FILE #' || RecordLineCount || '">'
        Codes = Codes || NL;
        Codes = Codes || '  <P>Column 1 = ' || Column.1;
        Codes = Codes || NL;
        Codes = Codes || '  <P>Column 2 = ' || Column.2;
        Codes = Codes || NL;
        Codes = Codes || '  <P>Column 3 = ' || Column.3;
        Codes = Codes || NL;
        Codes = Codes || '<' || '$EndsImportFiles>';
        Codes = Codes || NL;
        Codes = Codes || NL;
        ThisRecordsCodes = Codes;
#DefineRexx


;--- Import the data into the 'x' files -------------------------------------
#import INPUT.CMA CMA "" "First Name" "Surname" "Job"


;--- Report on the number of files created/records imported -----------------
<P>Thats all folks, created <??RecordLineCount $$AddComma> files.

;--- Finish off HTML for "control" page -------------------------------------
</BODY></HTML>


[Top][Contents][Search][Prev]: Importing fields into 3 HTML documents[Next]: Resource Validation - Local

PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Tuesday January 02 2001 at 7:37am