title: How to access the data in the table used for the FOR ALL ENTRIES statement?
body: <p>I need some data from the tables BKPF and BSEG compressed in one table. For example let's say the final table has to look something like this:</p>
  
  <pre><code>| BKPF-BUKRS | BKPF-GJAHR | BKPF-MONAT | BSEG-DMBTR |
  |============|============|============|============|
  |         01 |       2014 |         02 |   1,751.55 |
  |         01 |       2014 |         02 |     526.45 |
  |         02 |       2014 |         02 |  32,112.01 |
  |            |            |            |     ...... |
  |============|============|============|============|
  </code></pre>
  
  <p>To make the program efficient I wanted to use the statement FOR ALL ENTRIES. So it looked like this:</p>
  
  <pre><code>SELECT BUKRS BELNR GJAHR MONAT 
    FROM BKPF 
    INTO CORRESPONDING FIELDS OF TABLE IT_BKPF
    WHERE .... 
  
  IF IT_BKPF IS NOT INITIAL. 
    SELECT DMBTR
      FROM BSEG 
      INTO CORRESPONDING FIELDS OF LS_BSEG 
      FOR ALL ENTRIES IN IT_BKPF 
      WHERE BUKRS = IT_BKPF-BUKRS AND 
            BELNR = IT_BKPF-BELNR AND 
            GJAHR = IT_BKPF-GJAHR. 
  
      LS_RESULT-BUKRS = LS_BSEG-BUKRS.
      LS_RESULT-GJAHR = LS_BSEG-GJAHR.
      LS_RESULT-MONAT = ???
      LS_RESULT-DMBTR = LS_BSEG-DMBTR.
  
      COLLECT LS_RESULT INTO IT_RESULT.
    ENDSELECT.
  ENDIF.
  </code></pre>
  
  <p>Problem now is: How do I get the value of BKPF-MONAT for each entry? Is there a way to do this with FOR ALL ENTRIES? Another solution would be two SELECT loops, something like:</p>
  
  <pre><code>SELECT BUKRS BELNR GJAHR MONAT 
    FROM BKPF 
    INTO CORRESPONDING FIELDS OF LS_BKPF
    WHERE .... 
  
    SELECT DMBTR
      FROM BSEG 
      INTO CORRESPONDING FIELDS OF LS_BSEG 
      WHERE BUKRS = LS_BKPF-BUKRS AND 
            BELNR = LS_BKPF-BELNR AND 
            GJAHR = LS_BKPF-GJAHR. 
  
      LS_RESULT-BUKRS = LS_BKPF-BUKRS.
      LS_RESULT-GJAHR = LS_BKPF-GJAHR.
      LS_RESULT-MONAT = LS_BKPF-MONAT.
      LS_RESULT-DMBTR = LS_BSEG-DMBTR.
  
      COLLECT LS_RESULT INTO IT_RESULT.
    ENDSELECT.
  ENDSELECT.
  </code></pre>
  
  <p>But I assume this isn't very efficient..
  Normally you would use a JOIN for this but AFAIK you can't do that with a cluster table (BSEG).</p>