Object Oriented ALV

OO ALV için

BC (CL_GUI_ALV_GRID) veya SALV (CL_SALV_TABLE) sınıfları kullanılmaktadır.

SE24 işlem kodu ile sınıfları incelenebilir.

BC ALV

Klasik ABAP listesi veya ızgara içerisinde çıktıyı gösterebilir. Liste görünümünde tüm ekranı kaplar ve sadece bir tablo gösterilebilir.

Izgara görünümünde tam ekran veya container nesnesi aracılığıyla bir ekranda birden fazla tablo gösterilebilir. Tam ekran görünümünde tüm ekranı kaplar ve sadece bir tablo gösterilebilir. Container’ lar aracılığıyla ekranda birden fazla tablo gösterilebilir.

Örnek: Programınızda bir ekran oluşturun.

Ekranı SE51 işlem kodundan veya ABAP düzenleyici içerisindeki nesne listesi görüntüleyicisini kullanarak oluşturabilirsiniz.

ABAP Düzenleyiciden Nesne listesi görüntüsü ( ) butonunu tıklayın. Programa ait nesneler listelenecektir. Nesne listesi üzerine sağ tıklayarak açılan menüden Create->Screen seçeneğini seçerek ekran oluşturabilirsiniz.

Ekran numarasını olarak “100” girin.

Yeni ekranda Short Description alanına ekranla ilgili kısa tanım girin.

Element list sekmesinde OK elementine değişken ismi olarak “OK_CODE” girin.

Flow logic sekmesine geçin MODULE ile başlayan satırların başından yıldız işaretlerini kaldırın ve kaydedin.

Ekrana ait olayları kontrol etmek için programa bir GUI status nesnesi eklemek gerekir. GUI status nesnesini SE41 işlem kodundan veya ABAP düzenleyiciden nesne listesini kullanarak oluşturabilirsiniz.

GUI status tanımları ekranı açılacaktır. Status alanına “100” girin, Short Text alanına kısa tanım bilgisi girin.

İşlev tuşları sekmesini açın. Resimde gösterilen şekilde 3 buton için fonksiyon kodunu doldurun.

GUI status nesnesini aktif edin.

Dilerseniz nesne görüntüleyiciyi kullanarak ekran için Title bar nesnesi ekleyebilirsiniz.

Programa aşağıdaki kod bloğunu ekleyin.

TABLES spfli.
DATA gt_spfli TYPE STANDARD TABLE OF spfli.
DATA: ok_code LIKE sy-ucomm,
g_grid_100    TYPE REF TO cl_gui_alv_grid,
gs_variant    LIKE disvariant.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_grid_100 IS INITIAL.
CREATE OBJECT g_grid_100
EXPORTING
i_parent = cl_gui_container=>screen0.
gs_variant-report = sy-repid.
CALL METHOD g_grid_100->set_table_for_first_display
EXPORTING i_structure_name = ‘SFLIGHT’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_spfli.
ENDIF.
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

ABAP kodunu ve ekran nesnesini aktif edin.

Programı çalıştırdığınızda SPFLI tablosu içeriğini görebilirsiniz.

Örnek 2: docking container kullanarak ekrana yerleştirilen custom control nesnesi üzerinde ALV’ yi gösteren örnek.

Nesne görüntüleyici içerisinden ekran nesnesine çift tıklayın. Araç çubuğundaki Layout butonuna tıklayarak. Screen painter’ ı açın. Sol taraftaki menüden Custom Control butonuna tıklayarak ekran üzerine yeni bir custom Control ekleyin.

Custom Control’ un ismini “CONT100” yapın ve ekranı aktif edin.

DATA gt_spfli TYPE STANDARD TABLE OF spfli.
DATA: ok_code LIKE sy-ucomm,
g_grid_100    TYPE REF TO cl_gui_alv_grid,
gs_variant    LIKE disvariant,
g_custom_container_100 TYPE REF TO cl_gui_custom_container.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_custom_container_100 IS INITIAL.
CREATE OBJECT g_custom_container_100
EXPORTING container_name = ‘CONT100’.
CREATE OBJECT g_grid_100
EXPORTING i_parent = g_custom_container_100.
gs_variant-report = sy-repid.
CALL METHOD g_grid_100->set_table_for_first_display
EXPORTING i_structure_name = ‘SFLIGHT’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_spfli.
ENDIF.
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

Programı çalıştırdığınızda Custom Container içerisinde görüntülenen ALV’ yi görebilirsiniz.

Örnek 3: Ekrana Custom Container yerleştirmeden gösterilen ALV.

DATA gt_spfli TYPE STANDARD TABLE OF spfli.
DATA: ok_code LIKE sy-ucomm,
g_grid_100    TYPE REF TO cl_gui_alv_grid,
gs_variant    LIKE disvariant,
g_docking_container_100 TYPE REF TO cl_gui_docking_container.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_docking_container_100 IS INITIAL.
CREATE OBJECT g_docking_container_100
EXPORTING
side       = g_docking_container_100->dock_at_top
extension  = 2000.
CREATE OBJECT g_grid_100
EXPORTING i_parent = g_docking_container_100.
gs_variant-report = sy-repid.
CALL METHOD g_grid_100->set_table_for_first_display
EXPORTING i_structure_name = ‘SFLIGHT’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_spfli.
ENDIF.
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

SALV ÖRNEKLERİ

Örnek:

TABLES spfli.
DATA gt_spfli TYPE STANDARD TABLE OF spfli.
DATA: g_salv_table TYPE REF TO cl_salv_table.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = ‘X’
IMPORTING
r_salv_table = g_salv_table
CHANGING
t_table = gt_spfli ).
CATCH cx_salv_msg.
ENDTRY.
g_salv_table->display( ).

Örnek: Aşağıdaki kod SALV ile oluşturulan ALV yi konteyner içerisinde gösterir.

TABLES spfli.
DATA gt_spfli TYPE STANDARD TABLE OF spfli.
DATA: g_salv_table TYPE REF TO cl_salv_table,
g_custom_container_100 TYPE REF TO cl_gui_custom_container,
ok_code LIKE sy-ucomm,
g_functions type ref to cl_salv_functions_list,
gc_true  type sap_bool value ‘X’.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_custom_container_100 IS INITIAL.
CREATE OBJECT g_custom_container_100
EXPORTING container_name = ‘CONT100’.
TRY.
cl_salv_table=>factory(
EXPORTING
r_container    = g_custom_container_100
IMPORTING
r_salv_table = g_salv_table
CHANGING
t_table = gt_spfli ).
CATCH cx_salv_msg.
ENDTRY.
g_functions = g_salv_table->get_functions( ).
g_functions->set_all( gc_true ).
g_salv_table->display( ).
ENDIF.
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.                 <I>” USER_COMMAND_0100  INPUT</I>

Örnek: SAPLKKBL programından Copy status butonunu kullanarak kendi programınıza GUI status kopyalayabilirsiniz.

Nesne listesinde görebilirsiniz.

Aktif edin.

TYPE-POOLS: slis.
DATA: gt_fieldcat  TYPE slis_t_fieldcat_alv,
gs_fieldcat  TYPE slis_fieldcat_alv,
gs_layout    TYPE slis_layout_alv.
TYPES: BEGIN OF gy_sbook,
box       TYPE c LENGTH 1,
checkbox  TYPE c LENGTH 1,
carrid    TYPE sbook-carrid,
connid    TYPE sbook-connid,
fldate    TYPE sbook-fldate,
metin     TYPE c LENGTH 20,
END OF gy_sbook.
DATA: gt_sbook TYPE STANDARD TABLE OF gy_sbook,
gv_repid TYPE sy-repid.
SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE gt_sbook.
CLEAR gs_fieldcat.
gs_fieldcat-tabname    = ‘GT_SBOOK’.
gs_fieldcat-fieldname  = ‘CHECKBOX’.
gs_fieldcat-seltext_m  = ‘CHECKBOX’.
gs_fieldcat-outputlen  = 3.
gs_fieldcat-checkbox   = ‘X’.
gs_fieldcat-edit       = ‘X’.
gs_fieldcat-input      = ‘X’.
*gs_fieldcat-no_out     = ‘X’.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘CARRID’.
gs_fieldcat-seltext_m  = ‘ID’.
gs_fieldcat-outputlen  = 7.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘CONNID’.
gs_fieldcat-seltext_m  = ‘No’.
gs_fieldcat-outputlen  = 8.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘FLDATE’.
gs_fieldcat-seltext_m  = ‘Uçuş tarihi’.
gs_fieldcat-outputlen  = 9.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘METIN’.
gs_fieldcat-seltext_m  = ‘Açıklama’.
gs_fieldcat-outputlen  = 20.
gs_fieldcat-edit       = ‘X’.
APPEND gs_fieldcat TO gt_fieldcat.
gv_repid = sy-repid.
gs_layout-box_fieldname     = ‘BOX’.
gs_layout-no_input          = ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program        = gv_repid
it_fieldcat               = gt_fieldcat
i_save                    = ‘A’
i_callback_pf_status_set  = ‘F_GUI_STATUS’
i_callback_user_command   = ‘F_USER_COMMAND’
is_layout                 = gs_layout
TABLES
t_outtab                  = gt_sbook
EXCEPTIONS
program_error             = 1
OTHERS                    = 2.
FORM f_gui_status USING p_extab TYPE slis_t_extab.
SET PF-STATUS ‘STANDARD_FULLSCREEN’.
ENDFORM.
FORM f_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA ref_grid TYPE REF TO cl_gui_alv_grid.
DATA: ls_sbook TYPE gy_sbook,
lv_tabix TYPE c LENGTH 4,
lv_mesaj TYPE c LENGTH 50.
IF ref_grid IS INITIAL.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data .
ENDIF.
CASE r_ucomm.
WHEN ‘&DATA_SAVE’.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE checkbox = ‘X’.
WRITE sy-tabix TO lv_tabix.
CONCATENATE lv_mesaj lv_tabix ‘,’ INTO lv_mesaj.
ENDLOOP.
CONCATENATE ‘Seçilen checkbox:’ lv_mesaj INTO lv_mesaj SEPARATED BY space.
MESSAGE lv_mesaj TYPE ‘I’.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE box = ‘X’.
WRITE sy-tabix TO lv_tabix.
CONCATENATE lv_mesaj lv_tabix ‘,’ INTO lv_mesaj.
ENDLOOP.
CONCATENATE ‘Seçilen kutular:’ lv_mesaj INTO lv_mesaj SEPARATED BY space.
MESSAGE lv_mesaj TYPE ‘I’.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE metin IS NOT INITIAL.
MESSAGE ls_sbook-metin TYPE ‘I’.
ENDLOOP.
ENDCASE.
rs_selfield-refresh = ‘X’.
ENDFORM.

Örnek: Bu sefer GUI status 100.

DATA: gt_fieldcat  TYPE lvc_t_fcat,
gs_fieldcat  TYPE lvc_s_fcat.
TYPES: BEGIN OF gy_sbook,
box       TYPE c LENGTH 1,
checkbox  TYPE c LENGTH 1,
carrid    TYPE sbook-carrid,
connid    TYPE sbook-connid,
fldate    TYPE sbook-fldate,
metin     TYPE c LENGTH 20,
END OF gy_sbook.
DATA : g_docking_container TYPE REF TO cl_gui_docking_container,
g_alv_grid          TYPE REF TO cl_gui_alv_grid,
ok_code LIKE sy-ucomm,
g_valid TYPE c,
gt_sbook TYPE STANDARD TABLE OF gy_sbook,
ls_sbook TYPE gy_sbook,
lv_tabix TYPE c LENGTH 4,
lv_mesaj TYPE c LENGTH 50,
is_layout   TYPE lvc_s_layo.
DATA: et_index_rows TYPE lvc_t_row ,
et_row_no     TYPE lvc_t_roid ,
wa_row_no     LIKE LINE OF et_row_no.
DATA gv_stbl TYPE lvc_s_stbl.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed ,
data_changed_finished
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells .
PRIVATE SECTION.
DATA: error_in_data TYPE c.
ENDCLASS.                    “lcl_event_receiver DEFINITION
DATA: main_event_receiver TYPE REF TO lcl_event_receiver.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD  handle_data_changed.
DATA ls_deleted_rows TYPE lvc_s_moce.
ENDMETHOD.                    <I>”HANDLE_DATA_CHANGED</I>
METHOD data_changed_finished.
DATA : lt_cells TYPE lvc_t_cell,
ls_cells TYPE lvc_s_cell.
ENDMETHOD.                    “DATA_CHANGED_FINISHED
ENDCLASS.                    “LCL_EVENT_RECEIVER IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE gt_sbook.
CALL SCREEN 0100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
PERFORM create_gui_objects_0100.
ENDMODULE.                ” STATUS_0100  OUTPUT
MODULE user_command_0100 INPUT.
CLEAR g_valid.
CALL METHOD g_alv_grid->check_changed_data
IMPORTING e_valid = g_valid.
CASE ok_code.
WHEN ‘&DATA_SAVE’.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE checkbox = ‘X’.
WRITE sy-tabix TO lv_tabix.
CONCATENATE lv_mesaj lv_tabix ‘,’ INTO lv_mesaj.
ENDLOOP.
CONCATENATE ‘Seçilen checkbox:’ lv_mesaj INTO lv_mesaj SEPARATED BY space.
MESSAGE lv_mesaj TYPE ‘I’.
CALL METHOD g_alv_grid->get_selected_rows
IMPORTING
et_index_rows = et_index_rows
et_row_no     = et_row_no.
LOOP AT et_row_no INTO wa_row_no  .
ls_sbook-box = ‘X’ .
MODIFY gt_sbook INDEX wa_row_no-row_id FROM ls_sbook TRANSPORTING box  .
ENDLOOP.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE box = ‘X’.
WRITE sy-tabix TO lv_tabix.
CONCATENATE lv_mesaj lv_tabix ‘,’ INTO lv_mesaj.
ENDLOOP.
CONCATENATE ‘Seçilen kutular:’ lv_mesaj INTO lv_mesaj SEPARATED BY space.
MESSAGE lv_mesaj TYPE ‘I’.
CLEAR lv_mesaj.
LOOP AT gt_sbook INTO ls_sbook WHERE metin IS NOT INITIAL.
MESSAGE ls_sbook-metin TYPE ‘I’.
ENDLOOP.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
CALL METHOD g_alv_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE.                 ” USER_COMMAND_0100  INPUT
MODULE exit INPUT.
LEAVE TO SCREEN 0.
ENDMODULE.                 ” EXIT  INPUT
FORM create_gui_objects_0100 .
DATA: lt_fieldcat TYPE lvc_t_fcat,
is_variant  TYPE disvariant,
is_layout   TYPE lvc_s_layo,
lt_toolbar_excluding TYPE ui_functions.
DATA : lt_cells TYPE lvc_t_cell,
ls_cells TYPE lvc_s_cell.
IF g_docking_container IS INITIAL.
CALL METHOD cl_gui_cfw=>dispatch.
CREATE OBJECT g_docking_container
EXPORTING
side       = g_docking_container->dock_at_top
extension  = 2000.
CREATE OBJECT g_alv_grid
EXPORTING
i_parent          = g_docking_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init   = 2
error_cntl_link   = 3
error_dp_create   = 4
OTHERS            = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
APPEND g_alv_grid->mc_fc_graph              TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_info               TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_append_row TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_copy           TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_copy_row       TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_cut            TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_delete_row TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_insert_row     TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_move_row       TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_paste          TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_paste_new_row  TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_loc_undo           TO lt_toolbar_excluding.
APPEND g_alv_grid->mc_fc_check              TO lt_toolbar_excluding.
CLEAR gs_fieldcat.
gs_fieldcat-tabname    = ‘GT_SBOOK’.
gs_fieldcat-fieldname  = ‘CHECKBOX’.
gs_fieldcat-seltext    = ‘CHECKBOX’.
gs_fieldcat-outputlen  = 3.
gs_fieldcat-checkbox   = ‘X’.
gs_fieldcat-edit       = ‘X’.
*    gs_fieldcat-no_out     = ‘X’.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘CARRID’.
gs_fieldcat-seltext    = ‘ID’.
gs_fieldcat-outputlen  = 7.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘CONNID’.
gs_fieldcat-seltext    = ‘No’.
gs_fieldcat-outputlen  = 8.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘FLDATE’.
gs_fieldcat-seltext    = ‘Uçuş tarihi’.
gs_fieldcat-outputlen  = 9.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname  = ‘METIN’.
gs_fieldcat-seltext    = ‘Açıklama’.
gs_fieldcat-outputlen  = 20.
gs_fieldcat-edit       = ‘X’.
APPEND gs_fieldcat TO gt_fieldcat.
is_layout-box_fname    = ‘BOX’.
CALL METHOD g_alv_grid->set_table_for_first_display
EXPORTING
i_save                        = ‘A’
is_variant                    = is_variant
is_layout                     = is_layout
it_toolbar_excluding          = lt_toolbar_excluding
CHANGING
it_outtab                     = gt_sbook
it_fieldcatalog               = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error                 = 2
too_many_lines                = 3
OTHERS                        = 4.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT main_event_receiver.
SET HANDLER main_event_receiver->handle_data_changed FOR g_alv_grid.
SET HANDLER main_event_receiver->data_changed_finished FOR g_alv_grid.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = g_alv_grid.
CALL METHOD g_alv_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
CALL METHOD g_alv_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD g_alv_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CLEAR: lt_cells[], ls_cells.
ls_cells-row_id-index = 1.
CALL METHOD g_alv_grid->set_selected_cells
EXPORTING
it_cells = lt_cells.
ELSE.
CALL METHOD g_alv_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
ENDIF.
ENDFORM.                    ” CREATE_GUI_OBJECTS_0100

Alan kataloğları kontrol edilecek.

Örnek: İki ALV gösteren örnek.

TABLES spfli.
DATA: gt_spfli TYPE STANDARD TABLE OF spfli,
gt_sbook type standard table of sbook.
DATA: ok_code LIKE sy-ucomm,
g_grid1 TYPE REF TO cl_gui_alv_grid,
g_grid2 TYPE REF TO cl_gui_alv_grid,
gs_variant LIKE disvariant,
g_docking_container1 TYPE REF TO cl_gui_docking_container,
g_docking_container2 TYPE REF TO cl_gui_docking_container.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
SELECT * FROM sbook
INTO CORRESPONDING FIELDS OF TABLE gt_sbook.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_docking_container1 IS INITIAL.
CREATE OBJECT g_docking_container1
EXPORTING
side       = g_docking_container1->dock_at_top
ratio      = 50.
CREATE OBJECT g_grid1
EXPORTING i_parent = g_docking_container1.
gs_variant-report = sy-repid.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING i_structure_name = ‘SPFLI’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_spfli.
ENDIF.
IF g_docking_container2 IS INITIAL.
CREATE OBJECT g_docking_container2
EXPORTING
side       = g_docking_container2->dock_at_bottom
ratio      = 50.
CREATE OBJECT g_grid2
EXPORTING i_parent = g_docking_container2.
gs_variant-report = sy-repid.
CALL METHOD g_grid2->set_table_for_first_display
EXPORTING i_structure_name = ‘SBOOK’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_sbook.
ENDIF.
ENDMODULE.                 ” STATUS_0100  OUTPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.                 ” USER_COMMAND_0100  INPUT

Örnek: İki Custom konteyner kullanarak iki farklı alv gösteren örnek.

TABLES spfli.
DATA: gt_spfli TYPE STANDARD TABLE OF spfli,
gt_sbook type standard table of sbook.
DATA: ok_code LIKE sy-ucomm,
g_grid1    TYPE REF TO cl_gui_alv_grid,
g_grid2    TYPE REF TO cl_gui_alv_grid,
gs_variant    LIKE disvariant,
g_custom_container1 TYPE REF TO cl_gui_custom_container,
g_custom_container2 TYPE REF TO cl_gui_custom_container.
START-OF-SELECTION.
SELECT * FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_spfli.
SELECT * FROM sbook
INTO CORRESPONDING FIELDS OF TABLE gt_sbook.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
SET TITLEBAR ‘100’.
IF g_custom_container1 IS INITIAL.
CREATE OBJECT g_custom_container1
EXPORTING container_name = ‘CONT1’.
CREATE OBJECT g_grid1
EXPORTING i_parent = g_custom_container1.
gs_variant-report = sy-repid.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING i_structure_name = ‘SPFLI’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_spfli.
ENDIF.
IF g_custom_container2 IS INITIAL.
CREATE OBJECT g_custom_container2
EXPORTING container_name = ‘CONT2’.
CREATE OBJECT g_grid2
EXPORTING i_parent = g_custom_container2.
gs_variant-report = sy-repid.
CALL METHOD g_grid2->set_table_for_first_display
EXPORTING i_structure_name = ‘SBOOK’
i_save           = ‘A’
is_variant       = gs_variant
CHANGING  it_outtab        = gt_sbook.
ENDIF.
ENDMODULE.                 <I>” STATUS_0100  OUTPUT</I>
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.                 ” USER_COMMAND_0100  INPUT

Örnek:

DATA: gt_fieldcat  TYPE lvc_t_fcat,
gs_fieldcat  TYPE lvc_s_fcat.
DATA : g_docking_container TYPE REF TO cl_gui_docking_container,
g_alv_grid          TYPE REF TO cl_gui_alv_grid,
ok_code LIKE sy-ucomm,
gt_mara TYPE STANDARD TABLE OF mara,
gs_mara TYPE mara,
gs_layout   TYPE lvc_s_layo.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS : handle_hotspot_click FOR EVENT hotspot_click OF
cl_gui_alv_grid
IMPORTING
e_row_id e_column_id es_row_no.
ENDCLASS.                    “lcl_event_receiver DEFINITION
DATA: main_event_receiver TYPE REF TO lcl_event_receiver.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_hotspot_click.
CASE e_column_id.
WHEN ‘MATNR’.
CLEAR gs_mara.
READ TABLE gt_mara INTO gs_mara INDEX e_row_id-index.
IF sy-subrc EQ 0.
SET PARAMETER ID ‘MAT’ FIELD gs_mara-matnr.
CALL TRANSACTION ‘MM03’ AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDMETHOD.
ENDCLASS.                    “LCL_EVENT_RECEIVER IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM mara UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_mara.
CALL SCREEN 0100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
PERFORM create_gui_objects_0100.
ENDMODULE.                 ” STATUS_0100  OUTPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.                 ” USER_COMMAND_0100  INPUT
MODULE exit INPUT.
LEAVE TO SCREEN 0.
ENDMODULE.                 ” EXIT  INPUT
FORM create_gui_objects_0100 .
DATA: lt_fieldcat TYPE lvc_t_fcat,
gs_variant  TYPE disvariant,
gs_layout   TYPE lvc_s_layo,
lt_toolbar_excluding TYPE ui_functions.
IF g_docking_container IS INITIAL.
CALL METHOD cl_gui_cfw=>dispatch.
CREATE OBJECT g_docking_container
EXPORTING
side       = g_docking_container->dock_at_top
extension  = 2000.
CREATE OBJECT g_alv_grid
EXPORTING
i_parent          = g_docking_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init   = 2
error_cntl_link   = 3
error_dp_create   = 4
OTHERS            = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
i_structure_name             = ‘MARA’
CHANGING
ct_fieldcat                  = gt_fieldcat
EXCEPTIONS
inconsistent_interface       = 1
program_error                = 2
OTHERS                       = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
gs_fieldcat-hotspot = ‘X’.
MODIFY gt_fieldcat FROM gs_fieldcat
TRANSPORTING hotspot
WHERE fieldname = ‘MATNR’.
gs_variant-report = sy-repid.
CALL METHOD g_alv_grid->set_table_for_first_display
EXPORTING
i_save                        = ‘A’
is_variant                    = gs_variant
is_layout                     = gs_layout
it_toolbar_excluding          = lt_toolbar_excluding
CHANGING
it_outtab                     = gt_mara
it_fieldcatalog               = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error                 = 2
too_many_lines                = 3
OTHERS                        = 4.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT main_event_receiver.
SET HANDLER main_event_receiver->handle_hotspot_click FOR g_alv_grid.
ELSE.
CALL METHOD g_alv_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
ENDIF.
ENDFORM.                    ” CREATE_GUI_OBJECTS_0100

Örnek: Veritabanı erişim işlemlerini gösteren örnek.

DATA : g_docking_container TYPE REF TO cl_gui_docking_container,
g_alv_grid          TYPE REF TO cl_gui_alv_grid,
ok_code LIKE sy-ucomm,
gt_sflight TYPE STANDARD TABLE OF sflight,
gs_sflight TYPE sflight.
CLASS lcl_alv DEFINITION.
PUBLIC SECTION.
METHODS:
alv_olustur,
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive
sender,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm sender.
ENDCLASS.
DATA g_alv TYPE REF TO lcl_alv.
CLASS lcl_alv IMPLEMENTATION.
METHOD alv_olustur.
DATA: lt_fieldcat   TYPE lvc_t_fcat,
ls_fieldcat   TYPE lvc_s_fcat,
ls_variant    TYPE disvariant,
ls_layout     TYPE lvc_s_layo,
lt_toolbar_excluding TYPE ui_functions,
lv_repid      TYPE sy-repid.
DATA: lt_cells TYPE lvc_t_cell,
ls_cells TYPE lvc_s_cell.
IF g_docking_container IS INITIAL.
CREATE OBJECT g_docking_container
EXPORTING
side       = g_docking_container->dock_at_top
extension  = 2000.
CREATE OBJECT g_alv_grid
EXPORTING
i_parent          = g_docking_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init   = 2
error_cntl_link   = 3
error_dp_create   = 4
OTHERS            = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
i_structure_name        = ‘ZSFLIGHT’
CHANGING
ct_fieldcat             = lt_fieldcat
EXCEPTIONS
inconsistent_interface  = 1
program_error           = 2
OTHERS                  = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ls_fieldcat-edit = ‘X’.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING edit
WHERE fieldname = ‘PRICE’.
ls_layout-box_fname    = ‘BOX’.
lv_repid = sy-repid.
ls_variant-report      = lv_repid.
CALL METHOD g_alv_grid->set_table_for_first_display
EXPORTING
i_save                        = ‘A’
is_variant                    = ls_variant
is_layout                     = ls_layout
it_toolbar_excluding          = lt_toolbar_excluding
CHANGING
it_outtab                     = gt_sflight
it_fieldcatalog               = lt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error                 = 2
too_many_lines                = 3
OTHERS                        = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
SET HANDLER me->handle_toolbar FOR g_alv_grid.
SET HANDLER me->handle_user_command FOR g_alv_grid.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = g_alv_grid.
CALL METHOD g_alv_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD g_alv_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
ENDIF.
ENDMETHOD.
METHOD handle_toolbar.
DATA ls_toolbar TYPE stb_button.
CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE ‘DOLDUR’           TO ls_toolbar-function.
MOVE icon_activity      TO ls_toolbar-icon.
MOVE ‘Tabloyu doldur’   TO ls_toolbar-text.
MOVE ‘select ve insert’ TO ls_toolbar-quickinfo.
APPEND ls_toolbar       TO e_object->mt_toolbar.
CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE ‘TUMUNUSIL’        TO ls_toolbar-function.
MOVE icon_delete        TO ls_toolbar-icon.
MOVE ‘Tümünü sil’       TO ls_toolbar-text.
MOVE ‘delete’           TO ls_toolbar-quickinfo.
APPEND ls_toolbar       TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE ‘SATIRSIL’         TO ls_toolbar-function.
MOVE icon_delete_row    TO ls_toolbar-icon.
MOVE ‘Seçileni sil’     TO ls_toolbar-text.
MOVE ‘delete’           TO ls_toolbar-quickinfo.
APPEND ls_toolbar       TO e_object->mt_toolbar.
CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE ‘GUNCELLEM’        TO ls_toolbar-function.
MOVE ‘Güncelle(modify)’ TO ls_toolbar-text.
MOVE ‘modify’           TO ls_toolbar-quickinfo.
APPEND ls_toolbar       TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE ‘GUNCELLEU’        TO ls_toolbar-function.
MOVE ‘Güncelle(update)’ TO ls_toolbar-text.
MOVE ‘update’           TO ls_toolbar-quickinfo.
APPEND ls_toolbar       TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
DATA: et_index_rows TYPE lvc_t_row,
et_row_no     TYPE lvc_t_roid,
wa_row_no     LIKE LINE OF et_row_no.
CASE e_ucomm.
WHEN ‘DOLDUR’.
REFRESH gt_sflight.
SELECT * FROM sflight UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
INSERT zsflight FROM TABLE gt_sflight.
CALL METHOD sender->refresh_table_display.
WHEN ‘TUMUNUSIL’.
DELETE FROM zsflight.
COMMIT WORK AND WAIT.
REFRESH gt_sflight.
CALL METHOD sender->refresh_table_display.
WHEN ‘SATIRSIL’.
CALL METHOD g_alv_grid->get_selected_rows
IMPORTING
et_index_rows = et_index_rows
et_row_no     = et_row_no.
LOOP AT et_row_no INTO wa_row_no.
READ TABLE gt_sflight INTO gs_sflight INDEX wa_row_no-row_id.
DELETE FROM zsflight WHERE carrid = gs_sflight-carrid AND
connid = gs_sflight-connid AND
fldate = gs_sflight-fldate.
COMMIT WORK AND WAIT.
DELETE gt_sflight WHERE carrid = gs_sflight-carrid AND
connid = gs_sflight-connid AND
fldate = gs_sflight-fldate.
CALL METHOD sender->refresh_table_display.
ENDLOOP.
WHEN ‘GUNCELLEM’.
MODIFY zsflight FROM TABLE gt_sflight.
COMMIT WORK AND WAIT.
WHEN ‘GUNCELLEU’.
UPDATE zsflight FROM TABLE gt_sflight.
COMMIT WORK AND WAIT.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECT * FROM zsflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
CREATE OBJECT g_alv.
CALL SCREEN 0100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘100’.
CALL METHOD g_alv->alv_olustur.
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘GERI’ OR ‘CIKIS’ OR ‘IPTAL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

Leave a Reply

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