ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Is there command LIKE in COBOL?

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

  • Is there command LIKE in COBOL?

    Hello all...

    Wondering if there is a command in COBOL that functions similar to LIKE when you run queries? I know if I run a query on a file and have a 30 character field...if I want to know if a certain sequence or word is there but am unsure the exact position, I can say LIKE '%word%' and query will return matching results. I need to do something similar within my program and am unsure how to go about it in the best, most efficient way in COBOL.

    I know from past lives in RPGLE shops, that you can code for LIKE but am not sure if COBOL has a similar command.

    If anyone has a viable solution to this problem, I'd appreciate hearing it.

    Thanks...

    Caren

  • #2
    Re: Is there command LIKE in COBOL?

    Personally I use the Scan for String Pattern (QCLSCAN) API which is much more useful than the INSPECT stm.
    Code:
    Field                           
    STRING                     <== The field to be scanned
    STRLEN                     <== The length of the string to be scanned
    STRPOS                     <== Starting position
    PATTERN                    <== Value to scan
    PATLEN                     <== Length of character(s) to scan
    TRANSLATE                  <== No translation to upper char required
    TRIM                       <== Blank characters trimmed
    WILD                       <== No wildcard character
    RESULT                     <== A value returned to your program
    
    Call "QCLSCAN" Using STRING, STRLEN, ..., RESULT.
    
    If RESULT > 0  ==>  PATTERN found and the result is the position of
     the first character of the pattern in the string.
    Check out the QCLSCAN API for more details.

    Also an example here.
    Last edited by Mercury; September 8, 2009, 09:58 AM.
    Philippe

    Comment


    • #3
      Re: Is there command LIKE in COBOL?

      Perhaps, if allowed, you could go for the embedded SQL option.

      However, if you are modifying an existing program and need to find an equivalent to the %Scan of RPGLE, I guess the API provided by Mercury would help

      Comment

      Working...
      X