rspec/rules/S1900/rpg/rule.adoc

65 lines
1.5 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The ``++CONST++`` keyword on a subprocedure's parameter indicates that the parameter value will not be changed by the subprocedure. This is not just a nice way to communicate with the programmers who will call the procedure. It also offers performance benefits, because it allows the compiler to produce more optimized code. Further, using ``++CONST++`` means that a field of a similar data type will automatically be converted to the correct type and size for the parameter.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
D X S 15A INZ('ABC')
P SubProc1 B
D SubProc1 PI
D Parm1 15A // Noncompliant; read-only. Should be CONST
D Parm2 15A
/Free
X = Parm1;
Parm2 = X;
return;
/End-free
P SubProc1 E
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
D X S 15A INZ('ABC')
P SubProc1 B
D SubProc1 PI
D Parm1 15A CONST
D Parm2 15A
/Free
X = Parm1;
Parm2 = X;
return;
/End-free
P SubProc1 E
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add the "CONST" keyword to the declaration of "XXX"
'''
== Comments And Links
(visible only on this page)
=== is duplicated by: S1252
=== relates to: S995
endif::env-github,rspecator-view[]