ALV GRID – Membuat Sample Program sAp List Viewer SAP ABAP OOP

SAP List Viewer (ALV) adalah elemen terintegrasi dari lingkungan pemrograman Objek ABAP. Ini memungkinkan pengembang aplikasi untuk dengan cepat mengimplementasikan tampilan dataset terstruktur dengan menyediakan tiga alat ALV yang berbeda, masing-masing untuk tampilan:

  • Simple list:

  • Hierarchical sequential list:

  • Tree:

Pada kesempatan kali ini kita akan belajar membuat sebuah ALV Simple List berbasis Object Oriented Programming / OOP. Sebagai contoh kita akan menampilkan Kode Material dari table MARA dan Nama Material dari Table MAKT.

Script Code Program Abap (Full)

REPORT ywhy_test.
TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         maktx TYPE makt-maktx,
       END OF ty_mara.
DATA alv TYPE REF TO cl_salv_table.
DATA lt_table TYPE STANDARD TABLE OF ty_mara.
 
START-OF-SELECTION.
  PERFORM select_data.
  PERFORM buat_alv.
  PERFORM tampil_alv.
 
FORM select_data.
  SELECT a~matnr , b~maktx FROM mara AS a
    LEFT JOIN makt AS b
    ON a~matnr = b~matnr
     INTO TABLE @lt_table UP TO 5 ROWS
    WHERE b~spras = 'E'.
ENDFORM.
 
FORM buat_alv.
  DATA message TYPE REF TO cx_salv_msg.
  TRY.
      cl_salv_table=>factory(
      IMPORTING
        r_salv_table = alv
      CHANGING
        t_table      = lt_table ).
    CATCH cx_salv_msg INTO message.
      " error handling
  ENDTRY.
ENDFORM.
 
FORM tampil_alv.
  alv->display( ).
ENDFORM.

Keterangan Script:

  • Buat Type Terlebih Dahulu
TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         maktx TYPE makt-maktx,
       END OF ty_mara.
  • Buat Variable Data
DATA alv TYPE REF TO cl_salv_table.
DATA lt_table TYPE STANDARD TABLE OF ty_mara.
  • Buat 3 Subrutin
FORM select_data.
  SELECT a~matnr , b~maktx FROM mara AS a
    LEFT JOIN makt AS b
    ON a~matnr = b~matnr
     INTO TABLE @lt_table UP TO 5 ROWS
    WHERE b~spras = 'E'.
ENDFORM.
 
FORM buat_alv.
  DATA message TYPE REF TO cx_salv_msg.
  TRY.
      cl_salv_table=>factory(
      IMPORTING
        r_salv_table = alv
      CHANGING
        t_table      = lt_table ).
    CATCH cx_salv_msg INTO message.
      " error handling
  ENDTRY.
ENDFORM.
 
FORM tampil_alv.
  alv->display( ).
ENDFORM.
  • Buat event ketika kita akan memproses data, untuk memproses 3 subrutin tsb
START-OF-SELECTION.
  PERFORM select_data.
  PERFORM buat_alv.
  PERFORM tampil_alv.
  • Lalu F8 / Execute

Wahyu Amaldi has written 74 articles

Hi Reader, thank you for read this article, i hope this article can be useful.
If you will share knowladge to me, dont forget contact to me.

Email 1 : wahyu.amaldi@outlook.com
Email 2 : wahyu.amaldi@ilmuprogram.com

One thought on “ALV GRID – Membuat Sample Program sAp List Viewer SAP ABAP OOP

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>