Function Test_Convert_GAN_WIP_Status(Void)
#pragma precomp SRP_PreCompiler

$insert LOGICAL

Declare function    SRP_JSON, Error_Services, Obj_Gan
Declare subroutine  SRP_JSON, Error_Services

TableList   = obj_GaN('GetStatus')
TableList   = Delete(TableList, 1, 0, 0)

If SRP_JSON(hStatusObj, 'NEW', 'OBJECT') then
    If SRP_JSON(hStageArray, 'NEW', 'ARRAY') then
        PreviousStage   = ''
        For Each StatusLine in TableList using @FM
            Stage   = StatusLine<0, 1>
            If Stage NE '' then
                // New stage being introduced. Close the previous stage if one exists.
                If PreviousStage NE '' then
                    SRP_JSON(hStageObject, 'SET', 'RDS Items', hRDSArray)
                    SRP_JSON(hRDSArray, 'RELEASE')
                    SRP_JSON(hStageArray, 'ADD', hStageObject)
                    SRP_JSON(hStageObject, 'RELEASE')
                end
                SRP_JSON(hStageObject, 'NEW', 'OBJECT')
                SRP_JSON(hStageObject, 'SETVALUE', 'stage', Stage)
                SRP_JSON(hRDSArray, 'NEW', 'ARRAY')
                PreviousStage   = Stage
            end else
                RDSNo   = StatusLine<0, 2>
                If RDSNo NE '' then
                    // RDS / Wafer line being added to the current stage.
                    SRP_JSON(hRDSObject, 'NEW', 'OBJECT')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'RDS No', RDSNo, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Run ID', StatusLine<0, 3>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'EPI Part No', StatusLine<0, 4>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Tool Class', StatusLine<0, 5>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Wait Cnt', StatusLine<0, 6>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Wait Hrs', StatusLine<0, 7>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Wait Wfr IDs', StatusLine<0, 8>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Priority', StatusLine<0, 9>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Tool ID', StatusLine<0, 10>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Run Cnt', StatusLine<0, 11>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Run Hrs', StatusLine<0, 12>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Run Wfr IDs', StatusLine<0, 13>, 'STRING')
                    SRP_JSON(hRDSObject, 'SETVALUE', 'Run Priority', StatusLine<0, 14>, 'STRING')
                    SRP_JSON(hRDSArray, 'ADD', hRDSObject)
                    SRP_JSON(hRDSObject, 'RELEASE')
                end
            end
        Next StatusLine
        // Add the last stage object to the stage array.
        SRP_JSON(hStageObject, 'SET', 'RDS Items', hRDSArray)
        SRP_JSON(hRDSArray, 'RELEASE')
        SRP_JSON(hStageArray, 'ADD', hStageObject)
        SRP_JSON(hStageObject, 'RELEASE')
        SRP_JSON(hStatusObj, 'SET', 'stages', hStageArray)
        SRP_JSON(hStageArray, 'RELEASE')
    end
    JSON    = SRP_JSON(hStatusObj, 'STRINGIFY', 'FAST')
    SRP_JSON(hStatusObj, 'RELEASE')
end else
    Error_Services('Add', 'Error creating the GAN WIP Status JSON object.')
end

OSWrite JSON to 'C:\Users\mescatxmuser\Desktop\SRP\wip.json'

Return JSON or ''
