Re: Querying ISAM files
Posted in 1995
I am sorry I have been off the net for some time, so I didn't see this question until now. You may do something along these lines: (I would suggest C-functions but if you don't know C this may help you although it won't be fast.) If comp3 is a 32 bit unsigned integer: function comp3_to_integer(p_comp3) define p_comp3 char(4), p_int integer let p_int = chr_val(p_comp3[4]) let p_int = p_int + (chr_val(p_comp3[3]) * 256) let p_int = p_int + (chr_val(p_comp3[2]) * 65536) let p_int = p_int + (chr_val(p_comp3[1]) * 16777216) return p_int end function I didn't use a loop in the above as this is simpler to experiment with if there are swapped bytes, problem with signs and so on. chr_val is a function that returns the integer representation of a character value. If this isn't in your 4GL (it may be in newer versions) here is probably the most stupid version that can be written in 4GL (not fast!): function chr_val(p_char) define p_char char(1), p_1 smallint for p_1 = 0 to 255 if ascii(p_char) = p_1 then return p_1 end if end for end function I believe Informix use character value 0 to represent null that would give you problems. If you add this to the above it might work: if p_char is null then return 0 else ... for loop now starting from 1... end if Realy the above is to simple to write in C to use extensively. If you are working with BCD (2 digits to a byte) you might do something along these lines: function bcd_to_integer(p_bcd) define p_bcd char(8), # or whatever the length is. p_2digit, p_digit1, p_digit2, p_1 smallint, p_chr2digit char(2), p_int integer let p_int = 0 for p_1 = 1 to 8 let p_2digit = chr_val(p_bcd[p_1]) let p_chr2digit = p_2digit using "&&" let p_digit1 = chr_val(p_chr2digit[1]) let p_digit2 = chr_val(p_chr2digit[2]) let p_int = p_int + (p_digit1 * ... figure out this yourself ... end for end function This would be sloooowww with the above chr_val function... In addition to the above you will probably have to handle the representation of sign and where a decimal point should go. All this is just a starting point. C-functions could do this so much better, but... Nils.Myklebust@ccmail.telemax.no NM-data, Dalsbergstien 7, N-0170 Oslo, Norway My opinions are those of my company > akent@cix.compulink.co.uk ("Andy Kent") writes: > > If you don't write C-routines yourself you could even unscramble this > > with 4GL. You will need a function to convert a character to its integer > > representation. In the newest versions of 4GL I think I have seen this. > > We have even used a for loop for this without any problems with speed. > > Others will of course say you should use C, but for a kludge you do the > > simplest things. > > > > I don't remember the exact representation of COMP 3 fields in Cobol, but > > it shouldn't be very hard to find it out from you data. If i remember > > this correctly it is straight binary coded with some sign indicator. > > Probably the bytes are switched arround within each 16 bit word. > > If this is not the case it is BCD with 2 digits per character stored > > with binary values from 0 to 9 plus some special indicator for the sign. > > Equally simple to decode. > > Err... could you give me some examples of just *how* you would do this in > 4gl? > > I really have never seen 4gl used to get in beneath byte level. Love to > know how you do this. > > > akent@cix.compulink.co.uk (Andy Kent) > ------------------------------------------------ > Freelance Informix Database Specialist, > Redland, Bristol, England