ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How are CLOB program variables allocated?

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

  • How are CLOB program variables allocated?

    Say I define the following:
    Code:
    Dcl-S myClob    sqltype(clob:1000000);
    A 1 Megabyte CLOB.

    Is the entire 1MB allocated immediately at program start? Or does it only allocate enough memory to hold whatever I eventually put in it?

  • #2
    The SQL precompiler converts the CLOB variable into a data structure, consisting of a length sub-field (CLOBVariableName_LEN and the sub-field (CLOBVariableName_DATA) itself.
    Since the clob variable is converted into a regular RPG data structure it behaves in the same way as a data structure, i.e. the memory is completely allocated.

    Birgitta

    Comment


    • #3
      Even if the size of the clob exceeds the usual RPGLE variable size limits?

      Comment


      • #4
        I suspect it is limited to 16Mb as any method that required more than that would basically not be directly usable within an RPG program as it would require usage of pointer based terraspace. Don't know what the max clob size is for Db2 on IBM i.

        You can easily test for yourself by compiling a program and looking at what is generated by the pre-processor. That's how Birgitta knew the original answer.

        Comment


        • #5
          Thanks all

          Comment


          • #6
            Originally posted by Vectorspace View Post
            Even if the size of the clob exceeds the usual RPGLE variable size limits?
            A CLOB variable is restricted to 16 MB (RPG's LIMIT). If you want to handle larger CLOB values you need a CLOB Locator.
            Note: A CLOB variable can be accessed and handled with RPG functions. A CLOB Locator can only be handled with (embedded) SQL functions, i.e. instead of using the RPG %SUBST you need to use the SQL SUBSTR function.

            Birgitta

            Comment


            • #7
              I did not know that I could use a CLOB with regular RPG functions, that's good to know, thanks. So I guess that means it behaves pretty much like a varchar.

              By CLOB Locator, I assume you mean the file locators, where the CLOB references an IFS file?

              Comment


              • #8
                Originally posted by Vectorspace View Post
                I did not know that I could use a CLOB with regular RPG functions, that's good to know, thanks. So I guess that means it behaves pretty much like a varchar.

                By CLOB Locator, I assume you mean the file locators, where the CLOB references an IFS file?
                There are (C) LOB locators (SQLTYPE(CLOB_LOCATOR)) and (C)LOB File Reference variables (SQTYPE(CLOB_FILE)).
                The Locateor points to JSON data located for example in a column in an SQL table and a File reference variable points to an IFS file.
                If you are working with Locators, you must run the program or the enviornment under commitment control. For File Reference variables commitment control is not mandantory

                Birgitta

                Comment

                Working...
                X