The xsql-script grammar allows to develop a procedural code independent of database which can be performed both in the back-end and in a UDR Java or in the middle-tier (Axional Studio applicaciton servers). The implementation is originally based in the concepts detailled in XEXPR (A Scripting Language For XML).

1 include

Allows to include the code programmed in the repository of includes of XSQL-Script.

From a function or xsql-script routine, you can include the code programmed in the repository of includes, usually used to particularize part of the program and also for conditional code.

From the include you can accees to all the variables visibles from the xsql-script program which includes it in the point on which is invoqued. If from a xsql-script an include that does not exist is included, the interpreter continue with the following instruction. If it exist, the include can be executed and once finished, the execution of the main code can be returned in the following line to the include.

<include
    code='code'
    name='name'
/>
Example

The following example shows a xsql-script which has an include: xsql_code=gaut_ordrepa_abono, xsql_name=before. The include perform several operations to determine the value of the m-tipdoc variable. If the includes does not exist, you should continuate with the following instruction. If it exists, the include is executed and then it goes back to the main code.

Copy
<xsql-script name='gaut_ordrepa_abono'>    
    <test unit='1'>
        <arg name='p_cabped' value='12928' />
    </test>
    <args>
        <arg name='p_cabped' type='integer' />
    </args>
    <body>
        <null name='m_tipdoc' type='string' />
        <!-- This include performs the set of m_tipdoc. -->
        <include code='gaut_ordrepa_abono' name='before' />
        <if>
            <expr>
                <isnull><m_tipdoc/></isnull>
            <or/>
                <eq><string.length><m_tipdoc/></string.length>0</eq>
            </expr>
            <then>
                <exception>
                    gaut_ordrepa_abono: The type of delivery note to generate has not been possible to generate.
                </exception>
            </then>
        </if>
    </body>
</xsql-script>
        <!-- ============================================== -->
        <!-- The code of the include could be for example:  -->
        <!-- xsql_code=gaut_ordrepa_abono, xsql_name=before -->
        <!-- ============================================== -->
        <if>
            <expr><eq><p_cabped/>21</eq></expr>
            <then>
                <set name='m_tipdoc'>CON</set>
            </then>
        </if>

2 Flow control: code NOT allowed in an include

From an include, the execution flow can not alter or close iteration statements. You can not do an continue or an exit of a loop that that started in the main code of thexsql-script (the one who invokes). For example, it can not be performed a <foreach.continue/> of a <foreach> that began to run in the xsql-script program. The code of the include should have closed code for the execution flux and it can refer to the variables of the program.

Notes

From an include can not be alter the execution flux or close the iteration statements. You can not do a continue or an exit of a loop that started in the main code of the xsql-script (the one who invokes).

The following example shows a not allowed code:

Copy
<xsql-script name='test'>
    <body>
       <foreach>
            <select prefix='m_'>
                <columns>
                    codigo
                </columns>
                <from table='table' />
            </select>
            <do>
                <include code='test' name='atforeach' />
            </do>
        </foreach>
    </body>
</xsql-script>

For the xsql-script is not allowed the following include which affects to the execution of the foreach loop.

Copy
<if>
    <expr><eq><m_codigo/><string>A</string></eq></expr>
    <then>
        <!-- Illegal code because the loop was started in the main program -->
        <foreach.exit />
        <!-- Neither will be allowed <foreach.continue /> -->
    </then>
</if>