Referencing a list in an "if" statement in an xlat

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Referencing a list in an "if" statement in an xlat

  • Creator
    Topic
  • #52517
    Tom Arrowsmith
    Participant

    I’ve been meaning to ask this for some time now… in an xlate, is there a way to avoid having to mention the field over and over again when using the “&&” or “||” operators?

    For instance, I am used to having to do the following:

    If  ~1(0).PRA(0).#3(0).[0] eq=9 ||  ~1(0).PRA(0).#3(0).[0] eq=D ||  ~1(0).PRA(0).#3(0).[0] eq=G ||  ~1(0).PRA(0).#3(0).[0] eq=H ||  ~1(0).PRA(0).#3(0).[0] eq=J ||  ~1(0).PRA(0).#3(0).[0] eq=K ||  ~1(0).PRA(0).#3(0).[0] eq=M ||  ~1(0).PRA(0).#3(0).[0] eq=N || ~1(0).PRA(0).#3(0).[0] eq=O || ~1(0).PRA(0).#3(0).[0] eq=P  

    then do….

    Is there a way to cut down on the typing here?

    I’m used to things like Crystal where you can say if value is IN {9, D, G, H, J, K, M, N, O, P} then do…..

    thanks for any advice…..

    tom

Viewing 9 reply threads
  • Author
    Replies
    • #74524
      Chris Williams
      Participant

      Several options come to mind:

      (1) In later CL versions, the IF statement has the string operator “ct” for “Contains”.

      (2) If you’re just concerned about the keystrokes, you could copy the field reference to an @variable and use that instead.

      (3) You could do some tcl with [lcontain list element] before your IF to see if conditions are met and put the result (0 or 1) into an @variable and use that in your IF statement.

    • #74525
      Jim Kosloskey
      Participant

      How about using a lookup table?

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #74526
      Rehman Masood
      Participant

      Jim Kosloskey wrote:

      How about using a lookup table?

      +1. I was going to suggest the same thing.

    • #74527

      I’d do it in tcl.

      -- Max Drown (Infor)

    • #74528
      ian.smith
      Participant

      Chris Williams wrote:

      Several options come to mind:

      (1) In later CL versions, the IF statement has the string operator “ct” for “Contains”.

      (2) If you’re just concerned about the keystrokes, you could copy the field reference to an @variable and use that instead.

      (3) You could do some tcl with [lcontain list element] before your IF to see if conditions are met and put the result (0 or 1) into an @variable and use that in your IF statement.

      To elaborate on Chris’s options:

      COPY

      Source: =9 D G H J K M N O P

      Destination: @temp_var

      IF

      @temp_var ct ~1(0).PRA(0).#3(0).[0]

    • #74529
      Jim Beall
      Participant

      I need to check PR1.18 and if it’s one of five values do the same thing.  If I understand this right, instead of doing a bunch of “ors” I could do this:

      COPY

      Source: =ED OPS OBV CLI QER

      Destination: @temp_var

      IF

      @temp_var ct ~0(0).PV1(0).00148(0)

      Just want to confirm because the syntax seems almost backwards to me.  Thanks

    • #74530
      Chris Williams
      Participant

      Sounds right to me.

      IF contains

    • #74531
      Jim Beall
      Participant

      I ended up going back to multiple OR’s.  The value OP returned true for the variable containing ED OPS OBV CLI QER which I didn’t want.  I assume it did that because it matched the first two letters in OPS – or maybe I implemented it incorrectly?  Still good to know though; this will come in handy in the future.  Thanks!

    • #74532
      Chris Williams
      Participant

      We probably should have mentioned that. The ct operator looks for a pattern that matches anywhere in the string on the left side of the equation, similar to tcl’s [string first]. It is not comparable to [lcontain] which matches on list-elements. You can resolve the issue you encountered by using separators in the string of all your choices and also use them along with the item you are testing for to get a more exact match.

      Using your example, you could change the left side to “.ED.OPS.OBV.CLI.QER.” and add the separator character both before and after the right side item. “.OP.” to avoid matching on substrings.

    • #74533
      Ian Morris
      Participant

      Jim Beall wrote:

      I need to check PR1.18 and if it’s one of five values do the same thing.

Viewing 9 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10