Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hex Issue

Status
Not open for further replies.

OAKEJ

Programmer
Apr 13, 2005
39
US
I have users that are putting in invalid codes, the hex value is 2A but I want to see if I can store these codes in a file and use the program to read thru all of them and scan the fields for them, the reason is that when I encounter more of them it would be easier to update the file with those values instead of changing the program when this happens.

Here's the code that I have that doesn't work..
HEXCOD is the field in the Hex Code File that I created

Read FLOB
DOW NOT %EOF(FLOB)
Read HEXFILE
DOW NOT %EOF(HEXFILE)
IF %SCAN(HEXCOD:OBSITE) > 0 *NOTE HEXCOD Value is 2A
Eval @FLAG = 'Y'
Else
Eval @FLAG = 'N'
Read HEXFILE
ENDDO
Read FLOB
ENDDO

However if I define a Constant like
@Hex CONST(X'2A')

Then it works....

Read FLOB
DOW NOT %EOF(FLOB)
IF %SCAN(@HEX:OBSITE) > 0
Eval @FLAG = 'Y'
Else
Eval @FLAG = 'N'
Read FLOB
ENDDO

Any Ideas or Suggestions? Thanks in advance
 
Pls paste here the definition of HEXCOD in the file.

Philippe
 
I guess I am missing something,, why are the codes in Hex??
 
Another possibility: @FLAG will only contain the value for the last record tested in FLOB. If the last record in FLOB doesn't contain the last hex value from HEXFILE, then @FLAG will be 'N'.
 
I suspect that the HEXCOD field in your file is character. You cannot copare hexadecimal to a character representation of it. The reason using a named constant works is that it is hexadecimal.

You need to use the C function APIs to convert:

Code:
     H Option(*SRCSTMT : *NODEBUGIO)             
     H Dftactgrp(*NO) Actgrp(*CALLER)            
     H Bnddir('QC2LE')   
     H Datfmt(*USA) Timfmt(*HMS) Alwnull(*USRCTL)

       // Character to hexadecimal C function prototype      
     D Tohex           PR                  Extproc('cvthc')  
     D  Hexresult                 65534A   Options(*VARSIZE) 
     D  Charinp                   32767A   Options(*VARSIZE) 
     D  Charnibbles                  10I 0 Value             
                                                             
       // Hexadecimal to character C function prototype      
     D Fromhex         PR                  Extproc('cvtch')  
     D  Charresult                32767A   Options(*VARSIZE) 
     D  Hexinp                    65534A   Options(*VARSIZE) 
     D  Hexlen                       10I 0 Value             

       /Free
       // Call the API like this:
          Tohex(CharField : HexValue: %LEN(CharField));


-- Francis
I'd like to change the world, but I can't find the source code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top