-- ============================================================================
-- MARS-826 Export Step 03: CSM_ADJ Tables
-- ============================================================================
-- Purpose: Export CSM_ADJ table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 3 tables (~7,756 records total)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_CSM_ADJUSTMENTS_*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 03: Exporting CSM_ADJ Tables (3 tables)
PROMPT ============================================================================

-- Table 1: LEGACY_CSM_ADJ_HEADER (~186 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_CSM_ADJ_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_CSM_ADJ_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_CSM_ADJUSTMENTS_HEADER',
        pParallelDegree => 1
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_CSM_ADJ_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting CSM_ADJ_HEADER: ' || SQLERRM);
        RAISE;
END;
/

-- Table 2: LEGACY_CSM_ADJ_ITEM (~3,785 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_CSM_ADJ_ITEM...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_CSM_ADJ_ITEM',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_CSM_ADJUSTMENTS_ITEM',
        pParallelDegree => 2
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_CSM_ADJ_ITEM exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting CSM_ADJ_ITEM: ' || SQLERRM);
        RAISE;
END;
/

-- Table 3: LEGACY_CSM_ADJ_ITEM_HEADER (~3,785 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_CSM_ADJ_ITEM_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_CSM_ADJ_ITEM_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_CSM_ADJUSTMENTS_ITEM_HEADER',
        pParallelDegree => 2
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_CSM_ADJ_ITEM_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting CSM_ADJ_ITEM_HEADER: ' || SQLERRM);
        RAISE;
END;
/

PROMPT
PROMPT Step 03 completed: All CSM_ADJ tables exported
PROMPT
