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.
Noncompliant Code Example
D FirstName S 20A
D Initial S 1A
D LastName S 20A
D FullName S 43A
FirstName = 'John';
Initial = 'A';
LastName = 'Smith';
FullName = FirstName + ' ' + Initial + ' ' + LastName;
P FullName B
D FullName PI 43A
D FirstName 20A Const
D Initial 1A Const
D LastName 20A Const
return FirstName + ' ' + Initial + ' ' + LastName;