|
cobol400-l-request@xxxxxxxxxxxx Sent by: To: cobol400-l-bounces@xxxxxxxxxxxx cobol400-l@xxxxxxxxxxxx cc: 01/09/2004 01:00 PM Subject: COBOL400-L Please respond to cobol400-l Digest, Vol 2, Issue 8 What you're trying to do would require *dynamic* SQL rather than *static*. If you do your CRTSQL... command, you'll notice the parameter TOSRCFILE(QTEMP/QSQLTEMP). Change this to another file (not the one where your original source is kept). When you submit your CRTSQL... command, your actually submitting an 'precompiler' which translates your embedded SQL into calls to the database routines with files, fields, (aka tables, columns), and variables loaded into parameters that the database routines can use. The precompiler then submits a CRTCBL... command for the source it generates. This works fine for *static* SQL, but if you want to dynamically change the files (aka tables) and fields (aka columns), you need to use *dynamic* SQL. Check out the iSeries Information Center under "Database: Manuals: 'SQL Programming with Host Languages'". Unfortunately, it includes dynamic SQL examples only for ILE RPG and not for COBOL. However, the concept is pretty straight forward. You load a host variable with your statement, prepare it, and so forth. HTH Original message: ---------------------------------------------------------------------- date: Thu, 8 Jan 2004 21:07:32 -0000 from: "Chris Chambers \(M&M Software\)" <cchambers@xxxxxxxxxxxxxxxxxxxxxx> subject: [COBOL400-L] Embedded SQL examples Hi there, I'm trying to write an UPDATE statement within a COBOL program where the Filename as well as the values to update are all parameterised. I can get the FILENAME to work if I use the PREPARE statement but not the values - and I can get the values to work in a straightforward UPDATE but the FILENAME is then not allowed as a parameter. I had imagined I may be able to construct something like this: EXEC-SQL UPDATE :FILENAME SET :FIELDNAME1 TO :VALUE1 WHERE :FIELDNAME2 = :VALUE2 END-EXEC If I string it altogether as a prepared statement the resulting command does not execute from within the program as it assumes the values to be a fieldname but if I copy and paste the same command into STRSQL it works fine - so what am I doing wrong? Anyone got some examples that work?? Many Thanks, Chris
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.