Table creation/Postal addresses: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Add a Perl 6 example)
m (→‎version 1: changed the wording in the boxed comments, added/changed comments and whitespace, changed indentations of the output, simplified the specification for addresses, used a template for the output.)
Line 885: Line 885:
===version 1===
===version 1===
A REXX program can call SQL or any other database system, but the version shown here is a RYO (roll your own).
A REXX program can call SQL or any other database system, but the version shown here is a RYO (roll your own).

<br>Practically no error checking (for invalid fields, etc.) has been coded.
Practically no error checking (for invalid fields, etc.) has been coded.
<br>The fields are for the most part, USA specific, but could be expanded

for other countries.
The fields are for the most part, USA specific, but could be expanded for other countries.
<br>In addition to "state", fields such as province, municipality, ward,

parish, country, etc) could be added without exclusion.
In addition to "state", fields such as province, municipality, ward, parish, country, etc) could be added without exclusion.
<br>A logging facility is included which tracks who (by userID) did what update (or change), along with a timestamp.

Also, a history logging facility is included which tracks who (by userID) did what update (or change), along with a timestamp.
<pre>
<pre>
╔════════╤════════════════════════════════════════════════════════════════════════╤══════╗
╔═════════════════════════════════════════════════════════════════════════════════╗
╟───── Format of an entry in the USA address/city/state/zip code structure: ──────╢
╟────────┘ Format of an entry in the USA address/city/state/zip code structure: └──────╢
║ ║
║ The "structure" name can be any legal variable name, but here the name will be
║ The structure name can be any variable name, but here it'll be shortened to make these║
shortened to make these comments (and program) easier to read; its name will ║
║ comments and program easier to read; its name will be: @USA or @usa (or both).
║ be @USA (in any letter case). In addition, the following variable names ║
║ Each of the variable names beginning with an underscore (_) aren't to be used elsewhere║
║ (stemmed array tails) will need to be kept uninitialized (that is, not used ║
for any variable name). To that end, each of these variable names will have an
in the program. Other possibilities are to have a trailing underscore (or both) or
║ some other special eye─catching character such as: ! @ # $ ? ║
║ underscore in the beginning of each name. Other possibilities are to have a ║
║ trailing underscore (or both leading and trailing), or some other special eye─ ║
║ Any field not specified will have a value of a null (which has a length of zero). ║
catching character such as: ! @ # $ ?
║ ║
║ Any field not specified will have a value of "null" (which has a length of 0).
║ Any field may contain any number of characters, this can be limited by the
restrictions imposed by the standards or the USA legal definitions.
║ Any field can contain any number of characters, this can be limited by the
║ Any number of fields could be added (with testing for invalid fields).
╟────────────────────────────────────────────────────────────────────────────────────────╢
║ restrictions imposed by the standards or the USA legal definitions. ║
Any number of fields could be added (with testing for invalid fields). ║
@USA.0 the number of entries in the @USA stemmed array.
╟─────────────────────────────────────────────────────────────────────────────────╢
@USA.0 the number of entries in the @USA stemmed array. ║
nnn is some positive integer of any length (no leading zeros). ║
╟────────────────────────────────────────────────────────────────────────────────────────╢
║ ║
nnn is some positive integer of any length (no leading zeroes).
@USA.nnn._name is the name of person, business, or a lot description.
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._name is the name of person, business, or a lot description.
║ @USA.nnn._addr1 is the 1st street address
║ @USA.nnn._addr2 is the 2nd street address ║
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._addr is the 1st street address ║
║ @USA.nnn._addr3 is the 3rd street address
║ @USA.nnn._addr2 is the 2nd street address
║ @USA.nnn._addrNN ··· (any number, but in sequential order).
╟────────────────────────────────────────────────────────────────────────────────────────╢
@USA.nnn._addr3 is the 3rd street address
║ @USA.nnn._addrNN ··· (any number, but in sequential order) .
║ @USA.nnn._state is the USA postal code for the state, territory, etc.
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._state is the USA postal code for the state, territory, etc. ║
║ @USA.nnn._city is the official city name, it may include any character.
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._city is the official city name, it may include any character. ║
║ @USA.nnn._zip is the USA postal zip code (five or ten digit format).
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._zip is the USA postal zip code (five or ten digit format).
║ @USA.nnn._upHist is the update history: userID who did the update; date, timestamp.║
╚════════════════════════════════════════════════════════════════════════════════════════╝
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._upHist is the update history (who, date, and timestamp). ║
╚═════════════════════════════════════════════════════════════════════════════════╝
</pre>
</pre>
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/
@usa.=; @usa.0=0 /*initialize stemmed array & 1st value.*/
@usa.=; @usa.0=0; $='@USA.' /*initialize array and first value.*/
@usa.0=@usa.0+1 /*bump the unique number for usage. */
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/
call USA '_city' , 'Boston'
call USA '_city' , 'Boston'
call USA '_state' , 'MA'
call USA '_state' , 'MA'
call USA '_addr' , "51 Franklin Street"
call USA '_addr1' , "51 Franklin Street"
call USA '_name' , "FSF Inc."
call USA '_name' , "FSF Inc."
call USA '_zip' , '02110-1301'
call USA '_zip' , '02110-1301'
@usa.0=@usa.0+1 /*bump the unique number for usage. */
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/
call USA '_city' , 'Washington'
call USA '_city' , 'Washington'
call USA '_state' , 'DC'
call USA '_state' , 'DC'
call USA '_addr' , "The Oval Office"
call USA '_addr1' , "The Oval Office"
call USA '_addr2' , "1600 Pennsylvania Avenue NW"
call USA '_addr2' , "1600 Pennsylvania Avenue NW"
call USA '_name' , "The White House"
call USA '_name' , "The White House"
call USA '_zip' , 20500
call USA '_zip' , 20500 /*no need for quotes for a number. */
call USA 'list'
call USA 'list'
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
tell: parse arg a; z=value($||#"."a); if z\='' then say right(translate(a,,'_'),9) "──►" z
list: call tell '_name'
call tell '_addr'
do j=2 until $==''; call tell "_addr"j; end /*j*/
call tell '_city'
call tell '_state'
call tell '_zip'
say copies('─', 40)
return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
USA: procedure expose @usa. $; parse arg what; arg ?
tell: $=value('@USA.'#"."arg(1));if $\='' then say right(translate(arg(1),,'_'),6) "──►" $
if ?=='LIST' then do #=1 for @usa.0
return
call tell '_name'
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=1 until z=''; call tell "_addr"j; end
USA: procedure expose @USA.; parse arg what,txt; arg ?; @='@USA.'
if ?=='LIST' then do #=1 for @usa.0; call list; end /*#*/
call tell '_city'
else do
call tell '_state'
call value @ || @usa.0 || . || what , txt
call tell '_zip'
call value @ || @usa.0 || . || 'upHist', userid() date() time()
say copies('', 45)
end
end /*#*/
else do; call value $ || @usa.0'.'what , arg(2)
return</lang>
call value $ || @usa.0'.upHist' , userid() date() time()
'''output''' &nbsp; (data used is within the REXX program):
end
return</lang>
{{out|output|text=&nbsp; (data used is within the REXX program):}}
<pre>
<pre>
name ──► FSF Inc.
name ──► FSF Inc.
addr ──► 51 Franklin Street
addr1 ──► 51 Franklin Street
city ──► Boston
city ──► Boston
state ──► MA
state ──► MA
zip ──► 02110-1301
zip ──► 02110-1301
─────────────────────────────────────────────
────────────────────────────────────────
name ──► The White House
name ──► The White House
addr ──► The Oval Office
addr1 ──► The Oval Office
addr2 ──► 1600 Pennsylvania Avenue NW
addr2 ──► 1600 Pennsylvania Avenue NW
city ──► Washington
city ──► Washington
state ──► DC
state ──► DC
zip ──► 20500
zip ──► 20500
─────────────────────────────────────────────
────────────────────────────────────────
</pre>
</pre>