title: Variable Encapsulation in Case Statement
body: <p>While modifying an existing program's CASE statement, I had to add a second block where some logic is repeated to set NetWeaver portal settings. This is done by setting values in a local variable, then assigning that variable to a Changing parameter. I copied over the code and did a Pretty Print, expecting to compiler to complain about the unknown variable. To my surprise however, this code actually compiles just fine:</p>
  
  <pre><code>CASE i_actionid.
      WHEN 'DOMIGO'.
          DATA:   ls_portal_actions  TYPE powl_follow_up_sty.
          CLEAR ls_portal_actions.
          ls_portal_actions-bo_system = 'SAP_ECC_Common'.
          " [...]
          c_portal_actions = ls_portal_actions.
      WHEN 'EBELN'.
          ls_portal_actions-bo_system = 'SAP_ECC_Common'.
          " [...]
          C_PORTAL_ACTIONS = ls_portal_actions.
  ENDCASE.
  </code></pre>
  
  <p>As I have seen in every other programming language, the <code>DATA:</code> declaration in the first <code>WHEN</code> statement should be encapsulated and available only inside that switch block. Does SAP ignore this encapsulation to make that value available in the entire CASE statement? Is this documented anywhere?</p>
  
  <p>Note that this code compiles just fine and double-clicking the local variable in the second switch takes me to the data declaration in the first. I have however not been able to test that this code executes properly as our testing environment is down.</p>