ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Operands are not compatible with the type of operator

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

  • Operands are not compatible with the type of operator

    I'm once again being a rebel and using /free. I'm trying to do some simple string concatenation to build an sql statement. I have a piece of code that goes a little something like this...

    Code:
                 IF STATE <> *BLANKS;
                   WHERECLAUSE += ' AND CSTE='+STATE;
                 ENDIF;
    STATE is a 3A in my DDS, and WHERECLAUSE is a 75A in my program.

    What's with the error?
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

  • #2
    Re: Operands are not compatible with the type of operator

    I think += can only be used in numerical situations.

    It should probably read:

    WHERECLAUSE = %TRIM(WHERECLAUSE) + ' AND CSTE= ' + STATE;

    Note: There is a blank between the quote and the A in and as well as one after the equal sign in my example.
    http://www.linkedin.com/in/chippermiller

    Comment


    • #3
      Re: Operands are not compatible with the type of operator

      varying. WHERECLAUSE has to be created as varying.
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment


      • #4
        Re: Operands are not compatible with the type of operator

        isn't the purpose of += notation so that you don't have to waste those precious keystrokes rewriting the variable over again?
        Your future President
        Bryce

        ---------------------------------------------
        http://www.bravobryce.com

        Comment


        • #5
          Re: Operands are not compatible with the type of operator

          Originally posted by bryce4president View Post
          varying. WHERECLAUSE has to be created as varying.
          Originally posted by bryce4president View Post
          isn't the purpose of += notation so that you don't have to waste those precious keystrokes rewriting the variable over again?
          I've never tried this method -- I'll have to try this -- you may have taught me something new.
          http://www.linkedin.com/in/chippermiller

          Comment


          • #6
            Re: Operands are not compatible with the type of operator

            It works I just tried it out. And you can thank Mr. Klement. I found an example he gave in some other forum(not to be named) and the big ordeal was that the variable had to varying, otherwise doing a += on a 30A would try to concatenate it starting at position 31.

            Gotta love the dynamic fun stuff
            Your future President
            Bryce

            ---------------------------------------------
            http://www.bravobryce.com

            Comment


            • #7
              Re: Operands are not compatible with the type of operator

              yep the alternative for fixed length is well....the same ol' same ol'
              Code:
              WHERECLAUSE = %TrimR(WHERECLAUSE) + ' AND CSTE='+STATE;
              i wouldn't use %trim() since i might chop out leading blanks that were sopposed to be there....but i love the += and -= opcode usage.
              I'm not anti-social, I just don't like people -Tommy Holden

              Comment


              • #8
                Re: Operands are not compatible with the type of operator

                Yep, building the whereClause of my sql is oh so simple....
                Code:
                             IF COMP <> *ZEROS;
                               WHERECLAUSE += ' AND CCOMP=' + %char(comp);
                             ENDIF;
                
                             IF STATE <> *BLANKS;
                               WHERECLAUSE += ' AND CSTE=''' + %Trim(STATE) + '''';
                             ENDIF;
                
                             IF COUNTY <> *BLANKS;
                               WHERECLAUSE += ' AND CREF02=''' + %Trim(COUNTY) + '''';
                             ENDIF;
                
                             IF ZIP <> *BLANKS;
                               WHERECLAUSE += ' AND CZIP='''+ %Trim(ZIP) + '''';
                             ENDIF;
                
                             IF CUSTTYPE <> *BLANKS;
                               WHERECLAUSE += ' AND CTYPE=''' + %Trim(CUSTTYPE) + '''';
                             ENDIF;
                no need for anything real fancy

                If anyone knows of a way to shorten this up, then I'd be pumped. I like short speedy code
                Your future President
                Bryce

                ---------------------------------------------
                http://www.bravobryce.com

                Comment


                • #9
                  Re: Operands are not compatible with the type of operator

                  looks good to me...not a whole lot of options...i've been there, done that. it sucks but what can ya do??

                  but...i hate typing so i'd just do:
                  Code:
                  if field1 <> 0;
                  
                  or 
                  if field1 <> ' ';
                  i gave up typing *ZERO and *BLANKS a long time ago
                  Last edited by tomholden; March 6, 2008, 04:19 PM.
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment


                  • #10
                    Re: Operands are not compatible with the type of operator

                    Thanks for the tip. I'll probably do that
                    Your future President
                    Bryce

                    ---------------------------------------------
                    http://www.bravobryce.com

                    Comment

                    Working...
                    X