0

I am looking at a data flow in SAP Data Services (BODS). One of the column 'Reg' in a table (WORKCODE) has double values (for e.g. 8.33E-02). Can anyone please explain the below expression and what is the function of 'index' in the below expression:

substr(WORKCODES.Reg, 1, (index (upper ( WORKCODES.Reg ),'E',1 )-1 ) )

2 Answers 2

2

I've just seen your post cause I'm looking for information about Index function in BODS. The index function returns the position of a character in a string value. The equivalent sql function is INSTR.

In your example (for e.g. 8.33E-02):

SUBSTR( '8.33E-02', 1, INDEX ( '8.33E-02', 'E', 1)-1 ) 

==> INDEX ( '8.33E-02', 'E', 1) will return the position of the letter 'E' starting at position 1. It should be 5.

Then you use SUBSTR function to extract the first part of your number :

SUBSTR( String Value, Start Pos, End Pos )
SUBSTR( '8.33E-02',       1,           INDEX ( '8.33E-02', 'E', 1)-1 )
SUBSTR( '8.33E-02',       1,           5-1 )

You subtract 1 to the position of 'E' to keep the first part !

It's never too late to answer ! =)

SQL Equivalent :

SELECT SUBSTR( '8.33E-02', 1, INSTR ( '8.33E-02', 'E')-1 ) 
     , INSTR ( '8.33E-02', 'E')
FROM DUAL

Flavour

0

Just saw this & thought if someone else gets here let's talk about the whole statement:

substr(WORKCODES.Reg, 1, (index (upper ( WORKCODES.Reg ),'E',1 )-1 ) )

Let's work it from the inside out, and start with the second reference to the variable WORKCODES.Reg:

(index (upper ( WORKCODES.Reg ),'E',1 )-1)

upper is a function that will make the variable all uppercase. This was done because it's making reference to the letter 'E'. lowercase 'e' will be converted to 'E'.

Next is the index function. The index function will return the position number for the first occurrence of the string after the comma, in this case, the letter 'E'. It will start counting from position 1, that's what the 1 after the last comma is for. So let's say the word is 'tree'. This section will uppercase the word to 'TREE', then count from the first position to the first occurrence of the letter 'E', which would be 3. Now the -1 will back that number to 2.

So we will change that part of the statement to 2:

substr(WORKCODES.Reg, 1, 2)

Now it's looking for the substring of the variable WORKCODES.Reg starting at position 1 (that's what the number 1 is for) continuing for 2 characters.

So for the word tree the answer is tr

For whatever reason, the person who wrote this wanted all of the characters BEFORE the first occurrence of the letter e.

Not the answer you're looking for? Browse other questions tagged or ask your own question.