[ABAP] Verwendung des GUI-Controls cl_gui_calendar

* SAPCALENDAR_DEMO1
* SAPCALENDAR_DRAG_DROP
* RSDEMO_CALENDAR_CONTROL
DATA: o_cnt TYPE REF TO cl_gui_dialogbox_container.
DATA: o_cal TYPE REF TO cl_gui_calendar.

* Dummyparameter für Selektion im Kalender
PARAMETERS: p_week TYPE string.
PARAMETERS: p_date TYPE string.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS on_close FOR EVENT close OF cl_gui_dialogbox_container
      IMPORTING
          sender.
    CLASS-METHODS on_date_selected FOR EVENT date_selected OF cl_gui_calendar
      IMPORTING
          date_begin
          date_end
          sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Event, wenn auf das Schließen-Kreuz geklickt wird
  METHOD on_close.
    sender->free( ).
  ENDMETHOD.

* Event für Datumsselektion im Kalender
  METHOD on_date_selected.
    DATA: lv_date_begin TYPE cnca_utc_date.

    TRY.
        sender->get_selection( IMPORTING date_begin = lv_date_begin ).

        p_week = cl_bs_period_toolset_basics=>get_calendar_week( CONV #( lv_date_begin ) ).
        p_date = lv_date_begin.
      CATCH cx_root INTO DATA(e_txt).
    ENDTRY.

  ENDMETHOD.

ENDCLASS.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_week.
* Popupfenster
  o_cnt = NEW #( no_autodef_progid_dynnr = abap_true
                 caption = 'Kalender'
                 top = 100
                 left = 200
                 width = 640
                 height = 120 ).

* on_close Handler für Popup setzen
  SET HANDLER lcl_events=>on_close FOR o_cnt.

* neues Kalenderobjekt erzeugen (überschreibt vorherige Referenz!)
  o_cal = NEW #( parent          = o_cnt
                 selection_style = cnca_sel_week
                 view_style      = cnca_style_h_navigator ).

  DATA: it_events TYPE cntl_simple_events.

  it_events = VALUE #( ( eventid = cl_gui_calendar=>m_id_date_selected
                         appl_event = abap_true ) ).

  o_cal->set_registered_events( events = it_events ).

  SET HANDLER lcl_events=>on_date_selected FOR o_cal.

START-OF-SELECTION.
  WRITE / p_week.
  WRITE / p_date.