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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Define Field based on characters in a String

Status
Not open for further replies.

tj98cobra

Technical User
Jun 26, 2006
2
US
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.
 
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 '??';
 
Thanks so much focwizard! I used the last code you provided and it worked perfectly. Thanks !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top