ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%check sqlrpgle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %check sqlrpgle

    Hi,

    I know this is just an easy question for you guys.... could you help me interpret below commands.. especially in the area of %check .. im a little bit confuse on check command.

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    values:

    Num$ = '0123456789'
    N102 = america, angela
    baltazar, anthony
    behrens, mike
    3016


    IF (%len(%trim(N102)) <> 4 OR
    %check(Num$:N102:1) <> 5)

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    thanks in advance.

    regards,
    christina

  • #2
    Re: %check sqlrpgle

    %CHECK (Check Characters)

    %CHECK returns the first position of the string base that contains a character that does not appear in string comparator. If all of the characters in base also appear in comparator, the function returns 0.

    The check begins at the starting position and continues to the right until a
    character that is not contained in the comparator string is found. The starting
    position defaults to 1.

    The first parameter must be of type character, graphic, or UCS-2, fixed or varying
    length. The second parameter must be the same type as the first parameter. The
    third parameter, if specified, must be a non-float numeric with zero decimal
    positions.

    Example

    *--------------------------------------------------
    * A string contains a series of numbers separated
    * by blanks and/or commas.
    * Use %CHECK to extract the numbers
    *--------------------------------------------------
    D string s 50a varying
    D inz(â??12,233 17,1,234â??)
    D delimiters C â?? ,â??
    D digits C â??0123456789â??
    D num S 50a varying
    D pos S 10i 0
    D len S 10i 0
    D token s 50a varying
    /free
    // make sure the string ends with a delimiter
    string = string + delimiters;
    dou string = â??â??;
    // Find the beginning of the group of digits
    pos = %check (delimiters : string);
    if (pos = 0);
    leave;
    endif;
    // skip past the delimiters
    string = %subst(string : pos);
    // Find the length of the group of digits
    len = %check (digits : string) - 1;
    // Extract the group of digits
    token = %subst(string : 1 : len);
    dsply â?? â?? â?? â?? token;
    // Skip past the digits
    if (len < %len(string));
    string = %subst (string : len + 1);
    endif;
    enddo;
    /end-free

    -------------------------------------------

    %CHECKR (Check Reverse)
    %CHECKR(comparator : base {: start})

    %CHECKR returns the last position of the string base that contains a character that does not appear in string comparator. If all of the characters in base also appear in comparator, the function returns 0.

    The check begins at the starting position and continues to the left until a character
    that is not contained in the comparator string is found. The starting position
    defaults to the end of the string.

    The first parameter must be of type character, graphic, or UCS-2, fixed or varying
    length. The second parameter must be the same type as the first parameter. The
    third parameter, if specified, must be a non-float numeric with zero decimal
    positions.

    Example
    ---------
    *---------------------------------------------
    * If a string is padded at the end with some
    * character other than blanks, the characters
    * cannot be removed using %TRIM.
    * %CHECKR can be used for this by searching
    * for the last character in the string that
    * is not in the list of "pad characters".
    *---------------------------------------------
    D string1 s 50a varying
    D inz(â??My *dog* Spot.* @ * @ *â??)
    D string2 s 50a varying
    D inz(â??someone@somewhere.comâ??)
    D padChars C â?? *@â??
    /free
    %len(string1) = %checkr(padChars:string1);
    // %len(string1) is set to 14 (the position of the last character
    // that is not in "padChars").
    // string1 = â??My *dog* Spot.â??
    %len(string2) = %checkr(padChars:string2);
    // %len(string2) is set to 21 (the position of the last character
    // that is not in "padChars").
    // string2 = â??someone@somewhere.comâ?? (the string is not changed)
    /end-free


    *------------------------------------------------------
    * A string contains a numeric value, but it might
    * be surrounded by blanks and asterisks and might be
    * preceded by a currency symbol.
    *------------------------------------------------------
    D string s 50a varying inz(â??$****12.345*** â??)
    /free
    // Find the position of the first character that is not one of â?? $*â??
    numStart = %CHECK (â?? $*â?? : string);
    // = 6
    // Find the position of the last character that is not one of â?? *â??
    numEnd = %CHECKR (â?? *â?? : string);
    // = 11
    // Extract the numeric string
    string = %SUBST(string : numStart : numEnd - numStart + 1);
    // = â??12.345â??
    /end-free
    Thanks,
    Giri

    Comment

    Working...
    X