HOWTO:Compiling

From Remain Software
Jump to navigation Jump to search

Back.gif

Compiling - How to Compile

How to define a Compile Type

You can create a compile type by entering the Type Maintenance function. You can change the Type Variant in the top of the display to '0' which should already be the default.

You can use option 3 to copy a Type or press F6 to add a new Type.

Defining Compile Commands

After the type is added you can use option 12 to work with the Type Details. This will bring you to screen OMC02001 where you can add compile commands and commands that need to be executed at the end (post) or at the beginning (pre) of the compile command. You may have many pre- and post commands but only on compile command.


Omc02001.png


Press F6 to add or option 2 to change a pre-, compile- or post command.


Omc02002.png


Command Type
Specify the execution moment of the command.
  • '1' or *PRE

This command type must be used for the Pre-create object commands.

  • '2' or *COMPILE

This command type must be used for the create object commands.

  • '3' or *POST

This command type must be used for the Post create object commands.

Sequence
This field determines the order of execution in case you have multiple pre- or post commands.
Behavior on error
  • '0' Always

This command will be executed regardless of the result of any previously executed commands.

  • '1' Not if Error

This command will be executed only if the previous commands were successfully executed.

  • '2' If Error

This command will be executed if any of the previous commands ended in error.

Command
Specify the command to be executed. The command may contain substitution variables and/or user-defined variables.

Specify pre and post compile commands

Pre- and Post compile commands are part of the compile type.

If pre- and post commands are needed depends on the type of command. Pre- and Post commands that are associated with the managing of the objects are done by TD/OMS. This means that you do not have to worry about removing indexes and logicals from a table before compilation.

Compilation Library List

The compilation library list is set in the Environment Maintenance function. You can set the compilation libraries in many different and easy ways. Please read the following topic.

How to Compile during Transfer

Setup the Compile Instructions with Type Maintenance

Use the Type Maintenance (STRTCM) function to create Compile instructions and attach these to a selection (i.e. when should this compile be executed)

Define a Compile Action

The Action "Compile using types" is already shipped with TD/OMS. If this is not the case follow these instructions on how to create the compile action

Define a Compile Action Group

The Action Group is already shipped with TD/OMS. If this is not the case follow these instructions on how to create the compile group. Then add the action to the action group

Define an Action Selection

Attach one or more Action Selections to the group to determine when the Compile Group should be executed. An example can be found here.

Create SQL with RUNSQLSTM

If you want to create your database with SQL instead of DDS then the "compile" command is RUNSQLSTM.

Caveats

How to use the library list with RUNSQLSTM

RUNSQLSTM assumes that all your tables and indexes are in your target schema. This is often not the way we work in IBM i. Our community is happy to create a logical in DEV over a physical in TST. The RUNSQLSTM command is not designed to handle this and most other databases do not even support this feature.

You can use the Default Collection (DFTRDBCOL) parameter to point to a specific schema but this will not take the library list into consideration. Using the DFTRDBCOL parameter will create your SQL object in this library but it also assumes that all references are also in this library.

It so happens that if you leave the DFTRDBCOL set to *NONE then the library list will be used to create the SQL object. However, your object will be created in the same library as the reference object so this is not a complete solution.

In order to take advantage of the library list (DFTRDBCOL is set to *NONE) we need to qualify the target element in the SQL source. We can use a TD/OMS variable for this:

  CREATE INDEX &TOOL/MYINDEX ON MYTABLE

When you pre-process the source before compile with the SBSVAROMS command, it will replace &TOOL with the correct target library:

 SBSVAROMS SRCF(&SRCL/&SRCF) SRCM(&SRCM) TSRF(QTEMP/&SRCF) TSRM(&SRCM) BUF(&BUF)

Howto createSQL01.png

PLEASE NOTE: We now use QTEMP as the source location because that is where the source is converted to


SBSVAROMS and QTEMP source member

In the example above we described how to use QTEMP as an intermediate source library. In some cases this can conflict with the SQL preprocessor when creating a Function and possible other SQL artifacts.

Assume a DB2 function entirely in SQL:

Pre-Compile:

SBSVAROMS to QTEMP/QSQLSRC(EXAMPLE)

Compile:

RUNSQLSTM from QTEMP/QSQLSRC(EXAMPLE)

Source Code:

CREATE FUNCTION &TOOL.EXAMPLE( "ORDER" DECIMAL(8, 0),
                                    ITEM VARCHAR(35),
                                    QTYPROD DECIMAL(11, 3) )
      LANGUAGE SQL

This fails. This is because the DB2 function actually creates a CLE *SRVPGM called EXAMPLE. To do this, it takes the SQL member, precompiles it to C code, and then compiles the *SRVPGM using the C compiler. The precompiled C code is stored in QTEMP/QSQLSRC(EXAMPLE) as well as QTEMP/QSQLT00000(EXAMPLE). When the SBSOMSVAR command is used to QTEMP, the precompiler cannot overwrite the member in QTEMP/QSQLSRC(EXAMPLE) because it is in use.

In order to get around this change the SBSVAROMS destination source file to use QTEMP/&SRCFX (this will lead to use a source file appended with 'X', e.g. 'QSQLSRCX') and then the RUNSQLSTM to match:

Pre-Compile:

SBSVAROMS to QTEMP/&SRCFX(EXAMPLE)

Compile:

RUNSQLSTM from QTEMP/&SRCFX(EXAMPLE)

This completes successfully.

Create SQL with RUNSQLSTM from IFS

The RUNSQLSTM can also process sources from the IFS.

How to use the library list with RUNSQLSTM

RUNSQLSTM assumes that all your tables and indexes are in your target schema.

You can use the Default Collection (DFTRDBCOL) parameter to point to a specific schema. Using the DFTRDBCOL parameter will create your SQL object in this library but it also assumes that all references are also in this library.

Substitution variable &TIOL (To IFS Object Library)

To be able to run the DFTRDBCOL parameter in the RUNSQLSTM substitution variable &TIOL is available in the compile commands.

IfsCompileCommand.png

How is the “To IFS Object Library (&TIOL)” determined.

The “To IFS Object Library” is retrieved from the Environment definitions.

The library list sequence of the IFS file (Route) is retrieved and used to determine the corresponding target library (&TIOL):

  1. The sub-environment is searched with the “Location type” for the IFS file.
  2. If no target found then a search is done for object type “*STMF”.
  3. If still no target is found the *ALL library will be used.

How to use the Source Attribute in selections

The source attribute is filled with the extension of the IFS file, e.g. for *STMF “Customer.PFSQL” the source attribute is “PFSQL”. This source attribute can then be used as selection criteria in:

Parallel Compile

The TD/OMS parallel compile option enables you to define a job queue for objects that can be compiled in parallel, like programs. Suppose you have a task with 5 files and 50 programs. After the files are compiled one by one, the programs can be compiled in parallel.

In order to activate parallel compiles, you have to create a job queue that will release multiple jobs at a time. How many depends on you. You can use the job queue OMSJOBQ that is created in the TD/OMS subsystem or you can create one yourself.

After the job queue is created you have to add the single and parallel queues to the system registry.

Since
This function is available since V11.0M01 HOWTO:Compiling/Get a compile listing in RDi/en

How to Override the Default Compile Command

In the green screen you may go to the fix maintenance function (STRFM) use option 12 to work with solutions and then use option 12 to override the compile commands for this specific object.

Using the GUI

The TD/OMS Compile View enables you to overrides creation commands for the selected component. You will see in this section that sometimes we talk about Create and sometimes about Compile, we mean the same thing (strictly speaking, the compilation is just one way to create something). Compile overrides are create commands that differ from the normal commands for this specific type. Suppose you want to create all physical files with MAXMBRS(1) except for some special files. We are going to take this example in the following explanation.


TD/OMS Compile View

Open the Compile View by using the "Show in" context menu on a solution or component. In our case, we have selected file OMAPP. The following view is opened:


Ewm com01.png


The view shows overrides on the selection tab. In this case, there is already an override for this file when it is created in environment *DEV in application DEMO. If you click on this line then its create commands are loaded on the tab "Create Commands for Selected Line". Click on this tab to see the create commands for this selected line. If you want to see the default create commands for this object then press CTRL and click on the line again. The will be "unselected" and the second tab will change the contents to "Default Create Commands (not editable)". The default create commands for this component can then be viewed.

Creating a new Override

Press the big green Plusbutton.png button to create a new override selection. The "Copy Selected Set" tickbox determines if you want to copy the creation commands for the selected line into the new override. If you untick this box, the default create commands will be copied for this new override.


Ewm com02.png


The tick boxes indicate the selection for which this override is active. If you leave all the tick boxes unselected as shown in the previous picture then this override will be active for all occurrences of this file. You can restrict when the override is active by selecting one or more selection boxes.


Ewm com03.png


In this case we want to make one additional override to compile the file always with the MAXMBRS(*NOMAX) setting anywhere in the DEMO application. Tick the Application box as indicated in the above picture. Press the "Finish" button to create the override.


Changing the creation commands

Ewm com04.png


The "Selections" tab will be loaded with our new entry and it will be automatically selected. Selecting a line in the "Selections" tab will load the create commands in the "Create Commands for Selected Line" tab. Click on the tab to reveal the commands. Please note that the "Object Data" section will be collapsed to make more room for the create commands. If you wish, you can expand it manually.


Ewm com05.png


As you can see from the image, there are already compile commands created for this new entry. If you want to remove one of the default commands you can select it and press Deletebutton.png to remove it.

To create a new compile command, select the middle line that says "Compile Commands" and then press the Plusbutton.png button.


Ewm com06.png


a new wizard will pop up that enables you to create a new command. The command can be created in the "Pre" ,"Compile" or "Post" section. Since our view is already filled correctly, we just press "Finish". If you get a warning telling you that the sequence is already taken or the Finish button is not enabled, then press the "Check Availability" button to tell you if the sequence is available. Change the sequence if needed. There can only be one compile command, but many pre and post commands.

Also, specify the Behavior on Error field to indicate if you want this command to be executed:

No Error
Execute this command if no errors were found in any of the preceding commands.
Error
Execute this command if errors were found in any of the preceding commands. You can use this field to send a message or do error recovery.
Always
Always execute the command no matter how the previous commands ended.

Ewm com05.png


When we return to the Compile view we see that the compile command is copied from the default compile command. All we have to do is to alter our command and we can do that by pressing the "Prompt" (Promptbutton.png) button.

Ewm com08.png


In the prompt dialog we can change the values that we want and press "Finish" Please note that you can use Substitution variables that will be filled in by TD/OMS.


Ewm com09.png

Finally, press the "Save" button to save your work.

If you select a solution for Compile, you will see that the new compile command is active.

Compilation command execution hook

The execution of the compilation instructions has been moved to the user program OMC022EXC. The source of this program can be found in the QUSRSRC file. See the program source for additional instructions.