Question:
I have an I1 item in a set and I need to check the value of the first digit of each number in each entry. The maximum number for the item is 9999. I have tried to convert the I1 to a byte field then test the value using the offset. Campus-bldg is the I1 item.
def a,campus-bldg,6,byte def b,a[2],1 if b = ("2","3,"4") ext campus-bldg output campbldgI'm getting junk for some reason even if I output as ASCII.
Answer:
What is not obvious at first is that Define commands are just redefinitions of the input record. Defines do not create new storage, and they do not convert data from one format to another. If you are a COBOL programmer, think of the REDEFINES clause. Therefore your Define commands told Suprtool this:
def a,campus-bldg,6,byteHey, Suprtool, I want to give the six bytes of my input record, starting at the same position as campus-bldg, a name of A. If campus-bldg started at byte 37 of the input record (for a length of 2 bytes because it is an I1), the field A will also start at byte 37, but will go for a length of 6. The thing called A will have all 16 bits of campus-bldg plus the next 4 bytes. This definitely won't work.
def b,a[2],1Now you're telling Suprtool to treat the second byte of A (which is the second byte or rightmost eight bits of campus-bldg) as a field called B. This still doesn't work.
The standard answer to the generic question, "How do I test a single digit of a binary number" is, "You need to use two passes." Let's see how to do this the standard way, then let's see some one-pass solutions for this specific case.
Two passes:
get <dataset> extract <all the desired fields including campus-bldg> output <filename>,ascii xeq input <filename> define a,<position of the thousands digit in the ascii-field campus-bldg>,1,byte if a = "2","3","4" ...The downside of this approach is that all the numeric fields that you extracted are now in ASCII format. The resulting file may not be compatible with whatever program is supposed to read the output.
Three(!) passes:
get <dataset> define a,1,<length of whole record in bytes>,byte extract a extract campus-bldg output <filename>,ascii xeq input <filename> define b,<position of the thousands digit in the ascii-field campus-bldg>,1,byte if b = "2","3","4" extract a output <filename2> input <filename2>=<dataset> ...With this approach the output record produced by the second pass still has all the input fields in their original format. The input filename=dataset syntax tells Suprtool to trust you that the input file has the same layout as the dataset. That way you can use all the dataset's fieldnames when reading the file.
One pass (style A):
Assuming that I understand correctly that you have an I1 field whose values never exceed 9999, and you want to select records if the thousands digit is a 2, 3, or 4, you could just do this:
input <dataset> if campus-bldg >= 2000 and campus-bldg <=4999 ...This works only because we are testing the high-order or most-significant digit. This wouldn't work if we were trying to test for one of the other digits.
One pass (style B):
input <dataset> if campus-bldg / 1000 = 2,3,4 ...Again, this works only for testing the most significant digit.
[Mike Shumko]