FUNCTION "FC_Call_Jams" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_TEMP 
      nIdx : Int;
   END_VAR


BEGIN
	    REGION Jam Füllstände
	        
	        REGION Hyper-Jam
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikHyperJam"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikHyperJam"],
	                     arInOutJamCarrier := "DB_HyperJam".stHyperJam.arCarrier,
	                     stInOutData := "DB_HyperJam".stHyperJam.stData);
	            
	            "DB_Statistics".nJamCount := "DB_HyperJam".stHyperJam.stData.Status.nCount;
	            
	        END_REGION
	        
	        REGION JamArea4000
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4000_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4000_1"],
	                     arInOutJamCarrier := "DB_JamArea4000".stJam4000_1.arCarrier,
	                     stInOutData := "DB_JamArea4000".stJam4000_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4000".stJam4000_1.stData.Status.nCount;
	            
	        END_REGION
	        
	        REGION JamArea4001
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4001_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4001_1"],
	                     arInOutJamCarrier := "DB_JamArea4001".stJam4001_1.arCarrier,
	                     stInOutData := "DB_JamArea4001".stJam4001_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4001".stJam4001_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4001_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4001_2"],
	                     arInOutJamCarrier := "DB_JamArea4001".stJam4001_2.arCarrier,
	                     stInOutData := "DB_JamArea4001".stJam4001_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4001".stJam4001_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4002
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4002_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4002_1"],
	                     arInOutJamCarrier := "DB_JamArea4002".stJam4002_1.arCarrier,
	                     stInOutData := "DB_JamArea4002".stJam4002_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4002".stJam4002_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4002_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4002_2"],
	                     arInOutJamCarrier := "DB_JamArea4002".stJam4002_2.arCarrier,
	                     stInOutData := "DB_JamArea4002".stJam4002_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4002".stJam4002_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4003
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_1"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_1.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_2"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_2.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_2.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_3"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_3"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_3.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_3.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_3.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_4"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_4"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_4.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_4.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_4.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_5"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_5"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_5.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_5.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_5.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_6"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_6"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_6.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_6.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_6.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_7"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_7"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_7.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_7.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_7.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4003_8"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4003_8"],
	                     arInOutJamCarrier := "DB_JamArea4003".stJam4003_8.arCarrier,
	                     stInOutData := "DB_JamArea4003".stJam4003_8.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4003".stJam4003_8.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4004
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4004_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4004_1"],
	                     arInOutJamCarrier := "DB_JamArea4004".stJam4004_1.arCarrier,
	                     stInOutData := "DB_JamArea4004".stJam4004_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4004".stJam4004_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4004_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4004_2"],
	                     arInOutJamCarrier := "DB_JamArea4004".stJam4004_2.arCarrier,
	                     stInOutData := "DB_JamArea4004".stJam4004_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4004".stJam4004_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4005
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4005_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4005_1"],
	                     arInOutJamCarrier := "DB_JamArea4005".stJam4005_1.arCarrier,
	                     stInOutData := "DB_JamArea4005".stJam4005_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4005".stJam4005_1.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4006
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4006_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4006_1"],
	                     arInOutJamCarrier := "DB_JamArea4006".stJam4006_1.arCarrier,
	                     stInOutData := "DB_JamArea4006".stJam4006_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4006".stJam4006_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4006_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4006_2"],
	                     arInOutJamCarrier := "DB_JamArea4006".stJam4006_2.arCarrier,
	                     stInOutData := "DB_JamArea4006".stJam4006_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4006".stJam4006_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4007
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4007_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4007_1"],
	                     arInOutJamCarrier := "DB_JamArea4007".stJam4007_1.arCarrier,
	                     stInOutData := "DB_JamArea4007".stJam4007_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4007".stJam4007_1.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4008
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4008_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4008_1"],
	                     arInOutJamCarrier := "DB_JamArea4008".stJam4008_1.arCarrier,
	                     stInOutData := "DB_JamArea4008".stJam4008_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4008".stJam4008_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4008_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4008_2"],
	                     arInOutJamCarrier := "DB_JamArea4008".stJam4008_2.arCarrier,
	                     stInOutData := "DB_JamArea4008".stJam4008_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4008".stJam4008_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4009
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4009_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4009_1"],
	                     arInOutJamCarrier := "DB_JamArea4009".stJam4009_1.arCarrier,
	                     stInOutData := "DB_JamArea4009".stJam4009_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4009".stJam4009_1.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4010
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4010_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4010_1"],
	                     arInOutJamCarrier := "DB_JamArea4010".stJam4010_1.arCarrier,
	                     stInOutData := "DB_JamArea4010".stJam4010_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4010".stJam4010_1.stData.Status.nCount;
	            
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4010_2"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4010_2"],
	                     arInOutJamCarrier := "DB_JamArea4010".stJam4010_2.arCarrier,
	                     stInOutData := "DB_JamArea4010".stJam4010_2.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4010".stJam4010_2.stData.Status.nCount;
	        END_REGION
	        
	        REGION JamArea4011
	            "FC_Jam"(stOutCarrierStatsStandard => "DB_Statistics".arJamStatisticsStandard["cStatistikJam4011_1"],
	                     stOutCarrierStatsAdv => "DB_Statistics".arJamStatisticsAdvanced["cStatistikJam4011_1"],
	                     arInOutJamCarrier := "DB_JamArea4011".stJam4011_1.arCarrier,
	                     stInOutData := "DB_JamArea4011".stJam4011_1.stData);
	            
	            "DB_Statistics".nJamCount := "DB_Statistics".nJamCount + "DB_JamArea4011".stJam4011_1.stData.Status.nCount;
	        END_REGION
	        
	    END_REGION
	    
	    REGION Auswertung
	        REGION Leere Carrier
	            "DB_Statistics".nEmptyCarrierCount := 0;
	            FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                "DB_Statistics".nEmptyCarrierCount := "DB_Statistics".nEmptyCarrierCount + "DB_Statistics".arJamStatisticsStandard[#nIdx].nEmptyCarrier;
	            END_FOR;
	            
	        END_REGION
	        
	        REGION Beladene Carrier
	            "DB_Statistics".nLoadedCarrierCount := 0;
	            FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                "DB_Statistics".nLoadedCarrierCount := "DB_Statistics".nLoadedCarrierCount + "DB_Statistics".arJamStatisticsStandard[#nIdx].nLoadedCarrier;
	            END_FOR;
	        END_REGION
	        
	        REGION Dummy
	            "DB_Statistics".nDummyCount := 0;
	            FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                "DB_Statistics".nDummyCount := "DB_Statistics".nDummyCount + "DB_Statistics".arJamStatisticsStandard[#nIdx].nDummyCarrier;
	            END_FOR;
	        END_REGION
	        
	        REGION Advanced
	            REGION Multi-Purpose-Station 1
	                //RealCount = Pre-Buffer Workstation real
	                //ReservedCount = Anzahl Carrier die noch zu dieser Station wollen
	                //TotalCount = Real + Reserved
	                
	                "DB_Statistics".stWorkstations.MPS1.nRealCount := "DB_JamArea4008".stJam4008_1.stData.Status.nCount;
	                
	                "DB_Statistics".stWorkstations.MPS1.nReservedCount := 0;
	                FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                    IF (#nIdx <> "cStatistikJam4008_1") AND (#nIdx <> "cStatistikJam4008_2") AND (#nIdx <> "cStatistikJam4009_1") THEN //eigene Station nicht mitzählen...oder Destination bei Einfahrt in Station ändern, dann wäre es egal
	                        "DB_Statistics".stWorkstations.MPS1.nReservedCount := "DB_Statistics".stWorkstations.MPS1.nReservedCount + "DB_Statistics".arJamStatisticsAdvanced[#nIdx].nDestMPS1;
	                    END_IF;
	                END_FOR;
	                
	                "DB_Statistics".stWorkstations.MPS1.nTotalCount := "DB_Statistics".stWorkstations.MPS1.nRealCount + "DB_Statistics".stWorkstations.MPS1.nReservedCount;
	                
	            END_REGION ;
	            
	            REGION Multi-Purpose-Station 2
	                "DB_Statistics".stWorkstations.MPS2.nRealCount := "DB_JamArea4006".stJam4006_1.stData.Status.nCount;
	                
	                "DB_Statistics".stWorkstations.MPS2.nReservedCount := 0;
	                FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                    IF (#nIdx <> "cStatistikJam4006_1") AND (#nIdx <> "cStatistikJam4006_2") AND (#nIdx <> "cStatistikJam4007_1") THEN //eigene Station nicht mitzählen...oder Destination bei Einfahrt in Station ändern, dann wäre es egal
	                        "DB_Statistics".stWorkstations.MPS2.nReservedCount := "DB_Statistics".stWorkstations.MPS2.nReservedCount + "DB_Statistics".arJamStatisticsAdvanced[#nIdx].nDestMPS2;
	                    END_IF;
	                END_FOR;
	                
	                "DB_Statistics".stWorkstations.MPS2.nTotalCount := "DB_Statistics".stWorkstations.MPS2.nRealCount + "DB_Statistics".stWorkstations.MPS2.nReservedCount;
	            END_REGION
	            
	            REGION Multi-Purpose-Station 3
	                "DB_Statistics".stWorkstations.MPS3.nRealCount := "DB_JamArea4004".stJam4004_1.stData.Status.nCount;
	                
	                "DB_Statistics".stWorkstations.MPS3.nReservedCount := 0;
	                FOR #nIdx := 0 TO "cNoStatistikJam" DO
	                    IF (#nIdx <> "cStatistikJam4004_1") AND (#nIdx <> "cStatistikJam4004_2") AND (#nIdx <> "cStatistikJam4005_1") THEN //eigene Station nicht mitzählen...oder Destination bei Einfahrt in Station ändern, dann wäre es egal
	                        "DB_Statistics".stWorkstations.MPS3.nReservedCount := "DB_Statistics".stWorkstations.MPS3.nReservedCount + "DB_Statistics".arJamStatisticsAdvanced[#nIdx].nDestMPS3;
	                    END_IF;
	                END_FOR;
	                
	                "DB_Statistics".stWorkstations.MPS3.nTotalCount := "DB_Statistics".stWorkstations.MPS3.nRealCount + "DB_Statistics".stWorkstations.MPS3.nReservedCount;
	            END_REGION
	            
	            REGION Recirce
	                "DB_Statistics".nRecircCount := 0;
	                FOR #nIdx := 0 TO "cNoStatistikJam" DO //eingrenzen?
	                    IF NOT (#nIdx = "cStatistikJam4003_2") THEN
	                        "DB_Statistics".nRecircCount := "DB_Statistics".nRecircCount + "DB_Statistics".arJamStatisticsAdvanced[#nIdx].nDestRecirce;
	                    END_IF;
	                END_FOR;
	                
	            END_REGION 
	            
	        END_REGION
	    END_REGION 
	    
	    REGION Prozessdaten
	        "DB_Prozessdaten".stWorkStations.stMPS1.nCountReal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS1.nRealCount);
	        "DB_Prozessdaten".stWorkStations.stMPS1.nCountReserved := UINT_TO_INT("DB_Statistics".stWorkstations.MPS1.nReservedCount);
	        "DB_Prozessdaten".stWorkStations.stMPS1.nCountTotal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS1.nTotalCount);
	        
	        "DB_Prozessdaten".stWorkStations.stMPS2.nCountReal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS2.nRealCount);
	        "DB_Prozessdaten".stWorkStations.stMPS2.nCountReserved := UINT_TO_INT("DB_Statistics".stWorkstations.MPS2.nReservedCount);
	        "DB_Prozessdaten".stWorkStations.stMPS2.nCountTotal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS2.nTotalCount);
	        
	        "DB_Prozessdaten".stWorkStations.stMPS3.nCountReal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS3.nRealCount);
	        "DB_Prozessdaten".stWorkStations.stMPS3.nCountReserved := UINT_TO_INT("DB_Statistics".stWorkstations.MPS3.nReservedCount);
	        "DB_Prozessdaten".stWorkStations.stMPS3.nCountTotal := UINT_TO_INT("DB_Statistics".stWorkstations.MPS3.nTotalCount);
	        
	    END_REGION
	    
	    REGION HMI
	        "DB_Interface_HMI".stStatistics.nJamCount := "DB_Statistics".nJamCount;
	        "DB_Interface_HMI".stStatistics.nLoadedCount := "DB_Statistics".nLoadedCarrierCount;
	        "DB_Interface_HMI".stStatistics.nEmptyCount := "DB_Statistics".nEmptyCarrierCount;
	        "DB_Interface_HMI".stStatistics.nDummyCount := "DB_Statistics".nDummyCount;
	    END_REGION
	    
END_FUNCTION

