SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
An introduction to Embedded
SQL for NonStop SQL/MX
Frans Jongma,
Hewlett Packard Enterprise
Advanced Technology Center
NonStop Enterprise Division
Version 1.0
Date: October 11, 2019
Contents
Introduction................................................................................................................................ 2
Audience ................................................................................................................................ 2
Assumptions........................................................................................................................... 2
Best practice........................................................................................................................... 3
From source to executable......................................................................................................... 3
Preprocessing and compilation............................................................................................... 3
Example 1, simple...................................................................................................................... 3
Downside of simple example.................................................................................................. 4
Example 2, managed module location ....................................................................................... 4
Controlling the module names................................................................................................ 5
Controlling schema names ..................................................................................................... 6
Example 3, schema flexibility ..................................................................................................... 6
Example 4, combined module control and schema flexibility...................................................... 8
Examine execution plans ........................................................................................................... 9
Summary ..................................................................................................................................10
References............................................................................................................................10
Appendix...................................................................................................................................11
COBOL Compilation process flow .........................................................................................11
C C++ Compilation process flow............................................................................................12
Simple example verbose output.............................................................................................13
Example 1 COBOL source code............................................................................................14
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -2-
Introduction
3GL languages such as COBOL and C have a specific SQL syntax that is translated by a
preprocessor into native calls to the database before the language and SQL compilers execute
and produce an executable program. This method is referred to as embedded SQL or static
SQL and differs from the more dynamic ways that is used in ODBC or JDBC programs, where
the statements are compiled as needed when the program executes. The SQL execution plans
that are created by a post-compilation step (the SQL compile) are stored by SQL/MX in so-
called module files separated from the executable program.
There are many options in creating and managing programs and module files, all of them are
listed in the SQL/MX Programming Manual for C and COBOL. However, for a first time user,
this amount of information may be overwhelming and confusing. This document will provide an
introduction to give users a fast start.
Audience
The paper is written for users who are new to NonStop SQL/MX and need to develop programs
in C or COBOL. The audience includes NonStop users that are familiar with NonStop SQL/MP
and how SQL/MP supports embedded SQL.
Assumptions
I assume the natural environment for NonStop SQL/MX, operation in the OSS operating
environment. While SQL/MX supports the Guardian environment, for ease of use and
understanding, it is not my recommended environment.
The examples show examples in COBOL, however since the method to compile is the same
between COBOL and C, C/C++ developers will find it useful too. The difference in compilers is
listed in the table below. The process flows are listed in the sections COBOL Compilation
process flow and C C++ Compilation process flow in the Appendix.
COBOL C/C++
SQL/MX Host language
precompiler
mxsqlco mxsqlc
Host language compiler xcobol or ecobol for J-series
software releases
c89
SQL/MX SQL Compiler mxCompileUserModule mxCompileUserModule
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -3-
Best practice
Naming tables and views in the source programs may best be done without qualifying them to a
dedicated catalog and schema. It is a better option to set the catalog and schema at a central
place in the source program with a DECLARE CATALOG or DECLARE SCHEMA statement. It
is also possible to define the catalog or schema as compiler options for the ultimate flexibility.
From source to executable
Host language source code uses SQL with a specific syntax called embedded SQL. These
statements are identified by the begin and end tags EXEC SQL and END-EXEC.
Some examples of embedded SQL are shown below. They show definition of variables used by
the program in the DECLARE section of the programs and an example of a SQL DML
statement.
EXEC SQL BEGIN DECLARE SECTION.
EXEC SQL INVOKE PARTS END-EXEC.
EXEC SQL END DECLARE SECTION.
EXEC SQL SELECT * FROM PARTS WHERE …… END-EXEC.
The statements between these tags, are processed by a SQL/MX preprocessor and translated
into host language (COBOL or C) statements, and these will be translated into machine code by
the standard COBOL and C compilers.
Preprocessing and compilation
The SQL/MX preprocessor takes a source input file, and produces a language source file that is
in turn the input for the language processor which produces an object file. This object can be a
load module or an executable object, depending on the type of program.
The SQL statements are processed by the SQL compiler, which uses the database metadata
and table statistics to produce an execution plan. This execution plan is stored in a module file
on disk. The executable program includes references to this module file (generated by the
preprocessor), such that when a program is executed, the corresponding modules can be
loaded to obtain and execute the execution plan.
Example 1, simple
The simplest way to compile a program is by invoking the language compiler which uses
definitions in the program and some defaults to produce the executable and the module file.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -4-
Let’s look at the following example, which compiles a COBOL source code1
sampl.ecob into
an executable called sampl. The xcobol compiler will invoke the necessary compiler programs,
based on the execution options
xcobol –Wsqlmx –Wmxcmp sampl.ecob –o sampl -Wverbose
The –Wsqlmx option tells the compiler that the program contains SQL/MX embedded SQL,
and so it will launch the SQ/MX COBOL preprocessor mxsqlco.
The –Wmxcmp option tells the compiler that the generated object (sampl) needs to be
processed by the SQL/MX compilers mxCompileUserModule and mxcmp.
The –Wverbose option causes the individual steps to be listed. It shows all the steps of the
compilation process and is listed in the appendix Simple example verbose output.
With this simple command, the generated modules will be stored in the default module directory,
/usr/tandem/sqlmx/USERMODULES. While it is nice to have a default place for all the
modules, the downside of the simple compilation is a single directory filled with many modules.
Downside of simple example
The SQL compiler will generate unique module files unless instructed by either compiler options
or an embedded SQL statement that defines the name of the module. An example of a default
module name is FRANS.PERF.SQLMX_DEFAULT_MODULE_259723530653478123. The
SQL preprocessor includes a catalog and schema name (in this case, FRANS.PERF) in the
name of the generated module. A subsequent compilation of the program will create a new
module, which means that the default USERMODULES directory will contain many modules
very quickly. There are ways to get a better control over the name of the module and the
location it is stored in as is shown in the next examples.
Example 2, managed module location
The simple one-step example will create all modules in the same location. A better option is to
co-locate the modules with the executables or to place them in separate directories. This can be
done by executing the SQL compile step as a separate one after the language compilation.
Such a 2-step compilation is shown below. Note, the –Wverbose option omitted in the
following examples.
xcobol -Wsqlmx sampl.ecob -o sampl
mxCompileUserModule -g moduleLocal sampl
1 The source code is listed in the appendix of this paper.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -5-
The mxCompileUserModule program invokes the SQL/MX compiler and will now create a
module in the local directory due to the –g moduleLocal option. It is even possible to
specify a specific directory to place the modules. That is useful, however, it requires that this
directory needs to be defined in an environment variable when the program is executed or else
the module will not be found. The environment variable, called _MX_MODULE_SEARCH_PATH,
is used as a search path and needs to contain the names of the directories to search for
modules, similar to the PATH and CLASSPATH variables. This paper will use discuss co-
located modules, where program and module are placed in the same directory.
Controlling the module names
Automatically generated module names are easy for a developer, but it will burden a system
administrator with the task of removing stale modules2
. It may therefore be better to explicitly
name the modules and let SQL/MX add the catalog and schema names to the name, since it is
useful to know to which schema a module belongs.
With the simple 2-step example, the module name can be defined with a DECLARE MODULE
statement in the program source. The example also uses DECLARE statements to define the
catalog and schema that the program will use.
The name of the module is defined along with the other data fields, while the catalog and
schema are defined later in the PROCEDURE DIVISION of the program.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
* The MODULE statement will cause a module created
* named <cat>.<sch>.SAMPL in the module directory
EXEC SQL MODULE "SAMPL" END-EXEC.
….. data definitions
…..
PROCEDURE DIVISION.
…..
EXEC SQL DECLARE CATALOG 'frans' END-EXEC.
EXEC SQL DECLARE SCHEMA 'perf' END-EXEC.
When this code is compiled, a module called FRANS.PERF.SAMPL is created, either in the
default (global) directory, or in the local directory if the moduleLocal option is used. When
2 Note: The mxci command DISPLAY USE OF SOURCE [‘module name’] will show the source file
belonging to this module. In case of stale modules, multiple modules will be referring to the same source
file. See the SQL/MX Reference Manual for information about the DISPLAY USE OF …. Command.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -6-
the program is subsequently recompiled, this module will be replaced and no stale modules will
exist, unless the program is removed without removing the corresponding module.
Controlling schema names
The SQL/MX precompiler creates the name of the module, which includes the catalog and
schema name. The DECLARE MODULE statement contains only the part of the name without
catalog and schema. The desired catalog and schema name to name the module can be
passed to the language compiler with the –WmoduleSchema=<cat.schema> option.
xcobol -Wsqlmx -WmoduleSchema=frans.perf sampl.ecob -o sampl
mxCompileUserModule -g moduleLocal sampl
Catalog and schema are SQL identifiers and are used in uppercase by SQL/MX3
. After these
two steps, a module with the name FRANS.PERF.SAMPLE is created in the current directory
along with the sampl executable.
Example 3, schema flexibility
To further improve, the source program can be made independent of the schema4
that is used.
The next example shows how to compile the program with the possibility to create modules in a
different schema (for example when moving from development to test to production) without
having to recompile from scratch. This allows the compiled program to be moved from one
system to another, only SQL-compiling the module to the target database environment.
In the previous examples, we let the source program define the schema with a DECLARE
SCHEMA statement. To provide schema flexibility, omit the DECLARE CATALOG and
DECLARE SCHEMA statements. This however means that the precompiler must be executed
as a separate step, because it needs another parameter that the language compiler does not
pass. This parameter is invokeSchema, which is used when EXEC SQL INVOKE is used to
import the column definitions from the database, which is used to make sure that a program
uses the correct column definitions.
The program sampl3 uses the INVOKE statement to obtain the column definitions of the PARTS
table, but does not declare the schema.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
EXEC SQL MODULE "SAMPL" END-EXEC.
3 It is possible to use mixed case and special characters in SQL/MX, by enclosing them in double quotes.
I consider it bad practice and will not discuss it here.
4 For readability, I use the term schema as the combination of catalog and schema.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -7-
* Get the record layout of PARTS
EXEC SQL INVOKE PARTS END-EXEC.
….. data definitions
…..
PROCEDURE DIVISION.
…..
* In reality, these lines are not present in the source.
* EXEC SQL DECLARE CATALOG 'frans' END-EXEC.
* EXEC SQL DECLARE SCHEMA 'perf' END-EXEC.
…..
To compile the program we use three steps, the preprocessor, the language processor and the
SQL compiler. The precompiler for COBOL, mxsqlco, uses value of moduleSchema to
create the name of the module and the –Q invokeSchema value to retrieve the record
definition of the PARTS table. And produces the generated COBOL source in sampl3.cbl. This
is input to the language compiler.
mxsqlco -g moduleSchema=frans.perf -Q invokeSchema=frans.perf
sampl3.ecob
xcobol -Wsqlmx -o sampl3 sampl3.cbl
mxCompileUserModule -g moduleLocal –d schema=frans.perf sampl3
The final step, mxCompileUserModule, creates the modules locally (this means they are
not created I the SQL/MX USERMODULES directory), and uses the schema name to get the
information it needs to compile an execution plan.
The next sequence of events show how the program can be targeted to use a new schema. In
this example, a row will be inserted in the PERF.PARTS table, but it will fail on a duplicate key
exception. The program shows the full name of the table, which includes the schema it
accesses. Then the only the module is recompiled to use the HR schema and the program
outpur shows that the same business code in sampl3 will access the HR.PARTS table.
~/compile> ./sampl3
This example uses a static cursor.
Enter lowest part number to be retrieved:
11
sqlerrors: 23000, -000008102
Table : FRANS.PERF.PARTS
Column :
SQLSTATE: 23000
Message : *** ERROR[8102] The operation is prevented by a
primary key PARTS_564349585_9263 on table FRANS.PERF.PARTS.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -8-
Create a module to use the frans.HR schema.
~/compile> mxCompileUserModule -g moduleLocal -d schema=frans.HR
sampl3
Run the same executable
~/compile> ./sampl3
This example uses a static cursor.
Enter lowest part number to be retrieved:
11
sqlerrors: 23000, -000008102
Table : FRANS.HR.PARTS
Column :
SQLSTATE: 23000
Message : *** ERROR[8102] The operation is prevented by a
primary key PARTS_118992335_3782 on table FRANS.HR.PARTS.
~/compile>
This example shows the method to move binary programs from one system to another and only
the module files need to be recompiled on the target database.
Note however, that this example uses a module called FRANS.PERF.SAMPL even though it
can access the PARTS table in schema PERF or HR. The first two parts of the module name
represent a catalog and schema, however, this is only a convention. The next example shows
how to control the complete module name.
Example 4, combined module control and schema flexibility
In this example, modules have names that do not include a catalog or schema, since the
application business code can run in different environments (for example development, test,
integration and production). Instead, in this example, the catalog and schema parts of the
module name are used for application name and version5
.
Important note: Do not use special characters (especially period) in the module name. While
the program may execute fine with such a module, the mxci DISPLAY USE OF commands
expect a three part name, with a “.” as separation character.
5 Including the version number in a module is used as an example of how one might organize modules.
Lifecycle version information might also be kept in source control systems such as git.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -9-
The module directive in the source file (sampl4.ecob) is specified as follows:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
* The MODULE statement will cause a module created named
* MYAPP.V_0_1.SAMPL4 in the module directory
EXEC SQL MODULE "MYAPP"."V_0_1"."SAMPL4" END-EXEC.
To compile the program in three steps:
# Use 2 environment variables to keep things simple:
export P=sampl4
export SCHEMA=FRANS.PERF
# run the three steps
mxsqlco -Q invokeSchema=$SCHEMA $P.ecob
xcobol -Wsqlmx -o $P $P.cbl
mxCompileUserModule -g moduleLocal -d SCHEMA=$SCHEMA $P
SQL compile the module for use on a different schema, use:
mxCompileUserModule -g moduleLocal -d SCHEMA=frans.hr sampl4
Examine execution plans
An advantage of having meaningful names for modules is that they now can be used easily to
examine the generated SQL execution plans. The following EXPLAIN statement shows the
formatted execution plans used by program sampl3.
~/compile> mxci
Hewlett Packard Enterprise NonStop(TM) SQL/MX Conversational Interface 3.6.1
(c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP.
>>EXPLAIN options 'f' '%' from '/home/hp/frans/compile/FRANS.PERF.SAMPL3' ;
Statement: GET_BY_PARTNUM
LC RC OP OPERATOR OPT DESCRIPTION CARD
---- ---- ---- -------------------- -------- -------------------- ---------
2 . 3 root 3.29E+001
1 . 2 partition_access 3.29E+001
. . 1 file_scan fr PARTS (s) 3.29E+001
…. ….
(Other statements omitted)
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -10-
Summary
Using a few simple examples we have seen how SQL/MX translates embedded SQL statement
into an executable program and a SQL module file. The examples have been kept very simple,
and do not discuss adding multiple object files that are linked together into an executable
program. The Programming Manual for C and COBOL has the details. This paper will help you
finding the right options for building larger programs.
The module file names can be defined by the user, which has system management advantages.
Using the default location and the default naming scheme will result in a large amount of, often
unused, modules in the /usr/tandem/sqlmx/USERMODULES directory. Decoupling the
program source code from the actually used catalog and schema allow an easy move of objects
between execution environments. In cases where application run on systems with differently
named catalogs or schemas, it is good practice to define module names based on a convention
that is not based on catalog and schema, but on something else, such as application name and
possibly version or subclass of the application.
References
The following manuals can be used to get more detailed information. They are accessible via
the HPE Support Center, for L-series software go to https://hpe.com/info/nonstop-ldocs, and for
J-series software use https://hpe.com/info/nonstop-jdocs.
Some manuals have the release number in the title and not shown in the titles below.
SQL/MX Programming Manual for C and COBOL.
SQL/MX Reference manual.
SQL/MP to SQL/MX Database and Application Migration Guide.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -11-
Appendix
COBOL Compilation process flow
The following diagram shows the compilation steps. This figure was taken from the SQL/MX
Programming C and COBOL manual
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -12-
C C++ Compilation process flow
The following diagram shows the compilation steps. This figure was taken from the SQL/MX
Programming C and COBOL manual
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -13-
Simple example verbose output
This is the output from the one-step compilation in example 1.
~/compile> xcobol -Wsqlmx -Wmxcmp sampl.ecob -o sampl -Wverbose
xcobol: running /usr/tandem/sqlmx/bin/mxsqlco sampl.ecob -c sampl.cob
-l /dev/null
xcobol: running /usr/cmplr/xcobfe -Wcobol="Consult
/usr/tandem/sqlmx/lib/xsqlcli.o" sampl.cob -
XS"/tmp/tAAAqaaaha2030043143.T" -XK/tmp/tAAAqaaaha2030043143.K -
XFsampl.FDBK -I/usr/include -Wsystype=oss -Wsuppress -
XR/G/system/zdll012/xcredll -XZ/G/system/zdll012/xcobdll -
XY/G/system/zdll012/xcobadll -XE/G/system/system/xcobext
xcobol: /usr/cmplr/xcobfe exited, returning 0.
xcobol: running /usr/cmplr/be -PHASE:c -G8 -O1 -LANG:=cobol -
TARG:sse3=on -TARG:processor=wolfdale -TARG:sse2=on -TARG:mmx=on -
TARG:sse=on -TARG:3dnow=off -TARG:sse4a=off -TENV:PIC -TARG:BEX=BE -
TARG:abi=p64 -TARG:datamode=32 -fT,/tmp/tAAAqaaaha2030043143.T -s -
fs,sampl.s sampl.ecob
xcobol: /usr/cmplr/be exited, returning 0.
xcobol: running /usr/cmplr/xas -mlanguage=cobol --fatal-warnings -
mfloattype=neutral -mcode-big-endian -lcf /tmp/tAAAqaaaha2030043143.K
-o sampl.o sampl.s
xcobol: /usr/cmplr/xas exited, returning 0.
xcobol: running /usr/bin/xld -o sampl -set systype oss -set highpin on
-set highrequestor on -set inspect on sampl.o -lcli -lcob -L
/G/system/sys07 -lcre -lcrtl -lossk -lossf -lsec -li18n -licnv -losse
-linet -lossh -lossc -lcli
xcobol: /usr/bin/xld exited, returning 0.
xcobol: running /usr/tandem/sqlmx/bin/mxCompileUserModule sampl
Hewlett Packard Enterprise NonStop(TM) SQL/MX Embedded Module Compile
Utility 3.6.1
(c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP.
/G/system/system/mxcmp /tmp/AAAqaabWa197661ACICCH
Hewlett Packard Enterprise NonStop(TM) SQL/MX Compiler 3.6.1
(c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -14-
/tmp/AAAqaabWa197661ACICCH
(/usr/tandem/sqlmx/USERMODULES/FRANS.PERF.SQLMX_DEFAULT_MODULE_2597235
31183946022)
0 errors, 0 warnings, 0 statements affected; 17 statements total
1 modules found, 1 modules extracted.
1 mxcmp invocations: 1 succeeded, 0 failed.
xcobol: /usr/tandem/sqlmx/bin/mxCompileUserModule exited, returning 0.
xcobol: Exiting with status 0; 0 error(s).
~/compile>
Example 1 COBOL source code
This sample program is a slightly changed copy of the example from the SQL/MX 3.6
Programming Manual for C and COBOL. The change is the addition of the INSERT statement
right before the cursor is opened. Note that duplicate keys will cause an error, this error is used
to show that the examples can run the same code on different schemas.
* ---------------------------------------------------------------
* compile this program simply in OSS with:
* [x|e]cobol -Wsqlmx -Wmxcmp sampl.ecob -o sampl –Wverbose
*
* Description: Using a Static SQL Cursor
* Statements: Static DECLARE CURSOR
* BEGIN WORK
* OPEN
* FETCH
* Positioned UPDATE
* CLOSE
* COMMIT WORK
* WHENEVER
* GET DIAGNOSTICS
*---------------------------------------------------------------
* Table definition
* CREATE TABLE PARTS
* (
* PARTNUM NUMERIC(4, 0) UNSIGNED NO DEFAULT HEADING
* 'Part/Num' NOT NULL
* , PARTDESC CHAR(18) CHARACTER SET ISO88591 NO
* DEFAULT HEADING 'Part Description' NOT NULL
* , PRICE NUMERIC(8, 2) NO DEFAULT HEADING 'Price'
* NOT NULL
* , QTY_AVAILABLE NUMERIC(5, 0) DEFAULT 0 HEADING
* 'Qty/Avail' NOT NULL
* , ORDER_DATE DATE DEFAULT CURRENT_DATE
* , PRIMARY KEY (PARTNUM ASC)
* )
* ;
* --- SQL operation complete.
*
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -15-
IDENTIFICATION DIVISION.
PROGRAM-ID. Program-exF62.
DATA DIVISION.
WORKING-STORAGE SECTION.
* program uses the INVOKE HVs to insert the row
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
* The MODULE statement will cause a module created named
* MYAPP.V_0_1.SAMPL4 in the module directory
* Note that the three part name must follows the rules
* for SQL/MX Catalog,schema, and object, separated by a "."
EXEC SQL MODULE "MYAPP"."V_0_1"."SAMPL4" END-EXEC.
* GET THE CORRECT RECORD LAYOUT
* if the table name is not qualified with cat and schema,
* the preprocessor must be called
* with -Q invokeSchema=cat.sch
*
EXEC SQL INVOKE PARTS END-EXEC.
01 sqlstate pic x(5).
01 sqlcode pic s9(9) comp.
01 hv-partnum pic 9(4) comp.
01 hv-partdesc pic x(18).
01 hv-price pic s9(6)v9(2) comp.
01 hv-qty-available pic s9(7) comp.
* in SQL/MP the date column is declared as PIC X(10) ,
* and the insert uses the TYPE AS DATE clause when inserting a row
* SQL/MX however supports (and needs) the column defined as DATE,
* the INSERT statment does not require the non-ANSI TYPE AS construct.
01 hv-order-date DATE value "2019-09-12".
* hv-order-date for SQLMP definition
*01 hv-order-date pic x(10) value "2019-09-12".
01 hv-num pic s9(9) comp.
01 hv-sqlstate pic x(5).
01 hv-tabname pic x(128).
01 hv-colname pic x(128).
01 hv-msgtxt pic x(128).
01 in-partnum pic 9(4) comp.
01 i pic s9(9) comp.
EXEC SQL END DECLARE SECTION END-EXEC.
01 sqlstate-ok pic x(5) value "00000".
01 sqlstate-nodata pic x(5) value "02000".
01 sqlstate-save pic x(5).
01 sqlcode-save pic s9(9) comp.
PROCEDURE DIVISION.
START-LABEL.
DISPLAY "This example uses a fully qualified module name, but catalog and schema
names are independent".
EXEC SQL WHENEVER SQLERROR GOTO sqlerrors END-EXEC.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -16-
* Declare static cursor.
EXEC SQL DECLARE get_by_partnum CURSOR FOR
SELECT partnum, partdesc, price, qty_available
FROM parts
WHERE partnum >= :in-partnum
FOR UPDATE OF partdesc, price, qty_available
END-EXEC.
* Read in-partnum from terminal.
DISPLAY "Enter lowest part number to be retrieved: ".
ACCEPT in-partnum.
* Begin the transaction.
move in-partnum to partnum
move "New part" to partdesc
move 120 to price
move 528 to qty-available
move "2019-09-13" to order-date.
EXEC SQL BEGIN WORK END-EXEC.
EXEC SQL INSERT INTO PARTS (
PARTNUM,
PARTDESC,
PRICE,
QTY_AVAILABLE,
ORDER_DATE ) VALUES
(
:partnum,
:partdesc,
:price,
:qty-available,
:order-date
)
END-EXEC.
* Open the cursor.
EXEC SQL OPEN get_by_partnum END-EXEC.
* Fetch the first row of the result from table.
EXEC SQL FETCH get_by_partnum
INTO :hv-partnum, :hv-partdesc,
:hv-price, :hv-qty-available
END-EXEC.
* Update qty_available if qty_available is less than 1000.
PERFORM UNTIL sqlstate = sqlstate-nodata
IF hv-qty-available < 1000
EXEC SQL UPDATE parts
SET qty_available = qty_available + 100
WHERE CURRENT OF get_by_partnum
END-EXEC.
DISPLAY "Update of part number: " hv-partnum
END-IF
EXEC SQL FETCH get_by_partnum
INTO :hv-partnum, :hv-partdesc,
:hv-price, :hv-qty-available
END-EXEC.
END-PERFORM.
* Close the cursor.
EXEC SQL CLOSE get_by_partnum END-EXEC.
NonStop Advanced Technology Center
An introduction to Embedded SQL for NonStop SQL/MX -17-
* Commit any changes.
EXEC SQL COMMIT WORK END-EXEC.
IF sqlstate = sqlstate-ok
DISPLAY "The program completed successfully.".
STOP RUN.
****************************************************************
sqlerrors SECTION.
****************************************************************
move sqlstate to sqlstate-save.
move sqlcode to sqlcode-save.
display "sqlerrors: " sqlstate ", " sqlcode.
EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
IF sqlstate not = sqlstate-ok
EXEC SQL GET DIAGNOSTICS
:hv-num = NUMBER
END-EXEC.
PERFORM VARYING i FROM 1 BY 1 UNTIL i > hv-num
MOVE SPACES TO hv-msgtxt
EXEC SQL GET DIAGNOSTICS EXCEPTION :i
:hv-tabname = TABLE_NAME,
:hv-colname = COLUMN_NAME,
:hv-sqlstate = RETURNED_SQLSTATE,
:hv-msgtxt = MESSAGE_TEXT
END-EXEC.
DISPLAY "Table : " hv-tabname
DISPLAY "Column : " hv-colname
DISPLAY "SQLSTATE: " hv-sqlstate
DISPLAY "Message : " hv-msgtxt
END-PERFORM
END-IF.
move sqlstate-save to sqlstate.
move sqlcode-save to sqlcode.
* STOP RUN.
****************************************************************
END PROGRAM Program-exF62.
****************************************************************

Weitere ähnliche Inhalte

Was ist angesagt?

Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...
Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...
Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...Odinot Stanislas
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화OpenStack Korea Community
 
Nick Fisk - low latency Ceph
Nick Fisk - low latency CephNick Fisk - low latency Ceph
Nick Fisk - low latency CephShapeBlue
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance BenchmarkingRenat Khasanshyn
 
Using ZFS file system with MySQL
Using ZFS file system with MySQLUsing ZFS file system with MySQL
Using ZFS file system with MySQLMydbops
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd Marian Marinov
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and PropertiesSaadi Rahman
 
IPsec Basics: AH and ESP Explained
IPsec Basics: AH and ESP ExplainedIPsec Basics: AH and ESP Explained
IPsec Basics: AH and ESP ExplainedAndriy Berestovskyy
 
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDS
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDSAccelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDS
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDSCeph Community
 
GlusterFs Architecture & Roadmap - LinuxCon EU 2013
GlusterFs Architecture & Roadmap - LinuxCon EU 2013GlusterFs Architecture & Roadmap - LinuxCon EU 2013
GlusterFs Architecture & Roadmap - LinuxCon EU 2013Gluster.org
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsBrendan Gregg
 
IBM DS8880 and IBM Z - Integrated by Design
IBM DS8880 and IBM Z - Integrated by DesignIBM DS8880 and IBM Z - Integrated by Design
IBM DS8880 and IBM Z - Integrated by DesignStefan Lein
 
Cci cheat sheet_v107
Cci cheat sheet_v107Cci cheat sheet_v107
Cci cheat sheet_v107ramparasa
 

Was ist angesagt? (20)

Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...
Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...
Ceph: Open Source Storage Software Optimizations on Intel® Architecture for C...
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
 
NTLM
NTLMNTLM
NTLM
 
Nick Fisk - low latency Ceph
Nick Fisk - low latency CephNick Fisk - low latency Ceph
Nick Fisk - low latency Ceph
 
Couchbase Performance Benchmarking
Couchbase Performance BenchmarkingCouchbase Performance Benchmarking
Couchbase Performance Benchmarking
 
Using ZFS file system with MySQL
Using ZFS file system with MySQLUsing ZFS file system with MySQL
Using ZFS file system with MySQL
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
IPsec Basics: AH and ESP Explained
IPsec Basics: AH and ESP ExplainedIPsec Basics: AH and ESP Explained
IPsec Basics: AH and ESP Explained
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Storage overview
Storage overviewStorage overview
Storage overview
 
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDS
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDSAccelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDS
Accelerating Cassandra Workloads on Ceph with All-Flash PCIE SSDS
 
Sun NFS , Case study
Sun NFS , Case study Sun NFS , Case study
Sun NFS , Case study
 
Linux Hardening - nullhyd
Linux Hardening - nullhydLinux Hardening - nullhyd
Linux Hardening - nullhyd
 
DAS RAID NAS SAN
DAS RAID NAS SANDAS RAID NAS SAN
DAS RAID NAS SAN
 
GlusterFs Architecture & Roadmap - LinuxCon EU 2013
GlusterFs Architecture & Roadmap - LinuxCon EU 2013GlusterFs Architecture & Roadmap - LinuxCon EU 2013
GlusterFs Architecture & Roadmap - LinuxCon EU 2013
 
Backup strategy
Backup strategyBackup strategy
Backup strategy
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame Graphs
 
IBM DS8880 and IBM Z - Integrated by Design
IBM DS8880 and IBM Z - Integrated by DesignIBM DS8880 and IBM Z - Integrated by Design
IBM DS8880 and IBM Z - Integrated by Design
 
Cci cheat sheet_v107
Cci cheat sheet_v107Cci cheat sheet_v107
Cci cheat sheet_v107
 

Ähnlich wie Introduction to Embedded SQL for NonStop SQL/MX

PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
cbmanual
cbmanualcbmanual
cbmanualMatt D
 
Office OpenXML: a technical approach for OOo.
Office OpenXML: a technical approach for OOo.Office OpenXML: a technical approach for OOo.
Office OpenXML: a technical approach for OOo.Alexandro Colorado
 
Oracle E-Business Suite Custom Library New Look
Oracle E-Business Suite Custom Library New LookOracle E-Business Suite Custom Library New Look
Oracle E-Business Suite Custom Library New LookDonald Ferreira
 
Introduction tococoon2 (1)
Introduction tococoon2 (1)Introduction tococoon2 (1)
Introduction tococoon2 (1)Duong Duong
 
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored ProceduresConcepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored ProceduresFrans Jongma
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilitiesdpcobb
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Christos Manios
 
Code That Writes Code : Automatic Programming for NHibernate
Code That Writes Code : Automatic Programming for NHibernateCode That Writes Code : Automatic Programming for NHibernate
Code That Writes Code : Automatic Programming for NHibernateDeepak Sahu
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQLKailash N
 

Ähnlich wie Introduction to Embedded SQL for NonStop SQL/MX (20)

Pl sql chapter 1
Pl sql chapter 1Pl sql chapter 1
Pl sql chapter 1
 
Micro Assembler
Micro AssemblerMicro Assembler
Micro Assembler
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
 
cbmanual
cbmanualcbmanual
cbmanual
 
Pl sql-ch1
Pl sql-ch1Pl sql-ch1
Pl sql-ch1
 
tutorialSCE
tutorialSCEtutorialSCE
tutorialSCE
 
Readme
ReadmeReadme
Readme
 
Pl sql
Pl sqlPl sql
Pl sql
 
Office OpenXML: a technical approach for OOo.
Office OpenXML: a technical approach for OOo.Office OpenXML: a technical approach for OOo.
Office OpenXML: a technical approach for OOo.
 
Oracle E-Business Suite Custom Library New Look
Oracle E-Business Suite Custom Library New LookOracle E-Business Suite Custom Library New Look
Oracle E-Business Suite Custom Library New Look
 
Introduction tococoon2 (1)
Introduction tococoon2 (1)Introduction tococoon2 (1)
Introduction tococoon2 (1)
 
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored ProceduresConcepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilities
 
Open Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFVOpen Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFV
 
Es build presentation
Es build presentationEs build presentation
Es build presentation
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 
Mkl mic lab_0
Mkl mic lab_0Mkl mic lab_0
Mkl mic lab_0
 
Code That Writes Code : Automatic Programming for NHibernate
Code That Writes Code : Automatic Programming for NHibernateCode That Writes Code : Automatic Programming for NHibernate
Code That Writes Code : Automatic Programming for NHibernate
 
MFC Whitepaper
MFC WhitepaperMFC Whitepaper
MFC Whitepaper
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 

Mehr von Frans Jongma

HPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - IntroductionHPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - IntroductionFrans Jongma
 
DbVisualizer for NonStop SQL
DbVisualizer for NonStop SQLDbVisualizer for NonStop SQL
DbVisualizer for NonStop SQLFrans Jongma
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureFrans Jongma
 
Database consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MXDatabase consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MXFrans Jongma
 
Native tables in NonStop SQL database
Native tables in NonStop SQL databaseNative tables in NonStop SQL database
Native tables in NonStop SQL databaseFrans Jongma
 
NonStop SQL/MX DBS demo with iTP Webserver
NonStop SQL/MX DBS demo with iTP WebserverNonStop SQL/MX DBS demo with iTP Webserver
NonStop SQL/MX DBS demo with iTP WebserverFrans Jongma
 
NonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedNonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedFrans Jongma
 
Understanding NonStop SQLMX SDA and its impact on performance
Understanding NonStop SQLMX SDA and its impact on performanceUnderstanding NonStop SQLMX SDA and its impact on performance
Understanding NonStop SQLMX SDA and its impact on performanceFrans Jongma
 
Native tables in NonStop SQL/MX
Native tables in NonStop SQL/MXNative tables in NonStop SQL/MX
Native tables in NonStop SQL/MXFrans Jongma
 
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objectsConcepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objectsFrans Jongma
 
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to MetadataConcepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to MetadataFrans Jongma
 
Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.Frans Jongma
 

Mehr von Frans Jongma (12)

HPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - IntroductionHPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - Introduction
 
DbVisualizer for NonStop SQL
DbVisualizer for NonStop SQLDbVisualizer for NonStop SQL
DbVisualizer for NonStop SQL
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
 
Database consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MXDatabase consistency in NonStop SQL/MX
Database consistency in NonStop SQL/MX
 
Native tables in NonStop SQL database
Native tables in NonStop SQL databaseNative tables in NonStop SQL database
Native tables in NonStop SQL database
 
NonStop SQL/MX DBS demo with iTP Webserver
NonStop SQL/MX DBS demo with iTP WebserverNonStop SQL/MX DBS demo with iTP Webserver
NonStop SQL/MX DBS demo with iTP Webserver
 
NonStop SQL/MX DBS Explained
NonStop SQL/MX DBS ExplainedNonStop SQL/MX DBS Explained
NonStop SQL/MX DBS Explained
 
Understanding NonStop SQLMX SDA and its impact on performance
Understanding NonStop SQLMX SDA and its impact on performanceUnderstanding NonStop SQLMX SDA and its impact on performance
Understanding NonStop SQLMX SDA and its impact on performance
 
Native tables in NonStop SQL/MX
Native tables in NonStop SQL/MXNative tables in NonStop SQL/MX
Native tables in NonStop SQL/MX
 
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objectsConcepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
Concepts of NonStop SQL/MX: Part 2 - Introduction to catalogs and other objects
 
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to MetadataConcepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
Concepts of NonStop SQL/MX: Part 3 - Introduction to Metadata
 
Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.Concepts of NonStop SQL/MX: Part 4 - Storage.
Concepts of NonStop SQL/MX: Part 4 - Storage.
 

Kürzlich hochgeladen

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Kürzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

Introduction to Embedded SQL for NonStop SQL/MX

  • 1. An introduction to Embedded SQL for NonStop SQL/MX Frans Jongma, Hewlett Packard Enterprise Advanced Technology Center NonStop Enterprise Division Version 1.0 Date: October 11, 2019 Contents Introduction................................................................................................................................ 2 Audience ................................................................................................................................ 2 Assumptions........................................................................................................................... 2 Best practice........................................................................................................................... 3 From source to executable......................................................................................................... 3 Preprocessing and compilation............................................................................................... 3 Example 1, simple...................................................................................................................... 3 Downside of simple example.................................................................................................. 4 Example 2, managed module location ....................................................................................... 4 Controlling the module names................................................................................................ 5 Controlling schema names ..................................................................................................... 6 Example 3, schema flexibility ..................................................................................................... 6 Example 4, combined module control and schema flexibility...................................................... 8 Examine execution plans ........................................................................................................... 9 Summary ..................................................................................................................................10 References............................................................................................................................10 Appendix...................................................................................................................................11 COBOL Compilation process flow .........................................................................................11 C C++ Compilation process flow............................................................................................12 Simple example verbose output.............................................................................................13 Example 1 COBOL source code............................................................................................14
  • 2. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -2- Introduction 3GL languages such as COBOL and C have a specific SQL syntax that is translated by a preprocessor into native calls to the database before the language and SQL compilers execute and produce an executable program. This method is referred to as embedded SQL or static SQL and differs from the more dynamic ways that is used in ODBC or JDBC programs, where the statements are compiled as needed when the program executes. The SQL execution plans that are created by a post-compilation step (the SQL compile) are stored by SQL/MX in so- called module files separated from the executable program. There are many options in creating and managing programs and module files, all of them are listed in the SQL/MX Programming Manual for C and COBOL. However, for a first time user, this amount of information may be overwhelming and confusing. This document will provide an introduction to give users a fast start. Audience The paper is written for users who are new to NonStop SQL/MX and need to develop programs in C or COBOL. The audience includes NonStop users that are familiar with NonStop SQL/MP and how SQL/MP supports embedded SQL. Assumptions I assume the natural environment for NonStop SQL/MX, operation in the OSS operating environment. While SQL/MX supports the Guardian environment, for ease of use and understanding, it is not my recommended environment. The examples show examples in COBOL, however since the method to compile is the same between COBOL and C, C/C++ developers will find it useful too. The difference in compilers is listed in the table below. The process flows are listed in the sections COBOL Compilation process flow and C C++ Compilation process flow in the Appendix. COBOL C/C++ SQL/MX Host language precompiler mxsqlco mxsqlc Host language compiler xcobol or ecobol for J-series software releases c89 SQL/MX SQL Compiler mxCompileUserModule mxCompileUserModule
  • 3. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -3- Best practice Naming tables and views in the source programs may best be done without qualifying them to a dedicated catalog and schema. It is a better option to set the catalog and schema at a central place in the source program with a DECLARE CATALOG or DECLARE SCHEMA statement. It is also possible to define the catalog or schema as compiler options for the ultimate flexibility. From source to executable Host language source code uses SQL with a specific syntax called embedded SQL. These statements are identified by the begin and end tags EXEC SQL and END-EXEC. Some examples of embedded SQL are shown below. They show definition of variables used by the program in the DECLARE section of the programs and an example of a SQL DML statement. EXEC SQL BEGIN DECLARE SECTION. EXEC SQL INVOKE PARTS END-EXEC. EXEC SQL END DECLARE SECTION. EXEC SQL SELECT * FROM PARTS WHERE …… END-EXEC. The statements between these tags, are processed by a SQL/MX preprocessor and translated into host language (COBOL or C) statements, and these will be translated into machine code by the standard COBOL and C compilers. Preprocessing and compilation The SQL/MX preprocessor takes a source input file, and produces a language source file that is in turn the input for the language processor which produces an object file. This object can be a load module or an executable object, depending on the type of program. The SQL statements are processed by the SQL compiler, which uses the database metadata and table statistics to produce an execution plan. This execution plan is stored in a module file on disk. The executable program includes references to this module file (generated by the preprocessor), such that when a program is executed, the corresponding modules can be loaded to obtain and execute the execution plan. Example 1, simple The simplest way to compile a program is by invoking the language compiler which uses definitions in the program and some defaults to produce the executable and the module file.
  • 4. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -4- Let’s look at the following example, which compiles a COBOL source code1 sampl.ecob into an executable called sampl. The xcobol compiler will invoke the necessary compiler programs, based on the execution options xcobol –Wsqlmx –Wmxcmp sampl.ecob –o sampl -Wverbose The –Wsqlmx option tells the compiler that the program contains SQL/MX embedded SQL, and so it will launch the SQ/MX COBOL preprocessor mxsqlco. The –Wmxcmp option tells the compiler that the generated object (sampl) needs to be processed by the SQL/MX compilers mxCompileUserModule and mxcmp. The –Wverbose option causes the individual steps to be listed. It shows all the steps of the compilation process and is listed in the appendix Simple example verbose output. With this simple command, the generated modules will be stored in the default module directory, /usr/tandem/sqlmx/USERMODULES. While it is nice to have a default place for all the modules, the downside of the simple compilation is a single directory filled with many modules. Downside of simple example The SQL compiler will generate unique module files unless instructed by either compiler options or an embedded SQL statement that defines the name of the module. An example of a default module name is FRANS.PERF.SQLMX_DEFAULT_MODULE_259723530653478123. The SQL preprocessor includes a catalog and schema name (in this case, FRANS.PERF) in the name of the generated module. A subsequent compilation of the program will create a new module, which means that the default USERMODULES directory will contain many modules very quickly. There are ways to get a better control over the name of the module and the location it is stored in as is shown in the next examples. Example 2, managed module location The simple one-step example will create all modules in the same location. A better option is to co-locate the modules with the executables or to place them in separate directories. This can be done by executing the SQL compile step as a separate one after the language compilation. Such a 2-step compilation is shown below. Note, the –Wverbose option omitted in the following examples. xcobol -Wsqlmx sampl.ecob -o sampl mxCompileUserModule -g moduleLocal sampl 1 The source code is listed in the appendix of this paper.
  • 5. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -5- The mxCompileUserModule program invokes the SQL/MX compiler and will now create a module in the local directory due to the –g moduleLocal option. It is even possible to specify a specific directory to place the modules. That is useful, however, it requires that this directory needs to be defined in an environment variable when the program is executed or else the module will not be found. The environment variable, called _MX_MODULE_SEARCH_PATH, is used as a search path and needs to contain the names of the directories to search for modules, similar to the PATH and CLASSPATH variables. This paper will use discuss co- located modules, where program and module are placed in the same directory. Controlling the module names Automatically generated module names are easy for a developer, but it will burden a system administrator with the task of removing stale modules2 . It may therefore be better to explicitly name the modules and let SQL/MX add the catalog and schema names to the name, since it is useful to know to which schema a module belongs. With the simple 2-step example, the module name can be defined with a DECLARE MODULE statement in the program source. The example also uses DECLARE statements to define the catalog and schema that the program will use. The name of the module is defined along with the other data fields, while the catalog and schema are defined later in the PROCEDURE DIVISION of the program. EXEC SQL BEGIN DECLARE SECTION END-EXEC. * The MODULE statement will cause a module created * named <cat>.<sch>.SAMPL in the module directory EXEC SQL MODULE "SAMPL" END-EXEC. ….. data definitions ….. PROCEDURE DIVISION. ….. EXEC SQL DECLARE CATALOG 'frans' END-EXEC. EXEC SQL DECLARE SCHEMA 'perf' END-EXEC. When this code is compiled, a module called FRANS.PERF.SAMPL is created, either in the default (global) directory, or in the local directory if the moduleLocal option is used. When 2 Note: The mxci command DISPLAY USE OF SOURCE [‘module name’] will show the source file belonging to this module. In case of stale modules, multiple modules will be referring to the same source file. See the SQL/MX Reference Manual for information about the DISPLAY USE OF …. Command.
  • 6. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -6- the program is subsequently recompiled, this module will be replaced and no stale modules will exist, unless the program is removed without removing the corresponding module. Controlling schema names The SQL/MX precompiler creates the name of the module, which includes the catalog and schema name. The DECLARE MODULE statement contains only the part of the name without catalog and schema. The desired catalog and schema name to name the module can be passed to the language compiler with the –WmoduleSchema=<cat.schema> option. xcobol -Wsqlmx -WmoduleSchema=frans.perf sampl.ecob -o sampl mxCompileUserModule -g moduleLocal sampl Catalog and schema are SQL identifiers and are used in uppercase by SQL/MX3 . After these two steps, a module with the name FRANS.PERF.SAMPLE is created in the current directory along with the sampl executable. Example 3, schema flexibility To further improve, the source program can be made independent of the schema4 that is used. The next example shows how to compile the program with the possibility to create modules in a different schema (for example when moving from development to test to production) without having to recompile from scratch. This allows the compiled program to be moved from one system to another, only SQL-compiling the module to the target database environment. In the previous examples, we let the source program define the schema with a DECLARE SCHEMA statement. To provide schema flexibility, omit the DECLARE CATALOG and DECLARE SCHEMA statements. This however means that the precompiler must be executed as a separate step, because it needs another parameter that the language compiler does not pass. This parameter is invokeSchema, which is used when EXEC SQL INVOKE is used to import the column definitions from the database, which is used to make sure that a program uses the correct column definitions. The program sampl3 uses the INVOKE statement to obtain the column definitions of the PARTS table, but does not declare the schema. EXEC SQL BEGIN DECLARE SECTION END-EXEC. EXEC SQL MODULE "SAMPL" END-EXEC. 3 It is possible to use mixed case and special characters in SQL/MX, by enclosing them in double quotes. I consider it bad practice and will not discuss it here. 4 For readability, I use the term schema as the combination of catalog and schema.
  • 7. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -7- * Get the record layout of PARTS EXEC SQL INVOKE PARTS END-EXEC. ….. data definitions ….. PROCEDURE DIVISION. ….. * In reality, these lines are not present in the source. * EXEC SQL DECLARE CATALOG 'frans' END-EXEC. * EXEC SQL DECLARE SCHEMA 'perf' END-EXEC. ….. To compile the program we use three steps, the preprocessor, the language processor and the SQL compiler. The precompiler for COBOL, mxsqlco, uses value of moduleSchema to create the name of the module and the –Q invokeSchema value to retrieve the record definition of the PARTS table. And produces the generated COBOL source in sampl3.cbl. This is input to the language compiler. mxsqlco -g moduleSchema=frans.perf -Q invokeSchema=frans.perf sampl3.ecob xcobol -Wsqlmx -o sampl3 sampl3.cbl mxCompileUserModule -g moduleLocal –d schema=frans.perf sampl3 The final step, mxCompileUserModule, creates the modules locally (this means they are not created I the SQL/MX USERMODULES directory), and uses the schema name to get the information it needs to compile an execution plan. The next sequence of events show how the program can be targeted to use a new schema. In this example, a row will be inserted in the PERF.PARTS table, but it will fail on a duplicate key exception. The program shows the full name of the table, which includes the schema it accesses. Then the only the module is recompiled to use the HR schema and the program outpur shows that the same business code in sampl3 will access the HR.PARTS table. ~/compile> ./sampl3 This example uses a static cursor. Enter lowest part number to be retrieved: 11 sqlerrors: 23000, -000008102 Table : FRANS.PERF.PARTS Column : SQLSTATE: 23000 Message : *** ERROR[8102] The operation is prevented by a primary key PARTS_564349585_9263 on table FRANS.PERF.PARTS.
  • 8. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -8- Create a module to use the frans.HR schema. ~/compile> mxCompileUserModule -g moduleLocal -d schema=frans.HR sampl3 Run the same executable ~/compile> ./sampl3 This example uses a static cursor. Enter lowest part number to be retrieved: 11 sqlerrors: 23000, -000008102 Table : FRANS.HR.PARTS Column : SQLSTATE: 23000 Message : *** ERROR[8102] The operation is prevented by a primary key PARTS_118992335_3782 on table FRANS.HR.PARTS. ~/compile> This example shows the method to move binary programs from one system to another and only the module files need to be recompiled on the target database. Note however, that this example uses a module called FRANS.PERF.SAMPL even though it can access the PARTS table in schema PERF or HR. The first two parts of the module name represent a catalog and schema, however, this is only a convention. The next example shows how to control the complete module name. Example 4, combined module control and schema flexibility In this example, modules have names that do not include a catalog or schema, since the application business code can run in different environments (for example development, test, integration and production). Instead, in this example, the catalog and schema parts of the module name are used for application name and version5 . Important note: Do not use special characters (especially period) in the module name. While the program may execute fine with such a module, the mxci DISPLAY USE OF commands expect a three part name, with a “.” as separation character. 5 Including the version number in a module is used as an example of how one might organize modules. Lifecycle version information might also be kept in source control systems such as git.
  • 9. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -9- The module directive in the source file (sampl4.ecob) is specified as follows: EXEC SQL BEGIN DECLARE SECTION END-EXEC. * The MODULE statement will cause a module created named * MYAPP.V_0_1.SAMPL4 in the module directory EXEC SQL MODULE "MYAPP"."V_0_1"."SAMPL4" END-EXEC. To compile the program in three steps: # Use 2 environment variables to keep things simple: export P=sampl4 export SCHEMA=FRANS.PERF # run the three steps mxsqlco -Q invokeSchema=$SCHEMA $P.ecob xcobol -Wsqlmx -o $P $P.cbl mxCompileUserModule -g moduleLocal -d SCHEMA=$SCHEMA $P SQL compile the module for use on a different schema, use: mxCompileUserModule -g moduleLocal -d SCHEMA=frans.hr sampl4 Examine execution plans An advantage of having meaningful names for modules is that they now can be used easily to examine the generated SQL execution plans. The following EXPLAIN statement shows the formatted execution plans used by program sampl3. ~/compile> mxci Hewlett Packard Enterprise NonStop(TM) SQL/MX Conversational Interface 3.6.1 (c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP. >>EXPLAIN options 'f' '%' from '/home/hp/frans/compile/FRANS.PERF.SAMPL3' ; Statement: GET_BY_PARTNUM LC RC OP OPERATOR OPT DESCRIPTION CARD ---- ---- ---- -------------------- -------- -------------------- --------- 2 . 3 root 3.29E+001 1 . 2 partition_access 3.29E+001 . . 1 file_scan fr PARTS (s) 3.29E+001 …. …. (Other statements omitted)
  • 10. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -10- Summary Using a few simple examples we have seen how SQL/MX translates embedded SQL statement into an executable program and a SQL module file. The examples have been kept very simple, and do not discuss adding multiple object files that are linked together into an executable program. The Programming Manual for C and COBOL has the details. This paper will help you finding the right options for building larger programs. The module file names can be defined by the user, which has system management advantages. Using the default location and the default naming scheme will result in a large amount of, often unused, modules in the /usr/tandem/sqlmx/USERMODULES directory. Decoupling the program source code from the actually used catalog and schema allow an easy move of objects between execution environments. In cases where application run on systems with differently named catalogs or schemas, it is good practice to define module names based on a convention that is not based on catalog and schema, but on something else, such as application name and possibly version or subclass of the application. References The following manuals can be used to get more detailed information. They are accessible via the HPE Support Center, for L-series software go to https://hpe.com/info/nonstop-ldocs, and for J-series software use https://hpe.com/info/nonstop-jdocs. Some manuals have the release number in the title and not shown in the titles below. SQL/MX Programming Manual for C and COBOL. SQL/MX Reference manual. SQL/MP to SQL/MX Database and Application Migration Guide.
  • 11. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -11- Appendix COBOL Compilation process flow The following diagram shows the compilation steps. This figure was taken from the SQL/MX Programming C and COBOL manual
  • 12. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -12- C C++ Compilation process flow The following diagram shows the compilation steps. This figure was taken from the SQL/MX Programming C and COBOL manual
  • 13. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -13- Simple example verbose output This is the output from the one-step compilation in example 1. ~/compile> xcobol -Wsqlmx -Wmxcmp sampl.ecob -o sampl -Wverbose xcobol: running /usr/tandem/sqlmx/bin/mxsqlco sampl.ecob -c sampl.cob -l /dev/null xcobol: running /usr/cmplr/xcobfe -Wcobol="Consult /usr/tandem/sqlmx/lib/xsqlcli.o" sampl.cob - XS"/tmp/tAAAqaaaha2030043143.T" -XK/tmp/tAAAqaaaha2030043143.K - XFsampl.FDBK -I/usr/include -Wsystype=oss -Wsuppress - XR/G/system/zdll012/xcredll -XZ/G/system/zdll012/xcobdll - XY/G/system/zdll012/xcobadll -XE/G/system/system/xcobext xcobol: /usr/cmplr/xcobfe exited, returning 0. xcobol: running /usr/cmplr/be -PHASE:c -G8 -O1 -LANG:=cobol - TARG:sse3=on -TARG:processor=wolfdale -TARG:sse2=on -TARG:mmx=on - TARG:sse=on -TARG:3dnow=off -TARG:sse4a=off -TENV:PIC -TARG:BEX=BE - TARG:abi=p64 -TARG:datamode=32 -fT,/tmp/tAAAqaaaha2030043143.T -s - fs,sampl.s sampl.ecob xcobol: /usr/cmplr/be exited, returning 0. xcobol: running /usr/cmplr/xas -mlanguage=cobol --fatal-warnings - mfloattype=neutral -mcode-big-endian -lcf /tmp/tAAAqaaaha2030043143.K -o sampl.o sampl.s xcobol: /usr/cmplr/xas exited, returning 0. xcobol: running /usr/bin/xld -o sampl -set systype oss -set highpin on -set highrequestor on -set inspect on sampl.o -lcli -lcob -L /G/system/sys07 -lcre -lcrtl -lossk -lossf -lsec -li18n -licnv -losse -linet -lossh -lossc -lcli xcobol: /usr/bin/xld exited, returning 0. xcobol: running /usr/tandem/sqlmx/bin/mxCompileUserModule sampl Hewlett Packard Enterprise NonStop(TM) SQL/MX Embedded Module Compile Utility 3.6.1 (c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP. /G/system/system/mxcmp /tmp/AAAqaabWa197661ACICCH Hewlett Packard Enterprise NonStop(TM) SQL/MX Compiler 3.6.1 (c) Copyright 2003-2018 Hewlett Packard Enterprise Development LP.
  • 14. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -14- /tmp/AAAqaabWa197661ACICCH (/usr/tandem/sqlmx/USERMODULES/FRANS.PERF.SQLMX_DEFAULT_MODULE_2597235 31183946022) 0 errors, 0 warnings, 0 statements affected; 17 statements total 1 modules found, 1 modules extracted. 1 mxcmp invocations: 1 succeeded, 0 failed. xcobol: /usr/tandem/sqlmx/bin/mxCompileUserModule exited, returning 0. xcobol: Exiting with status 0; 0 error(s). ~/compile> Example 1 COBOL source code This sample program is a slightly changed copy of the example from the SQL/MX 3.6 Programming Manual for C and COBOL. The change is the addition of the INSERT statement right before the cursor is opened. Note that duplicate keys will cause an error, this error is used to show that the examples can run the same code on different schemas. * --------------------------------------------------------------- * compile this program simply in OSS with: * [x|e]cobol -Wsqlmx -Wmxcmp sampl.ecob -o sampl –Wverbose * * Description: Using a Static SQL Cursor * Statements: Static DECLARE CURSOR * BEGIN WORK * OPEN * FETCH * Positioned UPDATE * CLOSE * COMMIT WORK * WHENEVER * GET DIAGNOSTICS *--------------------------------------------------------------- * Table definition * CREATE TABLE PARTS * ( * PARTNUM NUMERIC(4, 0) UNSIGNED NO DEFAULT HEADING * 'Part/Num' NOT NULL * , PARTDESC CHAR(18) CHARACTER SET ISO88591 NO * DEFAULT HEADING 'Part Description' NOT NULL * , PRICE NUMERIC(8, 2) NO DEFAULT HEADING 'Price' * NOT NULL * , QTY_AVAILABLE NUMERIC(5, 0) DEFAULT 0 HEADING * 'Qty/Avail' NOT NULL * , ORDER_DATE DATE DEFAULT CURRENT_DATE * , PRIMARY KEY (PARTNUM ASC) * ) * ; * --- SQL operation complete. *
  • 15. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -15- IDENTIFICATION DIVISION. PROGRAM-ID. Program-exF62. DATA DIVISION. WORKING-STORAGE SECTION. * program uses the INVOKE HVs to insert the row EXEC SQL BEGIN DECLARE SECTION END-EXEC. * The MODULE statement will cause a module created named * MYAPP.V_0_1.SAMPL4 in the module directory * Note that the three part name must follows the rules * for SQL/MX Catalog,schema, and object, separated by a "." EXEC SQL MODULE "MYAPP"."V_0_1"."SAMPL4" END-EXEC. * GET THE CORRECT RECORD LAYOUT * if the table name is not qualified with cat and schema, * the preprocessor must be called * with -Q invokeSchema=cat.sch * EXEC SQL INVOKE PARTS END-EXEC. 01 sqlstate pic x(5). 01 sqlcode pic s9(9) comp. 01 hv-partnum pic 9(4) comp. 01 hv-partdesc pic x(18). 01 hv-price pic s9(6)v9(2) comp. 01 hv-qty-available pic s9(7) comp. * in SQL/MP the date column is declared as PIC X(10) , * and the insert uses the TYPE AS DATE clause when inserting a row * SQL/MX however supports (and needs) the column defined as DATE, * the INSERT statment does not require the non-ANSI TYPE AS construct. 01 hv-order-date DATE value "2019-09-12". * hv-order-date for SQLMP definition *01 hv-order-date pic x(10) value "2019-09-12". 01 hv-num pic s9(9) comp. 01 hv-sqlstate pic x(5). 01 hv-tabname pic x(128). 01 hv-colname pic x(128). 01 hv-msgtxt pic x(128). 01 in-partnum pic 9(4) comp. 01 i pic s9(9) comp. EXEC SQL END DECLARE SECTION END-EXEC. 01 sqlstate-ok pic x(5) value "00000". 01 sqlstate-nodata pic x(5) value "02000". 01 sqlstate-save pic x(5). 01 sqlcode-save pic s9(9) comp. PROCEDURE DIVISION. START-LABEL. DISPLAY "This example uses a fully qualified module name, but catalog and schema names are independent". EXEC SQL WHENEVER SQLERROR GOTO sqlerrors END-EXEC.
  • 16. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -16- * Declare static cursor. EXEC SQL DECLARE get_by_partnum CURSOR FOR SELECT partnum, partdesc, price, qty_available FROM parts WHERE partnum >= :in-partnum FOR UPDATE OF partdesc, price, qty_available END-EXEC. * Read in-partnum from terminal. DISPLAY "Enter lowest part number to be retrieved: ". ACCEPT in-partnum. * Begin the transaction. move in-partnum to partnum move "New part" to partdesc move 120 to price move 528 to qty-available move "2019-09-13" to order-date. EXEC SQL BEGIN WORK END-EXEC. EXEC SQL INSERT INTO PARTS ( PARTNUM, PARTDESC, PRICE, QTY_AVAILABLE, ORDER_DATE ) VALUES ( :partnum, :partdesc, :price, :qty-available, :order-date ) END-EXEC. * Open the cursor. EXEC SQL OPEN get_by_partnum END-EXEC. * Fetch the first row of the result from table. EXEC SQL FETCH get_by_partnum INTO :hv-partnum, :hv-partdesc, :hv-price, :hv-qty-available END-EXEC. * Update qty_available if qty_available is less than 1000. PERFORM UNTIL sqlstate = sqlstate-nodata IF hv-qty-available < 1000 EXEC SQL UPDATE parts SET qty_available = qty_available + 100 WHERE CURRENT OF get_by_partnum END-EXEC. DISPLAY "Update of part number: " hv-partnum END-IF EXEC SQL FETCH get_by_partnum INTO :hv-partnum, :hv-partdesc, :hv-price, :hv-qty-available END-EXEC. END-PERFORM. * Close the cursor. EXEC SQL CLOSE get_by_partnum END-EXEC.
  • 17. NonStop Advanced Technology Center An introduction to Embedded SQL for NonStop SQL/MX -17- * Commit any changes. EXEC SQL COMMIT WORK END-EXEC. IF sqlstate = sqlstate-ok DISPLAY "The program completed successfully.". STOP RUN. **************************************************************** sqlerrors SECTION. **************************************************************** move sqlstate to sqlstate-save. move sqlcode to sqlcode-save. display "sqlerrors: " sqlstate ", " sqlcode. EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC. IF sqlstate not = sqlstate-ok EXEC SQL GET DIAGNOSTICS :hv-num = NUMBER END-EXEC. PERFORM VARYING i FROM 1 BY 1 UNTIL i > hv-num MOVE SPACES TO hv-msgtxt EXEC SQL GET DIAGNOSTICS EXCEPTION :i :hv-tabname = TABLE_NAME, :hv-colname = COLUMN_NAME, :hv-sqlstate = RETURNED_SQLSTATE, :hv-msgtxt = MESSAGE_TEXT END-EXEC. DISPLAY "Table : " hv-tabname DISPLAY "Column : " hv-colname DISPLAY "SQLSTATE: " hv-sqlstate DISPLAY "Message : " hv-msgtxt END-PERFORM END-IF. move sqlstate-save to sqlstate. move sqlcode-save to sqlcode. * STOP RUN. **************************************************************** END PROGRAM Program-exF62. ****************************************************************