rspec/rules/S2016/rpg/rule.adoc

61 lines
1.6 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Subprocedures and subroutines are both mechanisms to segregate logic, but subprocedures are preferred for three reasons:
* their local files and variables make maintenance faster and cleaner. They allow you to create variables without worrying about name clashes, and to change fields without worrying about negatively impacting other parts of the program.
* their local files and variables make code reuse easy.
* they can be called with parameters as functions, yielding clearer more readable code.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
D FirstName S 20A
D Initial S 1A
D LastName S 20A
D FullName S 43A
/free
FirstName = 'John';
Initial = 'A';
LastName = 'Smith';
EXSR SPFullName;
DSPLY FullName;
...
begsr SPFullName;
FullName = FirstName + ' ' + Initial + ' ' + LastName;
endsr;
/end-free
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
/free
DSPLY FullName('John':'A':'Smith');
...
/end-free
P FullName B
D FullName PI 43A
D FirstName 20A Const
D Initial 1A Const
D LastName 20A Const
/free
return FirstName + ' ' + Initial + ' ' + LastName;
/end-Free
P E
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]