Skip to Content
0

accessing SQL Preview from a GTL template

Dec 06, 2016 at 08:59 PM

103

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Ondrej Divis Dec 07, 2016 at 11:04 AM
0

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.


Show 3 Share
10 |10000 characters needed characters left characters exceeded

Thanks. It's strange that I can't include the Code Preview in a template; I'm sure there's some logic to that, but can't see it myself.

Looks like I may have to resort to using a script to create the generated files, though it can still use templates to construct the XML wrapper. I might have to create a full bespoke process, as I need to have the DROP statements following the CREATE statements, in a <Rollback> section. Perhaps I can do it this way:

* set generation options to include CREATE and exclude DROP

* copy Preview to variable A

* set generation options to include DROP and exclude CREATE

* copy Preview to variable B

* wrap both variables in XML

How I'm going to handle ALTER statements, I don't know yet :).

0

I'm sure I can define multiple settings sets for model generation - that'll do it

0

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

0