field character into field numeric

Hi,
can i convert field character into field numeric?

I read: #text (a50)
’ 12345’
’ 4445565 ’
'1234 ’

(have spaces after and before the numbers)

And i need to move only numeric into #numeric (n 8 ) ?

IF #text IS (N8)
#num := VAL(#text)
ElSE
write #text “not a valid number”
END-IF

Thanks.

Minor enhancement:

IF  #TEXT IS (N8)
 AND #TEXT <> ' '          /* <--
  THEN 
    #NUM := VAL (#TEXT) 
  ELSE 
    WRITE #TEXT 'not a valid number' 
END-IF 

Ralph,

Why the check to make sure it isn’t blank? At least on HPUX, blank does not pass the “IS (N8)” test. Is the IS functionality not consistent on other platforms?

Thanks.

Hi Claudio;

Was just a bit curious re your question.

Do you want to extract all numeric strings from #text?

If so you would SEPARATE #text into #ARRAY () / a blank is one of the default delimiters

Then you could test the members of #array to see if they are numeric (as discussed in earlier posts).

steve

I dont use array with VAL…

I had presumed that the LUW behavior matched the mainframe, where the IS clause accepts a blank value but the VAL function does not. I’ll continue to use the additional test until Natural’s syntax is synchronized on the two platforms. Version 8, perhaps?

Good to know Ralph, in case I get canned here and have to find employment in a Mainframe shop. Thanks.

Hi guys,
Just FYI I wanted to mention that Ralph was absolutely right:
on Natural Version 8.2.2.3 (mainframe) blank is NOT (N whatever); apparently, you just need to upgrade your mainframe environment :slight_smile:
Best regards.