modalen Fenster

www.4AP.de - alles über ABAP  -  Anzeige eines modalen Fensters beim Auslösen einer Drucktaste

Beispielcoding: wenn z.B. auf Tastendruck ein weiteres Fenster 'aufgehen' soll um weitere Daten anzuzeigen, so kann man das gut mit einem modalen Fenster lösen. Im Coding nur die wichtigsten Abschnitte.


*
* Coded by Thorsten Neubüser - www.4ap.de
*

 

*======================================================================*
* *
* TABELLEN- und DATENDEKLARATION *
* *
*======================================================================*


* Dialogbox Container
*----------------------------------------------------------------------*
* Objekt-Referenzvariablen (Anwender-Control)
*----------------------------------------------------------------------*

DATA: obj_dialogbox_container TYPE REF TO cl_gui_dialogbox_container,
* obj_picture TYPE REF TO cl_gui_picture.
grid_dialog TYPE REF TO cl_gui_alv_grid.
*----------------------------------------------------------------------*
* Klasse zum Event Handler und Objektreferenz definieren
*----------------------------------------------------------------------*

************************************************************************
* CLASS cl_event_receiver
* DEFINITION
************************************************************************

CLASS cl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS on_dialogbox_close
FOR EVENT close OF cl_gui_dialogbox_container
IMPORTING sender.
ENDCLASS. "cl_event_receiver DEFINITION
************************************************************************
* CLASS cl_event_receiver
* IMPLEMENTATION
************************************************************************

CLASS cl_event_receiver IMPLEMENTATION.
*----------------------------------------------------------------------*
* METHOD on_dialogbox_close
*----------------------------------------------------------------------*

METHOD on_dialogbox_close.
* grid_dialog Control
IF NOT grid_dialog IS INITIAL.
CALL METHOD grid_dialog->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc >< 0.
MESSAGE i398(00) WITH 'Fehler'(100) sy-subrc
'bei Methode FREE zum Objekt grid_dialog'(102) ''.
ENDIF.
FREE grid_dialog.
ENDIF.
* Dialogbox Control
IF NOT obj_dialogbox_container IS INITIAL.
CALL METHOD obj_dialogbox_container->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc >< 0.
MESSAGE i398(00) WITH 'Fehler'(100) sy-subrc
'bei Methode FREE zum DIALOGBOX_CONTAINER'(103) ''.
ENDIF.
FREE obj_dialogbox_container.
ENDIF.
*----------------------------------------------------------------------*
* Synchronisieren der Automation Queue
*----------------------------------------------------------------------*

CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2
OTHERS = 3.
IF sy-subrc >< 0.
MESSAGE i398(00) WITH 'Fehler'(100) sy-subrc
'bei FLUSH'(104) ''.
ENDIF.
ENDMETHOD. "on_dialogbox_close
ENDCLASS. "cl_event_receiver IMPLEMENTATION

DATA:
obj_event_receiver TYPE REF TO cl_event_receiver,
it_fieldcat_grid_dialog TYPE lvc_t_fcat WITH HEADER LINE,
it_sort_grid_dialog TYPE lvc_t_sort WITH HEADER LINE,
is_layout TYPE lvc_s_layo.



* beim Anklicken der Drucktast wird folgendes aufgerufen
PERFORM modales_fenster_alv.




*---------------------------------------------------------------------*
* Form modales_fenster_alv
*---------------------------------------------------------------------*

FORM modales_fenster_alv .

*&--------------------------
* Instanz anlegen
*---------------------------

IF obj_dialogbox_container IS INITIAL.
*----------------------------------------------------------------*
* Instanz zum Dialogbox Container Control anlegen
*----------------------------------------------------------------*

CREATE OBJECT obj_dialogbox_container
EXPORTING
* PARENT =
width = 950 "Breite
height = 350 "Höhe
* STYLE =
* REPID =
* DYNNR =
* LIFETIME = lifetime_default

top = 30 "Abstand nach oben
left = 100 "Abstand von links
caption = 'Buchungsdatenanzeige'(033)
* NO_AUTODEF_PROGID_DYNNR =
* METRIC = 0
* NAME =

EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
event_already_registered = 6
error_regist_event = 7
OTHERS = 8.
IF sy-subrc >< 0.
MESSAGE i398(00) WITH 'Fehler' sy-subrc
'beim Anlegen des Dialogbox Container Controls' ''.
ENDIF.
*-----------------------------------------------------------------*
* Instanz zum grid_dialog Control anlegen
*-----------------------------------------------------------------*

CREATE OBJECT grid_dialog
EXPORTING
i_parent = obj_dialogbox_container.
IF sy-subrc >< 0.
MESSAGE i398(00) WITH 'Fehler' sy-subrc
'beim Anlegen des Picture Controls' ''.
ENDIF.
ENDIF. " obj_dialogbox_container IS INITIAL

*-----------------------------------------------------------------*
* Eventhandler anlegen und Ereignisse registrieren
*-----------------------------------------------------------------*

IF obj_event_receiver IS INITIAL.
CREATE OBJECT obj_event_receiver.
SET HANDLER obj_event_receiver->on_dialogbox_close
FOR ALL INSTANCES.
ENDIF.

*-----------------------------------------------------------------*
* grid_dialog mit Inhalt füllen und ausgeben
*-----------------------------------------------------------------*

* !!!! jetzt gehts los

IF it_fieldcat_grid_dialog[] IS INITIAL.
PERFORM set_fieldcat_grid_dialog.
PERFORM set_layout_grid_dialog.

* Sortierung voreinstellen
CLEAR: it_sort_grid_dialog. REFRESH: it_sort_grid_dialog.
it_sort_grid_dialog-spos = '1'. " Sortierreihenfolge
it_sort_grid_dialog-fieldname = 'SKONT_TEXT'.
it_sort_grid_dialog-up = 'X'.
* it_sort_grid_dialog-down = 'X'.
APPEND it_sort_grid_dialog.

CLEAR: it_sort_grid_dialog.
it_sort_grid_dialog-fieldname = 'SKONT'.
it_sort_grid_dialog-spos = '2'. " Sortierreihenfolge
it_sort_grid_dialog-subtot = 'X'.
APPEND it_sort_grid_dialog.

* Liste anreichern
LOOP AT itab_buch.
CLEAR: itab_buch-skont_text.
IF itab_buch-skont = '593400'.
itab_buch-skont_text = text-027.
MODIFY itab_buch.
ELSEIF itab_buch-skont = '593450'.
itab_buch-skont_text = text-026.
MODIFY itab_buch.
ENDIF.
ENDLOOP. " at itab_buch
ENDIF. " it_fieldcat_grid_dialog[] is initial.
* ALV ausgeben
CALL METHOD grid_dialog->set_table_for_first_display
EXPORTING
* I_BYPASSING_BUFFER = 'X'
* I_BUFFER_ACTIVE = 'X' " Typ Any
* I_CONSISTENCY_CHECK =

i_structure_name = 'ITAB_BUCH_TYPE' " Typ DD02L-TABNAME
is_variant = is_variant " Typ DISVARIANT
* U = User darf Varianten nur für sich oder A = für alle abspeichern
i_save = 'A' " Typ CHAR01
i_default = 'X' " Typ CHAR01
is_layout = is_layout " Typ LVC_S_LAYO
* IS_PRINT = " Typ LVC_S_PRNT
* IT_SPECIAL_GROUPS = " Typ LVC_T_SGRP
* IT_TOOLBAR_EXCLUDING = " Typ UI_FUNCTIONS
* IT_HYPERLINK = " Typ LVC_T_HYPE
* IT_ALV_GRAPHICS = " Typ DTC_T_TC
* IT_EXCEPT_QINFO =

CHANGING
it_outtab = itab_buch[]
it_fieldcatalog = it_fieldcat_grid_dialog[]
it_sort = it_sort_grid_dialog[]
* IT_FILTER = " Typ LVC_T_FILT
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
. " Punkt
IF sy-subrc >< 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " modales_fenster_alv


*---------------------------------------------------------------------*
* Form set_fieldcat_grid_dialog
*---------------------------------------------------------------------*

FORM set_fieldcat_grid_dialog .
CLEAR: it_fieldcat_grid_dialog.
REFRESH: it_fieldcat_grid_dialog.
it_fieldcat_grid_dialog-fieldname = 'SKONT'.
it_fieldcat_grid_dialog-inttype = 'C'.
it_fieldcat_grid_dialog-outputlen = 6.
it_fieldcat_grid_dialog-coltext = 'Spediteur'.
APPEND it_fieldcat_grid_dialog.
CLEAR: it_fieldcat_grid_dialog.

it_fieldcat_grid_dialog-fieldname = 'KOSTL'.
it_fieldcat_grid_dialog-ref_table = 'ZT959K'.
APPEND it_fieldcat_grid_dialog.
CLEAR: it_fieldcat_grid_dialog.

it_fieldcat_grid_dialog-fieldname = 'SOLL'.
it_fieldcat_grid_dialog-do_sum = 'X'.
it_fieldcat_grid_dialog-inttype = 'P'.
it_fieldcat_grid_dialog-outputlen = 15.
it_fieldcat_grid_dialog-coltext = 'Soll'.
APPEND it_fieldcat_grid_dialog.
CLEAR: it_fieldcat_grid_dialog.

it_fieldcat_grid_dialog-fieldname = 'KTEXT'.
it_fieldcat_grid_dialog-ref_table = 'CSKT'.
it_fieldcat_grid_dialog-ref_field = 'LTEXT'.
APPEND it_fieldcat_grid_dialog.
CLEAR: it_fieldcat_grid_dialog.

it_fieldcat_grid_dialog-fieldname = 'SKONT_TEXT'.
it_fieldcat_grid_dialog-inttype = 'C'.
it_fieldcat_grid_dialog-outputlen = 20.
it_fieldcat_grid_dialog-coltext = 'Kontoart'.
APPEND it_fieldcat_grid_dialog.
CLEAR: it_fieldcat_grid_dialog.
ENDFORM. " set_fieldcat_grid_dialog


*&---------------------------------------------------------------------*
*& Form set_layoutgrid_dialog
*&---------------------------------------------------------------------*

FORM set_layout_grid_dialog.
* Layout Struktur
CLEAR is_layout.
is_layout-smalltitle = 'X'.
is_layout-cwidth_opt = 'X'.
* is_layout-info_fname = 'LCOLOR'.
* is_layout-sel_mode = 'D'.
*TNT hier Header-Infossetzen! VKORG etc.

CONCATENATE text-007 text-031 sy-datum '|' text-034 '|' text-035
INTO is_layout-grid_title SEPARATED BY ' '. " max 70 Char
* gestreifte Ausgabe
is_layout-zebra = 'X'.
* Summen oben
is_layout-totals_bef = 'X'.
* is_layout-NUMC_TOTAL = 'X'. " Summieren von NUMC-Feldern zulassen
ENDFORM. " set_layoutgrid_dialog