Page 1 of 1

Binary to Integer

Posted: Tue Jun 21, 2022 7:12 pm
by kathan.p@gmail.com
I have SQL table with Binary field

Code: Select all

               Data        Field  Buffer    Buffer 
 Field      Type       Length  Length  Position 
 PKEY       BINARY      18  0       8     15492  
 
When i retrieve the value in program in 20I variable it comes as
4629771061636907072

But the data in the actual file field is - (getting below value using STRSQL)
19,461,757

Not sure how to get that actual value in the program? As i need that value to find that record again the that to update certain value.

Re: Binary to Integer

Posted: Tue Jun 21, 2022 8:18 pm
by jonboy49
It is tough to tell what you have done wrong since you have omitted the most important thing - how the field is defined in your RPG or how you populated it. What i can tell you is that the value you see equates to spaces - so I would guess that the field is defined in an unititialized DS and is never being populated.

Just to be sure I created a file with just an 8 byte Int like so:

Code: Select all

CREATE  or replace TABLE bincheck ( int20 BIGINT NOT NULL) RCDFMT bincheckr;
insert into bincheck values(19461757);
And then ran this RPG code.

Code: Select all

Dcl-F BinCheck;
Read BinCheck;
Dsply ('Value is ' + %Char(Int20));
I get the expected result.

So you need to study your code to see why you are not populating the field.

Re: Binary to Integer

Posted: Tue Jun 21, 2022 8:56 pm
by Scott Klement
4629771061636907072 is hex x'4040404040404040'

So what you are seeing are blanks in the space where you are expecting the field to be. Either you're failing to read the record, or you've done something unusual in the way you've defined things in RPG.

Like Jon said, it's difficult to help you since you have omitted the most important things that we'll need to know to answer your question.

Re: Binary to Integer

Posted: Wed Jun 22, 2022 10:00 pm
by kathan.p@gmail.com
Field was part of DS and i was not fetching data correctly from the particular length. I fixed it.

Thank you!!