Thanks Chuck, especially for the IBM site references.

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of CRPence
Sent: Friday, March 21, 2014 10:08 AM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: Run Sql Scripts Global Variables question

On 21-Mar-2014 08:24 -0700, Gary Thompson wrote:
Got latest version of Run Sql Scripts and noticed a new (to me) Global
Variables Tab at the bottom, to the right of the familiar Messages.

I created a variable:


Variable shows in the Global Variables Tab as:

I then try a query:
select * from @LIB1/MYFILE;

QGPL is in the list of schemas in Sys i Nav and in the lib list of the
job supporting my Run Sql Scripts session, yet I've not been able to
run the query ?

Message SQL0204 shows the variable name used as the file name and the
file name used as the member name.

The jog log for my session shows: MYFILE in @LIB1 type *FILE not

Similar results when using Naming convention *SQL ?

They are SQL [Global] Variables, not script[ing] variables. Where a [host or other] variable can be used within a SLQ statement remains the same as before; i.e. "Global variables can be used in any SQL statement that allows a variable."

FWiW, [ignoring the inconsistency in naming as both @VAR1 and @LIB1, thus assuming each reference is the one name @LIB1] even if the variable were supported in that context, the name would need to be explicitly qualified to ensure the value is not ambiguous; i.e. @LIB would need to be referred to in the statement as "select * from qgpl.@LIB/MYFILE"
because, per the docs, "Names that are the same should be explicitly qualified."

IBM i 7.1 Information Center -> Database -> Reference -> SQL reference
-> Statements
"The CREATE VARIABLE statement defines a global variable at the application server. ..."

IBM i 7.1 Information Center -> Database -> Reference -> SQL reference
-> Language elements
"A variable in an SQL statement specifies a value that can be changed when the SQL statement is executed.

There are several types of variables used in SQL statements:

_global variable_
Global variables are defined using the CREATE VARIABLE statement.
For more information about how to refer to global variables see Global variables.

IBM i 7.1 Information Center -> Database -> Reference -> SQL reference
-> Language elements -> Variables
_Global variables_
"Global variables are named memory variables that you can access and modify through SQL statements.

Global variables enable you to share relational data between SQL statements without the need for application logic to support this data transfer. ...
Global variable names are qualified names. When a global variable is referenced without the schema name, the SQL path is used for name resolution.
Global variables can be used in any SQL statement that allows a variable. Global variables can be referenced within any expression except ...

Regards, Chuck
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at

This thread ...


Return to Archive home page | Return to MIDRANGE.COM home page