PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: FileMake - Create File[Next]: Importing Fields, Each Record To Its Own File
\ -> Examples / Tips -> Importing fields into 3 HTML documents

Importing fields into 3 HTML documents

This example shows how to import a comma delimited file into multiple HTML pages. The page each record goes into depends on the first character of the "surname" field. This basic process would also work for Fixed Field and Multi Line imports.


;    DESCRIPTION:   Example file of import of a comma delimited file into
;                   3 separate HTML files based on the surname field (the
;                   second field).
;                   Imported file looks like:
;                   ~~~~~~~~~~~~~~~~~~~~~~~~~
;                   Dennis,Bareis,Programmer
;                   Wendy,Buxton,Librarian
;                   Fred,Nerk,Idiot

;--- Start and end main HTML file -------------------------------------------
<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 put the record into a
particular html page based on the surname field.

<P>The following imported tables are available:
   <LI><A HREF="p_a2l.htm">A - L</A>
   <LI><A HREF="p_m2z.htm">M - Z</A>
   <LI><A HREF="p_oth.htm">Others</A>

;--- Define HTML to start the import data files -----------------------------
#define StartsImportFiles                           \
        #output 'p_{$Suffix}.htm' ASIS             -\
        <HTML>                                     %\
        <HEAD>                                     %\
           <?PpwizardGeneratorMetaTags>            %\
        </HEAD>                                    %\
        <BODY>                                     %\
        <CENTER>                                   %\
        <H1>IMPORTED: {$DESCRIPTION}</H1>          %\
        <TABLE BORDER=5 CELLSPACING=5>             %\

;--- Define HTML to end the import data files -------------------------------
#define TrNoRecords   <TD ALIGN=CENTER><FONT COLOR="RED">No records</FONT></TD>
#define EndsImportFiles                                          \
        #output 'p_{$Suffix}.htm' ASIS APPEND                   -\
        #if {$Suffix} = 'N'                                     -\
            <TR><$TrNoRecords><$TrNoRecords><$TrNoRecords></TR> -\
        #endif                                   -\
        </TABLE>                                 %\
        </CENTER>                                %\
        </BODY></HTML>                           %\

;--- Create 3 output files and fill with start of HTML and start table etc ---
<$StartsImportFiles SUFFIX="oth" DESCRIPTION="OTHER">
<$StartsImportFiles SUFFIX="a2l" DESCRIPTION="A to L">
<$StartsImportFiles SUFFIX="m2z" DESCRIPTION="M to Z">

;--- Prepare for import -----------------------------------------------------
#evaluate ''  'NL = d2c(10)'                        ;;NL = Newline Code
#evaluate ''  'oth = 'N'; a2l = 'N'; m2z = 'N';'    ;;No records output yet
#define     IMPORT_PROTECT_START                    ;;We don't want imported data "protected" or #output etc won't get executed
#define     IMPORT_HEADER                           ;;We will output our own headers
#define     IMPORT_BEFORE
#define     IMPORT_AFTER                            ;;We will output our own trailers
        ;--- Which output file should contain this record? ---
        Char1 = translate(left(Column.2, 1));
        if Char1 < 'A' & Char1 > 'Z' then
           Suffix = 'oth';    ;;Not a letter
           oth    = 'Y';
           ;--- We have a letter ---
           if Char1 < 'M' then
              Suffix = 'a2l';
              a2l    = 'Y';
              Suffix = 'm2z';
              m2z    = 'Y';

        ;--- make sure output will go to correct file ---
        call WriteLineToTmpImportFile '#if <?OutputLevel> > 1' || NL || '   #output' || NL || '#endif';
        call WriteLineToTmpImportFile '#output ^p_' || Suffix || '.htm^ ASIS APPEND';

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

;--- Close last file --------------------------------------------------------
#if <?OutputLevel> > 1

;--- Finish off 3 html tables and files ----
<$EndsImportFiles SUFFIX="oth">
<$EndsImportFiles SUFFIX="a2l">
<$EndsImportFiles SUFFIX="m2z">

Note that the example above overrides "IMPORT_PROTECT_START" and "IMPORT_PROTECT_END"; this allows the generated PPWIZARD commands such as #if and #output to be interpreted, rather than simply passed through as data.

In some cases this may not be desirable, as depending on exactly what you are doing you could put PPWIZARD into a situation where it could "make mistakes" (such as if a field contained '<$').

Although it can be desirable that PPWIZARD interpret macros and expand them if you catered for this in your design, I will demonstrate how you can ensure that they will not be - no matter what. This will demonstrate an alternative approach to using the two "WriteLineToTmpImportFile" lines in the example above and will also ensure that the record line is "protected" from PPWIZARD:

        ;--- Update what will get written to temp file ---                                     \
        AddB =         '#if <?OutputLevel> > 1' || NL || '   #output' || NL || '#endif' || NL; \
        AddB = AddB || '#output ^p_' || Suffix || '.htm^ ASIS APPEND' || NL;                   \
        AddB = AddB || '<?ProtectFromPpwStart>' || NL;                                         \
        AddA = NL   || '<?ProtectFromPpwEnd>';                                                 \
        ThisRecordsCodes = AddB || ThisRecordsCodes || AddA;

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

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: FileMake - Create File[Next]: Importing Fields, Each Record To Its Own File

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am