The following is the ESL code required to create the sample program described in this section. Before you compile this application, you must have Compiled the SAM and Created the Variable File, as discussed in Creating the Program with DB/Assist. The Source Code include two string variables, which must be set to your DB2 UserID and Password.
#################################################################
# SAMPLE ESL CODE EXECUTING POSITIONED
# UPDATE AND DELETE STATEMENTS
#################################################################
stimulus DB "edb2"
#---------------------------------------------------------------#
#------------------------( Variable.inc )-----------------------#
#---------------------------------------------------------------#
integer Dummy_IV # Dummy Integer
integer Count_IV # for loop processes
string Dummy_SV # Used mostly for messages
string Message_SV # Used mostly for messages
string DatabaseName_SV # Used for name of database
string UserID_SV # Change this to your DB2 User
string Password_SV # Password for the DB2 User above
string DEPTNAME_SV # Used to Convert Dept details
#----------------------------------------------------------------
# DB2 Host Variables Generated by DB/Assist
#----------------------------------------------------------------
include POSITION.VAR
# INCLUDE FILES
include esqlca.inc
include esqlda.inc
include edb2.inc
include message.inc
#----------------------------------------------------------------
# ESL Action Routines code Generated by DB/Assist
#----------------------------------------------------------------
include position.act
#################################################################
#OBJECT DEFINITIONS
#################################################################
action bar PrimaryWindow_AB is
pulldown File text "~File"
choice Exit text "E~xit"
end pulldown
end action bar
enabled invisible primary dialog region PrimaryWindow_DR
size 399 200
at position 10 10
in desktop size border
title bar "Employee Administrator"
system menu
action bar PrimaryWindow_AB
minimize button
maximize button
disabled visible color 26 multiline entry field Message_MLE
size 399 20
at position 0 0
in PrimaryWindow_DR
in desktop
color 27 foreground
word wrap
enabled invisible temporary modeless dialog box UpdateStaff_DB
size 216 152
at position 58 44
in desktop
border
title bar "Update Staff Information"
system menu
enabled visible static text LastName_ST
size 55 10
at position 10 137
in UpdateStaff_DB
left align
top align
text "Last Name"
enabled visible static text StaffID_ST
size 59 10
at position 130 137
in UpdateStaff_DB
left align
top align
text "Employee ID"
enabled visible required entry field LastName_EF
size 116 12
at position 10 124
in UpdateStaff_DB
text size 9
columns left align
disabled visible required entry field StaffID_EF
size 55 12
at position 130 124
in UpdateStaff_DB
text size 6 columns
left align
validation is numberonly range 1 32767
enabled visible static text StaffDept_ST
size 49 10
at position 9 107
in UpdateStaff_DB
left align
top align
text "Department:"
enabled visible dropdown list Department_CMB
size 121 47
at position 66 71
in UpdateStaff_DB
text size 32 columns
insert
"Great Lakes\n"
"Head Office\n"
"Mid Atlantic\n"
"Mountain\n"
"New England\n"
"Pacific\n"
"Plains\n"
"South Atlantic"
disabled visible group box JobInfo_GB
size 175 79
at position 9 25
in UpdateStaff_DB
text "Job Info"
enabled visible static text Job_ST
size 55 10
at position 22 82
in UpdateStaff_DB
right align
top align
text "Job:"
enabled visible entry field Job_EF
size 40 12
at position 87 82
in UpdateStaff_DB
text size 5 columns
left align
enabled visible static text Years_ST
size 59 10
at position 17 66
in UpdateStaff_DB
right align
top align
text "Years:"
enabled visible entry field Years_EF
size 40 12
at position 87 65
in UpdateStaff_DB
text size 3 columns
left align
validation is numberonly range 0 255
enabled visible static text Salary_ST
size 54 10
at position 23 49
in UpdateStaff_DB
right align
top align
text "Salary:"
enabled visible entry field Salary_EF
size 70 12
at position 87 49
in UpdateStaff_DB
text size 10
columns left align
validation is floatonly range 0.000000 99999.990000
enabled visible static text Commission_ST
size 61 10
at position 15 33
in UpdateStaff_DB
right align
top align
text "Commission:"
enabled visible entry field Commission_EF
size 70 12
at position 87 33
in UpdateStaff_DB
text size 10 columns
left align
validation is floatonly range 0.000000 99999.990000
enabled visible default push button Update_PB
size 38 12
at position 11 6
in UpdateStaff_DB
group is Actions
text "~Update"
enabled visible push button Delete_PB
size 38 12
at position 57 6
in UpdateStaff_DB
group is Actions
text "D~elete..."
enabled visible push button Next_PB
size 48 12
at position 103 6
in UpdateStaff_DB
text "~Next"
enabled visible cancel push button Cancel
size 47 12
at position 161 6
in UpdateStaff_DB
text "Cancel"
#################################################################
# ACTIONS AND SUBROUTINES
#################################################################
subroutine ChangeMessage(string : Message) is
change Message_MLE text to Message
subroutine DeptName2Id(string: Name, integer: Id) is
integer Count_LIV
string Names[8] is "Great Lakes",
"Head Office",
"Mid Atlantic",
"Mountain",
"New England",
"Pacific",
"Plains",
"South Atlantic"
integer Ids[8] is 42,10,20,84,15,66,51,38
for Count_LIV = 1 to 8 loop
if (Names[ Count_LIV] = Name) then
copy Ids[Count_LIV] to Id
leave loop
end if
end loop
action GetFirstStaffRow is
action OPEN_SelectStaffUpdate
action FETCH_SelectStaffUpdate
action SetupUpdateStaff_DB is
change StaffID_EF in UpdateStaff_DB text to ID_IV
change LastName_EF in UpdateStaff_DB text to NAME_SV
change Job_EF in UpdateStaff_DB text to JOB_SV
change Years_EF in UpdateStaff_DB text to YEARS_IV
change Salary_EF in UpdateStaff_DB text to SALARY_FV
change Commission_EF in UpdateStaff_DB text to COMM_FV
for Count_IV = 1 to (bottom of Department_CMB in UpdateStaff_DB) loop
copy textual line Count_IV from Department_CMB in UpdateStaff_DB to DEPTNAME_SV
call DeptName2Id(DEPTNAME_SV, Dummy_IV)
if (DEPT_IV = Dummy_IV) then
select line Count_IV in Department_CMB in UpdateStaff_DB
end if
end loop
copy "Update Staff Information." to Dummy_SV
call ChangeMessage(Dummy_SV)
make UpdateStaff_DB visible
action QueryUpdateStaff_DB is
copy text of StaffID_EF in UpdateStaff_DB to ID_IV
copy text of LastName_EF in UpdateStaff_DB to NAME_SV
copy selected line from Department_CMB in UpdateStaff_DB to Count_IV
if (Count_IV = 0) then
copy 1 to Count_IV
end if
copy textual line Count_IV from Department_CMB in UpdateStaff_DB to DEPTNAME_SV
call DeptName2Id(DEPTNAME_SV, DEPT_IV)
copy text of Job_EF in UpdateStaff_DB to JOB_SV
copy text of Years_EF in UpdateStaff_DB to YEARS_IV
copy text of Salary_EF in UpdateStaff_DB to SALARY_FV
copy text of Commission_EF in UpdateStaff_DB to COMM_FV
subroutine DeleteCurStaff() is
action EXECUTE_DeleteCurrentStaff
copy "Record deleted successfully." to Dummy_SV
call ChangeMessage(Dummy_SV)
subroutine UpdateCurStaff() is
action EXECUTE_UpdateCurrentStaff
call EDB2Commit (Esqlca)
copy "Updated record successfully." to Dummy_SV call ChangeMessage(Dummy_SV)
#################################################################
# RESPONSES
#################################################################
response to start
make PrimaryWindow_DR permanent
make PrimaryWindow_DR visible
make UpdateStaff_DB permanent
make UpdateStaff_DB visible
copy "Connecting to database SAMPLE. Please wait..." to Dummy_SV
call ChangeMessage(Dummy_SV)
copy "SAMPLE" to DatabaseName_SV
copy "DB2ADMIN" to UserID_SV
copy "db2admin" to Password_SV
call EDB2Connect(DatabaseName_SV, UserID_SV, Password_SV, SQL_USE_SHR,Esqlca)
response to stimulus DB EDB2_STARTED
if (Esqlca.Sqlcode != 0) then
call EDB2Error(Dummy_SV, Esqlca)
call ChangeMessage(Dummy_SV)
else
action GetFirstStaffRow
action SetupUpdateStaff_DB
end if
response to stimulus DB EDB2_ERROR
call EDB2Error(Dummy_SV, Esqlca)
call ChangeMessage(Dummy_SV)
response to PrimaryWindow_DR
on close
call EDB2Disconnect(Esqlca) exit
response to item Exit
call EDB2Disconnect(Esqlca) exit
#
# Update STAFF WHERE CURRENT OF CURSOR
#
response to Update_PB in UpdateStaff_DB
action QueryUpdateStaff_DB
call UpdateCurStaff()
response to Cancel in UpdateStaff_DB
action CLOSE_SelectStaffUpdate
make UpdateStaff_DB invisible
#
# Delete STAFF WHERE CURRENT OF CURSOR #
response to Delete_PB in UpdateStaff_DB
if (ReplyToMessage("Delete Staff Record",
"Do you really want to delete this employee?",
MessageYesNo,
2,
MessageWarning) = "yes") then
call DeleteCurStaff()
action FETCH_SelectStaffUpdate
action SetupUpdateStaff_DB
end if
#
# FETCH Next Row of STAFF
#
response to Next_PB in UpdateStaff_DB
action FETCH_SelectStaffUpdate
if (Esqlca.Sqlcode = END_OF_DATA) then
if (ReplyToMessage("End of STAFF List",
"Do you want to start over from the beginning?",
MessageYesNo,
2,
MessageWarning) = "yes") then
action CLOSE_SelectStaffUpdate
action GetFirstStaffRow
end if
end if
action SetupUpdateStaff_DB