ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using QXXCHGDA API

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

  • Using QXXCHGDA API

    I have an RPGLE program and was wanting to use the QXXCHGDA in it. No matter what I try however, I keep getting error "CPF1088 - Starting position outside of data area." I have no idea what I'm doing wrong on this. My test DTAARA is a character DTAARA, 10 characters long. My test code is:

    Code:
         D ChgDtaAra       PR                  ExtPgm('QXXCHGDA')
         D  prQualDtaAra                       LikeDS(qualdtaara) Const
         D  prStart                            Like(startpos)
         D  prLength                           Like(length)
         D  prNewData                      *
    
         D QualDtaAra      DS                  Qualified
         D  Name                         10a   Inz('TESTARA')
         D  Library                      10a   Inz('TESTLIB')
         D StartPos        S              5i 0 Inz(1)
         D Length          S              5i 0 Inz(4)
         D ptrNewData      S               *   Inz(%Addr(newdata))
         D NewData         S           2000a   Inz('Test')
    
          ************************************************************************************
          /FREE
    
           ChgDtaAra(qualdtaara : startpos : length : ptrnewdata);
    
           *INLR = *ON;
    
          /END-FREE
    Changing the size of NewData to match the DTAARA size makes no difference (though I didn't think it would) though I don't want to do that as eventually it should be able to updated others with different lengths. Any help appreciated.

  • #2
    You main problem is that the start and length parms should be ints (10 i) not shorts (5 i) make that change and it works just fine. The manual definition is confusing because it does say short int.

    I would also change the last parm to be just a regular char field (with const if you wish) - that avoids the need for ptrNewData and makes the whole thing a lot more obvious to those who come after.

    You know you don't need /Free and /End-Free right?

    By the way - why use the API at all and not just use RPG's native Data Area support? Again it will be far more obvious to those who come after you.

    Comment


    • #3
      Thanks for that. Never thought of changing that as, well the documentation does say short int. I used the pointer because the API needed one but as the system will pass the parm as a pointer anyway, you're right it's not needed.

      As to the /free /end-free - you're making assumptions ;-) Yes, I do need to use that as we're still on V6R1... Which also explains the D specs... We're finally in the process of upgrading though so will be able to get rid of that and go fully free-form soon.

      I thought about using native IN/OUT, however the process will use different DTAARAs of different lengths and it didn't seem to like me creating a very long variable when the DTAARA was much shorter so this seems to be the only way?

      Comment


      • #4
        Originally posted by john.sev99 View Post
        I thought about using native IN/OUT, however the process will use different DTAARAs of different lengths and it didn't seem to like me creating a very long variable when the DTAARA was much shorter so this seems to be the only way?
        In that case I would suggest wrapping the API calls as subprocedures to make what is going on more obvious to future maintenance programmers. That way they don't have to know how it is being done. Personally I tend to use User Spaces rather than Data Areas because they are less restrictive and can be updated like any other variable in a program.

        Comment


        • #5
          You couldn't use one long DTAARA field in your RPG program anyway. RPG doesn't allow the actual data area to have a different length than than the RPG field length. So you'd need a separate field with its own DTAARA keyword in your RPG program for each possible length of data area. Using this API, or the CHGDTAARA command, seems like the right way to go.

          Comment

          Working...
          X