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 TYPEREF TO cl_salv_table.DATA lt_table TYPESTANDARD 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
LEFTJOIN makt AS b
ON a~matnr = b~matnr
INTOTABLE @lt_table UP TO5ROWSWHERE b~spras ='E'.ENDFORM.FORM buat_alv.DATAmessageTYPEREF TO cx_salv_msg.TRY.
cl_salv_table=>factory(IMPORTING
r_salv_table = alv
CHANGING
t_table = lt_table ).CATCH cx_salv_msg INTOmessage." error handlingENDTRY.ENDFORM.FORM tampil_alv.
alv->display().ENDFORM.
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.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_mara.
Buat Variable Data
DATA alv TYPEREF TO cl_salv_table.DATA lt_table TYPESTANDARD TABLE OF ty_mara.
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
LEFTJOIN makt AS b
ON a~matnr = b~matnr
INTOTABLE @lt_table UP TO5ROWSWHERE b~spras ='E'.ENDFORM.FORM buat_alv.DATAmessageTYPEREF TO cx_salv_msg.TRY.
cl_salv_table=>factory(IMPORTING
r_salv_table = alv
CHANGING
t_table = lt_table ).CATCH cx_salv_msg INTOmessage." error handlingENDTRY.ENDFORM.FORM tampil_alv.
alv->display().ENDFORM.
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
1 thought on “ALV GRID – Membuat Sample Program sAp List Viewer SAP ABAP OOP”