SELECT DISTINCT in SAP ABAP

Fetching distinct values from a column in SAP Tables using open SQL statement SELECT DISTINCT

+ -

SELECT DISTINCT is a SQL Select query, which is used to get distinct values of a column from a database table.

SELECT DISTINCT eliminates duplicates records of a column of a table.

Syntax for SELECT DISTINCT in SAP ABAP

SELECT DISTINCT  FROM  INTO TABLE  WHERE .

Example for SELECT DISTINCT in SAP ABAP

The below example is used to get distinct MTART(Material type) from MARA(Material Master) table.

  TYPES: BEGIN OF ty_mtart,
           mtart TYPE mara-mtart,
         END OF ty_mtart.
  DATA: it_mtart TYPE TABLE OF ty_mtart,
        wa_mtart TYPE          ty_mtart.
START-OF-SELECTION.
  SELECT DISTINCT mtart FROM mara INTO TABLE it_mtart UP TO 5 ROWS.

  LOOP AT it_mtart INTO wa_mtart.
    WRITE:/ wa_mtart-mtart.
  ENDLOOP.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 6 People out of 6 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →