diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt index cb2c50a31..af96b4816 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt @@ -961,7 +961,7 @@ class ExpressionEvaluation( start: IntValue?, length: IntValue?, operator: ComparisonOperator - ): Value { + ): IntValue { val arrayLength = arrayType.numberOfElements() val isSequenced = arrayType.ascend != null diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt index c25c6c153..f5d405716 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt @@ -115,6 +115,9 @@ fun lookUp(statement: LookupStmt, interpreterCore: InterpreterCore, charset: Cha arraySearchingParameters.indexVar?.let { interpreterCore.assign(it, searchResult.oneBasedIndex.asValue()) } + + // Lookup is relevant for %FOUND + interpreterCore.getStatus().lastFound = searchResult !is NotFound } class FoundIndexes(var hi: Int, var lo: Int, var eq: Int) { diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt index 2590694e0..6aa2c198f 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt @@ -2369,6 +2369,9 @@ data class ScanStmt( val leftLength = leftLengthExpression?.let { interpreter.eval(it).asString().value.toInt() } val start = startPosition?.let { interpreter.eval(it).asString().value.toInt() } ?: 1 + // SCAN is relevant for %FOUND calls + interpreter.getStatus().lastFound = false + val stringToSearch = interpreter.eval(left).asString().value.substringOfLength(leftLength) val searchInto = interpreter.eval(right).asString().value.substring(start - 1) val occurrences = mutableListOf() @@ -2391,6 +2394,9 @@ data class ScanStmt( interpreter.assign(it, occurrences[0]) } } + + // Update found status + interpreter.getStatus().lastFound = true } } diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt index aff073601..ecd6aae67 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt @@ -908,4 +908,24 @@ open class MULANGT10BaseCodopTest : MULANGTTest() { val expected = listOf("END") assertEquals(expected, "smeup/MUDRNRAPU00188".outputOf(configuration = smeupConfig)) } + + /** + * SCAN followed by %FOUND + * @see #LS24005347 + */ + @Test + fun executeMUDRNRAPU00279() { + val expected = listOf("3", "FOUND", "0", "NOT FOUND") + assertEquals(expected, "smeup/MUDRNRAPU00279".outputOf(configuration = smeupConfig)) + } + + /** + * LOOKUP followed by %FOUND + * @see #LS24005347 + */ + @Test + fun executeMUDRNRAPU00280() { + val expected = listOf("1", "0") + assertEquals(expected, "smeup/MUDRNRAPU00280".outputOf(configuration = smeupConfig)) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle index 27e162a82..7c2203cb9 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle @@ -6,7 +6,7 @@ V* ============================================================== O * JARIKO ANOMALY O * Before the fix, jariko throw a syntax error - V* ============================================================== DA1 S 1 + V* ============================================================== DN2 S 2 0 D T$C5MD S 15 DA1 S 2 diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle new file mode 100644 index 000000000..af462f8e8 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle @@ -0,0 +1,29 @@ + V* ============================================================== + V* 11/12/2024 APU002 Creation + V* ============================================================== + O * PROGRAM GOAL + O * SCAN followed by %FOUND + V* ============================================================== + O * JARIKO ANOMALY + O * Before the fix, jariko did not consider SCAN accountable for %FOUND + V* ============================================================== + D RESULT S 1 0 + D BASE S 6 INZ('XCABCD') + + C 'ABC' SCAN BASE RESULT + C RESULT DSPLY + C IF %FOUND + C 'FOUND' DSPLY + C ELSE + C 'NOT FOUND' DSPLY + C ENDIF + + C 'FOO' SCAN BASE RESULT + C RESULT DSPLY + C IF %FOUND + C 'FOUND' DSPLY + C ELSE + C 'NOT FOUND' DSPLY + C ENDIF + + C SETON RT \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle new file mode 100644 index 000000000..a43fbed95 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle @@ -0,0 +1,23 @@ + V* ============================================================== + V* 11/12/2024 APU002 Creation + V* ============================================================== + O * PROGRAM GOAL + O * LOOKUP followed by %FOUND + V* ============================================================== + O * JARIKO ANOMALY + O * Before the fix, jariko did not consider LOOKUP accountable for %FOUND + V* ============================================================== + D RESULT S 1 0 + D FND S N + D ARY S 3 DIM(10) + C EVAL ARY(1)='ABC' + C* Lookup opcode found + C 'ABC' LOOKUP ARY 26 + C EVAL FND=%FOUND + C FND DSPLY + C* Lookup opcode not found + C 'FOO' LOOKUP ARY 26 + C EVAL FND=%FOUND + C FND DSPLY + + C SETON RT \ No newline at end of file