FUNCTION "FC_CARR_GLOB_CORRECTION" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInStart : Bool;   // Ausführen der Funktion
      nInBarcodeScan : DInt;   // Gescannter Barcode
      nInStation : Int;   // Scanner-Nummer für Unterscheidungen
   END_VAR

   VAR_OUTPUT 
      arOutEventLogInfo : Array[0..1] of "stEventCorrectionInfo";   // Informationen für Log-Baustein
   END_VAR

   VAR_IN_OUT 
      InOutCarrierExpect : "stCarrier";   // Erwarteter Carrier in ScannerStation
   END_VAR

   VAR_TEMP 
      tmpPartJam : "stCarrier";   // Zwischengespeicherter Carrier, gefunden in Jambereich
      tmpPartHyperJam : "stCarrier";   // Zwischengespeicherter Carrier, gefunden in JHyperjam
      tmpDummy : "stCarrier";   // Leerer Dummy mit speziellem Barcode
      tmpEmpty : "stCarrier";   // Leerer Carrier
      nCounter : DInt;
      i : Int;   // Schleifenindex
      tempStatus : Int;
      xResult : Bool;
   END_VAR


BEGIN
	(*************************************************************************************
	Durchsucht alle Jam- und Lagerberieche nach den Daten die mit dem gescannten Barcode verbunden sind falls am Scanner ein anderes Teil erwartet wird.
	    -Suche beginnt immer im Hyperjam.
	    -Wenn fündig im Hyperjam, dann wird erwartetes Teil durch das Teil vom Hyperjam ersetzt, dafür kommt erwartetes Teil in Hyperjam.
	    -Ansonsten wenn fündig in Jambereichen, dann werden Daten aus dem Jambereich übernommen und diese durch Dummy ersetzt
	*************************************************************************************)
	
	#tmpDummy.nBarcode := 1;
	#tmpDummy.bStatus.%X0 := TRUE;
	
	IF #xInStart AND #nInBarcodeScan > 0 THEN //Barcode muss einen Wert haben
	    REGION Hyperjam
	        FOR #i := 1 TO "cHyperJam" DO
	            IF "DB_HyperJam".stHyperJam.arCarrier[#i].nBarcode = #nInBarcodeScan THEN //Merke gefundenes Teil und lösche ursprüngliches
	                #tmpPartHyperJam := "DB_HyperJam".stHyperJam.arCarrier[#i];
	                "DB_HyperJam".stHyperJam.arCarrier[#i] := #tmpEmpty;
	                
	                REGION Event Log
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 0;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'HyperJam';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartHyperJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5000_1
	        FOR #i := 1 TO "cJam5000_1" DO
	            IF "DB_JamArea5000".stJam5000_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5000".stJam5000_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5000".stJam5000_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5000_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5000".stJam5000_1.arCarrier);
	                "DB_JamArea5000".stJam5000_1.arCarrier["cJam5000_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5000_2
	        FOR #i := 1 TO "cJam5000_2" DO
	            IF "DB_JamArea5000".stJam5000_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5000".stJam5000_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5000".stJam5000_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5000_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5000".stJam5000_2.arCarrier);
	                "DB_JamArea5000".stJam5000_2.arCarrier["cJam5000_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5000_3
	        FOR #i := 1 TO "cJam5000_3" DO
	            IF "DB_JamArea5000".stJam5000_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5000".stJam5000_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5000".stJam5000_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5000_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5000".stJam5000_3.arCarrier);
	                "DB_JamArea5000".stJam5000_3.arCarrier["cJam5000_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5001_1
	        FOR #i := 1 TO "cJam5001_1" DO
	            IF "DB_JamArea5001".stJam5001_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5001".stJam5001_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5001".stJam5001_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5001_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5001".stJam5001_1.arCarrier);
	                "DB_JamArea5001".stJam5001_1.arCarrier["cJam5001_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5001_2
	        FOR #i := 1 TO "cJam5001_2" DO
	            IF "DB_JamArea5001".stJam5001_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5001".stJam5001_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5001".stJam5001_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5001_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5001".stJam5001_2.arCarrier);
	                "DB_JamArea5001".stJam5001_2.arCarrier["cJam5001_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5001_3
	        FOR #i := 1 TO "cJam5001_3" DO
	            IF "DB_JamArea5001".stJam5001_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5001".stJam5001_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5001".stJam5001_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5001_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5001".stJam5001_3.arCarrier);
	                "DB_JamArea5001".stJam5001_3.arCarrier["cJam5001_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5002_1
	        FOR #i := 1 TO "cJam5002_1" DO
	            IF "DB_JamArea5002".stJam5002_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_1.arCarrier);
	                "DB_JamArea5002".stJam5002_1.arCarrier["cJam5002_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_2
	        FOR #i := 1 TO "cJam5002_2" DO
	            IF "DB_JamArea5002".stJam5002_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_2.arCarrier);
	                "DB_JamArea5002".stJam5002_2.arCarrier["cJam5002_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_3
	        FOR #i := 1 TO "cJam5002_3" DO
	            IF "DB_JamArea5002".stJam5002_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_3.arCarrier);
	                "DB_JamArea5002".stJam5002_3.arCarrier["cJam5002_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_4
	        FOR #i := 1 TO "cJam5002_4" DO
	            IF "DB_JamArea5002".stJam5002_4.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_4.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_4.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_4" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_4.arCarrier);
	                "DB_JamArea5002".stJam5002_4.arCarrier["cJam5002_4"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_5
	        FOR #i := 1 TO "cJam5002_5" DO
	            IF "DB_JamArea5002".stJam5002_5.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_5.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_5.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_5" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_5.arCarrier);
	                "DB_JamArea5002".stJam5002_5.arCarrier["cJam5002_5"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_6
	        FOR #i := 1 TO "cJam5002_6" DO
	            IF "DB_JamArea5002".stJam5002_6.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_6.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_6.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_6" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_6.arCarrier);
	                "DB_JamArea5002".stJam5002_6.arCarrier["cJam5002_6"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_7
	        FOR #i := 1 TO "cJam5002_7" DO
	            IF "DB_JamArea5002".stJam5002_7.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_7.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_7.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_7" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_7.arCarrier);
	                "DB_JamArea5002".stJam5002_7.arCarrier["cJam5002_7"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_8
	        FOR #i := 1 TO "cJam5002_8" DO
	            IF "DB_JamArea5002".stJam5002_8.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_8.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_8.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_8" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_8.arCarrier);
	                "DB_JamArea5002".stJam5002_8.arCarrier["cJam5002_8"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5002_9
	        FOR #i := 1 TO "cJam5002_9" DO
	            IF "DB_JamArea5002".stJam5002_9.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_9.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_9.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_9" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_9.arCarrier);
	                "DB_JamArea5002".stJam5002_9.arCarrier["cJam5002_9"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5002_10
	        FOR #i := 1 TO "cJam5002_10" DO
	            IF "DB_JamArea5002".stJam5002_10.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5002".stJam5002_10.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5002".stJam5002_10.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5002_10" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5002".stJam5002_10.arCarrier);
	                "DB_JamArea5002".stJam5002_10.arCarrier["cJam5002_10"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    
	    REGION Jam Area 5004_1
	        FOR #i := 1 TO "cJam5004_1" DO
	            IF "DB_JamArea5004".stJam5004_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5004".stJam5004_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5004".stJam5004_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5004_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5004".stJam5004_1.arCarrier);
	                "DB_JamArea5004".stJam5004_1.arCarrier["cJam5004_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5004_2
	        FOR #i := 1 TO "cJam5004_2" DO
	            IF "DB_JamArea5004".stJam5004_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5004".stJam5004_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5004".stJam5004_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5004_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5004".stJam5004_2.arCarrier);
	                "DB_JamArea5004".stJam5004_2.arCarrier["cJam5004_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5005_1
	        FOR #i := 1 TO "cJam5005_1" DO
	            IF "DB_JamArea5005".stJam5005_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5005".stJam5005_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5005".stJam5005_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5005_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5005".stJam5005_1.arCarrier);
	                "DB_JamArea5005".stJam5005_1.arCarrier["cJam5005_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5005_2
	        FOR #i := 1 TO "cJam5005_2" DO
	            IF "DB_JamArea5005".stJam5005_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5005".stJam5005_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5005".stJam5005_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5005_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5005".stJam5005_2.arCarrier);
	                "DB_JamArea5005".stJam5005_2.arCarrier["cJam5005_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5005_3
	        FOR #i := 1 TO "cJam5005_3" DO
	            IF "DB_JamArea5005".stJam5005_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5005".stJam5005_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5005".stJam5005_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5005_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5005".stJam5005_3.arCarrier);
	                "DB_JamArea5005".stJam5005_3.arCarrier["cJam5005_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area 5006_1
	        FOR #i := 1 TO "cJam5006_1" DO
	            IF "DB_JamArea5006".stJam5006_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5006".stJam5006_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5006".stJam5006_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5006_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5006".stJam5006_1.arCarrier);
	                "DB_JamArea5006".stJam5006_1.arCarrier["cJam5006_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5006_2
	        FOR #i := 1 TO "cJam5006_2" DO
	            IF "DB_JamArea5006".stJam5006_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5006".stJam5006_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5006".stJam5006_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5006_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5006".stJam5006_2.arCarrier);
	                "DB_JamArea5006".stJam5006_2.arCarrier["cJam5006_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5006_3
	        FOR #i := 1 TO "cJam5006_3" DO
	            IF "DB_JamArea5006".stJam5006_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5006".stJam5006_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5006".stJam5006_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5006_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5006".stJam5006_3.arCarrier);
	                "DB_JamArea5006".stJam5006_3.arCarrier["cJam5006_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	    REGION Jam Area5007_1
	        FOR #i := 1 TO "cJam5007_1" DO
	            IF "DB_JamArea5007".stJam5007_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5007".stJam5007_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5007".stJam5007_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5007_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5007".stJam5007_1.arCarrier);
	                "DB_JamArea5007".stJam5007_1.arCarrier["cJam5007_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area5007_2
	        FOR #i := 1 TO "cJam5007_2" DO
	            IF "DB_JamArea5007".stJam5007_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5007".stJam5007_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5007".stJam5007_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5007_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5007".stJam5007_2.arCarrier);
	                "DB_JamArea5007".stJam5007_2.arCarrier["cJam5007_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area5007_3
	        FOR #i := 1 TO "cJam5007_3" DO
	            IF "DB_JamArea5007".stJam5007_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5007".stJam5007_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5007".stJam5007_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5007_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5007".stJam5007_3.arCarrier);
	                "DB_JamArea5007".stJam5007_3.arCarrier["cJam5007_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	  
	    
	   
	    
	    REGION Jam Area 5008_1
	        FOR #i := 1 TO "cJam5008_1" DO
	            IF "DB_JamArea5008".stJam5008_1.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5008".stJam5008_1.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5008".stJam5008_1.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5008_1" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5008".stJam5008_1.arCarrier);
	                "DB_JamArea5008".stJam5008_1.arCarrier["cJam5008_1"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5008_2
	        FOR #i := 1 TO "cJam5008_2" DO
	            IF "DB_JamArea5008".stJam5008_2.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5008".stJam5008_2.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5008".stJam5008_2.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5008_2" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5008".stJam5008_2.arCarrier);
	                "DB_JamArea5008".stJam5008_2.arCarrier["cJam5008_2"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    REGION Jam Area 5008_3
	        FOR #i := 1 TO "cJam5008_3" DO
	            IF "DB_JamArea5008".stJam5008_3.arCarrier[#i].nBarcode = #nInBarcodeScan (* AND #InOutCarrierExpect.nBarcode = 0 *)THEN
	                #tmpPartJam := "DB_JamArea5008".stJam5008_3.arCarrier[#i];
	                #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_JamArea5008".stJam5008_3.arCarrier,
	                                                COUNT := INT_TO_UDINT("cJam5008_3" - #i), //lösche Teil und rücke Rest nach
	                                                SRC_INDEX := #i,
	                                                DEST_INDEX := #i - 1,
	                                                DEST => "DB_JamArea5008".stJam5008_3.arCarrier);
	                "DB_JamArea5008".stJam5008_3.arCarrier["cJam5008_3"] := #tmpEmpty;//lösche letzte Position
	                REGION Event Log                           
	                    #arOutEventLogInfo[0].xTrigger := TRUE;
	                    #arOutEventLogInfo[0].nCorrectionType := 1;
	                    #arOutEventLogInfo[0].sBarcode := DINT_TO_STRING(#nInBarcodeScan);
	                    #arOutEventLogInfo[0].sLoc := 'JamPin';
	                    #arOutEventLogInfo[0].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[0].sDest := INT_TO_STRING(#tmpPartJam.nDestination);
	                END_REGION
	                GOTO END;
	            END_IF;
	        END_FOR;
	    END_REGION
	    
	END:
	    ;
	    REGION Handling
	        IF #tmpPartHyperJam.nBarcode <> 0 THEN //Gefundenes Teil aus Hyperjam
	            REGION Teil aus Hyperjam
	                IF #InOutCarrierExpect.nBarcode > 10000 THEN //Wenn erwarteter Carrier einen Barcode hat, füge ihn am Ende des Hyperjams ein
	                    "FC_TSHR_AddAtEnd"(stInTrolley := #InOutCarrierExpect,
	                                       nOutCounter => #nCounter,
	                                       xOutResult => #xResult,
	                                       arTSHR := "DB_HyperJam".stHyperJam.arCarrier);
	                    
	                    REGION Event log
	                        
	                        #arOutEventLogInfo[1].xTrigger := TRUE;
	                        #arOutEventLogInfo[1].nCorrectionType := 3;
	                        #arOutEventLogInfo[1].sBarcode := DINT_TO_STRING(#InOutCarrierExpect.nBarcode);
	                        #arOutEventLogInfo[1].sLoc := 'HyperJ';
	                        #arOutEventLogInfo[1].sPos := INT_TO_STRING(#i);
	                        #arOutEventLogInfo[1].sDest := INT_TO_STRING(#InOutCarrierExpect.nDestination);
	                        
	                    END_REGION
	                    
	                END_IF;
	                FOR #i := 1 TO "cHyperJam" DO //Durchsuche Hyperjam nach Lücke
	                    IF NOT "DB_HyperJam".stHyperJam.arCarrier[#i].bStatus.%X0 THEN
	                        #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_HyperJam".stHyperJam.arCarrier,
	                                                        COUNT := INT_TO_UDINT("cHyperJam" - #i), //Wo die Lücke im Hyperjam entstanden ist, rücke Rest nach
	                                                        SRC_INDEX := #i,
	                                                        DEST_INDEX := #i - 1,
	                                                        DEST => "DB_HyperJam".stHyperJam.arCarrier);
	                        "DB_HyperJam".stHyperJam.arCarrier["cHyperJam"] := #tmpEmpty; //lösche letztes Teil
	                        EXIT;
	                    END_IF;
	                END_FOR;
	                #InOutCarrierExpect := #tmpPartHyperJam; //Gib gefundenes Teil aus
	            END_REGION
	        ELSIF #tmpPartJam.nBarcode <> 0 THEN //Gefundenes Teil aus Jambereich
	            REGION Teil aus Jam
	                IF #InOutCarrierExpect.nBarcode > 10000 THEN //Wenn erwarteter Carrier einen Barcode hat, füge ihn am Ende des Hyperjams ein
	                    "FC_TSHR_AddAtEnd"(stInTrolley := #InOutCarrierExpect,
	                                       nOutCounter => #nCounter,
	                                       xOutResult => #xResult,
	                                       arTSHR := "DB_HyperJam".stHyperJam.arCarrier);
	                    
	                    REGION Event log
	                        
	                        #arOutEventLogInfo[1].xTrigger := TRUE;
	                        #arOutEventLogInfo[1].nCorrectionType := 3;
	                        #arOutEventLogInfo[1].sBarcode := DINT_TO_STRING(#InOutCarrierExpect.nBarcode);
	                        #arOutEventLogInfo[1].sLoc := 'HyperJ';
	                        #arOutEventLogInfo[1].sPos := INT_TO_STRING(#i);
	                        #arOutEventLogInfo[1].sDest := INT_TO_STRING(#InOutCarrierExpect.nDestination);
	                        
	                    END_REGION
	                    
	                END_IF;
	                FOR #i := 1 TO "cHyperJam" DO //Durchsuche Hyperjam nach Lücke
	                    IF NOT "DB_HyperJam".stHyperJam.arCarrier[#i].bStatus.%X0 THEN
	                        #tempStatus := MOVE_BLK_VARIANT(SRC := "DB_HyperJam".stHyperJam.arCarrier,
	                                                        COUNT := INT_TO_UDINT("cHyperJam" - #i), //Wo die Lücke im Hyperjam entstanden ist, rücke Rest nach
	                                                        SRC_INDEX := #i,
	                                                        DEST_INDEX := #i - 1,
	                                                        DEST => "DB_HyperJam".stHyperJam.arCarrier);
	                        "DB_HyperJam".stHyperJam.arCarrier["cHyperJam"] := #tmpEmpty; //lösche letztes Teil
	                        EXIT;
	                    END_IF;
	                END_FOR;
	                #InOutCarrierExpect := #tmpPartJam; //Gib gefundenes Teil aus
	            END_REGION
	        ELSE
	            //Teil bei Suche nicht gefunden, aber das erwartete soll trotzdem in den Hyperjam kommen und außerhalb des FC dann durch den gescannten ersetzt werden
	            IF #InOutCarrierExpect.nBarcode > 10000 THEN //Wenn erwarteter Carrier einen gültigen Barcode hat, füge ihn am Ende des Hyperjams ein
	                "FC_TSHR_AddAtEnd"(stInTrolley := #InOutCarrierExpect,
	                                   nOutCounter => #nCounter,
	                                   xOutResult => #xResult,
	                                   arTSHR := "DB_HyperJam".stHyperJam.arCarrier);
	                //Es gibt keine Lücke in der Liste die man schließen muss
	                REGION Event log
	                    
	                    #arOutEventLogInfo[1].xTrigger := TRUE;
	                    #arOutEventLogInfo[1].nCorrectionType := 3;
	                    #arOutEventLogInfo[1].sBarcode := DINT_TO_STRING(#InOutCarrierExpect.nBarcode);
	                    #arOutEventLogInfo[1].sLoc := 'HyperJ';
	                    #arOutEventLogInfo[1].sPos := INT_TO_STRING(#i);
	                    #arOutEventLogInfo[1].sDest := INT_TO_STRING(#InOutCarrierExpect.nDestination);
	                    
	                END_REGION
	                
	            END_IF;
	            
	            // #xOutNotFound := TRUE;
	            #InOutCarrierExpect.nDestination := 0;
	            #InOutCarrierExpect.nBarcode := #nInBarcodeScan; //Hier werden neue Carrier im System angelegt
	            #InOutCarrierExpect.bStatus.%X0 := TRUE;
	        END_IF;
	    END_REGION
	END_IF;
END_FUNCTION

