Re: Lookup Screens 4gl and/or ESQL
Posted in 1994
harvancik@fox.sownmc.state.wi.us (Steven S. Harvancik) writes:
>Need code that works with Informix SE; SQL 4.10.UC1 and the corresponding ESQL
>on an AT&T 3B2-600 running Unix 3.2.3 for window lookups in 4gl and ESQL
>programs. Attempted to code such a creature, but having problems.
>Requirements:
>We would like a lookup screen that displays an array of records and that the
>user may page through these records by typing in text. The lookup application
>would then inturn position itself within the array based on the information
>typed in. Example: If Cities were the lookup window and the user type in Mad
>The application would position itself on the first occurance of a city record
>that begins with Mad. The user could then move up or down to find the
>appropriate city. The user will also have the option to re-type in another
>city match to begin another search.
The following code does most of what you need, save that it matches only on a
single letter input, which should be a fairly easy adjustment to the .per and
.4gl file. It swaps in/out of a temp table and uses INPUT ARRAY to present to
the end user. Let me know if it's what you need, but you need help to implement.
=======================================================================
Dennis J. Pimple dennisp@informix.com Opinions expressed
Senior Consultant -------------------- are mine, and do not
Informix Software Inc Voice: 303-850-0210 necessarily reflect
Denver Colorado USA Fax: 303-779-4025 those of my employer.
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Dennis Pimple <dennisp@mantis> on Mon Nov 7 13:00:08 1994
#
# This archive contains:
# pick.4gl ptest.4gl pick.per
#
LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH
echo x - pick.4gl
cat >pick.4gl <<'@EOF'
# Module: %M% SCCS: %I% %P%
# Program: *.4gi
# Purpose: Functions to work with a generic pick array
# Author: Dennis J. Pimple
# Date: %G% %U%
# counters to work with ma_pick
DEFINE mpick_x SMALLINT # max array size
DEFINE mpick_s SMALLINT # screen record
DEFINE mpick_t SMALLINT # total records in temp table
DEFINE mseltxt CHAR(500) # Select clause
DEFINE ma_pick ARRAY[15] OF RECORD
pck CHAR(1), # cursor/input field
jump CHAR(10), # field we're jumping to; NOENTRY
descr CHAR(45) # any other display; NOENTRY
END RECORD
DEFINE ma_pct ARRAY[15] OF RECORD # non-screen values
arr SMALLINT, # array value; order we inserted the records
cod CHAR(10), # code to return when picked
ct SMALLINT # order we picked the record in
END RECORD
DEFINE m_picktab RECORD
pck CHAR(1), # cursor/input field
jump CHAR(10), # field we're jumping to; NOENTRY
descr CHAR(45), # any other display; NOENTRY
arr SMALLINT, # array value; order we inserted the records
cod CHAR(10), # code to return when picked
ct SMALLINT # order we picked the record in
END RECORD
#---------------------------------------------------------------------#
FUNCTION init_pick()
# Arguments: N/A
# Purpose: Initialize modular variables for working with picker.
# This function should be called in the MAIN of each
# module that may use a picker.
# Returns: N/A
#---------------------------------------------------------------------#
LET mpick_x = 15
LET mpick_s = 15
# do the thing we do for each change in picker
CALL reset_pick()
END FUNCTION
# init_pick()
#---------------------------------------------------------------------#
FUNCTION reset_pick()
# Arguments: N/A
# Purpose: Clear the temp table and prepare to fill it with the
# pick values of a new table, or with a different SELECT
# clause of the same table.
# Returns: N/A
#---------------------------------------------------------------------#
LET mpick_t = 0
LET mseltxt = ""
# in case we have the pick temp table already, drop it
WHENEVER ERROR CONTINUE
DROP TABLE picktabWHENEVER ERROR STOP
# we rebuild the temp table each time because it's generally
# faster than a DELETE FROM picktab WHERE 1=1
# when the table has a lot of records in it
CREATE TEMP TABLE picktab
(
pck CHAR(1),
jump CHAR(10),
descr CHAR(45),
arr SMALLINT, # array value; order we inserted the records
cod CHAR(10), # code to return when picked
ct SMALLINT # order we picked the record in
)
DECLARE c_picktab CURSOR FOR
SELECT * FROM picktab
ORDER BY arr
END FUNCTION
# reset_pick()
#---------------------------------------------------------------------#
FUNCTION sel_pick(lseltxt)
# Arguments: SELECT clause for the pick
# Purpose: Declare cursor to fill pick. The cursor MUST select
# exactly three fields, for ma_pick.jump, descr, & cod
# The other way to fill the pick screen is via ins_pick()
# from a CURSOR in the calling function.
# Returns: N/A
#---------------------------------------------------------------------#
DEFINE lseltxt CHAR(500)
DEFINE l_pick RECORD # record for the select
jump CHAR(10),
descr CHAR(45),
cod CHAR(10)
END RECORD
IF LENGTH(mseltxt) > 0 AND mseltxt = lseltxt THEN
# this is the same pick as before, so no need to fill again;
# but reset the pck field
CALL null_pick()
RETURN
END IF
# reset the temp table from any previous fill
CALL reset_pick()
# save the select for next time
LET mseltxt = lseltxt
PREPARE st_pick FROM lseltxt
DECLARE c_pick CURSOR FOR st_pick
FOREACH c_pick INTO l_pick.*
CALL ins_pick(l_pick.*)
END FOREACH
END FUNCTION
# decl_pick(lseltxt)
#---------------------------------------------------------------------#
FUNCTION null_pick()
# Arguments: N/A
# Purpose: Set the pck fields to null for temp table
# Returns: N/A
#---------------------------------------------------------------------#
UPDATE picktab SET pck = NULL, ct = 0 WHERE 1=1
END FUNCTION
# null_pick()
#---------------------------------------------------------------------#
FUNCTION ins_pick(l_pick)
# Arguments: jump, desc, and cod values to insert into the temp table
# Purpose: Fill the temp table from a locally-run cursor
# The other way to fill the pick screen is via decl_pick()
# Returns: N/A
#---------------------------------------------------------------------#
DEFINE l_pick RECORD # record for the select
jump CHAR(10),
descr CHAR(45),
cod CHAR(10)
END RECORD
LET mpick_t = mpick_t + 1
INITIALIZE m_picktab.* TO NULL
LET m_picktab.jump = l_pick.jump
LET m_picktab.descr = l_pick.descr
LET m_picktab.