× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello,
Maybe this can helps you:

Declaration of the variables:

       01  WORK-FIELDS.

           05  THE-STRING                  LIKE OBEC OF P001800T.
           05  FIND-STRING                 LIKE OBEC OF P001800T.
           05  MASTER-STRING               LIKE OBEC OF P001800T.
           05  PATTERN-MATCHING            PIC X(3)  VALUE 'NO '.
               88  PATTERN-NOT-FOUND                 VALUE 'NO '.
               88  PATTERN-FOUND                     VALUE 'YES'.
       ...

       01  STRING-LENGTH                   PIC  9(2) COMP.
       01  F-LENGTH                        PIC  9(2) COMP.
       01  M-LENGTH                        PIC  9(2) COMP.
       01  I                               PIC  9(2) COMP.
       01  J                               PIC  9(2) COMP.


Declaration of the Paragraphs:

       COMPUTE-LENGTH-OF-THE-STRING.
      ***  compute length of THE-STRING
           IF THE-STRING NOT = SPACES THEN
              PERFORM VARYING STRING-LENGTH FROM 42 BY -1
                   UNTIL THE-STRING(STRING-LENGTH:1) NOT = SPACE
                CONTINUE
              END-PERFORM
           ELSE
              MOVE 0 TO STRING-LENGTH
           END-IF.

       FIND-PATTERN.
      ***  detect length of the string MASTER-STRING
           MOVE MASTER-STRING TO THE-STRING.
           PERFORM COMPUTE-LENGTH-OF-THE-STRING.
           MOVE STRING-LENGTH TO M-LENGTH.
      ***  finding the pattern FIND-STRING in the MASTER-STRING
           SET PATTERN-NOT-FOUND TO TRUE.
           PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > M-LENGTH - F-LENGTH + 1 OR
                          PATTERN-FOUND
               IF MASTER-STRING(I:F-LENGTH) = FIND-STRING(1:F-LENGTH)
                  SET PATTERN-FOUND TO TRUE
               END-IF
           END-PERFORM.


Possible Usage:

      *    Moving pattern to FIND-STRING
           MOVE ZW-STRING TO FIND-STRING
      ***  Compute the length of the FIND-STRING
           MOVE FIND-STRING TO THE-STRING
           PERFORM COMPUTE-LENGTH-OF-THE-STRING
           MOVE STRING-LENGTH TO F-LENGTH
           MOVE OBEC OF P001800T TO MASTER-STRING.
           PERFORM FIND-PATTERN.
      ***  When pattern found do something
           IF PATTERN-FOUND THEN
              PERFORM something
           END-IF.




"M.Kamaleshwar" <kamal_citse@xxxxxxxxx> 
Sent by: cobol400-l-bounces@xxxxxxxxxxxx
08.11.2005 14:09
Please respond to
COBOL Programming on the iSeries/AS400 <cobol400-l@xxxxxxxxxxxx>


To
cobol400-l@xxxxxxxxxxxx
cc

Subject
[COBOL400-L] Equivalent of SCAN (as in RPG)  in COBOL/400






HI , 
 
     Can anybody help me out with this - my reqmt. is to search for the 
occurence of a string (more than 1 character) in a variable and if the 
string occurs then get the position of occurence in the variable
In RPG one can use SCAN to know whether the string is found in the 
variable as well as get starting position of the occurence. What is the 
equivalent keyword in COBOL/400 . I believe INSPECT only says whether the 
string occurs or not - it doesn't give the starting position of occurence 
of the string. 
 
Please suggest.
 
Thanks
 



 
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click. 

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.