Re: Recursion
Posted in 1995
Several people have asked me for my examples of true recursion in 4GL. One
even suggested posting it to the list so it gets auto-archived at Emory.
Anyway, I'm not into giving out proprietary code so this past weekend I
whipped up this little demo. If you don't already have the "stores" database
on your system, create it. Build the "equipment" table by typing the
following:
dbaccess stores equipment.sql
After the table is built and loaded, compile the program by typing:
make
That's all there is to it. RDS only people, you'll have to build a custom
runner for this sucker. Grab my "db4glgen" program for help in making it.
The i_equip.4ge program is fully functional. It can do Queries, Adds,
Updates, Removes, Lookups, and a whole bunch of other stuff. The program
relies on the constraints attached to the equipment table for data validation.
The only data validation the program does itself is for recursive loops.
(Someone want to help me write a trigger :-)
The o_equip.4ge program is a simple report program. Provide an id along with
the direction you want to go and it dumps the explosion (or implosion?) to a
file called "report.out".
I've documented the ESQL/C recursion routines somewhat. It may look messy
but there's nothing really complicated going on (remember I'm NOT a regular C
programmer). I've documented the recursive loop routine extensively. If it
sounds complicated, that's because it is!
If you have any questions, send me email. If you have some suggestions,
please let me know about them. Enjoy!
Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip
#!/bin/sh
# This is a shell archive (produced by GNU shar 4.0).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2358 -rw-rw-r-- Makefile
# 554 -rw-rw-r-- equipment.sql
# 278 -rw-rw-r-- equipment.unl
# 32298 -rw-rw-r-- i_equip.4gl
# 3619 -rw-rw-r-- i_equip.hlp
# 818 -rw-rw-r-- i_equip.per
# 733 -rw-rw-r-- i_equipb.per
# 7291 -rw-rw-r-- lu_equip.4gl
# 539 -rw-rw-r-- lu_equip.per
# 4825 -rw-rw-r-- o_equip.4gl
# 754 -rw-rw-r-- o_equip.hlp
# 662 -rw-rw-r-- o_equip.per
# 3326 -rw-rw-r-- recursive.ec
# 4544 -rw-rw-r-- usr_funcs.c
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo 'WARNING: not restoring timestamps'
fi
rm -f 1231235999 $$.touch
#
# ============= Makefile ==============
if test -f 'Makefile' && test X"$1" != X"-c"; then
echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (gzipped)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shargzi.tmp
M'XL(`*UOOS`"`[U546O;,!!^MG[%00I+H#8,NH<:!@L)VTO'H'T=%$<^.R*R
MSI/L=/GWDS/7.G<.6UD3/9WN=*?3=]^=9O`UVV&A-$(,U;-8D`7\\B;)MLHW?
MJD?\\T:H:YKV0W)2X$#-847VPJMPV,%\\MX/WM[0>`=;97.2P3>#"''"W`4FNX
M[PXYN$>'=H^Y$&+U^6[YY>%C+"'^)N[6_<YYR^R-E\\]SC36:'(U4Z(YODQ:S
M1ID2FBV"I*K6V"`\\D=UU2N?-:!*87K.WSU!D6J?`P!WDPE;/\\H9ODLJ50,R!
MF,-W<4R4V%'=!ONE,58F5YX3;:89IZZ[,]4U9":'+>H:.MZYY(P8,W@#UA20
M(;`^.>O4'KW<.OM8M$:ZA$0D;TK]*A=?@@C@:MX3>P$Q\\?*&9'PY0C(U6A%U
ML'37Q6ZD%YP%:>#$"9_-R*FC0+AFJVL15;L*G<L8U;R:LTL(XH#1ZP&C_P2,
M.&#$`:,3@'&](/YVFGX[4_-V$8+W2QKR?WGAR'#AM@J]],Y!17G+^N>"HVMH
M"S[`=$^!J_FJK^?(]LD/J;@8='*04(:Z4<H8\\&=`F@A(0T!B`0/[6"6G0HZ-
M?<Q!*8/8165$3AFKO>EEV+&Q#QN4\\LS$.?RFC<;,=+1I:WC:H@'_Y4!.!O]"
MF?,1YYA1*J(Q%_CG1__V#1Y'Q]1?2*-?D0TAWMUC]R[>J1%EL2;;)-0VXA?B
'K^3+-@D``*(Q
`
end
SHAR_EOF
echo 'gunzipping file Makefile' &&
gzip -d < _shargzi.tmp > 'Makefile' && rm -f _shargzi.tmp &&
$shar_touch -am 1201161295 'Makefile' &&
chmod 0664 'Makefile' ||
echo 'restore of Makefile failed'
shar_count="`wc -c < 'Makefile'`"
test 2358 -eq "$shar_count" ||
echo "Makefile: original size 2358, current size $shar_count"
fi
# ============= equipment.sql ==============
if test -f 'equipment.sql' && test X"$1" != X"-c"; then
echo 'x - skipping equipment.sql (File already exists)'
else
echo 'x - extracting equipment.sql (gzipped)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shargzi.tmp
M'XL(`#,^OS`"`UU136^",!B^]U<\\\\X3),-N2'<RR0U>J$A%FP8,GPJ0Z(F(%
M-/'?KUW-A!V:-._S]?:IZT*>SH4ZR*H=-:<2+N)E@&93%ZK%]EAC4\\NL+:H=
M!G_$`=KLJY3(JASE,<L-6K3$=<&.ZEH7N^\\6#AOB>3Q^!;SL4N2@(\\35-9<U
M0,L2PI`:"-G(^B)S0@@3G"8<"?T(^'TG`CCZ0$]2[1)SX=,`890@7`7!XPU2
M:94=)-B,"N?E:6C'*JNU06J%?ICP*1<6^13^@HHUYGP-YQ<?@D5AG`BJ>5![
M+2IRRUV%_G+%#<V&])AG351F:KELQMG\\YHB']]X&/9VQ3RN9*G/1TN$;(31(
MN/C_?%#/ZPA-&Y-(<'\\:VN7["8)/N.`AXW''H1.[W=M$$Q=$U,-$1(O.OX[.
653G05>F6$]-8=+=Y(S]%5J>7*@(``.`A
`
end
SHAR_EOF
echo 'gunzipping file equipment.sql' &&
gzip -d < _shargzi.tmp > 'equipment.sql' && rm -f _shargzi.tmp &&
$shar_touch -am 1201124195 'equipment.sql' &&
chmod 0664 'equipment.sql' ||
echo 'restore of equipment.sql failed'
shar_count="`wc -c < 'equipment.sql'`"
test 554 -eq "$shar_count" ||
echo "equipment.sql: original size 554, current size $shar_count"
fi
# ============= equipment.unl ==============
if test -f 'equipment.unl' && test X"$1" != X"-c"; then
echo 'x - skipping equipment.unl (File already exists)'
else
echo 'x - extracting equipment.unl (gzipped)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shargzi.tmp
M'XL(`%;]O3`"`R6/49*$(`Q$_SG%7B!5"ZCC?#(:A5H!"]"9P_3A-^S^=3HO
ME6Z-\\XHGG5H#RF`+A;_XTT+:K^JYT*:-+"P:'WSZG)B:MN(,J.P.JF:`AAKA
M<V7R9H2!FE!XX7#+>3$3+-0#MSMNIML\\.CYC=]?.M)NY\\T\\LN:RTF&=G]3=B
M;KE0-"*%EFC5NZU1M2+%4Y(I,:\\'4[*B9W$LZLGN1UX*93&)->`=TBI-Z&UE
?^#L<$<-2\\G^3:&7NY(17D;KTLB([]PO2N@W&%@$``%X*
`
end
SHAR_EOF
echo 'gunzipping file equipment.unl' &&
gzip -d < _shargzi.tmp > 'equipment.unl' && rm -f _shargzi.tmp &&
$shar_touch -am 1130135295 'equipment.unl' &&
chmod 0664 'equipment.unl' ||
echo 'restore of equipment.unl failed'
shar_count="`wc -c < 'equipment.unl'`"
test 278 -eq "$shar_count" ||
echo "equipment.unl: original size 278, current size $shar_count"
fi
# ============= i_equip.4gl ==============
if test -f 'i_equip.4gl' && test X"$1" != X"-c"; then
echo 'x - skipping i_equip.4gl (File already exists)'
else
echo 'x - extracting i_equip.4gl (gzipped)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 _shargzi.tmp
M'XL(`&UMOS`"`^T]^7/:2-:_\\U=TR`^!+&8AYR2UGBV,14(M!D:"\\<QN3;D$
M:HPF0L(Z3-BM[W__7A\\Z6FH)@<'V3(VK$ANIC]>OW]7O:%XB\\P;?!>:Z^>[6
M0F?HW9<!\\IS`G6.T<%R$O^-YX.LS"X?M4"WN@.N5EZCKK+>N>;OT4:U;1^U/
MG]XC=*G?FP;J-)%F;PWL(M2Q+*221AY2L8?=>VQ42%\\7ZSXVT&S[&1DS@.`6
MVPUT_Z[9:J%/[__>>O_W]@?4^O2Y]>YS^V.E4KGL3#H7'4U!GN^XV@@DQ