midrange.com code scratchpad
Name:
Michael Koester
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
09/08/2010 07:40:43 pm
IP:
Logged
Description:
Does not pass SQL precompiler due to multiple definitions of "Account"
using like(Account#) in subprocedures.

Code:
  1.      H DFTACTGRP(*NO) ACTGRP(*NEW) Option(*NoDebugIO)
  2.       *==============================================================
  3.       * Definitions
  4.       *==============================================================
  5.       * *Entry Parms
  6.      d TestThis        pr                  extpgm('TESTTHIS')
  7.      d Account#                       7a   const
  8.      d ResultString                   3a
  9.  
  10.      d TestThis        pi
  11.      d Account#                       7a   const
  12.      d ResultString                   3a
  13.  
  14.       * Subprocedure prototypes
  15.      D*--------------------------------------------------
  16.      D* Procedure name: ValidParms
  17.      D*--------------------------------------------------
  18.      D ValidParms      PR              N
  19.      D  Account                            LIKE(Account#)
  20.      D                                     CONST
  21.  
  22.      D*--------------------------------------------------
  23.      D* Procedure name: IsAcctValid
  24.      D*--------------------------------------------------
  25.      D IsAcctValid     PR              N
  26.      D  Account                            LIKE(Account#)
  27.      D                                     CONST
  28.  
  29.       *==============================================================
  30.       *‚Main Logic
  31.       *==============================================================
  32.       /free
  33.        // Set standard sql options.
  34.        EXEC SQL
  35.        SET OPTION  closqlcsr = *endmod,
  36.                       commit = *none,
  37.                       datfmt = *iso;
  38.  
  39.        // Test that incoming parms for unanticipated characters only...
  40.        if ValidParms(Account#)
  41.           // Check that the accountare for a known and valid account#
  42.           and IsAcctValid(Account#);
  43.  
  44.           ResultString = 'ok!';
  45.        endif;
  46.  
  47.        *INLR = *on;
  48.       /end-free
  49.  
  50.        //  ---------- end of Main Logic ---------------
  51.  
  52.      P*--------------------------------------------------
  53.      D* Procedure name: ValidParms
  54.      D* Purpose:        Test incoming parms for invalid characters.
  55.      D*--------------------------------------------------
  56.      P ValidParms      B
  57.      D ValidParms      PI              N
  58.      D  Account                            LIKE(Account#)
  59.      D                                     CONST
  60.  
  61.       * Local variables
  62.      d numerals        c                   '0123456789'
  63.  
  64.       /FREE
  65.        // Account must not contain any embedded blanks,
  66.        // and the first character must not be 0.
  67.        if %scan(' ' : Account) = 0
  68.         and %subst(Account : 1 : 1) <> '0';
  69.           Return *on;
  70.        else;
  71.           Return *off;
  72.        endif;
  73.  
  74.       /END-FREE
  75.      P ValidParms      E
  76.  
  77.      P*--------------------------------------------------
  78.      P* Procedure name: IsAcctValid
  79.      P* Purpose:        Determine if the account is known and valid
  80.      P*--------------------------------------------------
  81.      P IsAcctValid     B
  82.      D IsAcctValid     PI              N
  83.      D  Account                            LIKE(Account#) CONST
  84.  
  85.       ** To prevent the SQL0312 error, comment out line above
  86.       ** and activate line below.
  87.  
  88.      D* Account                       7A   CONST
  89.  
  90.       /FREE
  91.        // [real program checks the database here]
  92.        if Account = 'PigsFly';
  93.           // Pretend to do some random sql stuff here with :Account
  94.           exec sql
  95.           CREATE TABLE QTEMP/TEMPJUNK9Z
  96.             (COLUMN1 CHARACTER ( 7) NOT NULL);
  97.           exec sql
  98.            INSERT INTO QTEMP/TEMPJUNK9Z
  99.             VALUES(:Account) WITH NC;
  100.           exec sql
  101.           DROP TABLE QTEMP/TEMPJUNK9Z ;
  102.  
  103.           return *on;
  104.        endif;
  105.  
  106.       /END-FREE
  107.      P IsAcctValid     E
  108.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css