Using the "LIKE" operator in DS Routine

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
ririr
Participant
Posts: 84
Joined: Sun Apr 04, 2004 8:59 pm

Using the "LIKE" operator in DS Routine

Post by ririr »

I am trying to find a pattern in the source column and return Null, if the pattern is found.

For Ex: Source Column Record 1 has : "TBADA'
Record 2 has : "ADTBAAD"
Finding Pattern: "TBA"
Result : @NULL

Any help is appreciated!
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

I think I understand - you are currently getting a NULL (not found) and you should be getting a hit (found)?

I would use the Index function. Here is some documentation from BASIC.pdf:

Syntax
INDEX (string, substring, occurrence)

Description
Use the INDEX function to return the starting character position for the specified occurrence of substring in string.

Hope this helps,
John
ririr
Participant
Posts: 84
Joined: Sun Apr 04, 2004 8:59 pm

Post by ririr »

Thanks John, It worked like a charm!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The operator in DataStage BASIC is MATCHES rather than LIKE, and it uses a more flexible pattern-matching capability. In your case, all you need is the wild-card pattern element, which is either "..." or "0X".

Code: Select all

InLink.ColumnName MATCHES "...TBA..."
or, for case-insensitive matching

Code: Select all

UpCase(InLink.ColumnName) MATCHES "...TBA..."
When you're ready, find MATCHES in the on-line help or BASIC manual and learn about the other pattern-matching components. For example you can match specific or arbitrary numbers alphabetic or numeric characters.
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