Delimiter //
/**
 * Accounts ref data normalization
 * 
 */

Drop Procedure If Exists LOADER_REFDATA_NORMALIZE//
Create Procedure LOADER_REFDATA_NORMALIZE (
    In batchnum Int
)
MAIN_ACC_REF_DATA_NORMALIZE: Begin

    

    -- Mandatory checks

	call LOADER_REFDATA_NORMALIZE_CHECK_REFTYPE(batchnum);

    Call LOADER_REFDATA_NORMALIZE_ACCOUNT_REF_NOT_NULL(batchnum);

    Call LOADER_REFDATA_NORMALIZE_CHECK_ENTRIES_ACC_EXT_REF_NOTNULL(batchnum);

    Call LOADER_REFDATA_NORMALIZE_ENTITIES_REF_SEQUENCE_NOT_NULL(batchnum);

    Call LOADER_REFDATA_NORMALIZE_ENTITIES_REF_SEQUENCE_RANGE(batchnum);

    -- Create or update ?
--     Call LOADER_ACCOUNTS_NORMALIZE_MAP_ACCOUNT_CREATE_OR_UPDATE(batchnum);

    -- Mapping and linking
    Call LOADER_REFDATA_NORMALIZE_MAP_ACCOUNTS(batchnum);

    Call LOADER_REFDATA_NORMALIZE_MAP_ENTRIES(batchnum);

    Call LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF(batchnum);
    Call LOADER_REFDATA_NORMALIZE_MAP_ID_ENT_REF_DATAS(batchnum);
    

End//
Delimiter ;