Question

  Asked: May 7 2008   3:40 AM GMT
  Asked by: Crackers


convert alphanumeric to binary


RPGLE, RPG

hi, my program is receivng an "alphanumeric char 10 length " and im using it to chain a PF, but the field from the physical file is binary 9,0, how will i able to convert an alpha10 to binary 9,0 in RPGLE?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



Hi,

You should be able to MOVE your character field to your binary field. You'll need to check that you don't have any invalid data before you do the move.

Regards,

Martin Gilbert.

--------------------------------------------------------------------------------

Just to expand on Martin's idea a little bit. The following (as is pointed out in his answer) will work:


fBinKeyFileif e k disk

dAlphaKey s 10 inz('0000000002')

c move AlphaKey Key
c Key chain BinKeyFile 01
c *in01 ifeq *off
c Data dsply
c else
c 'Not Found' dsply
c endif
c move '1' *inlr
c return


where BinKeyFile is defined as:


R RECORD
KEY 9B 0
DATA 50
K KEY


BUT there is an assumption being made here, namely that your alphanumeric 10 byte field is using leading zeroes as in the sample program. If, on the other hand, the key value comes into your program as '2 ' then MOVE will toss the '2' due to how 9B 0 fields are implemented. There are ways around this but I won't go into them on the assumption that your field is formatted as above.

To test add a record to BinKeyFile with a key of 2. Using inz('0000000002') as above the record is found on the chain operation. Using inz('2') the record is not found on the chain operation.

Bruce Vining
  • AddThis Social Bookmark Button

Browse more Questions and Answers on AS/400.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register