how can I access bytes in a numeric field



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

how can I access bytes in a numeric field

Postby ajaygupta9 » Sat Jul 12, 2008 1:53 am

Hi, I have two questions
1. There is a technique in C, called bit field. Through this we can access bits. Is there anything like this in cobol?

Suppose I want to put an if condition based on the fourth byte of a field. If fourth byte contains 1 than set the flag and if fourth byte contains 0 than put some displays.

2. We have Union datastructure in C. Is there any datastructure like this in cobol?
ajaygupta9
 
Posts: 2
Joined: Mon Mar 10, 2008 9:34 am
Has thanked: 0 time
Been thanked: 0 time

Re: how can I access bytes in a numeric field

 

Re: how can I access bytes in a numeric field

Postby dick scherrer » Sat Jul 12, 2008 2:29 am

Hello ajaygupta9 and welcome to the forums,

You mention "bits", then switch to "fourth byte". . .

If you mean 4th byte, you can use reference modification.

If you want some particular bit of a byte, i've always "decomposed" a byte into the component bits (using powers of 2). If you move the byte to a ws binary number and compare the number > 127, 63, 31, etc you can derive which bits are "on" and "off".
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: how can I access bytes in a numeric field

Postby dick scherrer » Sat Jul 12, 2008 2:41 am

Hello again,

After replying, i noticed that your subject mentions a numeric field - i'd noticed that originally, but got caught up in the topic text and forgot about the number. . . :?

If i've not answered what you wanted to ask, please clarify the question.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: how can I access bytes in a numeric field

Postby ajaygupta9 » Sat Jul 12, 2008 2:08 pm

Hi Dick,
Thanks for your reply.
My question is that, suppose a variable A contains some value, and now i want to put some condition based on the value in its fourth byte. How can I do that?

Please sugest me something on my second question also:-

2. We have Union datastructure in C. Is there any datastructure like this in cobol?
ajaygupta9
 
Posts: 2
Joined: Mon Mar 10, 2008 9:34 am
Has thanked: 0 time
Been thanked: 0 time

Re: how can I access bytes in a numeric field

Postby dick scherrer » Sat Jul 12, 2008 2:35 pm

Hello,

As i mentioned before:
If you mean 4th byte, you can use reference modification.
Are you familiar with reference modification? Reference allows your code to "look at part of a field". If not, look here:
http://publibz.boulder.ibm.com/cgi-bin/ ... 10/1.7.1.8

I don't know how the "union datastructure" works. If you explain it clearly, i can tell you if there is a similar functon/process in cobol. My guess is that it is language specific.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post