Table creation/Postal addresses: Difference between revisions

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.
(→‎{{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:
===version 1===
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.
<br>The fields are for the most part, USA specific, but could be expanded
 
for other countries.
<br>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.
<br>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.
 
<br>AAlso, a history logging facility is included which tracks who (by userID) did what update (or change), along with a timestamp.
<pre>
╔════════╤════════════════════════════════════════════════════════════════════════╤══════╗
╔═════════════════════════════════════════════════════════════════════════════════╗
╟─────╟────────┘ Format of an entry in the USA address/city/state/zip code structure: ──────╢ └──────╢
║ The "structure" name can be any legal variable name, but here theit'll namebe willshortened beto make these║
shortened to make these 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 variablein name)the program. ToOther thatpossibilities end,are eachto ofhave thesea variabletrailing namesunderscore will(or both) have anor
║ some other special eye─catching character such as: ! @ # $ ? ║
║ underscore in the beginning of each name. Other possibilities are to have a ║
catching character such as: ! @ # $ ?
║ 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 notmay specifiedcontain willany havenumber of characters, this can be limited by the a value of "null" (which has a length of 0).
restrictions imposed by the standards or the USA legal definitions.
║ Any fieldnumber canof containfields could be added (with testing for invalid fields). any number of characters, this can be limited by the
╟────────────────────────────────────────────────────────────────────────────────────────╢
║ restrictions imposed by the standards or the USA legal definitions. ║
Any @USA.0 the number of fieldsentries couldin bethe added (with@USA testing forstemmed invalid fields)array.
@USA.nnn._addr3 is the 3rd street address
╟─────────────────────────────────────────────────────────────────────────────────╢
@USA.0 nnn the number of entriesis insome thepositive integer of any @USAlength (no stemmedleading arrayzeros). ║
╟────────────────────────────────────────────────────────────────────────────────────────╢
║ ║
@USA.nnn._name nnnis the name of person, business, or a lot description. is some positive integer of any length (no leading zeroes).
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._name _addr1 is the name1st street address of person, business, or a lot description.
║ @USA.nnn._addr2 is the 2nd street address ║
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._addr _addr3 is the 1st3rd street address
║ @USA.nnn._addr2 is the 2nd street address _addrNN ··· (any number, but in sequential order).
╟────────────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._addr3 is the 3rd street address ║
║ @USA.nnn._addrNN_state is the ···USA postal (anycode number,for the butstate, interritory, sequentialetc. order) .
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._state_city is the USAofficial postalcity codename, for theit state,may territory,include etcany character.
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._city_zip is the officialUSA citypostal name,zip code it may(five includeor anyten characterdigit format).
╟────────────────────────────────────────────────────────────────────────────────────────╢
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._zip _upHist is the USAupdate postalhistory: zip codeuserID who (fivedid orthe tenupdate; digitdate, format)timestamp.
╚════════════════════════════════════════════════════════════════════════════════════════╝
╟─────────────────────────────────────────────────────────────────────────────────╢
║ @USA.nnn._upHist is the update history (who, date, and timestamp). ║
╚═════════════════════════════════════════════════════════════════════════════════╝
</pre>
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/
@usa.=; @usa.0=0; $='@USA.' /*initialize stemmed array &and 1stfirst value.*/
@usa.0=@usa.0 + 1 /*bump the unique number for usage. */
call USA '_city' , 'Boston'
call USA '_state' , 'MA'
call USA '_addr_addr1' , "51 Franklin Street"
call USA '_name' , "FSF Inc."
call USA '_zip' , '02110-1301'
@usa.0=@usa.0 + 1 /*bump the unique number for usage. */
call USA '_city' , 'Washington'
call USA '_state' , 'DC'
call USA '_addr_addr1' , "The Oval Office"
call USA '_addr2' , "1600 Pennsylvania Avenue NW"
call USA '_name' , "The White House"
call USA '_zip' , 20500 /*no need for quotes for a number. */
call USA 'list'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tell: $parse arg a; z=value('@USA.'$||#"."arg(1)a); if $z\='' then say right(translate(arg(1)a,,'_'),69) "──►" $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
/*──────────────────────────────────────────────────────────────────────────────────────*/
USA: procedure expose @USAusa. $; parse arg what,txt; arg ?; @='@USA.'
tell: $=value('@USA.'#"."arg(1));if $\='' then say right(translate(arg(1),,'_'),6) "──►" $
if ?=='LIST' then do #=1 for @usa.0
return
list: call tell '_name'
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=21 until $=z=''; call tell "_addr"j; end /*j*/
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 ,tell txt'_zip'
say call value @ || @usa.0 || . || copies('upHist', userid() date() time(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>
name ──► FSF Inc.
addr addr1 ──► 51 Franklin Street
city ──► Boston
state ──► MA
zip ──► 02110-1301
─────────────────────────────────────────────
────────────────────────────────────────
name ──► The White House
addr addr1 ──► The Oval Office
addr2 ──► 1600 Pennsylvania Avenue NW
city ──► Washington
state ──► DC
zip ──► 20500
─────────────────────────────────────────────
────────────────────────────────────────
</pre>