MSCEWI2070

A return statement was added at the end of the label section to ensure the same execution flow

This is a deprecated version of the SnowConvert documentation, please visit the official site HERE.

Severity

Medium

Description

When a Goto statement is replaced with a Label section and it does not contain a return statement, then one is added at the end of the section to ensure the same execution flow.

In BTEQ after a Goto command is executed the statements that are between the goto command and the label command with the same name are ignored. So, to avoid those statements to be executed the label section should contains a return statement.

In addition, is worth value mentioning the Goto command skips all the other statements except for the Label with the same name, where is when the execution resumes. Therefore, the execution will never resume in a label section defined before the Goto command.

Example Code

Input Code:

.LOGON dbc,dbc;
select 'STATEMENTS';
.GOTO LABEL_B
select 'IGNORED STATEMENTS';
.label LABEL_B
select 'LABEL_B STATEMENTS';

Output Code

EXECUTE IMMEDIATE
$$
  DECLARE
    STATUS_OBJECT OBJECT;
  BEGIN
    /*** MSC-ERROR - MSCEWI1037 - TRANSLATION FOR SCRIPT STATEMENTS IS PLANNED TO BE DELIVERED IN THE FUTURE ***/
    /*.LOGON dbc,dbc;*/
     
    BEGIN
      SELECT
        'STATEMENTS';
      STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
    EXCEPTION
      WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
    END;
    /*** MSC-ERROR - MSCEWI2071 - GOTO LABEL_B WAS REPLACED WITH THE LABEL SECTION WITH THE SAME NAME ***/
     
    /*.label LABEL_B*/
     
    BEGIN
      SELECT
        'LABEL_B STATEMENTS';
      STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
    EXCEPTION
      WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
    END;
    /*** MSC-ERROR - MSCEWI2070 - A RETURN STATEMENT WAS ADDED AT THE END OF THE LABEL SECTION LABEL_B TO ENSURE THE SAME EXECUTION FLOW ***/
    RETURN 0;
    BEGIN
      SELECT
        'IGNORED STATEMENTS';
      STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
    EXCEPTION
      WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
    END;
    /*** MSC-WARNING - MSCEWI1002 - REMOVED NEXT STATEMENT, NOT APPLICABLE IN SNOWFLAKE.  ***/
    /*.label LABEL_B*/
     
    BEGIN
      SELECT
        'LABEL_B STATEMENTS';
      STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
    EXCEPTION
      WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
    END;
  END
$$

Recommendations

Last updated