Check whether string consists of alphanumeric characters

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Check whether string consists of alphanumeric characters

Post by DeepakCorning »

I was searching the Help Guide and found out that we have the follwing function in Parallel Edition --

AlNum
Return whether the given string consists of alphanumeric characters

DO we have a equivalent in Server Edition??
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I couldn't find a direct one but you could play around with DIGITS and LETTERS built-in transform functions and alpha function. Or are you already aware of them?
Kris

Where's the "Any" key?-Homer Simpson
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

Yep , Aware of them...Was searching for a direct one. But if not there then let me try to use these one somwhow. Thanks !!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There isn't a direct one. You could create a direct one.

Code: Select all

FUNCTION AlNum(TheString)
* Returns 1 (true) if all characters are alphanumeric, 0 (false) otherwise.
   Ans = @TRUE
   CharCount = Len(TheString)
   For ch = 1 To CharCount
      Character = TheString[ch,1]
      If Character Matches "1A" : @VM : "1N"
      Else
         Ans = @FALSE
         Exit  ; * as soon as a non-alphanumeric character found exit loop
      End
   Next ch
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
avi21st
Charter Member
Charter Member
Posts: 135
Joined: Thu May 26, 2005 10:21 am
Location: USA

Post by avi21st »

This is another way in which you can do it...........

Code: Select all

Input = TRIM(aNUMBERFIELD)
*********************************************************
*The function gets the non-numeric fields from the Input*
*********************************************************
Convert= Iconv(Input,"MD")

ConvStatus= Status()
*************************************************************************
* Output:  1 if there is error or warning in conversion                 *
*          0 if the conversion is successful                            *
*************************************************************************
Begin Case
Case (ConvStatus=1 or ConvStatus=2 or ConvStatus=3)
Output=1
Case ConvStatus=0
Output=0
End Case
Ans= Output

Ans= Output
Avishek Mukherjee
Data Integration Architect
Chicago, IL, USA.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ALPHAnumeric was specified in the subject.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
avi21st
Charter Member
Charter Member
Posts: 135
Joined: Thu May 26, 2005 10:21 am
Location: USA

Post by avi21st »

ray.wurlod wrote:ALPHAnumeric was specified in the subject.

Sorry I pasted the wrong one............

Code: Select all

Input = VarCharField

**********************************************************

*The function gets the non-numeric fields from the Input*

**********************************************************

Charac= Iconv(Input,"MC/N")

***************************************************************

*The function counts the non-numeric fields in the result set*

***************************************************************


NumofCharac= Len(Charac)

Begin Case

Case (NumofCharac >0)

Output=1

Case (NumofCharac=0)

Output=0

End Case

Ans= Output

Arg1 = Input field(Varchar: Datatype)

Called by:
Transformer

Parameters:
Arg1 = Input field


Checks for non-numeric character in numeric field.

Return Values: 0 = If the Input Field does NOT have non-numeric character
1 = If the Input Field has non-numeric character
Avishek Mukherjee
Data Integration Architect
Chicago, IL, USA.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've still missed the point. The OP required detection of non-alphanumerics, not non-numerics.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply