ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Defining APIs with char(*)

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

  • Defining APIs with char(*)

    Hello,

    Some API's have multiple result formats, i.e. a couple for QUSRMBRD;
    MBRD0100 Member name and basic source information. This is similar to the information provided by the List Database File Members (QUSLMBR) API using format MBRL0200. See MBRD0100 Format.
    MBRD0200 Member name and expanded information. The additional information requires more system processing and takes longer to produce than the MBRD0100 format. See MBRD0200 Format.

    I'm under the impression then that the first API variable is char(*) due to the fact there are multiple result types (due to varying sizes);
    1 Receiver variable Output Char(*)
    Using MBRD0100 as an example; the final field "source file" has on offset of 134 and a length of 1a, does this mean then that the "receiver variable" length on the QUSRMBRD definition is 135a? I've called it and the results seem fine but I just wanted to check.

    Cheers,
    R

  • #2
    char(*) means that there are multiple sizes that the API is capable of receiving. You have to read the text to determine what the actual sizes are.

    In the case of QUSRMBRD -- as well as many other APIs -- the 2nd parameter (Length of receiver variable) is what you should pass to tell the API what length you're passing for the first parameter. So if your RPG variable is CHAR(50), then you pass 50 in the 2nd parameter. If it is CHAR(135), then you pass 135 in the second parameter. I strongly recommend that you NEVER hard-code the 2nd parameter, but instead use the %SIZE() BIF. The API should allow any length -- the important part is that you are accurate in telling it the size you're providing.

    If you want to receive the ENTIRE MBRD0100 format, then you'd define a data structure, which contains all of the fields. Yes, you're right that it should work out to be 135 long, but I wouldn't hard-code that anywhere. Just define the data structure with all the fields, and then pass %SIZE(my-ds-name) for the 2nd parameter.

    Comment


    • #3
      Hi Scott,

      Thanks for the reply.

      I'm also against hardcoding, even if you know what something is always going to be.

      I was passing %len(myDatastructure), I'll switch to using %size albeit, even after reading the ibm docs, i'm not 100% clear on the differences in the case of standard datastructures.

      Cheers,
      R



      Comment


      • #4
        The difference in this specific case would just be semantics.

        %LEN = current length in digits or characters.
        %SIZE = amount of memory used in bytes.

        Since data structures always use characters that are one byte long, and the length of the structure itself cannot be "varying", %LEN and %SIZE should be the same for a data structure. Will that still be true 5 years from now? 10 years from now? These are more interesting questions, since its hard to forsee what changes IBM will make to data structures down the road. At some point, there might be a difference.

        Since the API is looking for the amount of memory, not the current text length, use %SIZE.

        Comment


        • #5
          Ah ok, that's makes a lot more sense now - thanks.

          Comment

          Working...
          X