5.30.3 SET

The SET command is used to set database connection properties before you perform any activity on the database. It is very important that you understand the full capabilities of this command.

Syntax:

Command

Keyword

Value

Developer notes

SET

ONERROR

*ROLLBACK

Optional. The keyword is used to indicate the action you want to take if an exception is encountered during the execution of the SQL statement.

If an exception is encountered during the execution of the SQL statement, a rollback will be initiated.

*CONTINUE

If an exception is encountered during the execution of the SQL statement, the processing will continue.

*DISCONNECT

If an exception is encountered during the execution of the SQL statement, the database connection will be closed.

Default.

ONWARNING

*STOP

Optional. This keyword is used to indicate the action you wish to take if a warning message is issued during the execution of the SQL statement.

If a warning is encountered during the execution of the SQL statement, the command will be stopped.

Default.

*CONTINUE

If a warning is encountered during the execution of the SQL statement, the processing will continue.

READONLY

*YES

Optional. Enables database connection read-only mode.

No default.

*NO

Disables database connection read-only mode.

AUTOCOMMIT

*YES

Optional. Enables database connection auto-commit mode.

No default.

*NO

Disables database connection auto-commit mode.

ISOLATION

*NONE

Optional. Set connection transaction isolation level to NONE.

No default.

*READCOMMITTED

Set connection transaction isolation level to READ COMMITTED.

*READUNCOMMITTED

Set connection transaction isolation level to READ UNCOMMITTED.

*REPEATABLEREAD

Set connection transaction isolation level to REPEATABLE READ.

*SERIALIZABLE

Set connection transaction isolation level to SERIALIZABLE.

SQLSTATE

*NONE

Optional. SQLException returns ERROR status.
SQLWarning returns WARNING status.

Default.

*ALL

SQLException and SQLWarning return SQLxxxxx status.

*ERROR

SQLException returns SQLxxxxx status.
SQLWarning returns WARNING status.

*WARNING

SQLWarning returns SQLxxxxx status.
SQLException returns ERROR status.

MAXROWS

integer

Optional. Specifies the maximum number of rows to be returned by a query.

*NOMAX

Default.

PARAMETER

*NONE

Optional. The PARAMETER keyword can be used to prepare the SQL statement prior to running the EXECUTE or READ commands. The value you specify here depends very much on the type of activity you wish to perform on the database.

Use the *NONE value to clear the current map, list and SQL statements.

*LIST

Use this value if you intend to use the UPDATE keyword of the EXECUTE command. When taking this approach, the values that you intend to add to, update, or delete from the database will be specified in a list that is included in the SERVICE_LIST of this command. It is recommended that you use this option if you will be updating (or inserting or deleting) more than a single record. If you have multiple records and don't use this value, you would have to run the EXECUTE as many times as there are records, and this would place unnecessary load on your system and network. Please refer to the following Lists and Variables and the Examples for this command.

*SQL

Set this value if to intend to prepare the SQL statement in advance of the EXECUTE command. By doing so, you place your SQL statement into a working list that is passed in the SERVICE_LIST of this command.
This feature is particularly useful if you are going to be using long SQL statements. It is particularly useful for RDML applications where the longest field length can only be 256 characters. Please refer to the following Lists and Variables and Examples following this table for further information.

*CALL

Set this value if you intend to use call procedures that have IN, OUT and INOUT parameters.

*MAP

If you are expecting a large result set to be returned from a query, then you should choose to use the READ command to receive the list of values. To use the READ command you need to set this keyword to *MAP to indicate that the SERVICE_LIST of this command will contain the column and field mapping information. For further information, refer to the following Lists and Variables and the Examples for this command.

 

Example

SET PARAMETER(*SQL) #WRKLST(TXT)

 

SET PARAMETER(*LIST) #WRKLST(COL1,COL2,COL3)

 

SET ISOLATION(*READCOMMITTED) AUTOCOMMIT(*NO) ONERROR(*ROLLBACK) ONWARNING(*CONTINUE)

Comments / Warnings

JDBC drivers have vendor defined default settings for such areas as commitment control and exception handling. As an example, auto-commit is normally switched on.

It is strongly recommended that you test your commit and rollback logic extensively.

Lists and Variables

The PARAMETER keyword provides some very useful techniques for preparing your SQL statements.

If you choose to use the PARAMETER keyword with a value of *LIST, *SQL, *MAP or *CALL, then you will need to supply a working list with the SET command. The information that the working list contains will depend upon which of the three values you specify. It is quite possible that you could use a number of these options in conjunction with each other as shown in the following examples.

The SET, EXECUTE, and READ commands of the SQLService service are very tightly related to each other.

RDML

* Define the field to hold the JSM command

DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)

 

Define the field and list that will hold the SQL command

DEFINE FIELD(#COLCMD) TYPE(*CHAR) LENGTH(100)

DEF_LIST NAME(#WRKCMD) FIELDS(#COLCMD) TYPE(*WORKING)

 

* SET the commitment control settings

CHANGE FIELD(#JSMCMD) TO('SET ISOLATION(*READCOMMITTED) AUTOCOMMIT(*NO) ONERROR(*ROLLBACK) ONWARNING(*CONTINUE)')

USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)

 

* Set up the SQL statement in the list then run the SET command

CHANGE FIELD(#COLCMD) TO('SELECT ID,NAME,AGE,SALARY')

ADD_ENTRY TO_LIST(#WRKCMD)

CHANGE FIELD(#COLCMD) TO('FROM TBLNAME')

ADD_ENTRY TO_LIST(#WRKCMD)

CHANGE FIELD(#JSMCMD) TO('SET PARAMETER(*SQL) SERVICE_LIST(COLCMD)')

USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #WRKCMD)

 

RDMLX

* Define the JSM Command related fields

Define Field(#JSMSTS) Type(*Char) Length(020)

Define Field(#JSMMSG) Type(*Char) Length(256)

Define Field(#JSMCMD) Type(*Char) Length(256)

Define Field(#JSMHND) Type(*Char) Length(4)

 

* Define the field and the list to hold an SQL statement

Define Field(#COLCMD) Type(*Char) Length(020)

Def_List Name(#WRKCMD) Fields(#COLCMD) Type(*WORKING)

 

* Set up the commitment control settings

#JSMCMD := 'Set Isolation(*READCOMMITTED) AutoCommit(*NO) OnError(*ROLLBACK) OnWarning(*CONTINUE)'

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG)

 

* Build an SQL statement then run the Set command

#COLCMD := 'Select ID,NAME,AGE,SALARY'

Add_Entry To_List(#WRKCMD)

#COLCMD := 'From TBLNAME'

Add_Entry To_List(#WRKCMD)

#JSMCMD := 'Set Parameter(*SQL) '

Use Builtin(JSMX_COMMAND) With_Args(#JSMHND #JSMCMD) To_Get(#JSMSTS #JSMMSG #MAPLST)