Skip to content

Commit

Permalink
Merge pull request #706 from smeup/bugfix/LS25000738/like-define-indi…
Browse files Browse the repository at this point in the history
…cators-improvement

Bugfix/ls25000738/like define indicators improvement
  • Loading branch information
lanarimarco authored Feb 11, 2025
2 parents 63d7b27 + 5c90852 commit 80a0f08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1455,20 +1455,25 @@ data class DefineStmt(
val newVarName: String,
override val position: Position? = null
) : Statement(position), StatementThatCanDefineData {
companion object {
private val INDICATOR_PATTERN = Regex("\\*IN\\(?(\\d\\d)\\)?", setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
}

override val loggableEntityName: String
get() = "DEFINE"

override fun dataDefinition(): List<InStatementDataDefinition> {
val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

val indicatorPattern = Regex("\\*IN\\d\\d")
val normalizedOriginalName = originalName.trim().uppercase()
val isIndicator = normalizedOriginalName.matches(indicatorPattern)
if (isIndicator) {
val indicatorKey = normalizedOriginalName.removePrefix("*IN").toIndicatorKey()
val setStatements = containingCU.main.stmts.explode(true).filterIsInstance<SetStmt>()
val definedIndicators = setStatements.map { it.indicators }.flatten().filterIsInstance<IndicatorExpr>()
val indicatorMatch = INDICATOR_PATTERN.find(normalizedOriginalName)
if (indicatorMatch != null) {
// First matching group is the indicator index
val (indicatorIndex) = indicatorMatch.destructured

val indicatorKey = indicatorIndex.toIndicatorKey()
val definedIndicators = containingCU.collectByType(IndicatorExpr::class.java)
val isIndicatorDefined = definedIndicators.any { it.index == indicatorKey }

if (!isIndicatorDefined) throw Error("Data reference $originalName not resolved")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,16 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
assertEquals(aDefinition?.elementSize(), bDefinition?.elementSize())
}

/**
* LIKE DEFINE on an indicator defined without a SET statement
* @see #LS25000738
*/
@Test
fun executeMUDRNRAPU00283() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00283".outputOf(configuration = smeupConfig))
}

/**
* Writing on a field of DS which use `EXTNAME` of a file. In this case the file in `EXTNAME` is different
* from `F` spec but shares same fields.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
V* ==============================================================
V* 11/02/2025 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * *LIKE DEFINE referencing an indicator turned on with an eval
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, jariko could not define XIN10
V* ==============================================================
C EVAL *IN10=*ON
C *LIKE DEFINE *IN10 XIN10
C 'ok' DSPLY

0 comments on commit 80a0f08

Please sign in to comment.