| DB Access Class Library for COBOL V1.0 API Reference - Microsoft(R) Windows(R) - - Microsoft(R) Windows NT(R) - - Microsoft(R) Windows(R) 2000 - |
Contents
Index
![]()
|
Chapter 4 Examples of Using the DB Access Class Library
4.1 Use a Recordset
Reference data using an object (recordset) of the FJDB-RECORDSET class and a bind table.
A recordset is created using the OPEN-RECORDSET method in the FJDB-DATABASE class. Data in the current row of the recordset can be referenced. When a new recordset is created, the current row is located on the first row of the recordset. Moving the current row across a recordset makes it possible to choose a particular row to be the object of manipulation.
Reference data in a database by creating a recordset as "RECORDSET-A " as explained in Data Reference Example.
Define the class to use in the repository paragraph of the configuration section, and a library of symbolic constants to use in the program in the special-names paragraph.
CONFIGURATION SECTION.
REPOSITORY.
:
CLASS FJDB-RECORDSET
:
SPECIAL-NAMES.
SYMBOLIC CONSTANT
COPY FJDBOPT.
.
Define the variables to use in the program.
WORKING-STORAGE SECTION.
*Define the object variable
:
01 RECORDSET-A USAGE OBJECT REFERENCE FJDB-RECORDSET.
:
*Define data setup variables
01 XSQL PIC X(255).
01 RS-OPT PIC S9(9) COMP-5.
:
*Define the return value variable
01 RET-CODE PIC S9(9) COMP-5.
:
Query the database by executing an SQL statement and create a recordset as a result of the search.
Use the OPEN-RECORDSET method in the FJDB-DATABASE class.
Create a recordset as "RECORDSET-A " as explained in Data Reference Example.
(1) Assign values to the variables (XSQL and RS-OPT) of the arguments specified when an OPEN-RECORDSET method is issued.
MOVE "SELECT NO,NAME,ADDRESS FROM EMPLOYEE" TO XSQL.
MOVE FJDB-SCRSOPT-DEFAULT TO RS-OPT.
(2) Create a recordset.
INVOKE DATABASE-A "OPEN-RECORDSET" USING XSQL RS-OPT RECORDSET-A
RETURNING RET-CODE.
Using the BIND-FIELDS method in the FJDB-RECORDSET class, associate the bind table and the recordset.
When a BIND-FIELDS method is issued, the variables registered in the bind table are loaded with the values of the current row of the recordset.
INVOKE RECORDSET-A "BIND-FIELDS" USING BIND-A RETURNING RET-CODE.
Using the IS-EOF and MOVE-NEXT methods in the FJDB-RECORDSET class, reference data until the current row of the recordset reaches the last row. The IS-EOF method returns information as to whether the current row is located after the last row.
PERFORM TEST BEFORE UNTIL RECORDSET-A::"IS-EOF" NOT = 0
DISPLAY "NO=" BIND-NO
DISPLAY "NAME=" BIND-NAME
DISPLAY "ADDRESS=" BIND-ADDRESS
INVOKE RECORDSET-A "MOVE-NEXT" RETURNING RET-CODE
END-PERFORM.
4.1.4.1 Data Reference Example (Using a recordset to reference data)
Contents
Index
![]()
|