Binary to Integer

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Binary to Integer

Post 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.
jonboy49
Posts: 58
Joined: Wed Jul 28, 2021 8:18 pm

Re: Binary to Integer

Post 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.
Scott Klement
Site Admin
Posts: 236
Joined: Sun Jul 04, 2021 5:12 am

Re: Binary to Integer

Post 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.
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: Binary to Integer

Post 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!!
Post Reply