home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
postpr.zip
/
POSTPROC.TXT
< prev
Wrap
Text File
|
1994-07-12
|
12KB
|
248 lines
POSTPROC.CMD - A "ratchetware" production by D.P. Babcock.
INTRODUCTION
We are using VisPro REXX as our sole 32 bit OS/2 Client Server
application development tool in conjunction with DB2/2. Via DDCS
we can then build applications which access our DB2/MVS databases
on the host. In building a number of these applications we've
developed some coding standards that we feel make our
applications more "robust" and "bullet proof." We found that we
were adding these to every VisPro generated database screen and
so I wrote a "Post-processor" to automatically add these to the
newly generated VisPro code.
LICENSE
There is no license because this is free for your use in whatever
way you see fit. All I ask is that you send me an E-MAIL (CIS
76077,3173) if you use it telling me a bit about what it has
done for you. Also, I'd like to encourage you to share your
tidbits of knowledge with the rest of us. In this fashion we can
all "ratchet" our skills in this environment to new heights. I've
always found that I learned best from looking at someone else's
real code. I hope that this little REXX program may benefit you
similarly and that you will in turn share goodies that you
develop. Thus, I've dubbed this kind of offering "ratchet-ware" -
FREEWARE for the price of an E-MAIL and in the hope that you will
produce other "ratchet-ware" for the good of us all.
THE PROGRAM
This is a simple REXX command file that is highly modular. It
takes one argument - the full pathname of the canvas (in OS/2
terms this is merely a subdirectory) that contains the event code
files (FORM.1, *.0 files, etc.) Thus, the easiest way to use this
program is to copy it to some directory and set up a PROGRAM
object that points to it. By then dragging any VisPro form
(canvas) icon and dropping on the program icon you will
automatically invoke the command file with the full pathname
passed via the drag/drop.
USE
Use the VisPro Database Diagrammer (DBD) to build a schema for
your table(s). Then build a VisPro default CReate, Update,
Delete, Search (CRUDS) screen by drag/dropping the table object
onto a new blank canvas. At this point you have the standard
VisPro application screen. Now, drag the ICON representing this
screen from the project folder and drop it on the POSTPROC
program icon you built above. An OS/2 window will open and you
will see a number of progress STDOUT messages. When this is
complete, go examine the events in the form (canvas - I use these
terms interchangeably) and see what has changed. I'll outline
these changes below for your convenience. Make sure your database
name and qualifier are set and then EXPORT the DDL to a file
named DDL.TXT. This file will be read later if it exists to
further refine the data types.
WHAT IT DOES
- Looks for an UNDO subdirectory below the directory containing
the form events. If one isn't found, create one and copy all of
the "as generated" event code into it so that we can always get
back to a "clean" start. This will be true the first time you
drag/drop the form icon on the post-generator. Otherwise, it
copies the files from the UNDO subdirectory into the parent to
restore the event code to the original VisPro generated state.
- Creates two subprocs in the subprocs folder of the project that
will be used by the generated code. SQUOTEIT and SQUOTEWC handle
the problem of text input that contains apostrophes. These must
be "doubled" (i.e. "O'Brien" becomes "O''Brien") for REXX/DB2
parsing to work correctly. In addition, the outer quotes are
added for character data types. SQUOTEIT (single-quote-it) and
SQUOTEWC (single-quote-it-wildcarded) are the same except that
the appropriate wildcarding per data type is added. This is only
used therefore in the SEARCH event.
- Looks in the form subdirectory for the FORM.1 (form open event)
and *.0 (form events) files. Read each of these to determine
which filename contains which event by looking for identifying
code fragments.
- Read the ADD event file to get a list of the column names used
in this generation. This is not necessarily all of the columns in
the table. Some may have been excluded by you (nullable) when you
generated the form. That's why I read them here instead of merely
getting them from the schema file (DDL.TXT). I also determine the
data types by both looking at the original VisPro code (quoted
VpGetItemValue() calls indicate character (C) data types - others
are assumed numeric) because DATE, TIME and TIMESTAMP types are a
hybrid of sorts (character in that they are quoted but not valid
for character wildcarding or as a LIKE predicate.) I then look
for a DDL.TXT file in the folder directly above the project
folder. If it exists, I read it to further distinguish TIME (T)
data types from character. The process will work without the
DDL.TXT file but the SEARCH code will have to be modified by hand
if you have any DATE, TIME or TIMESTAMP columns in the table to
change the postgenerated SQOUTEWC calls from type 'C' to type
'T'.
For documentation printing, I put a comment identifying each of
the events at the beginning of the event code. This is done as I
visit each event code file in the following steps.
- Remove the START USING DATABASE code from the ADD event (saving
it for later insertion into the FORM OPEN event)
- Put the SQUOTEIT call in the ADD pushbutton event and remove
the VisPro quoting around the VpGetItemValue() calls.
- Put the SQUOTEIT call in the CHANGE pushbutton event and remove
the VisPro quoting around the VpGetItemValue() calls.
- Remove the START USING DATABASE code from the CHANGE event.
- Put the SQUOTEIT call in the DELETE pushbutton event and remove
the VisPro quoting around the VpGetItemValue() calls.
- Remove the START USING DATABASE code from the DELETE event.
- We found that there is a bug in the 2.0 Vispro code that causes
your application to close if you perform two SEARCHES in a row
without an intervening CLEAR. After working with HOCKWARE they
gave us a workaround fix to put into the CONTAINER CLICKED event.
It does fix the problem but you get some unnecessary iterations
of this even which can be distracting. This post generator
installs this "collapse" fix at this time. However, the next
version of the VisPro REXX will fix this. Also, it appears that
this can be avoided by merely cutting the code from this event
and deletng the event and then pasting it into the CONTAINER
DOUBLE-CLICKED event. Actually, with the addition of the search
engine, we find this works rather nicely. Try it and see. I'd
have had the generator do this automatically but since VisPro
doesn't generate this event originally as a x.0 file, there was
no way I could change it automatically.
- Put the SQUOTEWC call in the SEARCH pushbutton event and remove
the VisPro quoting around the VpGetItemValue() calls.
- Remove the START USING DATABASE code from the SEARCH event.
- Put the START USING DATABASE code into the FORM OPEN event.
- Fully qualify the INSERT statement in the ADD event by adding
the explicit column names. We feel this is good coding practice
since it will keep your code from "breaking" if a nullable column
is added to the table.
- For similar reasons, fully qualify the column names in the
SELECT statement of the SEARCH event. Also, we add indicator
variables for ALL columns whether they are nullable or not. This
doesn't seem to hurt and it certainly keeps the code from
breaking if you later change a table column to nullable.
- Now for the best part. The SEARCH event is a bit anemic in that
it merely returns all of the records. We wanted to beef it up a
bit by creating a dynamic WHERE clause that would be built based
upon the user merely filling in one or more of the fields as
desired. This code is inserted. We think you'll like it and will
be inspired to do even more.
- We also deal with some LARGE databases. We've found that the
containers and list boxes will take only about a thousand or so
records max (depends on record length) before they just quit
updating. Nevertheless, the FETCH loop continues to churn while
the user looks at the clock. We decided to add a Read Limit
check. You can easily set the ReadLimit variable to whatever you
like. On slower PC's this should probably be only a few hundred.
Users can think their machines have locked up if the wait gets
too long. With the new search engine, we like to give them the
opportunity to quickly refine their search if they inadvertently
specify too large a return set.
- Finally, since the VisPro code doesn't check the indicator
variables, when you FETCH a column that is NULL it's FETCH
variable retains the last non-null value for that column which in
turn is loaded into the CONTAINER stem variable. This has the
undesirable effect of making it appear as though all records in
the CONTAINER have actual values for NULL columns that reflect
the first record above them for which the column had an actual
value. We added the code to clear the FETCH variables each time
through the FETCH loop to prevent this "aliasing" of the data
loaded into the container.
Well, there you have it so far. I'm sure that we'll discover more
changes but we've done a few apps with this and it gives us a
MUCH better starting place to begin customization of the
generated apps. With a little study of the REXX code you will see
that all of the pieces are modular and that you can pretty much
pull any of the pieces you don't want or add new ones by cloning.
This modularity results in a lot of re-reading of the same form
event file but I think this is more than offset by the
flexibility of the modularity. I know that this generator will
get "broken" by the next round of VisPro improvements but the
modularity will allow you (and us) to easily adapt it for the new
code. It also allows you to customize it to reflect your coding
standards. I'd love to hear of any that you have developed. Keep
the concept of "ratchetware" in mind. I believe that I have
coined this term.
Yours for growth in our mutual professions,
Don P. Babcock Jr. P.E.
REVISION HISTORY
7/8/94 Version 1.1
- Each module was converted into a subroutine and call from
the main program to increase the ease of module exclusion
and addition.
- Additional comment lines have been added at the beginning of
each event. Also, a second argument was added to the main
routine to allow the insertion of a programmer's initials.
By putting the prorammers initials in the arguments field of
a program object, they will show up as the first argument
when the form icon is drag/dropped on the program. The last
argument is always the system pathname for the drag/dropped
object. A bit more code was added to make the code backwards
compatible so that if the initials are omitted, the first
argument is considered to be the pathname.
- Three modules were added, CommitAddPB, CommitChangePB, and
CommitDeletePB to add COMMIT's at the end of each of the
respective events. We had been relying upon the process
termination to autocommit. This works unless the process
abends in which case all of the work is rolled back.
- A module was added, ConfirmDeletePB, that pop's up a "second
chance" confirmation for deleting records. It is too easy to
inadvertently click on the DELETE pushbutton!
7/12/94 Verision 1.2
- Added code to automaticall build a HINT file for the
pushbuttons.
- Also fixed a minor bug that would have eventually caused
problems in the SQUOTEIT and SQUOTEWC code generation. An
extra set of quotes was needed around one of the instances
of the term "value." The generated code was fine but if
VALUE had ever taken on a value in the generator, the code
would have used that instead of the literal value.