We can directly append records into an internal table with select statement by using APPENDING clause. Syntax is as follows.
SELECT db_field1, db_field2,…
  FROM db_table APPENDING TABLE internal_table
  WHERE db_field = condition.
Where is optional. By using APPENDING clause we can re-select and fetch another sort of records into the same internal table. Here the system appends the records to the last position of the internal table. After appending these records when we write the data then it will come one by one (not in the same row).
In below example at first we have selected PO number. So the system will append the PO numbers only. After that in the second select the system will select the materials and append those to the last position of the internal table and so on.
REPORT  zabap_gui.

TABLES: ekpo.

* Creating a custom structure of Item Table
TYPES:
      BEGIN OF ty_ekpo,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        lgort TYPE ekpo-lgort,
      END OF ty_ekpo.

* Creating a line type of predefined structure
DATA:
      wa_ekpo TYPE ty_ekpo,
      it_ekpo TYPE STANDARD TABLE OF ty_ekpo.

REFRESH it_ekpo.

SELECT ebeln
  FROM ekpo APPENDING TABLE it_ekpo
  WHERE ebeln = '3000000232'.

SELECT matnr
  FROM ekpo APPENDING TABLE it_ekpo
  WHERE ebeln = '3000000232'.

SELECT werks
  FROM ekpo APPENDING TABLE it_ekpo
  WHERE ebeln = '3000000232'.

SELECT lgort
  FROM ekpo APPENDING TABLE it_ekpo
  WHERE ebeln = '3000000232'.

LOOP AT it_ekpo INTO wa_ekpo.
  WRITE:/    wa_ekpo-ebeln,
             wa_ekpo-matnr,
             wa_ekpo-werks,
             wa_ekpo-lgort.
ENDLOOP.



Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP MM SD Consultant
Contact : serkurumsal@yandex.com