ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Searching A Field...

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

  • Searching A Field...

    I was wondering if this is possible: I want to search a field in a database file for a specific value that could contain data before and/or after the value.

    What I am trying to do is search a field that contains names and email addresses and whenever a specified email address is found branch to call another program. Data in the field may look like "Anybody ".

    How is this done in RPGLE?

    Thanks in advance for your help!

    Josh

  • #2
    It would like something like this

    Here is a simple example ...
    You will want to play around with the SCAN stuff to extract the email address.

    if you show me more examples of the data
    I can show more scan processes

    Code:
    fSOMEFILE  IF a E           K DISK
         Ã?*
         Ã?* constants for translation to upper case
         Ã?*
         d Up              C                   const('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
         d Low             C                   const('abcdefghijklmnopqrstuvwxyz')
          *
         d found           S              5  0
         d Str             S              5  0
         d End             S              5  0
         d Len             S              5  0
         d Email           S             50
          *
          * Anybody 
          *
         c                   read      SOMEFILE
         c                   dow       not%eof(SOMEFILE)
          *
         c                   eval      found = %scan('.com'  : SOMEFIELD)
          *
         c                   if        found > *zeros
         c                   exsr      $callprogram
         c                   endif
          *
         c                   read      SOMEFILE
         c                   enddo
          *
         c                   eval      *INLR = *on
         Ã?*-----------------------------------------------
         Ã?* $callprogram - call some program
         Ã?*-----------------------------------------------
         c     $callprogram  begsr
         Ã?*
         c                   eval      Str = %scan('<' : SOMEFIELD)
         c                   eval      End = %scan('>' : SOMEFIELD)
         c                   eval      Len = End - Str
         c                   eval      Email = %subst(SOMEFIELD:Str+1:len)
         c                   call(e)   'PROGRAM'
         c                   parm                    EMAIL
         Ã?*
         c                   endsr
         Ã?*-----------------------------------------------

    This will translate lowercase to upper if you need to do this in the scan.

    Code:
         C* BeforeString = my name is jimmyoctane
         C* AfterString =  MY NAME IS JIMMYOCTANE
    
         C                   Eval      AfterString = %xlate(Lo:Up:BeforeString)

    hope this helps


    jimmy

    Comment


    • #3
      but not just .com

      You would be better to use jimmy's method by searching for the "@" symbol, since .com doesn't exist in all email addresses. However, the %scan or SCAN opcode is the way to scan any string.

      Comment


      • #4
        Thanks so much! This is exactly what I needed!

        Comment

        Working...
        X