-- ============================================================================
-- MARS-826 Export Step 02: BALANCESHEET Tables  
-- ============================================================================
-- Purpose: Export BALANCESHEET table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 2 tables (~7.6M records total - LARGE DATASET)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_BALANCESHEET_*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 02: Exporting BALANCESHEET Tables (2 tables, ~7.6M records)
PROMPT WARNING: Large dataset - this may take significant time
PROMPT ============================================================================

-- START TIMING
PROMPT
SELECT 'START_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

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

-- Table 2: LEGACY_BALANCESHEET_ITEM (~7,603,340 records - VERY LARGE)
PROMPT
PROMPT Exporting OU_LM.LEGACY_BALANCESHEET_ITEM (LARGE TABLE ~7.6M records)...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_BALANCESHEET_ITEM',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_BALANCESHEET_ITEM',
        pParallelDegree => 16,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_BALANCESHEET_ITEM',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_BALANCESHEET_ITEM exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting BALANCESHEET_ITEM: ' || SQLERRM);
        RAISE;
END;
/

-- END TIMING
PROMPT
SELECT 'END_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

PROMPT
PROMPT Step 02 completed: All BALANCESHEET tables exported
PROMPT
