-- ============================================================================
-- MARS-826 Export Step 07: QR_ADJ Tables
-- ============================================================================
-- Purpose: Export QR_ADJ table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 3 tables (~62,573 records total)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_QRE_ADJUSTMENTS_*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 07: Exporting QR_ADJ Tables (3 tables)
PROMPT ============================================================================

-- Table 1: LEGACY_QR_ADJ_HEADER (~123 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_QR_ADJ_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_QR_ADJ_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_QRE_ADJUSTMENTS_HEADER',
        pParallelDegree => 1,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_QRE_ADJUSTMENTS_HEADER',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_QR_ADJ_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting QR_ADJ_HEADER: ' || SQLERRM);
        RAISE;
END;
/

-- Table 2: LEGACY_QR_ADJ_ITEM (~59,952 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_QR_ADJ_ITEM...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_QR_ADJ_ITEM',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_QRE_ADJUSTMENTS_ITEM',
        pParallelDegree => 4,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_QRE_ADJUSTMENTS_ITEM',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_QR_ADJ_ITEM exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting QR_ADJ_ITEM: ' || SQLERRM);
        RAISE;
END;
/

-- Table 3: LEGACY_QR_ADJ_ITEM_HEADER (~2,498 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_QR_ADJ_ITEM_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_QR_ADJ_ITEM_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_QRE_ADJUSTMENTS_ITEM_HEADER',
        pParallelDegree => 2,        pTemplateTableName => 'CT_ET_TEMPLATES.LM_QRE_ADJUSTMENTS_ITEM_HEADER',        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_QR_ADJ_ITEM_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting QR_ADJ_ITEM_HEADER: ' || SQLERRM);
        RAISE;
END;
/

PROMPT
PROMPT Step 07 completed: All QR_ADJ tables exported
PROMPT
