2

Following Input xml field needs to be substringed for 6 characters and each 6 characters should be splitted and saved in the option field of output.

Input: 
<feature>124414500045563879</feature>

output:
<option>124414</option>
<option>500045</option>
<option>563879</option>

Is there any tokenizer function available in IIB ESQL to achieve the above result.

ranaa
  • 57
  • 1
  • 5
  • 14

2 Answers2

7

As far as I know, no there isn't a String Tokenizer function in ESQL.

But you could use the following procedure as base to achieve your goal. This method splits S on Delim into an array in Env (Environment.Split.Array[]) and removes Environment.Split before refilling it.

In your case, you don't need the Delim, you should work with a fixed length in the Substring part.

CREATE PROCEDURE Split (IN S CHARACTER, IN Env REFERENCE, IN Delim CHARACTER) 
BEGIN 
   DECLARE P INTEGER; 
   DECLARE Idx INTEGER 1; 

   SET Env.Split = NULL; 

   REPEAT 
      SET P = POSITION(Delim IN S); 
      IF P = 0 THEN 
         SET Env.Split.Array[Idx] = S; 
      ELSE 
         SET Env.Split.Array[Idx] = LEFT(S, P - 1); 
         SET S = SUBSTRING(S FROM P + LENGTH(Delim)); 
         SET Idx = Idx + 1; 
      END IF; 
  UNTIL P = 0    
  END REPEAT;    
END;

Source: http://www.mqseries.net/phpBB2/viewtopic.php?p=97845&

VincentS
  • 602
  • 1
  • 10
  • 24
1

Another solution could be to take the value of feature as bitstream, build a new BLOB message from it, and have it re-parsed using a message definition that describes the tokens in that value. After the re-parsing, you can further process the new logical message.

Attila Repasi
  • 1,803
  • 10
  • 11
  • Really good answer. I generally use a loop for a small number of elements say less than 20, see above, due to the performance cost of setting up and invoking a Parser but where there could be lots and lots of elements creating a MessageModel for the DFDL parser could significantly reduce overhead. Remembering that every line of ESQL is a call to the underlying interpreter. – TJA May 12 '19 at 00:52