Delimiter //
/**
 * Credit limit data normalization
 * @param int batchnum
 * @author Ben
 */
Drop Procedure If Exists LOADER_CREDITLIMIT_NORMALIZE//

Create Procedure LOADER_CREDITLIMIT_NORMALIZE (
    In batchnum Int
)
MAIN_CREDITLIMIT_NORMALIZE: Begin

    set @lcn_batchnum = batchnum;
    if @lcn_batchnum = 0 then
        call LOADER_CREATE_TABLE_CREDITLIMIT_ACCOUNTS();
    End if;


    -- Mandatory checks
-- 	Call LOADER_CREDITLIMIT_NORMALIZE_ACCOUNT_REF_NOT_NULL(batchnum);
	Call LOADER_CREDITLIMIT_NORMALIZE_CHECK_ACCOUNT_PROVIDED(@lcn_batchnum);
	Call LOADER_CREDITLIMIT_NORMALIZE_AMOUNT_NOT_NULL(@lcn_batchnum);

	-- Mapping and linking
    Call LOADER_CREDITLIMIT_NORMALIZE_MAP_ACCOUNTS(@lcn_batchnum); -- before LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE
    Call LOADER_CREDITLIMIT_NORMALIZE_MAP_CREATE_OR_UPDATE(@lcn_batchnum); -- after LOADER_CREDITLIMIT_NORMALIZE_MAP_ACCOUNTS
    Call LOADER_CREDITLIMIT_NORMALIZE_MAP_DATE_NOT_PROVIDED(@lcn_batchnum);

End//

Delimiter ;