Page 1 of 1

how can I access bytes in a numeric field

PostPosted: Sat Jul 12, 2008 1:53 am
by ajaygupta9
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?

Re: how can I access bytes in a numeric field

PostPosted: Sat Jul 12, 2008 2:29 am
by dick scherrer
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".

Re: how can I access bytes in a numeric field

PostPosted: Sat Jul 12, 2008 2:41 am
by dick scherrer
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.

Re: how can I access bytes in a numeric field

PostPosted: Sat Jul 12, 2008 2:08 pm
by ajaygupta9
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?

Re: how can I access bytes in a numeric field

PostPosted: Sat Jul 12, 2008 2:35 pm
by dick scherrer
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.