Results 1 to 2 of 2

Thread: Split Variable

  1. #1
    Join Date
    Oct 2007
    Posts
    61

    Unanswered: Split Variable

    Hello.

    How I do split in SPL ?

    my variavel: "abc - def"

    I want split in two variable using the separator "-"

    var1 = abc
    var2 = def

    There are one way in spl to do this ??

    Yours
    Fernando.

  2. #2
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Hi, try this one...
    Code:
    CREATE FUNCTION splitvar(sep VARCHAR(255), str VARCHAR(255))
        RETURNING VARCHAR(255), VARCHAR(255);
    
        DEFINE i        SMALLINT;
        DEFINE j        SMALLINT;
        DEFINE len1     SMALLINT;
        DEFINE len2     SMALLINT;
    
        LET len1 = length(replace(sep, ' ', '@'));
        LET len2 = length(str);
        IF len1 > 0 AND len2 >= len1 THEN
            FOR i IN (1 TO len2)
                IF substr(sep, 1, 1) = substr(str, i, 1) THEN
                    LET j = 2;
                    IF len1 > 1 THEN
                        IF len1 - 1 > len2 - i THEN
                            RETURN '', '';
                        END IF
                        WHILE j <= len1
                            IF substr(sep, j, 1) != substr(str, i + j - 1, 1) THEN
                                EXIT WHILE;
                            END IF
                            LET j = j + 1;
                        END WHILE
                    END IF
                    IF j > len1 THEN
                        RETURN substr(str, 1, i - 1), substr(str, i + len1);
                    END IF
                END IF
            END FOR
        END IF
        RETURN '', '';
    
    END FUNCTION;
    The used built-in functions are available from IDS 7.x on I believe.

    Regards,
    Hans
    Last edited by Tyveleyn; 07-25-09 at 19:03.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •