On 15-Sep-2015 05:24 -0600,
jd...@arcor.de wrote:
> I'm trying to use RUNSQL instead of OPNQRY. For testing pruposes, I
> created the following CL which works fine:
>
> PGM
> DLTF FILE(QTEMP/LAW01*)
> MONMSG MSGID(CPF0000)
FWiW the above /ignore-all/ coding is a very poor choice; ignored
failures tend to push the revelation of the failure into later
processing from which the effect tends to be inferred to be much more
confounding, as seemingly contradictory or even seemingly impossible.
Allowing the failure to be manifest by the CL default-handler as
unexpected, reveals the error exactly where is the problem.
> RUNSQL SQL('CREATE TABLE QTEMP/LAW01# AS (SELECT * +
> FROM ASGDATA/LAW01P WHERE +
> UPPER(BEZ2_LAW01P) LIKE ''%DOSE%'') WITH +
> DATA') COMMIT(*NONE)
> ENDPGM
>
> When I declare a variable and transfer the SQL parameter from
> another program (COBOL or RPG) identical (quotes included) to what
> you see here the system produces error SQL0104 (Token 'CREATE TABLE
> QTEMP/LAW01# AS invalid.)
>
> Can somebody help me with that problem?
>
The -104 suggests that the string being passed to the program is an
apostrophe-delimited string instead of just the string; i.e. instead of
passing the character string "'CREATE TABLE ...", pass the string
"CREATE TABLE ...".
If the program had been building the entire command-statement to be
interpreted, then encapsulating the entire command string in the
variable would have required escaping the apostrophes in the SQL-string
parameter; i.e. that string could be passed either directly to a command
interpreter [such as QCMDEXC] or more indirectly to a CLP that invokes a
command interpreter. However if the CL is coded as RUNSQL
SQL(&MYSQLSTMT), those extra apostrophes will cause the msg SQL0104
being diagnosed.
Anyhow, given both RPG and COBOL have built-in SQL capability via the
SQL pre-compiler, using the CL interpreter so indirectly to issue the
SQL is rather daft; just pass the SQL string directly to the SQL
interpreter. Or use the SQL Call Level Interface (CLI).
--
Regards, Chuck