IMS Qualified SSAs and Boolean Operations
Basic SSAs get you started, but production IMS programs often need complex filtering — multiple conditions on a segment, boolean logic across fields, and carefully constructed path SSAs. This module covers advanced SSA techniques that separate experienced IMS programmers from beginners.
Dynamic vs Static SSAs
Most production programs build SSAs dynamically — populating the key value from a variable rather than coding the SSA as a literal:
01 ACCT-QUAL-SSA.
05 FILLER PIC X(9) VALUE 'ACCOUNT ('.
05 FILLER PIC X(8) VALUE 'ACCT-KEY'.
05 FILLER PIC X(2) VALUE ' ='.
05 SSA-ACCT-KEY PIC X(15).
05 FILLER PIC X(1) VALUE ')'.
* Before the call:
MOVE WS-ACCOUNT-NUMBER TO SSA-ACCT-KEY.This is far more flexible than static literals. Always define SSAs in WORKING-STORAGE as structured 01-level items with individual 05-level fields for each variable portion.
Range Queries with SSAs
To retrieve all accounts with balance above zero, use a > operator:
01 ACCT-BALANCE-SSA.
05 FILLER PIC X(9) VALUE 'ACCOUNT ('.
05 FILLER PIC X(8) VALUE 'ACCT-BAL'.
05 FILLER PIC X(2) VALUE ' >'.
05 FILLER PIC X(12) VALUE '+000000000000'.
05 FILLER PIC X(1) VALUE ')'.IMS compares the ACCT-BAL field in each ACCOUNT segment against the value in the SSA. Only segments where ACCT-BAL > 0 are returned.
Important: The SSA value must be in the same format as the field in the segment. For a packed decimal field, the SSA value should be in packed decimal format. For character fields, it is straight EBCDIC comparison.
Boolean AND in SSAs
Find accounts of type 'CHK' with positive balance:
01 ACCT-AND-SSA.
05 FILLER PIC X(9) VALUE 'ACCOUNT ('.
05 FILLER PIC X(8) VALUE 'ACCT-TYPE'.
05 FILLER PIC X(2) VALUE ' ='.
05 FILLER PIC X(3) VALUE 'CHK'.
05 FILLER PIC X(1) VALUE '*'. *> AND connector
05 FILLER PIC X(8) VALUE 'ACCT-BAL'.
05 FILLER PIC X(2) VALUE ' >'.
05 FILLER PIC X(12) VALUE '+000000000000'.
05 FILLER PIC X(1) VALUE ')'.The * between the two qualifications is the AND connector. Both conditions must be true for IMS to return the segment.
Boolean OR in SSAs
Find accounts of type 'CHK' OR type 'SAV':
01 ACCT-OR-SSA.
05 FILLER PIC X(9) VALUE 'ACCOUNT ('.
05 FILLER PIC X(8) VALUE 'ACCT-TYPE'.
05 FILLER PIC X(2) VALUE ' ='.
05 FILLER PIC X(3) VALUE 'CHK'.
05 FILLER PIC X(1) VALUE '+'. *> OR connector
05 FILLER PIC X(8) VALUE 'ACCT-TYPE'.
05 FILLER PIC X(2) VALUE ' ='.
05 FILLER PIC X(3) VALUE 'SAV'.
05 FILLER PIC X(1) VALUE ')'.The + connector means OR. IMS returns the segment if either condition is met.
Evaluating Boolean SSAs: No Precedence
IMS evaluates multiple boolean qualifications strictly left to right, with no operator precedence. A * B + C means (A AND B) OR C, not A AND (B OR C). Structure your conditions to account for this left-to-right evaluation.
Path SSAs with the D Command Code
The D command code retrieves multiple segment levels in a single call, placing them in a concatenated I/O area:
01 CUSTOMER-D-SSA.
05 FILLER PIC X(8) VALUE 'CUSTOMER'.
05 FILLER PIC X(1) VALUE '*'. *> command code prefix
05 FILLER PIC X(1) VALUE 'D'. *> D = return data
05 FILLER PIC X(1) VALUE ' '. *> no further qualificationA path call returns data from all D-coded intermediate segments plus the target segment in one concatenated I/O area, saving multiple round-trips through the call interface.
Null SSA for Skipping Levels
When you need IMS to skip a level but not apply any qualification, use a null SSA (segment name + one space, no qualification):
* GU to TRANSACT — skip CUSTOMER qualification,
* qualify only ACCOUNT and TRANSACT
CALL 'CBLTDLI' USING GU-FUNC
CUSTOMER-PCB
TRANSACT-IO-AREA
CUSTOMER-UNQUAL-SSA *> no filter on customer
ACCOUNT-QUAL-SSA *> specific account
TRANSACT-QUAL-SSA. *> specific transactionIMS finds the first CUSTOMER, then the specified ACCOUNT under it, then the specified TRANSACTION.
Frequently Asked Questions
Q: Can I use a wildcard in an SSA field value like SQL's LIKE operator?
No. IMS SSA qualifications only support exact relational comparisons (=, >, <, >=, <=, ^=). There is no pattern matching or LIKE equivalent. For wildcard searches, you must retrieve candidates sequentially with GN/GNP and test fields in COBOL after retrieval.
Q: What is the maximum length of a qualified SSA? The maximum SSA length is 256 bytes. This limits how many boolean qualifications can be chained in a single SSA. If your qualification requires more than 256 bytes, split the retrieval into multiple calls — use the first SSA to narrow the candidates, then test additional conditions in COBOL after retrieval.
Q: How do I handle a field that is blank or low-values in an SSA comparison? Compare against the actual byte values the field contains. For a character field that is padded with spaces, compare against spaces. For packed decimal fields, compare against packed zero (X'0C' for one-digit +0). Test your SSA values against actual database content to ensure the comparison works as expected.
Part of the IMS Mastery Course — Module 14 of 22.
