×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Define Field based on characters in a String

Define Field based on characters in a String

Define Field based on characters in a String

(OP)
Newbie to the forum here.  I'm looking forward to learning from everyone here.  

I'm working in Developers Studio 7.1.

I need to write a define based on characters in a string of data within our Item Numbers.  

ex: item = 3J9B051101
ex: item = 3J9C051102
I need to pull out the 3rd and 4th caracter and say:

If that equals 9B then Chemical
If that equals 9C then Industrial

I'm able to pull out the two fields using SBSTR, but I can't build a define off a define.  

There must be a better way?

Thanks in advance for any help anyone can provide.

RE: Define Field based on characters in a String

I'm not sure WHY you say you ' can't build a define off a define'? You definitely can.

There are several ways to accomplish what you want. First, you can extract the bytes in question, using SUBSTR or the EDIT function. Then use an IF/THEN/ELSE construct, like this:

CODE

TWOCHARS/A2 = EDIT(ITEM,'$$99$$$$$$');
VALUE/A10 = IF TWOCHARS EQ '9B' THEN 'CHEMICAL' ELSE
            IF TWOCHARS EQ '9C' THEN 'INDUSTRIAL' ELSE '??';

An alternative might be to use SUBSTR and DECODE:

CODE

TWOCHARS/A2 = SUBSTR(10,ITEM,3,4,2,'A2');
VALUE/A10 = DECODE TWOCHARS('9B' 'CHEMICAL' '9C' 'INDUSTRIAL' ELSE '??');

Or, use any combination as needed. There are always multiple ways to do what you want. You can even combine the logic into a single expression:

CODE

VALUE/A10 = IF EDIT(ITEM,'$$99$$$$$$') EQ '9B' THEN 'CHEMICAL' ELSE
            IF EDIT(ITEM,'$$99$$$$$$') EQ '9C' THEN 'INDUSTRIAL' ELSE '??';

RE: Define Field based on characters in a String

(OP)
Thanks so much focwizard!  I used the last code you provided and it worked perfectly.  Thanks !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close