ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Strange problem varying field

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

  • Strange problem varying field

    Hello,


    I have a very strange problem using varying fields in RPG. We are running on V7R2.

    I 've defined these three fields:

    Code:
    d Wrk_XML         s               a   len(131064) varying  
    d Wrk_S1          s               a   len(5000) varying    
    d Wrk_S2          s               a   len(5000) varying
    I than run the following code. The TestEncode function does not in particular here, but in the real business case I want to do something there. This is just to show te problem.

    Code:
    Wrk_XML = '';
    Wrk_S1 = 'Anthonis';
    Wrk_S2 = 'Kristof';
    Wrk_XML = Wrk_XML + '<Subject>' +
                          TestEncode(
                          'LabResult ' +
                          Wrk_S1 + ' ' + Wrk_S2) +
                          '</Subject>';
    
    p TestEncode      b                                               
    
    d TestEncode      pi              a   len(5000) varying           
    d pi_s                            a   len(5000) const varying     
    
     /free                                                                                                                               
      Return pi_s;                                                    
     /end-free                                                        
    
    p TestEncode      e
    The result in Wrk_XML = "<Subject> @#%t Anthonis Kristof</Subject>"
    So, that is not correct.

    When I change the definition of WRK_XML to

    d Wrk_XML s a len(131063) varying

    The result in WRK_XML = " <Subject>LabResult Anthonis Kristof</Subject>"
    That is correct.

    Can anyone explain this: why is this working ok for a length of 131063 or less, and not ok for 131064 and above??

  • #2
    Does it work if you define Wrk_XML as VARYING(4) ?

    Comment


    • #3
      Thanks
      No, I 've just tried but the problem stays te same. Ok for length 131063 or less, not ok for 131064 or more.

      Comment


      • #4
        That has to be a compiler bug and should be reported to IBM - or at least check your PTF levels. I just tried it on 7.3 and got similar results. It is a weird combination problem because if I assign the consolidated string to a fixed length field then it also works. Similarly if I take the Wrk_XML = Wrk_XML + '<... and just make it Wrk_XML = '<... that also produces the correct result. So the issue is with varying length fields in the build string. For sure a compiler error.

        P.S. Those are the strangest D specs I've ever seen - I'm actually a little surprised that they work. You're mixing free-form (Len) with fixed form D. Very odd - why not do one or the other. I even wondered if it might be the cause of the problem but it is not.

        Comment


        • #5
          Just did an additional test. It is actually the call to the subproc that is screwing it up. If you remove that call and simply concatenate the variables into the result it works just fine.

          Comment


          • #6
            Thanks Jon. I will open a call with IBM than. Do they respond fast to this kind of problem?

            You 're right about the len keyword and I 'd better put d-specs in free as well, but as you noticed yourself, that is not the problem.

            Comment


            • #7
              That 's right, but I need the call in my real situation. So, still need to turn to IBM than I guess?

              Comment


              • #8
                This works too. What fun!
                Code:
                       Wrk_XML = TestEncode(
                
                                             'LabResult ' +
                
                                             Wrk_S1 + ' ' + Wrk_S2);
                
                       Wrk_XML = '<Subject>' + Wrk_XML +
                
                                             '</Subject>';
                In a weird way it is possibly related to this PTF http://www-01.ibm.com/support/docvie...id=nas3SI39038

                Reason for thinking that is that the value being returned is screwed up when embedded in a concatenation. BUT if you modify the subproc logic like this:

                Code:
                     p TestEncode      b
                     d TestEncode      pi          5000a   varying
                     d pi_s                        5000a   const varying
                
                     d result          s           5000a   varying
                
                       result = pi_s;
                
                       Return result;
                Since your real code is not likely to simply return the parm passed in then the real thing should work OK.

                BUT this really needs to be reported as it is a potentially nasty little error.

                And now back to real work.

                Comment


                • #9
                  Originally posted by Tonny00400 View Post
                  Thanks Jon. I will open a call with IBM than. Do they respond fast to this kind of problem?
                  IF there is already a fix available it should be a fast response. Not quite so quick if they have to fix the compiler as until they determine the scope of the problem there's no way to know.

                  Luckily, as I mentioned in a later post it, would appear that if you actually code your subproc it is going to work anyway as long (I suspect) as you don't assign the return value to the inbound parameter.

                  Comment


                  • #10
                    Jon, I know that works. But like you said, it can be a real issue when you 're not aware of it.
                    When you 're talking about strange: try copying this part of code a second time for another name. The second time it works!

                    Code:
                    Wrk_XML = '';
                    Wrk_S1 = 'Anthonis';
                    Wrk_S2 = 'Kristof';
                    Wrk_XML = Wrk_XML + '<Subject>' +                      
                                          TestEncode('LabResult ' +
                                          Wrk_S1 + ' ' + Wrk_S2) +
                                          '</Subject>';  
                    
                    Wrk_XML = '';  
                     Wrk_S1 = 'Test';  
                     Wrk_S2 = 'Person';  
                     Wrk_XML = Wrk_XML + '<Subject>' +            
                                           TestEncode( 'LabResult ' + Wrk_S1 + ' ' + Wrk_S2) +
                                           '</Subject>';

                    Comment


                    • #11
                      Make sure you give that data to IBM. Looks like it may be a simple case of some intialization not being done on the first call.

                      Comment

                      Working...
                      X