This section lists the rules for embedding SQL statements within an assembler program.
| Note: | OPSYN and ICTL assembler statements may not be used. |
Uppercase must be used for all SQL statements, except for text within quotation marks, which will be left in the original case.
The following example shows an SQL declare section for an assembler program:
Col. 1 Col.16 Col. 72
| | |
| | |
LABEL EXEC SQL BEGIN DECLARE SECTION
AA DS F
BB DC H'3' comment
* comment card or
* comment section
CC DC CL80'xxxx......................................xxxx*
xxxx...............xxxxx'
XYZ DSECT
DD DS D
EE DS CL5
FF DS H,CL40
ORG FF
GG DS H
HH DS CL40 comment
* continued comment
II DS PL5
JJ DC PL5'123.45'
KK DS 0H
LL DS CL12
XX DS CL10 *
continuation of comment
LABEL2 EXEC SQL END DECLARE SECTION comment
|
The preceding example illustrates the following rules:
EXEC SQL BEGIN DECLARE SECTION
and end with:
EXEC SQL END DECLARE SECTION
Each of these two statements must be totally contained on one line.
| Note: | There is no semicolon delimiter at the end of the SQL statements. There may be a label on either of the statements, and host language comments are allowed after the statements. |
F F'5' H H'100' CL255 CL5'ABCDE' H,CL5 H'5',CL5'ABCDE' D D'2.5E10' PL2 PL5'123.45' P'123' P'123.45' P'1234' P'123.456' H,CL32767
The first character of the operand may also be zero and used as follows:
0H 0F 0D 0C
In this case, the line is ignored and the next line is processed.
If there are no errors at this stage, the variable is validly defined as a host variable. If there are errors, the line is flagged as an error, and the next line is processed.
The following are the rules for embedding SQL statements within assembler programs:
To include external secondary input, specify the following at the point in the source code where the secondary input is to be included:
EXEC SQL INCLUDE text_name
Text_name is the A-Type source member of a VSE library. Text_name is the file name of a CMS file with an "ASMCOPY" file type, located on a CMS minidisk accessed by the user.
The INCLUDE statement must be completely contained on one line. There may be a label on the command, and host language comments are allowed after the command.
When you place host variables within an SQL statement, you must put a colon (:) in front of every host variable, to distinguish them from the SQL identifiers (such as a column name). When the same variable is used outside of an SQL statement, do not use a colon.
A host variable can represent a data value, but not an SQL identifier. For example, you cannot assign a character constant, such as "MUSICIANS", to a host variable, and then use that host variable in a CREATE TABLE statement to represent the table name. The following pseudocode sequence is invalid:
The rules for the format and use of DBCS characters in SQL statements are the same for assembler language as for other host languages supported by the database manager. For a discussion of these rules, see Using a Double-Byte Character Set (DBCS).
Assembler language does not provide a way to define graphic host variables. If you want to add graphic data to or retrieve it from DB2 Server for VSE & VM tables, you must execute the affected statements dynamically. By doing so, the data areas that are referenced by each statement can be described in an SQLDA. In the SQLDA, you must set the data type of the areas containing graphic data to one of the graphic data types. For a discussion of the SQLDA, refer to the DB2 Server for VSE & VM SQL Reference manual.