I am working with DB2 V7 in OS/390.
I have a table (TB1) with a varchar column (C1) which was redefine in order to store a group of numeric values (up to 1500, like quantities or amounts) in packet format, back to back:
C1 = dddddddddddddddddz40dddddddddddddddddz40dddddddddd dddddddz ...
d: digit, z: sign, 40: space separation (hex)
Each one item has 9 bytes and represents an specific concept, like a payment/deduction amount or number of items.
Actually, to operate with these arguments, the portion correspondig to the item required is extracted from the column C1 using a "SUBSTR" function and moved to a 9 bytes character field (A1), redefined like PIC 9 (15.2) COMP-3:
For third item, it would be
Select substr(C1, 31, 9) into A1 from TB1 where ...
What can I do in order to DB2 returns the numeric value of the argument (or their sum using a grouping function) ?