Skip to Content

accessing SQL Preview from a GTL template

I want to create a model generation in a PDM that wraps XML around the SQL Preview (see my earlier question about Liquibase). It should be easy, all I need to do in a GTL template is define an XML wrapper as text, and insert %Preview% inside it. However, it won't let me insert it inside a template. So, I tried creating an extended attribute set to the value of obj.Preview, and then containing the result of GetPreview() - same problem with both of these.

If I can't include the SQL preview, I'll have to create my own SQL generation from scratch, which I'd rather not do.

Has anyone cracked this problem?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Dec 07, 2016 at 11:04 AM

    Hi George,

    I am afraid, that you will have problem going the GTL way. However, I was able to create computed extended attributes. See my attached screenshot (using PD 16.5 SP05 PL03). There are also the codes used for filling all three ext.attributes.

    As you can see in myPreview, I am using obj.Preview together with other strings. Unfortunately obj.Preview contains both the SQL Preview and contents of all Generated files in your def.file and extensions.

    GetPreview shows usage of obj.GetPreview() function, allowing you to display ONLY content of one chosen Generated File. You can put some additional text here too.

    combinedPreviews uses everything together: obj.Preview, additional text, obj.GetPreview and also direct evaluation of Template using EvaluateTemplateFor() method.


    I think, that this could solve your issue, but I see one potential obstacle here. If you have both some generated files and want to use ONLY your SQL preview (without Generated files) for wrapping into your XML wrapper, you will have no other option, than to use obj.Preview and then manually remove all Generated Files from that text. It will not be difficult, you can simply delete everything behind third occurence of the line: "//-----------------", but it will be far from being clean and elegant.

    HTH,
    Ondrej

    P.S. You can maybe let us know later, how you decided to solve this. I think your question was a good topic and it caught my attention.

    ,

    Hi George,

    I am afraid, that you will have problem going the GTL way. However, I was able to create computed extended attributes. See my attached screenshot (using PD 16.5 SP05 PL03). There are also the codes used for filling all three ext.attributes.

    As you can see in myPreview, I am using obj.Preview together with other strings. Unfortunately obj.Preview contains both the SQL Preview and contents of all Generated files in your def.file and extensions.

    GetPreview shows usage of obj.GetPreview() function, allowing you to display ONLY content of one chosen Generated File. You can put some additional text here too.

    combinedPreviews uses everything together: obj.Preview, additional text, obj.GetPreview and also direct evaluation of Template using EvaluateTemplateFor() method.


    I think, that this could solve your issue, but I see one potential obstacle here. If you have both some generated files and want to use ONLY your SQL preview (without Generated files) for wrapping into your XML wrapper, you will have no other option, than to use obj.Preview and then manually remove all Generated Files from that text. It will not be difficult, you can simply delete everything behind third occurence of the line: "//-----------------", but it will be far from being clean and elegant.

    HTH,
    Ondrej

    P.S. You can maybe let us know later, how you decided to solve this. I think your question was a good topic and it caught my attention.

    Add comment
    10|10000 characters needed characters exceeded

    • Arnaud at SAP kindly provided me with information on how to change the DB generation options in a script, so I don't have to rely on settings files. For example, the following code changes the options to prevent table Create statements being output, and allow Table Drop statements, then displays the SQL Preview for every table in the model in the Script tab of the Output window. There are a lot of options you may need to set if you're generating a preview for a whole database. See the Metamodel Objects Help - look for

      BasePhysicalPackageOptions within pdPDM.

      Set opts = activemodel.GetPackageOptions()

      dim myTab

      opts.GenerationCreateTable = false

      opts.GenerationDropTable = True

      for each mytab in activemodel.Tables
      if not mytab.isshortcut() then
      output vbcrlf & " ****** " & mytab.Name & vbcrlf & mytab.GetPreview("SQL")
      end if
      next