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 27a513566..d1532c8b0 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 @@ -1618,6 +1618,7 @@ data class ScanStmt( } while (index >= 0) if (occurrences.isEmpty()) { interpreter.setIndicators(this, BooleanValue.FALSE, BooleanValue.FALSE, BooleanValue.FALSE) + interpreter.assign(target, IntValue(0)) } else { interpreter.setIndicators(this, BooleanValue.FALSE, BooleanValue.FALSE, BooleanValue.TRUE) if (target.type().isArray()) { diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/misc.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/misc.kt index d8102479e..d89d7dd80 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/misc.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/misc.kt @@ -1326,6 +1326,8 @@ private fun FactorContext.toIndexedExpression(conf: ToAstConfiguration): Pair { + fun String.isLiteral(): Boolean { return (startsWith('\'') && endsWith('\'')) } + val baseStringTokens = this.split(":") val startPosition = when (baseStringTokens.size) { @@ -1334,7 +1336,10 @@ private fun String.toIndexedExpression(position: Position?): Pair null } val reference = baseStringTokens[0] - return DataRefExpr(ReferenceByName(reference), position) to startPosition + return when { + reference.isLiteral() -> StringLiteral(reference.trim('\''), position) + else -> DataRefExpr(ReferenceByName(reference), position) + } to startPosition } internal fun CsMOVEAContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): MoveAStmt { diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/InterpreterTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/InterpreterTest.kt index e63b17690..7ffebe938 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/InterpreterTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/InterpreterTest.kt @@ -1104,7 +1104,7 @@ Test 6 @Test fun executeSCANTEST() { - assertEquals(listOf("0", "4", "1", "5", "0"), "SCANTEST".outputOf()) + assertEquals(listOf("0", "4", "1", "5", "0", "0"), "SCANTEST".outputOf()) } @Test diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt index 45ecaf266..9db165d2e 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt @@ -284,4 +284,14 @@ open class SmeupInterpreterTest : AbstractTest() { val expected = listOf("1020") assertEquals(expected, "smeup/T10_A20_P19".outputOf()) } + + @Test + fun executeT15_A20_P04_06() { + val expected = listOf( + "RicercaDaPos01(1)_Trovato(1); RicercaDaPos02(5)_Trovato(1); RicercaDaPos05(5)_Trovato(1); RicercaDaPos07(0)_Trovato(0);", + "RicercaDaPos01(5)_Trovato(1); RicercaDaPos01(1)_Trovato(1); RicercaDaPos01(5)_Trovato(1);", + "RicercaDaPos01(2)_Trovato(1);" + ) + assertEquals(expected, "smeup/T15_A20_P04-06".outputOf()) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/SCANTEST.rpgle b/rpgJavaInterpreter-core/src/test/resources/SCANTEST.rpgle index 2a7fce4d6..242fd0b36 100644 --- a/rpgJavaInterpreter-core/src/test/resources/SCANTEST.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/SCANTEST.rpgle @@ -31,5 +31,12 @@ * Expected 0 because the search starts from 2nd character * for three characters: 'r. ' C dsply Msg + ********************************************************************* + * Test with start higher than length of word. + C EVAL $$SVAR='Dr. Doolittle' + C EVAL $BRACK=%SCAN('e':$$SVAR:14) + C Eval Msg = %CHAR($BRACK) + * Expected 0 the value of start higher than length of word. + C dsply Msg ********************************************************************* C SETON LR diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/T15_A20_P04-06.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/T15_A20_P04-06.rpgle new file mode 100644 index 000000000..2e9768445 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/T15_A20_P04-06.rpgle @@ -0,0 +1,46 @@ + D A20_A20A S 20 INZ('!ABC!ABCDEF') + D A20_N20R S 2 0 + D £DBG_Str S 100 VARYING + + C SETOFF 202122 + C '!':1 SCAN A20_A20A A20_N20R 20 + C EVAL £DBG_Str='RicercaDaPos01(' + C +%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN20)+');' + C '!':1 SCAN A20_A20A:2 A20_N20R 21 + C EVAL £DBG_Str=%TRIM(£DBG_Str) + C +' RicercaDaPos02('+%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN21)+');' + C '!':1 SCAN A20_A20A:5 A20_N20R 22 + C EVAL £DBG_Str=%TRIM(£DBG_Str) + C +' RicercaDaPos05('+%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN22)+');' + C SETOFF 20 + C '!':1 SCAN A20_A20A:7 A20_N20R 20 + C EVAL £DBG_Str=%TRIM(£DBG_Str) + C +' RicercaDaPos07('+%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN20)+');' + C £DBG_Str DSPLY + + C SETOFF 202122 + C '!ABCD' SCAN A20_A20A A20_N20R 20 + C EVAL £DBG_Str='RicercaDaPos01(' + C +%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN20)+');' + C '!ABCD':2 SCAN A20_A20A A20_N20R 21 + C EVAL £DBG_Str=%TRIM(£DBG_Str) + C +' RicercaDaPos01('+%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN21)+');' + C '!ABCD':5 SCAN A20_A20A A20_N20R 22 + C EVAL £DBG_Str=%TRIM(£DBG_Str) + C +' RicercaDaPos01('+%CHAR(A20_N20R) + C +')_Trovato('+%CHAR(*IN22)+');' + C £DBG_Str DSPLY + + + C SETOFF 20 + C '!':1 SCAN '?!/' NW20_N20 2 0 20 + C EVAL £DBG_Str='RicercaDaPos01(' + C +%CHAR(NW20_N20) + C +')_Trovato('+%CHAR(*IN20)+');' + C £DBG_Str DSPLY \ No newline at end of file