Thread: DB2

Dynamic WHERE for a CICS search screen - 7 optional fields

Started by Omar • user4 replies177 viewsLast activity 3 weeks ago
Post #1
0 votes
Omar
Reputation
155
Posts: 12
Joined: Jan 7, 2025, 10:05 AM
Posted: Jul 23, 2026, 8:27 AM

CICS screen used to search on policy issue date only. Now users can fill any combo of 7 fields. Spec says "any combination."

Building one giant static SQL with ORs is ugly and the DBA already hates it for index reasons. Dynamic SQL string in COBOL feels error-prone but maybe right.

What have you shipped for this pattern without creating 2^n programs?

Post #2
1 votes
Sandra
Reputation
198
Posts: 17
Joined: Oct 15, 2024, 8:30 AM
Posted: Jul 23, 2026, 11:27 AM

Priority rules first. If policy number is entered, ignore the fuzzy fields. That alone kills most combinations.

For the rest we build the WHERE in a VARCHAR and PREPARE. Validate every column name against a whitelist so you do not concatenate junk from the screen.

Post #3
0 votes
Elena
Reputation
391
Posts: 19
Joined: Apr 18, 2024, 9:30 AM
Posted: Jul 23, 2026, 4:27 PM

Watch OR-heavy predicates. They often go stage 2. Sometimes BETWEEN with host variables set to full range when a filter is unused indexes better than CASE tricks in the WHERE.

Post #4
0 votes
Omar
Reputation
155
Posts: 12
Joined: Jan 7, 2025, 10:05 AM
Posted: Jul 25, 2026, 10:27 AM

Went with priority + dynamic SQL for the leftover combos. EXPLAIN looks sane on the common paths. Thanks.

You must be signed in to reply to this thread