<MvCOMMENT>
|
| Miva Merchant v4.x
|
| This file and the source codes contained herein are the property 
| of Miva Corporation.  Use of this file is restricted to the specific 
| terms and conditions in the License Agreement associated with this 
| file.  Distribution of this file or portions of this file for uses
| not covered by the License Agreement is not allowed without a written 
| agreement signed by an officer of Miva Corporation.
| 
| Copyright 1998-2001 Miva Corporation.  All rights reserved.
| http://www.miva.com/
|
| dBase III Database Layer
| $Source: /home/cvs/merchant/Merchant/features/agr/agr_db.mv,v $
|
| Prefix         : MER-AGR-DB-
| Next Error Code: 0    
| Next Text ID   : 16   
|
</MvCOMMENT>


<MvFUNCTION NAME = "AGR_Store_Create" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AvailabilityGroups"
				  DATABASE = "{ g._DB_Store_Directory $ 'avlgrps.dbf' }"
				  FIELDS = "id			NUMBER,
							name		CHAR( 40 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00204', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroups_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroups"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }"
						 EXPRESSION = "{ AvailabilityGroups.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00205', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroups"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agrp_nm.mvx' }"
						 EXPRESSION = "{ toupper( AvailabilityGroups.d.name ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00206', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AvailabilityGroups">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroups_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AvailabilityGroupXProduct"
				  DATABASE = "{ g._DB_Store_Directory $ 'agpxprod.dbf' }"
				  FIELDS = "agrp_id		NUMBER,
							product_id	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00207', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXProduct_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxp_grp.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXProduct.d.agrp_id $ ':' $ padl( AvailabilityGroupXProduct.d.product_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00208', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxp_prd.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXProduct.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00209', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXProduct.d.agrp_id $ ':' $ AvailabilityGroupXProduct.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00210', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AvailabilityGroupXProduct">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXProduct_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AvailabilityGroupXCategory"
				  DATABASE = "{ g._DB_Store_Directory $ 'agpxcat.dbf' }"
				  FIELDS = "agrp_id		NUMBER,
							cat_id      NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00211', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCategory_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXCategory"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxc_grp.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXCategory.d.agrp_id $ ':' $ padl( AvailabilityGroupXCategory.d.cat_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00212', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXCategory"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxc_cat.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXCategory.d.cat_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00213', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXCategory"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXCategory.d.agrp_id $ ':' $ AvailabilityGroupXCategory.d.cat_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00214', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AvailabilityGroupXCategory">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCategory_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AvailabilityGroupXCustomer"
				  DATABASE = "{ g._DB_Store_Directory $ 'agpxcst.dbf' }"
				  FIELDS = "agrp_id		NUMBER,
							cust_id		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00215', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCustomer_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXCustomer"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXCustomer.d.cust_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00216', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AvailabilityGroupXCustomer"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }"
						 EXPRESSION = "{ AvailabilityGroupXCustomer.d.agrp_id $ ':' $ padl( AvailabilityGroupXCustomer.d.cust_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00217', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AvailabilityGroupXCustomer">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCustomer_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'AvailabilityGroups', 1 ) }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AGR_Store_Delete" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvASSIGN NAME = "l.directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">

	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'avlgrps.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agrp_id.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agrp_nm.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agpxprod.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxp_grp.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxp_prd.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxp_gpd.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agpxcat.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxc_grp.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxc_cat.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxc_gct.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agpxcst.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxct_ct.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'agxct_gp.mvx' ) }">

	<MvFUNCTIONRETURN VALUE = 1>	
</MvFUNCTION>
<MvFUNCTION NAME = "AGR_Create_Data_Files" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = "1">

	<MvLOCALIZED NAME = "l.privilege" ID = "MER-AGR-DB-00000">
		<MvLOCALIZED-TEXT LANGUAGE = "en-US">Availability Groups</MvLOCALIZED-TEXT>
	</MvLOCALIZED>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Privilege_Insert( 'AGRP', l.privilege ) }">
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AGR_Store_Close" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ g._DB_Store_AvailabilityGroups_Open }">
		<MvCLOSE NAME = "AvailabilityGroups">
		<MvASSIGN NAME = "g._DB_Store_AvailabilityGroups_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AvailabilityGroupXProduct_Open }">
		<MvCLOSE NAME = "AvailabilityGroupXProduct">
		<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXProduct_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AvailabilityGroupXCustomer_Open }">
		<MvCLOSE NAME = "AvailabilityGroupXCustomer">
		<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCustomer_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AvailabilityGroupXCategory_Open }">
		<MvCLOSE NAME = "AvailabilityGroupXCategory">
		<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCategory_Open" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "AGR_Store_Pack" PARAMETERS = "" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroups() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "AvailabilityGroups">
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00260', MvPACK_Error ) }">
		<MvELSE>
			<MvCLOSE NAME = "AvailabilityGroups">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroups_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AvailabilityGroupXProduct">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00261', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AvailabilityGroupXProduct">
				<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXProduct_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AvailabilityGroupXCategory">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00262', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AvailabilityGroupXCategory">
				<MvASSIGN NAME = "g._DB_Store_Open_AvailabilityGroupXCategory" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AvailabilityGroupXCustomer">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00263', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AvailabilityGroupXCustomer">
				<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCustomer" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| AvailabilityGroups 
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AvailabilityGroups" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AvailabilityGroups_Open }">
		<MvOPEN NAME = "AvailabilityGroups" 
				DATABASE = "{ g._DB_Store_Directory $ 'avlgrps.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'agrp_id.mvx, ' $ g._DB_Store_Directory $ 'agrp_nm.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00282', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AvailabilityGroups" FILTER = "{ NOT AvailabilityGroups.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroups_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Insert" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.prodgrp" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroups() }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "AvailabilityGroups.d.id" VALUE = "{ StoreKey_Generate( 'AvailabilityGroups' ) }">
		<MvASSIGN NAME = "AvailabilityGroups.d.name" VALUE = "{ l.name }">

		<MvADD NAME = "AvailabilityGroups">
		<MvASSIGN NAME = "l.prodgrp" VALUE = "{ AvailabilityGroups.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.prodgrp }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Update" PARAMETERS = "id, name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroups() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }">
		<MvFIND NAME = "AvailabilityGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AvailabilityGroups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00001">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Availability Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00283', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AvailabilityGroups.d.name" VALUE = "{ l.name }">

			<MvUPDATE NAME = "AvailabilityGroups">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroups() }"> 
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }">
		<MvFIND NAME = "AvailabilityGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AvailabilityGroups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00002">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Availability Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00284', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">
				<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.id $ ':' }">
				<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCustomer.d.EOF ) AND ( AvailabilityGroupXCustomer.d.agrp_id EQ l.id ) }">
					<MvDELETE NAME = "AvailabilityGroupXCustomer">
					<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
				</MvWHILE>
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_cat" VALUE = "{ _DB_Store_Open_Categories() }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() AND l.open_cat }">
				<MvIF EXPR = "{ l.ok }">
					<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_grp.mvx' }">
					<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
					<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.id $ ':' }">
					<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCategory.d.EOF ) AND ( AvailabilityGroupXCategory.d.agrp_id EQ l.id ) }">
						<MvFIND NAME = "Categories" VALUE = "{ AvailabilityGroupXCategory.d.cat_id }" EXACT>
						<MvIF EXPR = "{ NOT Categories.d.EOF }">
							<MvIF EXPR = "{ Categories.d.agrpcount GT 0 }">
								<MvASSIGN NAME = "Categories.d.agrpcount" VALUE = "{ Categories.d.agrpcount - 1 }">
								<MvUPDATE NAME = "Categories">
							</MvIF>
						</MvIF>

						<MvDELETE NAME = "AvailabilityGroupXCategory">
						<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>
					</MvWHILE>
				</MvIF>
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() AND l.open_prod }">
				<MvIF EXPR = "{ l.ok }">
					<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_grp.mvx' }">
					<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
					<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.id $ ':' }">
					<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXProduct.d.EOF ) AND ( AvailabilityGroupXProduct.d.agrp_id EQ l.id ) }">
						<MvFIND NAME = "Products" VALUE = "{ AvailabilityGroupXProduct.d.product_id }" EXACT>
						<MvIF EXPR = "{ NOT Products.d.EOF }">
							<MvIF EXPR = "{ Products.d.agrpcount GT 0 }">
								<MvASSIGN NAME = "Products.d.agrpcount" VALUE = "{ Products.d.agrpcount - 1 }">
								<MvUPDATE NAME = "Products">
							</MvIF>
						</MvIF>

						<MvDELETE NAME = "AvailabilityGroupXProduct">
						<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>
					</MvWHILE>
				</MvIF>
			</MvIF>

			<MvIF EXPR = "{ l.ok }">
				<MvDELETE NAME = "AvailabilityGroups">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Find_Name" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.id" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroups() }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_nm.mvx' }">
		<MvFIND NAME = "AvailabilityGroups" VALUE = "{ toupper( l.name ) }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroups.d.EOF }">
			<MvASSIGN NAME = "l.id" VALUE = "{ AvailabilityGroups.d.id }">
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00003">
				<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ encodeentities( l.name ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Availability Group '%name%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00285', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.id }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroups() }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }">
		<MvFIND NAME = "AvailabilityGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00004">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Availability Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00286', l.error ) }">
		</MvIF>
	</MvIF>
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroups() }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }">
		<MvGO NAME = "AvailabilityGroups" ROW = "top">
		<MvIF EXPR = "{ NOT AvailabilityGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroups() }">
		<MvPRIMARY NAME = "AvailabilityGroups" INDEX = "{ g._DB_Store_Directory $ 'agrp_id.mvx' }">
		<MvGO NAME = "AvailabilityGroups" ROW = "top">
		<MvSKIP NAME = "AvailabilityGroups" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT AvailabilityGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "AvailabilityGroups" ROWS = 1>
	<MvIF EXPR = "{ AvailabilityGroups.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| AvailabilityGroupXCategory
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AvailabilityGroupXCategory" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AvailabilityGroupXCategory_Open }">
		<MvOPEN NAME = "AvailabilityGroupXCategory"
				DATABASE = "{ g._DB_Store_Directory $ 'agpxcat.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'agxc_grp.mvx, ' $
						     g._DB_Store_Directory $ 'agxc_cat.mvx, ' $
							 g._DB_Store_Directory $ 'agxc_gct.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00287', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCategory_Open" VALUE = 1>
			<MvFILTER NAME = "AvailabilityGroupXCategory" FILTER = "{ NOT AvailabilityGroupXCategory.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCategory_Insert" PARAMETERS = "agrp_id, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">

		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' $ l.cat_id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXCategory.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00005">
				<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">
				<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%cat_id%' is already in availability group '%agrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00288', l.error ) }">
		<MvELSE>
			<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
				<MvFIND NAME = "Categories" VALUE = "{ l.cat_id }" EXACT>
				<MvIF EXPR = "{ Categories.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00006">
						<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%cat_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00289', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Categories.d.agrpcount" VALUE = "{ Categories.d.agrpcount + 1 }">
					<MvUPDATE NAME = "Categories">

					<MvASSIGN NAME = "AvailabilityGroupXCategory.d.agrp_id" VALUE = "{ l.agrp_id }">
					<MvASSIGN NAME = "AvailabilityGroupXCategory.d.cat_id" VALUE = "{ l.cat_id }">
					<MvADD NAME = "AvailabilityGroupXCategory">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCategory_Find" PARAMETERS = "agrp_id, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' $ l.cat_id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXCategory.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCategory_FindFirst_Category" PARAMETERS = "agrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_cat" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXCategory() AND l.open_cat }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_grp.mvx' }">

		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' }">
		<MvIF EXPR = "{ ( NOT AvailabilityGroupXcategory.d.EOF ) AND ( AvailabilityGroupXCategory.d.agrp_id EQ l.agrp_id ) }">
			<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
			<MvFIND NAME = "Categories" VALUE = "{ AvailabilityGroupXCategory.d.cat_id }" EXACT>
			<MvIF EXPR = "{ NOT categories.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCategory_FindNext_Category" PARAMETERS = "agrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>
	<MvIF EXPR = "{ ( AvailabilityGroupXCategory.d.EOF ) OR ( AvailabilityGroupXCategory.d.agrp_id NE l.agrp_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvELSE>
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ AvailabilityGroupXCategory.d.cat_id }" EXACT>
		<MvIF EXPR = "{ Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCategory_Delete" PARAMETERS = "agrp_id, cat_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Categories() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">

		<MvFIND NAME = "Categories" VALUE = "{ l.cat_id }" EXACT>
		<MvIF EXPR = "{ Categories.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00007">
				<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%cat_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00290', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">
				<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' $ l.cat_id }" EXACT>
				<MvIF EXPR = "{ AvailabilityGroupXCategory.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00008">
						<MvLOCALIZED-TOKEN NAME = "cat_id" VALUE = "{ encodeentities( l.cat_id ) }">
						<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Category '%cat_id%' is not in availability group '%agrp_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00291', l.error }">
				<MvELSE>
					<MvIF EXPR = "{ Categories.d.agrpcount GT 0 }">
						<MvASSIGN NAME = "Categories.d.agrpcount" VALUE = "{ Categories.d.agrpcount - 1 }">
						<MvUPDATE NAME = "Categories">
					</MvIF>

					<MvDELETE NAME = "AvailabilityGroupXCategory">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Category_FindOffset_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_cat" VALUE = "{ _DB_Store_Open_Categories() }">

	<MvIF EXPR = "{ l.open_cat AND _DB_Store_Open_AvailabilityGroupXCategory() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_ord.mvx' }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Category_Filter( l.search ) }">
		<MvFILTER NAME = "Categories" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Categories" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Categories.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' $ Categories.d.id }" EXACT>
			<MvIF EXPR = "{ AvailabilityGroupXCategory.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Categories" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Category_FindNext_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Categories" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Categories.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' $ Categories.d.id }" EXACT>
		<MvIF EXPR = "{ AvailabilityGroupXCategory.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Categories" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Categories" FILTER = "{ NOT Categories.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Category_FindOffset_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_cat" VALUE = "{ _DB_Store_Open_Categories() }">


	<MvIF EXPR = "{ l.open_cat AND _DB_Store_Open_AvailabilityGroupXCategory() }">
		<MvPRIMARY NAME = "Categories" INDEX = "{ g._DB_Store_Directory $ 'cat_id.mvx' }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">
		

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Category_Filter( l.search ) }">
		<MvFILTER NAME = "Categories" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.agrp_id $ ':' }">
		<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCategory.d.EOF ) AND ( AvailabilityGroupXCategory.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Categories" VALUE = "{ AvailabilityGroupXCategory.d.cat_id }" EXACT>
			<MvIF EXPR = "{ NOT Categories.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Category_FindNext_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCategory.d.EOF ) AND ( AvailabilityGroupXCategory.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Categories" VALUE = "{ AvailabilityGroupXCategory.d.cat_id }" EXACT>
		<MvIF EXPR = "{ NOT Categories.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Categories" FILTER = "{ NOT Categories.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvCOMMENT>
|
| AvailabilityGroupXProduct
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AvailabilityGroupXProduct" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AvailabilityGroupXProduct_Open }">
		<MvOPEN NAME = "AvailabilityGroupXProduct"
				DATABASE = "{ g._DB_Store_Directory $ 'agpxprod.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'agxp_grp.mvx, ' $
						     g._DB_Store_Directory $ 'agxp_prd.mvx, ' $
							 g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00292', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXProduct_Open" VALUE = 1>
			<MvFILTER NAME = "AvailabilityGroupXProduct" FILTER = "{ NOT AvailabilityGroupXProduct.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXProduct_Insert" PARAMETERS = "agrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' $ l.product_id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXProduct.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00009">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%cat_id%' is already in availability group '%agrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00293', l.error ) }">
		<MvELSE>
			<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
				<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
				<MvIF EXPR = "{ Products.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00010">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00294', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Products.d.agrpcount" VALUE = "{ Products.d.agrpcount + 1 }">
					<MvUPDATE NAME = "Products">

					<MvASSIGN NAME = "AvailabilityGroupXProduct.d.agrp_id" VALUE = "{ l.agrp_id }">
					<MvASSIGN NAME = "AvailabilityGroupXProduct.d.product_id" VALUE = "{ l.product_id }">
					<MvADD NAME = "AvailabilityGroupXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXProduct_Find" PARAMETERS = "agrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' $ l.product_id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXProduct_Delete" PARAMETERS = "agrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00011">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00295', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">
				<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' $ l.product_id }" EXACT>
				<MvIF EXPR = "{ AvailabilityGroupXProduct.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00012">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">

						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is not in availability group '%agrp_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00296', l.error ) }">
				<MvELSE>	
					<MvIF EXPR = "{ Products.d.agrpcount GT 0 }">
						<MvASSIGN NAME = "Products.d.agrpcount" VALUE = "{ Products.d.agrpcount - 1 }">
						<MvUPDATE NAME = "Products">
					</MvIF>

					<MvDELETE NAME = "AvailabilityGroupXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Product_FindOffset_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">

	<MvIF EXPR = "{ l.open_prod AND _DB_Store_Open_AvailabilityGroupXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' $ Products.d.id }" EXACT>
			<MvIF EXPR = "{ AvailabilityGroupXProduct.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Products" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Product_FindNext_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' $ Products.d.id }" EXACT>
		<MvIF EXPR = "{ AvailabilityGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Products" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Product_FindOffset_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">

	<MvIF EXPR = "{ l.open_prod AND _DB_Store_Open_AvailabilityGroupXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' }">
		<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXProduct.d.EOF ) AND ( AvailabilityGroupXProduct.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Products" VALUE = "{ AvailabilityGroupXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Product_FindNext_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXProduct.d.EOF ) AND ( AvailabilityGroupXProduct.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Products" VALUE = "{ AvailabilityGroupXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Products" FILTER = "{ NOT Products.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvCOMMENT>
|
| AvailabilityGroupXCustomer
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AvailabilityGroupXCustomer"
			STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AvailabilityGroupXCustomer_Open }">
		<MvOPEN NAME = "AvailabilityGroupXCustomer"
				DATABASE = "{ g._DB_Store_Directory $ 'agpxcst.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'agxct_ct.mvx, ' $
							 g._DB_Store_Directory $ 'agxct_gp.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00297', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AvailabilityGroupXCustomer_Open" VALUE = 1>
			<MvFILTER NAME = "AvailabilityGroupXCustomer" FILTER = "{ NOT AvailabilityGroupXCustomer.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCustomer_Insert" PARAMETERS = "agrp_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXCustomer.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00013">
				<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
				<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' is already in availability group '%agrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00316', l.error ) }">
		<MvELSE>
			<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Customers() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">
				<MvFIND NAME = "Customers" VALUE = "{ l.cust_id }" EXACT>
				<MvIF EXPR = "{ Customers.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00014">
						<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00317', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "AvailabilityGroupXCustomer.d.agrp_id" VALUE = "{ l.agrp_id }">
					<MvASSIGN NAME = "AvailabilityGroupXCustomer.d.cust_id" VALUE = "{ l.cust_id }">

					<MvADD NAME = "AvailabilityGroupXCustomer">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCustomer_Delete" PARAMETERS = "agrp_id, cust_id"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }">
		<MvIF EXPR = "{ AvailabilityGroupXCustomer.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-AGR-DB-00015">
				<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
				<MvLOCALIZED-TOKEN NAME = "agrp_id" VALUE = "{ encodeentities( l.agrp_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' is not a member of availability group '%agrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00298, l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "AvailabilityGroupXCustomer">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCustomer_Find" PARAMETERS = "agrp_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXCustomer.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCustomer_FindFirst_AvailabilityGroup" PARAMETERS = "agrp_id"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' }">
		<MvIF EXPR = "{ NOT AvailabilityGroupXCustomer.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXCustomer_FindNext_AvailabilityGroup" PARAMETERS = "agrp_id"
			STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
	<MvIF EXPR = "{ ( AvailabilityGroupXCustomer.d.EOF ) OR ( AvailabilityGroupXCustomer.d.agrp_id NE l.agrp_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_FindOffset_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.open_customer" VALUE = "{ _DB_Store_Open_Customers() }">
	<MvIF EXPR = "{  l.open_customer AND _DB_Store_Open_AvailabilityGroupXCustomer() }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">

		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.filter" VALUE = "{ _Customer_Filter( l.search ) }">
		<MvFILTER NAME = "Customers" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Customers" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Customers.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' $ padl( Customers.d.id, 10, '0' ) }" EXACT>
			<MvIF EXPR = "{ AvailabilityGroupXCustomer.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "Customers" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_FindNext_Unassigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Customers" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Customers.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' $ padl( Customers.d.id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ AvailabilityGroupXCustomer.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "Customers" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Customers" FILTER = "{ NOT Customers.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_FindOffset_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.open_cus" VALUE = "{ _DB_Store_Open_Customers() }">
	<MvIF EXPR = "{ l.open_cus AND _DB_Store_Open_AvailabilityGroupXCustomer() }">
		<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_gp.mvx' }">

		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.filter" VALUE = "{ _Customer_Filter( l.search ) }">
		<MvFILTER NAME = "Customers" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.agrp_id $ ':' }">
		<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCustomer.d.EOF ) AND ( AvailabilityGroupXCustomer.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Customers" VALUE = "{ AvailabilityGroupXCustomer.d.cust_id }" EXACT>
			<MvIF EXPR = "{ NOT Customers.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_FindNext_Assigned" PARAMETERS = "agrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCustomer.d.EOF ) AND ( AvailabilityGroupXCustomer.d.agrp_id EQ l.agrp_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Customers" VALUE = "{ AvailabilityGroupXCustomer.d.cust_id }" EXACT>
		<MvIF EXPR = "{ NOT Customers.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Customers" FILTER = "{ NOT Customers.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Category_Delete_AvailabilityGroupXCategory" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_cat.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ l.id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCategory.d.EOF ) AND ( AvailabilityGroupXCategory.d.cat_id EQ l.id ) }">
			<MvDELETE NAME = "AvailabilityGroupXCategory">
			<MvSKIP NAME = "AvailabilityGroupXCategory" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroupXProduct_Delete_Product" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_prd.mvx' }">
		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXProduct.d.EOF ) AND ( AvailabilityGroupXProduct.d.product_id EQ l.id ) }">
			<MvDELETE NAME = "AvailabilityGroupXProduct">
			<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXCategory" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCategory() }">
	</MvIF>
	
	<MvASSIGN NAME = "l.found" VALUE = 0>
	
	<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
	<MvPRIMARY NAME = "AvailabilityGroupXCategory" INDEX = "{ g._DB_Store_Directory $ 'agxc_gct.mvx' }">

	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.cust_id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT AvailabilityGroupXCustomer.d.EOF ) AND
						   ( AvailabilityGroupXCustomer.d.cust_id EQ l.cust_id ) }">
			<MvFIND NAME = "AvailabilityGroupXCategory" VALUE = "{ AvailabilityGroupXCustomer.d.agrp_id $ ':' $ l.id }" EXACT>

			<MvIF EXPR = "{ NOT AvailabilityGroupXCategory.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>

				<MvWHILESTOP>
			</MvIF>

			<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AvailabilityGroup_Customer_Find_ID_AvailabilityGroupXCategory_AND_AvailabilityGroupXProduct" PARAMETERS = "cust_id, id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXCustomer() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AvailabilityGroupXProduct() }">
	</MvIF>
	
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvPRIMARY NAME = "AvailabilityGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'agxct_ct.mvx' }">
	<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_gpd.mvx' }">

	<MvFIND NAME = "AvailabilityGroupXCustomer" VALUE = "{ l.cust_id }" EXACT>
	<MvWHILE EXPR = "{ 	( NOT l.found ) AND
						( NOT AvailabilityGroupXCustomer.d.EOF ) AND
						( AvailabilityGroupXCustomer.d.cust_id EQ l.cust_id ) }">
		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ AvailabilityGroupXCustomer.d.agrp_id $ ':' $ l.id }" EXACT>
		<MvIF EXPR = "{ NOT AvailabilityGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvSKIP NAME = "AvailabilityGroupXCustomer" ROWS = 1>
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_AvailabilityGroup" PARAMETERS = "agrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ _DB_Store_Open_AvailabilityGroupXProduct() AND l.open_prod }">
		<MvPRIMARY NAME = "AvailabilityGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'agxp_grp.mvx' }">

		<MvFIND NAME = "AvailabilityGroupXProduct" VALUE = "{ l.agrp_id $ ':' }">
		<MvIF EXPR = "{ ( NOT AvailabilityGroupXProduct.d.EOF ) AND ( AvailabilityGroupXProduct.d.agrp_id EQ l.agrp_id ) }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ AvailabilityGroupXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_AvailabilityGroup" PARAMETERS = "agrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "AvailabilityGroupXProduct" ROWS = 1>
	<MvIF EXPR = "{ ( AvailabilityGroupXProduct.d.EOF ) OR ( AvailabilityGroupXProduct.d.agrp_id NE l.agrp_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvELSE>
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ AvailabilityGroupXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_AvailabilityGroupCount" PARAMETERS = "agrpcount" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_gcnt.mvx' }">
		
		<MvFIND NAME = "Products" VALUE = "{ l.agrpcount $ ':' }">
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindNext_AvailabilityGroupCount" PARAMETERS = "agrpcount" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvIF EXPR = "{ Products.d.EOF OR ( Products.d.agrpcount NE l.agrpcount ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

