title: Passing parameters to macro with a loop
body: <p>There is a task to fill deep structure with macro, where names of structure components are similar and can be constructed by simple loop with index.
  For example, the structure is root-level1-level2-level3-level4</p>
  
  <p>I wanna fill it with following nested macros</p>
  
  <pre><code>DEFINE iterate_menges.
   do &amp;4 times.
    fill &amp;1 &amp;2 sy-index level4.
   enddo.
  END-OF-DEFINITION.
  
  DEFINE fill.
   cs_root-sheet&amp;1-&amp;2-level&amp;3-&amp;4 = 'some_value'.
  END-OF-DEFINITION.
  </code></pre>
  
  <p>But this concept doesn't work and <code>sy-index</code> is treated like a text. The error </p>
  
  <blockquote>
    <p>component cs_root-sheet1-level2-<em>levelsy-index-level4</em> is not found</p>
  </blockquote>
  
  <p>is shown, however numeric literal works wonderfully.</p>
  
  <p>What syntax should be used here?</p>
  
  <p><strong>ADDITION:</strong> here is an example snippet I found on SCN and it works perfectly. Why is so?</p>
  
  <pre><code>DEFINE ADD_MAPPING.
   p_c = &amp;1.
   CONDENSE p_c.
   CONCATENATE 'p_old' p_c INTO p_c.
   ASSIGN (p_c) TO &lt;fs&gt;.
   WRITE &lt;fs&gt;.
  END-OF-DEFINITION.
  
  DO 14 TIMES.
   ADD_MAPPING sy-index.
  ENDDO.
  </code></pre>
  
  <p>P.S. Yes, I know macros are undebuggable, unsafe and totally shouldn't be used, but I am interested in this particular problem and not best-practice advice.</p>