ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Concatenation

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

  • Concatenation

    Ok, I need some assistance here?.

    I?m trying to concatenate fields together and I?m having difficulties because, according to the manual:

    The book says?
    ?If no factor 1 is specified, factor 2 is concatenated to the end of the result field string? ? wrong, doesn?t work for me. All I get it the first field in the result field.

    The book says?
    If the number of blanks is not specified, the trailing and leading blanks of factor 1 and factor 2 are included in the result. If the number of blanks is specified, however, the trailing blanks of factor 1 are ignored and only as many blanks as specified are included in the result between the last nonblank character in factor 1 and the first character of factor 2. Leading blanks in factor 2 are always included. ? Wrong, losing my blank in position #1 of factor 2.

    Code:
                   MOVELSXCN09 $$IMPT175
    $$IMPT    CAT  SXCN10:0  $$IMPT   
    $$IMPT    CAT  SXCN11:0  $$IMPT   
    $$IMPT    CAT  SXCN12:0  $$IMPT   
    $$IMPT    CAT  SXCN13:0  $$IMPT   
    $$IMPT    CAT  SXCN14:0  $$IMPT   
    $$IMPT    CAT  SXCN15:0  $$IMPT   
                   MOVEL$$IMPT   VDIMPT
    In the above example, as it sits, I?m losing the blank at the beginning of factor 2, if one exists, so, I tried removing the ?:0?. This gave me a rather unusual outcome where the result field only contained the data contained in SXCN09! All the other data was missing.

    Than I tried removing both factor 1 and the ?:0? which also gave me the same result as before.

    Either my program has gremlins or the book is wrong!
    Everyday's a school day, what grade are you in?

  • #2
    Re: Concatenation

    Have you considered using the %trim family of BIFs? (provided can convert to ILE RPG)...

    Eval VDIMPT = %trimr(SXCN09) + %trimr(SXCN10) + %TRIMR(SXCN11)... etc.

    %trim - removes preceding and trailing blanks
    %trimr - removes trailing blanks
    %triml - removes leading blanks
    Last edited by gwilburn; August 24, 2010, 02:13 PM. Reason: Too long since i used RPG

    Comment


    • #3
      Re: Concatenation

      Hi Redvan:

      Both of these solutions result with $$impt = 'ABCDEF '

      Code:
      000001 d $$IMPT          S             15a                    
      000002 d sxcn10          S              2a   inz('A ')        
      000003 d sxcn11          S              2a   inz('B ')        
      000004 d sxcn12          S              2a   inz('C ')        
      000005 d sxcn13          S              2a   inz('D ')        
      000006 d sxcn14          S              2a   inz('E ')        
      000007 d sxcn15          S              2a   inz('F ')        
      000013 c                   eval      $$impt = %trimr($$impt) +
      000014 c                             %trimr(sxcn10) +         
      000015 c                             %trimr(sxcn11) +         
      000016 c                             %trimr(sxcn12) +         
      000017 c                             %trimr(sxcn13) +         
      000018 c                             %trimr(sxcn14) +         
      000019 c                             %trimr(sxcn15)    
      000020 c                   RESET                   $$IMPT
      000100 c     $$IMPT        CAT(P)    SXCN10:0      $$IMPT
      000200 c     $$IMPT        CAT(P)    SXCN11:0      $$IMPT
      000300 c     $$IMPT        CAT(P)    SXCN12:0      $$IMPT
      000400 c     $$IMPT        CAT(P)    SXCN13:0      $$IMPT
      000500 c     $$IMPT        CAT(P)    SXCN14:0      $$IMPT
      000600 c     $$IMPT        CAT(P)    SXCN15:0      $$IMPT
      000700 c                   EVAL      *INLR = *ON
      Best of Luck
      GLS
      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

      Comment


      • #4
        Re: Concatenation

        Originally posted by gwilburn View Post
        Have you considered using the %trim family of BIFs? (provided can convert to ILE RPG)...

        Eval VDIMPT = %trimr(SXCN09) + %trimr(SXCN10) + %TRIMR(SXCN11)... etc.

        %trim - removes preceding and trailing blanks
        %trimr - removes trailing blanks
        %triml - removes leading blanks
        Sorry, RPG III shop only.
        Everyday's a school day, what grade are you in?

        Comment


        • #5
          Re: Concatenation

          Originally posted by redvan
          Ok, I need some assistance here?.

          I?m trying to concatenate fields together and I?m having difficulties because, according to the manual:

          The book says?
          ?If no factor 1 is specified, factor 2 is concatenated to the end of the result field string? ? wrong, doesn?t work for me. All I get it the first field in the result field.

          The book says?
          If the number of blanks is not specified, the trailing and leading blanks of factor 1 and factor 2 are included in the result. If the number of blanks is specified, however, the trailing blanks of factor 1 are ignored and only as many blanks as specified are included in the result between the last nonblank character in factor 1 and the first character of factor 2. Leading blanks in factor 2 are always included. ? Wrong, losing my blank in position #1 of factor 2.

          Code:
                         MOVELSXCN09 $$IMPT175
          $$IMPT    CAT  SXCN10:0  $$IMPT   
          $$IMPT    CAT  SXCN11:0  $$IMPT   
          $$IMPT    CAT  SXCN12:0  $$IMPT   
          $$IMPT    CAT  SXCN13:0  $$IMPT   
          $$IMPT    CAT  SXCN14:0  $$IMPT   
          $$IMPT    CAT  SXCN15:0  $$IMPT   
                         MOVEL$$IMPT   VDIMPT
          In the above example, as it sits, I?m losing the blank at the beginning of factor 2, if one exists, so, I tried removing the ?:0?. This gave me a rather unusual outcome where the result field only contained the data contained in SXCN09! All the other data was missing.

          Than I tried removing both factor 1 and the ?:0? which also gave me the same result as before.

          Either my program has gremlins or the book is wrong!
          It's been a long time, but does it make a difference if you code it like this:


          Code:
          SXCN09   CAT:1   SXCN10    $$IMPT
                   CAT:1    SXCN10    $$IMPT
                   CAT:1    SXCN11    $$IMPT
          etc...

          Comment


          • #6
            Re: Concatenation

            I'm pretty sure (not positive) the cat(p) method is available in RPGIII

            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment


            • #7
              Re: Concatenation

              I found my solution....
              Code:
              SXCN01    CAT  SXCN02    $$CON1 50
              SXCN03    CAT  SXCN04    $$CON2 50
              SXCN05    CAT  SXCN06    $$CON3 50
              SXCN07    CAT  SXCN08    $$CON4 50
              SXUPC     CAT  SXRSKU    $$CON5 45
                                                
              $$CON1    CAT  $$CON2    $$CON6100
              $$CON3    CAT  $$CON4    $$CON7100
                                                
              $$CON6    CAT  $$CON7    $$CON8200
              $$CON8    CAT  $$CON5    VDCONT
              This gives me what I need.
              Thanks for your support and time.
              Everyday's a school day, what grade are you in?

              Comment


              • #8
                Re: Concatenation

                If you are a RPGIII shop only. Is it allowed to use embedded SQL?
                If so you can use the SQL functions TRIM, LTRIM and RTRIM and concate to concatenate strings:

                Example:
                Code:
                C/EXEC SQL
                C+   SET :MYTEXT = TRIM(:FLD1) CONCAT RTRIM(:FLD2) CONCAT RTRIM(:FLD3)
                C+                 CONCAT RTRIM(:FLD4)
                C/END-EXEC
                Birgitta

                Comment


                • #9
                  Re: Concatenation

                  Make sure a litter box is available before attempting the CAT(P), method

                  Comment


                  • #10
                    Re: Concatenation

                    Originally posted by Rico View Post
                    Make sure a litter box is available before attempting the CAT(P), method
                    Good one -- I love it!
                    http://www.linkedin.com/in/chippermiller

                    Comment

                    Working...
                    X