title: Concatenating strings in SAP Query
body: <p>I'm creating a BAPI for SAP R/3. The equivalent in MSSQL of what I'm trying to write is this:</p>
  
  <pre><code>select
      bkpf.BELNR,
      bkpf.BUKRS,
      bkpf.GJAHR,
      bkpf.AWKEY
  into
      #tab
  from
      bkpf
  where
      exists ( select 1 from #n_tab n where CONCAT(n.BELNR, n.GJAHR) = bkpf.AWKEY )
  ;
  </code></pre>
  
  <p>But apparently Open Sql doesn't allow operations in queries. So for what I researched, the table I want to "join" must be retrieved to an in memory table, create a new column in a loop doing the operation and the compare with the #tab table. But I'm struggling with the syntax. What I have so far is something like this:</p>
  
  <pre><code>FUNCTION ZBAPI_TEST.
  *"----------------------------------------------------------------------
  *"*"Local Interface:
  *"----------------------------------------------------------------------
  
  select 
      bkpf~BELNR
      bkpf~BUKRS
      bkpf~GJAHR
      bkpf~AWKEY
  into ITAB_BKPF
  from bkpf.
  
  loop at ITAB_BKPF.
  ITAB_BKPF-chkey = CONCATENATE BELNR GJAHR.
  modify ITAB_BKPF.
  endloop.
  
  ENDFUNCTION.
  </code></pre>
  
  <p>But I'm getting the following errors.</p>
  
  <blockquote>
    <p>Field "ITAB_BKPF" is unknown. It is neither in one of the
    specified tables nor defined by a "DATA" statement.   </p>
    
    <p>Field "ITAB_BKPF-GJAHR" is unknown. It is neither in one of
    the   specified tables nor defined by a "DATA" statement.</p>
    
    <p>Incorrect nesting: Before the statement "ENDFUNCTION", the
    control structure introduced by "SELECT" must be concluded with
    "ENDSELECT".</p>
    
    <p>Incorrect nesting: Before the statement
    "+END-OF-INCLUDE", the control    structure introduced by "FUNCTION" must
    be concluded with "ENDFUNCTION".</p>
  </blockquote>
  
  <p>There's clearly an open statement. But I'm not really familiar with the language and don't know where the period is required or if I misplaced any closing statement. Other approach I saw online was with a construct <code>SELECT..ENDSELECT</code>:</p>
  
  <pre><code>FUNCTION ZBAPI_TEST.
  *"----------------------------------------------------------------------
  *"*"Local Interface:
  *"----------------------------------------------------------------------
  
  select
      bkpf~belnr
      bkpf~bukrs
      bkpf~gjahr
      bkpf~awkey
  into corresponding fields
      wa_bkpf
  from bkpf.
  
  wa_bkpf-chkey = concatenate belnr gjahr.
  append wa_bkpf to itab_bkpf.
  endselect.
  
  ENDFUNCTION.
  </code></pre>
  
  <p>But this generate a new batch of errors:</p>
  
  <blockquote>
    <p>Field "CORRESPONDING" is unknown. It is neither in one of the
    specified tables nor defined by a "DATA" statement.        Field
    "WA_BKPF-CHKEY" is unknown. It is neither in one of the
    specified tables nor defined by a "DATA" statement.        Field "WA_BKPF"
    is unknown. It is neither in one of the specified tables nor defined
    by a "DATA" statement.</p>
  </blockquote>
  
  <p>I suspect the solutions and examples I found online skip some part where they define some of the structures they use. But I don't really know how to do it. Can someone help?</p>
  
  <p>EDIT:
  The final code looks like that:</p>
  
  <pre><code>types: begin of t_bkpf,
              belnr type belnr_d,
              bukrs type bukrs,
              gjahr type gjahr,
              awkey type awkey,
              chkey type string.
  types: end of t_bkpf.
  data: itab_bkpf type standard table of t_bkpf.
  field-symbols: &lt;wa&gt; type t_bkpf.
  
      select
          BELNR
          BUKRS
          GJAHR
          AWKEY
      into corresponding fields of table ITAB_BKPF
      from bkpf.
  
      loop at ITAB_BKPF assigning &lt;wa&gt;.
        CONCATENATE &lt;wa&gt;-BELNR &lt;wa&gt;-GJAHR into &lt;wa&gt;-chkey.
      endloop.
  </code></pre>