ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Concat message into one string

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

  • Concat message into one string

    I need to create a message with four variables.
    Variable 1: ITEM A 12
    Variable 2: TAB P 5 0
    Variable 3: Start Date A 10
    Variable 4: End Date A 10

    The message should be like this:
    Item: ITEM is already in Tab: TAB for START Date to End Date

    What is the most effective way to combine all 4 variables into one message. I am reviewing the concat option in RPG but someone have a nicer way?

    Thanks,

    DAC

  • #2
    Re: Concat message into one string

    Code:
    /free
    
       MyString = 'Item: ' + %TRIM(ITEM) + ' is already in Tab: ' + %TRIM(%EDITC(TAB : 'J'))
    + ' for ' + StartDate + ' to ' + EndDate;
    
    /end-free
    http://www.linkedin.com/in/chippermiller

    Comment


    • #3
      Re: Concat message into one string

      Code:
                                                                               
      d Message         s             52a   Varying                            
                                                                               
      d Item            s             12a   Inz( '100-A' )                     
      d Tab             s              5p 0 Inz( 3 )                           
      d StartDate       s             10a   Inz( '03/01/2011' )                
      d EndDate         s             10a   Inz( '03/15/2011' )                
                                                                               
       /free                                                                   
                                                                               
        Message = 'Item: ' + %trim( Item ) + ' is already in Tab: ' +          
                  %char( Tab ) + ' for ' + StartDate + ' to ' + EndDate;       
                                                                               
        dsply Message;                                                         
        *inlr = *on;

      Make sure to make your Message field "VARYING". This way, you can add data to the string in multiple steps, without having to %trim the blanks from the end every time. ie:

      Code:
       
      Message = 'Item: ' + %trim( Item );
      Message += ' More data added';
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #4
        Re: Concat message into one string

        Why not use a message subfile and message data? ..that's what it was made to do.
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Concat message into one string

          @Michael: Wow, I never knew varying could avoid the %TRIM method. Thanks for the tip!

          @Jamie: must confess -- haven't used msg sfls as much as I could have.
          http://www.linkedin.com/in/chippermiller

          Comment


          • #6
            Re: Concat message into one string

            Originally posted by Chipper View Post
            @Michael: Wow, I never knew varying could avoid the %TRIM method. Thanks for the tip!
            What's especially cool about it is that now you can append a number of blanks to the end of the field. For instance:

            Code:
            Message = 'New Message';
            Message += '   ';
            Message +='There will be 3 blanks between this and the New Message Text';
            If you dont use a varying field, then you will have to %trim or %trimr. In that case, there is no way to append a fixed number of blanks to the end of the field, because the next concatenation will have to make use of %trimr, which will remove them.

            By using a varying field, you can "break up" the code that loads the string, and you will always be appending at the end of the string in the exact position you want. It also executes much faster, as you dont have the trim overhead. Also, many bifs, such as %lookup and %subst process over a varying field much more quickly than one thats not.
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: Concat message into one string

              Thanks for the suggestions. If i have my start and ending dates coming in as 20010809 numeric, what is the most effective method for converting them to 08/09/2001 within the message line?

              DAC

              Comment


              • #8
                Re: Concat message into one string

                Something like this, for the date portion

                Code:
                MyDate = %char(%date(startdate:*iso):*usa)

                Comment

                Working...
                X