Former Member

# Index Function

Hi,

I need to input certain values based on certain logic.

It is like if the 8'th character is empty or contains numeric then PART field contains value BCI and if 8'th character contains alphabet, then PART = 'DFI'

Below is the example:

If ID = 1234567 then PART = 'BCI'

ID = 12345678 then PART = ''BCI'

ID = 1234567AP01 then PART = 'DFI'

How do I write it using INDEX?

10|10000 characters needed characters exceeded

### Related questions

• Former Member
Posted on Jul 14, 2011 at 07:41 AM

Hi Naga,

Do you have access to the online technical manuals that are supplied with Data Services ? If not, I suggest you installl them because you will get much faster answers to these types of questions (usage of the built-in functions) from the manuals (particularly the reference guide) than you will from forums (and more accurate in some cases). The manuals are very well written and there are usually lots of examples.

Having said that, to guide you in the right direction the 'substr' function is probably going to be the one to look at since you know exactly which character you need to identify in the string (i.e. the 8 th). The 'index' function is more suited to cases where you are looking for a sequence of characters in a string and want to know at which position the first occurrence of the character sequence begins.

So basically, use 'substr' to get the 8th character inside a 'decode' function to compare this value to your three cases and determine the output.

10|10000 characters needed characters exceeded
• Former Member Former Member

Also, you can handle all three of your conditions in one decode statement because decode works like nested ifthenelse functions, eg. in this example from the manual:

decode ((EMPNO = 1), '111',

(EMPNO = 2), '222',

(EMPNO = 3), '333',

(EMPNO = 4), '444',

'NO_ID')

If EMPNO=1 it returns '111', else it checks the next condition,

If EMPNO=2 it returns '222', else it checks the next condition,

If EMPNO=3 it returns '333', else it checks the next condition,

If EMPNO=4 it returns '444', else it returns the default expression 'NO_ID'