CompuServe Thread

#Superbase and Arexx

15 messages in this thread
#61267From: David MastersonAug 4, 1993 1:19 AM
Does anyone have any examples of Arexx programs that they use to control Superbase (as opposed to Arexx programs that Superbase calls). I'm having trouble getting Superbase to answer me (Arexx tells me "host environment not found" at the first DML command I send it). I'm using AmigaDOS 2.1 and SBpro4 1.01. Any hints? David – via Whap!
#61276From: Mark D. ManesAug 4, 1993 2:55 AM
David, You are not the only one. I have spent several fun filled hours trying to make that work. I got it to address the port, but once I did that I got 'zip'. Mike?
#61323From: Bob ChapmanAug 4, 1993 10:07 PM
David – Hope the following example helps. It is a simple arexx program that is run from the cli to add one record to SBase file that is already open. (I haven't tried this program under SBase4 v1.3 but it worked under previous SBase4 versions.) – – – – – – – – – – – – – – – – – – [Cut here] – – – – – /* AddRec.rexx – Add a SBPro record (to file already OPEN that has fields named FLD1, FLD2, FLD3 — Text, Text, Numeric — of proper size) */ pival = 3.14159 /* A constant for FLD3 of the new record */ call SndACmd 'BLANK' /* Have SBase create the new record */ call SndACmd 'FLD1="001"' /* Put values in fields */ call SndACmd 'FLD2="Wish you could send multiple commands:"' call SndACmd 'FLD3='pival /* FLD3 set to 3.14159 */ call SndACmd 'STORE' /* Have SBase store the new record */ exit /* SndACmd(cmd) – a procedure to send CMD to SBPro4 */ SndACmd: procedure parse arg cmd options no results /* Must Be 'NO results' for CMD to work */ signal on error /* Trap SB's dumb 4096 'OK' return */ address 'SBase4' cmd /* Send the command */ error: signal off error return – – – – – – – – – – – – – – – – – – – – [Cut Here] – – – – – – Note that the host name in the ARexx 'address' command IS CASE sensitive! i.e. if it is 'SBase4' then SBASE4 won't do — use "say show('P')" to be really sure. Further, if I remember correctly, for some unknown reason — you really DID have to have 'options no results' when you sent a SBase command to the SBase port. THEN if you wanted SBase to return some value to your ARexx program — you had to make sure that you had enabled results (options results) before you sent the request to the SBase port. Something like this: . . . . options results address 'SBase4' 'FLD1' /* Request value of FLD1 (in currently selected record */ if (RC = 0 | RC = 4096) then /* value is returned in ARexx RESULT var */ [ MORE ]
#61324From: Bob ChapmanAug 4, 1993 10:07 PM
[ continuation ] field1 = result /* otherwise is an error */ . . . . . As I said, this 'useta' work — current mileage unknown — Good Luck. REC ——
#61370From: Mark D. ManesAug 5, 1993 3:44 PM
Bob, Thanks for that piece of code. I'll bet the options command was wasting me when I tried it.
#61390From: Bob ChapmanAug 5, 1993 9:32 PM
Mark – I can't tell you how much time I wasted before learning that it HAD to be option NO RESULTS when you sent SBase a command and option RESULTS when you were requesting a value (of a field, function, variable, whatever). It's actually shown that way in the manual but never explained that it really has to be NO RESULTS when a command is sent. Although you didn't ask — and probably don't need it — my complete example ARexx program follows 🙂 I have checked it with SBase4 v1.2 and v1.3. You may be interested to note the use of GetAVal('STR$(FLD3,5,3)') instead of GetAVal('FLD3') in the list all records loop. Its the only way I've found (so far) to get more than two decimal places in a returned number and, of course, to ARexx a string like 123.456 IS a good number. – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – /* Add a SBase record (in file already OPEN of course) */ pival = 5000.236; fld1 = "045" call SndACmd 'BLANK' call SndACmd 'FLD1="'fld1'"' call SndACmd 'FLD2="More and more stuff"' call SndACmd 'FLD3='pival /* etc…. */ call SndACmd 'STORE' /* Now list all records in the file */ call SndACmd 'SELECT FIRST' call SndACmd 'VIEW' do while GetAVal('EOF("")') = 0 say GetAVal('FLD1') left(GetAVal('FLD2'), 40) GetAVal('STR$(FLD3,5,3)') call SndACmd 'SELECT NEXT'; call SndACmd 'VIEW' end /* do while */ exit /* End of Example */ /* SndACmd(cmd) – Send CMD to SBase4 */ SndACmd: procedure parse arg cmd options no results /* 'NO results' for command to work */ rlabl = "snderr" signal on error /* Trap SBPro's dumb 4096 'OK' return */ address 'SBase4' cmd /* Send the command */ snderr: signal off error if (RC = 0 | RC = 4096) then return 1 else return 0 /* GetAVal(item) – Get Value from SBase4 */ GetAVal: procedure parse arg item options results /* need 'results' here */ rlabl = "geterr" signal on error /* Trap SBase's dumb 4096 'OK' return */ address 'SBase4' item /* Send the item */ geterr: signal off error if (RC = 0 | RC = 4096) then return result else return "Error" RC /* The ERROR handler */ ERROR: signal value rlabl /* return to the right procedure */ – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – REC ——
#61393From: Bob ChapmanAug 5, 1993 9:51 PM
Darned Forum message formatting — sigh. It's probably obvious but the 'say' line in the list records loop got wrapped. It should have looked like: . . . . . . . . do while GetAVal('EOF("")') = 0 say GetAVal('FLD1') left(GetAVal('FLD2'), 40) , GetAVal('STR$(FLD3,5,3)') call SndACmd 'SELECT NEXT'; call SndACmd 'VIEW' . . . . . . . . REC ——
#61418From: Mark D. ManesAug 6, 1993 10:35 AM
Bob, Thanks for the example, honest, I really needed this!
#61450From: Bob ChapmanAug 6, 1993 8:45 PM
Mark – Hope it helps. It's been a while since I put it together (circa SBPro4 v1.01 I think) but I keep it around to help me remember how the interface works. BTW I forgot to include a definition of the SBase test file in the comments (although it's probably pretty obvious and not too critical): File definition Field name Attributes Format FLD1 TXT IXD 3 FLD2 TXT 20 FLD3 NUM -99999.000 If I were to redo the functions now, I'd probably just do an: options failat 4097 rather that go through all that complicated 'signal on error' stuff — it seemed like a good idea at the time though 🙂 Still can't fathom WHY SBase returns 4096 ('1000'x) as an OK in some cases when it sure SEEMS that a zero (0) return would be much more appropriate — perhaps the value was supposed to be masked? REC ——
#61524From: David MastersonAug 8, 1993 1:36 AM
Thanks for the Arexx Example — I'll give it a try. Are you sure about the port name being 'SBase4'? The manual suggests 'SBpro4' (v1.01). David – via Whap!
#61564From: Bob ChapmanAug 8, 1993 2:32 PM
David – > The manual suggests 'SBpro4' (v1.01). As I remember that is correct for v1.01 but you can always use the ARexx show('P') command from the CLI with SBase running to be sure. As you probably saw in my replies to Mark Manes, the examples were originally put together around the v1.01 timeframe. I checked and they still run under v1.2 and v1.3 (with the port name updated of course). IMHO the most annoying thing about the interface is SBase returning a value of 4096 ('1000'x) for 'OK' after most/many commands. Probably the easiest way around it is to do an: options failat 4097 but I sure wish that OXXI would change this to return a zero (0) instead!! REC ——
#61573From: David MastersonAug 8, 1993 5:27 PM
Your SndACmd() and GetAVal() functions were most helpful. I think I've got my program to work (download stock quotes from CIS, parse the data, and store it in Superbase) except for one small problem (ha!). At the end of the program, I try to shutdown Superbase by sending it a 'QUIT', but the command never returns to AREXX, so the script hangs waiting for Superbase to tell it it has shut down. Have any suggestions? David – via Whap!
#61593From: Bob ChapmanAug 8, 1993 10:59 PM
David – > download stock quotes from CIS, parse the data, and . . . Sounds like you've gone beyond anything I've done so far!! > so the script hangs waiting for Superbase . . . Have any suggestions? Gosh, never thought of that! I suppose if you 'RUN'ned a DML program it would also wait for the program to complete before it returns to ARexx — so you couldn't do a WAIT FOR 5: QUIT sorta thing in a program . . . guess not. REC ——
#61632From: Christian BusseAug 9, 1993 3:07 PM
Bob, sorry to but in, but shouldn't a function which returns whether it has succeeded or failed, return a TRUE when succeeded and a FALSE if not? That would be a return value of 0 (= FALSE) for 'not succeeded' and any other value (1, 3, 4096, 99999…) (= TRUE) for 'OK'. ??? :v) // Chris coming in from Germany \X/ on AutoPilot 1.06………..
#61656From: Bob ChapmanAug 9, 1993 8:44 PM
Christian – Nope. External commands and hosts are supposed to follow the DOS convention of returning zero to indicate OK and a non-zero value to indicate an error condition. Ref: ARexx User's Reference Manual Version 1.0 Chap. 10 p. 92. Result Fields When the host program finishes processing the command it must set the primary result field rm_Result1 to an error severity level or zero if no errors occurred. This is the field which will be assigned to the special variable RC . . . And, also see the ARexx User's Guide, P/N:368759-01, section on Interrupts, p.p. 6-6 and 6-7 where the 'ERROR' interrupt is described ERROR This interrupt is generated by any host command that returns a non-zero code. And, in the same source, the description of 'options failat' on p. 4-12. Or, for an answer beyond all doubt, ask Bill Hawes over in the ARexx section of the AmigaTech Forum 🙂 Finally, just to be picky — > and any other value (1, 3, 4096, 99999…) (= TRUE) ^^^^^^ Not so — in REXX and ARexx '0' is FALSE and '1' is TRUE and the use of a value other than 0 or 1 when a Boolean operand is expected will generate an error (ARexx User's Guide, p. 3-10). Try it and see 🙂 REC ——