× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello,

> There is column oriented file YCSC1. One of the field is YSTAT1 which is
> defined as
>  Type Character  &  Length  1.
> I need select records from this file YCSC1 when 7th bit of YSTAT1 is "on" .
> Can some one help me how to go about this and acheive records for this
> selection.

When you say "7th bit" do you mean the 7th bit from the left hand side of
the byte or the 7th from the right-hand side? Do you start numbering your
bits with 0?  or do you start numbering them from 1?

In other words, if you have a byte with a value of "10000000," which
bit is set?  Is it number 0, 1, 7 or 8?

Once you've decided which bit you want to check, create a mask (like
"01000000" , where each bit you want ot check is 1, and each bit you don't
care about is 0) convert the binary number to hex, and use the %bitand()
BIF to check it.

For example:

      /free

           // The binary number 01000000 is hex x'40'

           if (%bitand(YSTAT1: x'40') <> x'00');
               dsply ('7th bit from the right is set');
           endif;

           // The binary number 00000010 is hex x'02'

           if (%bitand(YSTAT1: x'02') <> x'00');
               dsply ('7th bit from the left is set');
           endif;

      /end-free


If you're running a release older than V5R2, you can accomplish the same
thing with the TESTB op-code:

      *
      *  The binary number 01000000 is hex x'40'
      *
      * N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
     c                   testb     x'40'         YSTAT1                   99
     c                   if        *in99 = *on
     c                   eval      msg = '7th bit from the right is on'
     c     msg           dsply
     c                   endif

      *
      *  The binary number 01000000 is hex x'02'
      *
      * N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
     c                   testb     x'02'         YSTAT1                   99
     c                   if        *in99 = *on
     c                   eval      msg = '7th bit from the left is on'
     c     msg           dsply
     c                   endif

Personally, I like to make it a more obvious WHY I'm checking this bit.
For that type of thing, I define a named constant that corresponds to the
bit I'm checking.  For example, if bit 7 is determined to be 01000000 and
I'm checking it because it's turned on when an account has been paid in
full, I'd define a constant like this:

     D PaidInFull      c                   x'40'

And then I'd do my test like this:

           if (%bitand(YSTAT1: PaidInFull) <> x'00');

or in older RPG programs:

      * N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
     c                   testb     PaidInFull    YSTAT1                   99

I usually bit all of these "bit flags" in a /copy member so that I can
reuse them in every program that might need to check the status of a bit
without needing to redefine them everywhere.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.