TechTalk: QRYSLT with Binary Fields

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

QRYSLT with Binary Fields

From: Debbie Abbott To: All

I need to pre-select records out of a physical file via either a logical or OPNQRYF file. My problem is the field I need to select on is a character field with one position that contains a binary switch. I need only records with certain bits 'on'. I have created a logical file and attempted to convert the field into a hexadecimal field by using the data type. Yet, when I use DFU to view the data via the logical, the data looks binary to me.

Has anyone done anything similar? Can anyone help? The program is currently reading 1.2 million records each night but only needs to process a handful of those. If I could get the select to work in some way, it would greatly improve our nightly processing. I have looked through both the CL Programmer's Guide manual and Open Query File Magic! from Midrange Computing to no avail.

From: Ted Holt To: Debbie Abbott

What you want to do is not impossible, just a little unusual.

File BINDATA contains a field FLAGS which is character, 10 bytes long. We wish to select records where the fifth byte of FLAGS is as follows: (1) The first bit (bit 0) is on and (2) either the fourth or fifth bit (bits 3 and 4) is on. See 3.

File BINDATA contains a field FLAGS which is character, 10 bytes long. We wish to select records where the fifth byte of FLAGS is as follows: (1) The first bit (bit 0) is on and (2) either the fourth or fifth bit (bits 3 and 4) is on. See Figure 3.

The three %AND functions isolate the three different bits we're testing. The %AND function does a logical AND operation. It compares two strings, bit by bit. If the same bit is on in both strings, it turns on the corresponding bit in the result string. 4 shows a couple of examples of how the first %AND would work with different values of TESTBYTE.

The three %AND functions isolate the three different bits we're testing. The %AND function does a logical AND operation. It compares two strings, bit by bit. If the same bit is on in both strings, it turns on the corresponding bit in the result string. Figure 4 shows a couple of examples of how the first %AND would work with different values of TESTBYTE.

TEST0 will come back as all zeros if bit 0 is not on. The same is true for the other two TESTx fields. You can use these fields to see if they are equal to hex 00 or not. If they are not equal, the bit is on.

By the way, if the flag field is only 1 byte long, you don't have to use the first mapped field; you can just use the flag field in the other three mapped fields instead of TESTBYTE. The QRYSLT doesn't change.

When I was writing Open Query File Magic!, I spent a good bit of time trying to come up with an example using a logical function, but everything I came up with seemed contrived, or there was an easier way to do it. I'll see about adding this to a future edition.


TechTalk: QRYSLT with Binary Fields

Figure 3 QRYSLT With Binary Fields

 PGM DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(256) CHGVAR VAR(&QRYSLT) VALUE('TEST0 *NE X''00'' *AND + TEST3 *NE X''00'' *OR TEST4 *NE X''00''') OVRDBF FILE(BINDATA) SHARE(*YES) OPNQRYF FILE((BINDATA)) QRYSLT(&QRYSLT) + MAPFLD((TESTBYTE '%SST(FLAGS 5 1)') + (TEST0 '%AND(TESTBYTE X''80'')') + (TEST3 '%AND(TESTBYTE X''10'')') + (TEST4 '%AND(TESTBYTE X''08'')')) CALL PGM(BINRPG) CLOF OPNID(BINDATA) DLTOVR FILE(BINDATA) ENDPGM 
TechTalk: QRYSLT with Binary Fields

Figure 4 Using %AND in QRYSLT

 TESTBYTE 10100010 00001111 X'80' 10000000 10000000 -------- -------- TEST0 10000000 00000000 
BLOG COMMENTS POWERED BY DISQUS