4.6.1 Private, Temporary Variables

    Temporary variables are created by RES-Reach programmers to hold temporary state information local to a particular NBT template file. They are the _PRI group of variables. If other variables (e.g. a form variable) have the same name, and the group has not been specified, then the value of this type of variable will be used when variable substitution is performed. See the discussion on precedence in section 4.1.1 above.

    Syntax:

    
    	<SET VARIABLE="varname" VALUE="some string">
    
    
    creates the temporary variable and assigns it a value.

    It is referenced by the

       {varname}
    or
       {_PRI.varname}
    syntax.

    When you set the value of a _PRI variable, do not prefix it with "_PRI": THE TAG DOES NOT RECOGNIZE THIS AS THE GROUP NAME. For example,

    
       <SET VARIABLE="TEMP" VALUE="joe">
    
    
    creates a temporary variable named "TEMP" which can be accessed with the notation
    {TEMP} or {_PRI.TEMP}.
    
       <SET VARIABLE="_PRI.TEMP" VALUE="SAM">
    
    
    creates a temporary variable named "_PRI.TEMP" which can only be accessed with the notation
    {_PRI._PRI.TEMP}.

    Values assigned to temporary, local variables are not escaped by RES-Reach; they are considered to be neither input nor output.

    Examples:

    Example 1: In this example, private variables are used to store the status of certain queries. This allows queries to be closed quickly instead of keeping them open just to have access to the status. Errors in complex transactions can also be processed properly.

    	<SET VARIABLE="CatSaved" VALUE="TRUE">
    	<![ Make sure the new category does not already exist. ]>
    	<DATA SQL="SELECT * FROM Category WHERE VendorCode='{[VendorCat.VendorCode]}' AND CategoryId='{NewSubCategoryId}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="READONLY", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    	<RECORD>
    	</RECORD>
    	<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    		<SET VARIABLE="CategoryExists" VALUE="FALSE">
    	</IF>
    	<IF VARIABLE="{TotalRows}" OPERATOR="NE" COMPARISON="0">
    		<SET VARIABLE="CategoryExists" VALUE="TRUE">
    	</IF>
    	</DATA>
    	<IF VARIABLE="{CategoryExists}" OPERATOR="EQ" COMPARISON="FALSE">
    		<[! Find the parent category. ]>
    		<DATA SQL="SELECT DISTINCTROW CategoryLevel, CategoryLevel+1 AS ChildLevel, NoOfSubcategories FROM Category WHERE VendorCode='{[VendorCat.VendorCode]}' AND CategoryId='{CategoryId}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="READONLY", ALIAS="ParentData", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    		<RECORD>
    			<SET VARIABLE="CategoryLevel" VALUE="{[ParentData.CategoryLevel]}">
    			<SET VARIABLE="NoOfSubcategories" VALUE="{[ParentData.NoOfSubcategories]}">
    		</RECORD>
    		<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    			<SET VARIABLE="CatSaved" VALUE="FALSE">
    		</IF>
    		</DATA>
    		<![ Continue only if the parent category was found. ]>
    		<IF VARIABLE="{CatSaved}" OPERATOR="EQ" COMPARISON="TRUE">
    			<![ Insert the new category. ]>
    			<DATA SQL="INSERT INTO Category (CategoryId, VendorCode, ParentCategoryId, NoOfSubcategories, CategoryLevel, DisplayAllProductsTogether, ShipTable, Shipping, ShippingSource) VALUES ('{NewSubCategoryId}', '{[VendorCat.VendorCode]}', '{CategoryId}', 0, {ChildLevel}, {DisplayAllProductsTogether}, '{ShipTable}', '{Shipping}', '{ShippingSource}');", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="SHARED", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    			<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    				<SET VARIABLE="CatSaved" VALUE="FALSE">
    			</IF>
    			</DATA>
    			<![ Continue only if the INSERT worked. ]>
    			<IF VARIABLE="{CatSaved}" OPERATOR="EQ" COMPARISON="TRUE">
    				<DATA SQL="SELECT Language FROM SupportedLanguages WHERE VendorCode = '{[VendorCat.VendorCode]}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="READONLY", ALIAS="SupportedLanguageInfo", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    				<RECORD>
    					<DATA SQL="UPDATE CategoryLanguage SET Description='{Description_{[LanguageInfo.Language]}}', ImageURL='{ImageURL_{[LanguageInfo.Language]}}', ImageWidth=0, ImageHeight=0, ProductDisplayStyle='{ProductDisplayStyle_{[LanguageInfo.Language]}}', ProductDisplayStyleSource='{ProductDisplayStyleSource_{[LanguageInfo.Language]}}', ProductListDisplayStyle='{ProductListDisplayStyle_{[LanguageInfo.Language]}}', ProductListDisplayStyleSource='{ProductListDisplayStyleSource_{[LanguageInfo.Language]}}', Attribute_1_Name='{Attribute_1_Name_{[LanguageInfo.Language]}}', Attribute_2_Name='{Attribute_2_Name_{[LanguageInfo.Language]}}', Attribute_3_Name='{Attribute_3_Name_{[LanguageInfo.Language]}}', Attribute_4_Name='{Attribute_4_Name_{[LanguageInfo.Language]}}', Attribute_1_Source='{Attribute_1_Source_{[LanguageInfo.Language]}}', Attribute_2_Source='{Attribute_2_Source_{[LanguageInfo.Language]}}', Attribute_3_Source='{Attribute_3_Source_{[LanguageInfo.Language]}}', Attribute_4_Source='{Attribute_4_Source_{[LanguageInfo.Language]}}', InputAttribute_1_Name='{InputAttribute_1_Name_{[LanguageInfo.Language]}}', InputAttribute_1_Source='{InputAttribute_1_Source_{[LanguageInfo.Language]}}', EncInputAttribute_1_Name='{EncInputAttribute_1_Name_{[LanguageInfo.Language]}}', InputAttribute_2_Name='{InputAttribute_2_Name_{[LanguageInfo.Language]}}', InputAttribute_2_Source='{InputAttribute_2_Source_{[LanguageInfo.Language]}}', EncInputAttribute_2_Name='{EncInputAttribute_2_Name_{[LanguageInfo.Language]}}' WHERE VendorCode='{[VendorCat.VendorCode]}' AND CategoryId='{NewSubCategoryId}' AND Language='{[LanguageInfo.Language]}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="SHARED", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    					<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    						<SET VARIABLE="DescUpdateSucceeded" VALUE="FALSE">
    					</IF>
    					<IF VARIABLE="{TotalRows}" OPERATOR="NE" COMPARISON="0">
    						<SET VARIABLE="DescUpdateSucceeded" VALUE="TRUE">
    					</IF>
    					</DATA>
    					<IF VARIABLE="{DescUpdateSucceeded}" OPERATOR="EQ" COMPARISON="FALSE">
    						<DATA SQL="INSERT INTO CategoryLanguage (CategoryId, VendorCode, Language, Description, ImageURL, ImageWidth, ImageHeight, ProductDisplayStyle, ProductDisplayStyleSource, ProductListDisplayStyle, ProductListDisplayStyleSource, Attribute_1_Name, Attribute_2_Name, Attribute_3_Name, Attribute_4_Name, Attribute_1_Source, Attribute_2_Source, Attribute_3_Source, Attribute_4_Source, InputAttribute_1_Name, InputAttribute_1_Source, EncInputAttribute_1_Name, InputAttribute_2_Name, InputAttribute_2_Source, EncInputAttribute_2_Name) VALUES ('{NewSubCategoryId}', '{[VendorCat.VendorCode]}', '{[LanguageInfo.Language]}', '{Description_{[LanguageInfo.Language]}}', '{ImageURL_{[LanguageInfo.Language]}}', 0, 0, '{ProductDisplayStyle_{[LanguageInfo.Language]}}', '{ProductDisplayStyleSource_{[LanguageInfo.Language]}}', '{ProductListDisplayStyle_{[LanguageInfo.Language]}}', '{ProductListDisplayStyleSource_{[LanguageInfo.Language]}}', '{Attribute_1_Name_{[LanguageInfo.Language]}}', '{Attribute_2_Name_{[LanguageInfo.Language]}}', '{Attribute_3_Name_{[LanguageInfo.Language]}}', '{Attribute_4_Name_{[LanguageInfo.Language]}}', '{Attribute_1_Source_{[LanguageInfo.Language]}}', '{Attribute_2_Source_{[LanguageInfo.Language]}}', '{Attribute_3_Source_{[LanguageInfo.Language]}}', '{Attribute_4_Source_{[LanguageInfo.Language]}}', '{InputAttribute_1_Name_{[LanguageInfo.Language]}}', '{InputAttribute_1_Source_{[LanguageInfo.Language]}}', '{EncInputAttribute_1_Name_{[LanguageInfo.Language]}}', '{InputAttribute_2_Name_{[LanguageInfo.Language]}}', '{InputAttribute_2_Source_{[LanguageInfo.Language]}}', '{EncInputAttribute_2_Name_{[LanguageInfo.Language]}}');", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="SHARED", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    						<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    							<SET VARIABLE="CatSaved" VALUE="FALSE">
    						</IF>
    						</DATA>
    					</IF>
    				</RECORD>
    				<IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    					<SET VARIABLE="CatSaved" VALUE="FALSE">
    				</IF>
    				</DATA>
    			</IF> <![ ENDIF category tombstone saved successfully ]>
    		</IF> <![ ENDIF found new category's parent ]>
    	</IF> <![ ENDIF new category does not exist ]>
    	<![ If the new category id already exists, tell the user. ]>
    	<IF VARIABLE="{CategoryExists}" OPERATOR="EQ" COMPARISON="TRUE">
    		{@testsuites/res-reach/normal/beginerror.fmt}
    		Category already exists. (CAL0214_CATEGORY_ID_EXISTS)
    		{@testsuites/res-reach/normal/enderror.fmt}
    	</IF>
    	<IF VARIABLE="{CatSaved}" OPERATOR="EQ" COMPARISON="FALSE">
    		<![ Recover from the error. Delete all partial stuff which may have been added. ]>
    		<DATA SQL="DELETE FROM Category WHERE VendorCode='{[VendorCat.VendorCode]}' AND CategoryId='{NewSubCategoryId}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="SHARED", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    		</DATA>
    		<DATA SQL="DELETE FROM CategoryLanguage WHERE VendorCode='{[VendorCat.VendorCode]}' AND CategoryId='{NewSubCategoryId}';", DATABASE="{DB}\mall.mdb", CONNECT="", MODE="SHARED", ERROR="testsuites/res-reach/normal/catalogreaderr.nbt">
    		</DATA>
    	</IF>
    </IF>
    
    
    Example 2: Private variables can be used as containers for language-dependent output strings which otherwise would have to be stored as distinct files.

    The main file would have the following code:

    
       <![ Include all the strings for the user's language. {[User.LANG]} would be "eng" or "fra"
    	   as selected by the user. ]>
       {@testsuites/res-reach/normal/catalogimage.{[User.LANG]}}
    
       {@testsuites/res-reach/normal/begintabledefinition.fmt}
       <TR VALIGN="top">
          <TD COLSPAN=4>
             {@testsuites/res-reach/normal/begintableheader.fmt}
             {catalogimage04}
             {@testsuites/res-reach/normal/endtableheader.fmt}
          </TD>
       </TR>
       {@testsuites/res-reach/normal/endtabledefinition.fmt}
    
    
    "catalogimage.eng" would be a file containing the private variable assignments for the English language:
    
       <SET VARIABLE="catalogimage01" VALUE="Images">
       <SET VARIABLE="catalogimage02" VALUE="Enter the location of the custom navigation images and/or imagemap coordinates
        to be used in your catalog.  If you are keeping images or imagemaps in the default
        directory assigned by your catalog administrator, you can just type the file names.
        Otherwise, give the full URL.  Consult Help for more information. ">
       <SET VARIABLE="catalogimage03" VALUE="Catalog frame:">
       <SET VARIABLE="catalogimage04" VALUE="Background Image URLs">
       <SET VARIABLE="catalogimage05" VALUE="Navigation frame:">