To improve source code readability and reusability, SQL operations should be located in dedicated procedures (sections or paragraphs) and should not be mixed with other SQL requests.


== Noncompliant Code Example

----
MAIN_PARAGRAPH.
  ...
  LOAD_SALARY.
  ...

LOAD_SALARY.
  EXEC SQL CONNECT :UID IDENTIFIED BY :PASS END-EXEC.
  EXEC SQL USE tempdb END-EXEC.   *< Noncompliant
  EXEC SQL
    SELECT   SALARY  
        INTO  :HV-SALARY
      FROM EMPLOYEE
        WHERE EMPNAME = 'XXXXXXX'
  END-EXEC.
  EXIT.
----


== Compliant Solution

----
MAIN_PARAGRAPH.
  ...
  CONNECT_TO_DB.
  USE_TMP_DB_SCHEMA.
  ...
  LOAD_SALARY.
  ...
CONNECT_TO_DB.
  EXEC SQL CONNECT :UID IDENTIFIED BY :PASS END-EXEC.
  EXIT.

USE_TMP_DB_SCHEMA.
  EXEC SQL USE tempdb END-EXEC.
  EXIT.

LOAD_SALARY.
  EXEC SQL
    SELECT   SALARY  
        INTO  :HV-SALARY
      FROM EMPLOYEE
        WHERE EMPNAME = 'XXXXXXX'
  END-EXEC.
  EXIT
----


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
