Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglich?

Die Frage ist als "gelöst" markiert. Den entsprechend Beitrag findest du hier.

Die Objektorientierung mit ABAP®: Vererbung, Dynamische Programmierung, GUI Controls (u.a. ALV im OO).
15 Beiträge • Seite 1 von 1
15 Beiträge Seite 1 von 1

Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglich?

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo ALV-OO-Experten,
für das folgende Problem habe ich, trotz intensivster Recherchen im Internet, bisher keine Lösung gefunden. Ich habe den Verdacht, dass das nicht geht, was ich realisieren will.

Ich habe einen ALV in einem Popup-Fenster!!! mit der Klasse CL_SALV_TABLE ausgegeben.
Dabei ist das Popup-Fenster aus "optischen" Gründen eine Bedingung, die ich in diesem speziellen Fall nicht anders lösen kann und will (Fullscreen usw).

Ist in diesem ALV die Implementierung einer Drag&Drop-Funktionalität von Zeilen möglich?
Wenn ja, wie kann man das lösen?
Wenn nein, wie kann man das anders lösen, wobei die Ausgabe in einem Popup wichtig ist?

Danke und Gruß an alle,
die mir evtl. Tipps geben können

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von black_adept (Top Expert / 4080 / 125 / 934 ) »
Hallo Einar,

ich glaube dass D&D nicht mit dem SALV direkt abbildbar ist.
Aber de facto verwendet der SALV letztendlich auch nur den cl_gui_alv_grid. Somit sollte es reichen, wenn du dir eine Referenz auf den angezeigten Grid holst und dann "wie üblich" das D&D ausprogrammierst.

Die Referenz auf den Grid bekommst du üblicherweise über den Weg "Container in dem der Grid angezeigt wird->Children"
live long and prosper
Stefan Schmöcker

email: stefan@schmoecker.de

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo black_adept,
danke erstmal für Deine schnelle Antwort.

Das habe ich mir fast gedacht, dass das nicht mit dem SALV geht.

Ich gebe den ALV, wie gesagt, mit der factory-Methode der Klasse CL_SALV_TABLE (Referenz GR_TABLE) aus,
aber ohne!!! Container-Angabe. Einfach als Popup. Die Funktionstasten liegen bei einem Popup am unteren Rand,
so ist es jedenfalls bei mir. Bei einer Ausgabe in einen Container (Fullscreen?) sieht das Layout anders aus (Buttons sind oben).

Oder verstehe ich da etwas falsch?

Ist die Container-Angabe erforderlich?
Wie komme ich genau an die von Dir genannte Referenz?

Danke und Gruß

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von a-dead-trousers (Top Expert / 4394 / 223 / 1182 ) »
Such mal hier im Forum... Ich glaub mich dunkel zu erinnern dass vor nicht all zu langer Zeit mal die selbe Frage gestellt wurde.
Ich glaub dafür gibt es einen Funktionsbaustein oder sowas.

lg ADT
Theory is when you know something, but it doesn't work.
Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.

ECC: 6.18
Basis: 7.50

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo a-dead-trousers,
ich habe intensiv im Forum gesucht, aber nichts gefunden, was auf mein Problem passen würde.

Ich kenne auch die ganzen Testprogramme von SAP zu der Klasse CL_SALV_TABLE und anderen Klassen.

Im Fullscreen-Modus habe ich das selbst schon mal programmiert, aber an das Coding (soviel war das nicht) komme ich nicht mehr heran (habs mir leider nicht aufgehoben), weil das bei einer anderen Firma war. Ich weiß nur noch, dass ich mich fürchterlich geplagt habe, bis das D&D funktioniert hat. Ein Knackpunkt war, wenn ich mich recht entsinne, dass man die Buttons zur Zeilenmarkierung nicht aktivieren darf. Zeilen werden einfach so markiert und dann per D&D verschoben.

Aber wie gesagt, ich habe das nicht im Popup-Modus hinbekommen.

Gruß Einar

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von a-dead-trousers (Top Expert / 4394 / 223 / 1182 ) »
hi!

Hab mir alles im SALV nochmal durchgeschaut. Der GUI-Container in dem das ALV-Grid liegt ist direct im CL_SALV_TABLE definiert. Leider aber PRIVATE.
Am Besten du machst das Popup-Dynpro samt GUI-Custom-Container selbst. Dann hast du auch eine Referenz auf den Container und kommst über dessen CHILDREN and die CL_GUI_ALV_GRID-Instanz.

Hab noch was gefunden:
Die Methode CL_SALV_FULLSCREEN_ADAPTER=>GET_GRID ruft den Funktionsbaustein GET_GLOBALS_FROM_SLVC_FULLSCR auf.
Vielleicht hilft ja das weiter.

lg ADT.
Theory is when you know something, but it doesn't work.
Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.

ECC: 6.18
Basis: 7.50

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von black_adept (Top Expert / 4080 / 125 / 934 ) »
Hallo Einar,

was mir nicht klar ist ist, wie du den Popupmodus aktivierst. Bei mir kommt der SALV dann immer im Fullscreenmodus daher wenn ich keinen Container angebe.
Kannst du nicht mal die wesentlichen Zeilen deines Progs in ein neues Prog einfügen, welches nichts anderes macht als die Tabelle T000 zu lesen und dann als Popup auszugeben und dann hier zu posten. Dann könnte ich zumindest mal nachschauen wie du an den cl_gui_alv_grid rankommst falls nicht der Weg über die GET_GLOBALS_FROM_SLVC_FULLSCR zum Erfolg führt.
live long and prosper
Stefan Schmöcker

email: stefan@schmoecker.de

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo black_adept,
der Weg über GET_GLOBALS_FROM_SLVC_FULLSCR führt nicht zum Erfolg.

Ich habe jetzt mal mein kleines Testprogramm in eine TXT-Datei im Anhang überführt. Ich hoffe, dass sie sichtbar ist.

D&D funktioniert leider immer noch nicht, die Ereignisse ONDROP und ONDRAG werden im Moment noch nicht angesprungen.
Ich habe mal die Editierbarkeit eines ALV als Button in das Programm integriert. Das funktioniert.
Im Coding siehst Du auch, wie man einen ALV als Popup ausgiebt, aber das ist im Moment auskommentiert.

Code: Alles auswählen.

REPORT zkar_dragdrop_5
       MESSAGE-ID ztass_util.
* Overcome the restriction of the SALV model using the power of the
* Object Oriented ABAP
TYPES:
  ty_t_sflights TYPE STANDARD TABLE OF sflights.

DATA:
  gt_data TYPE ty_t_sflights.

* Class declaration
CLASS:
  lcl_salv_model DEFINITION DEFERRED,
  lcl_objdragdropapp DEFINITION DEFERRED.

* Data declarations for alv
DATA:
  gr_container TYPE REF TO cl_gui_custom_container,
  gr_dragdropapp TYPE REF TO lcl_objdragdropapp,
  gr_alv TYPE REF TO cl_gui_alv_grid,
* Reference variable to CL_DRAGDROP
  gr_dragdropalv TYPE REF TO cl_dragdrop.

* Declarations for handle event
DATA:
  gv_effect TYPE i,
  gv_handle_alv TYPE i,
  gv_okcode TYPE syucomm.

DATA:
  gr_salv TYPE REF TO cl_salv_table,
  gr_salv_model TYPE REF TO lcl_salv_model.

*-----------------------------------------------------------------------
* Define the Local class inheriting from the CL_SALV_MODEL_LIST
* to get an access of the model, controller and adapter which inturn
* provides the Grid Object
*-----------------------------------------------------------------------
CLASS lcl_salv_model DEFINITION INHERITING FROM cl_salv_model_list.
  PUBLIC SECTION.
    DATA:
      lo_control TYPE REF TO cl_salv_controller_model,
      lo_adapter TYPE REF TO cl_salv_adapter.

    METHODS:
      grabe_model
        IMPORTING
          io_model TYPE REF TO cl_salv_model,

      grabe_controller,
      grabe_adapter.

  PRIVATE SECTION.
    DATA:
      lo_model TYPE REF TO cl_salv_model.
ENDCLASS.                    "LCL_SALV_MODEL DEFINITION

* LCL_SALV_MODEL implementation
CLASS lcl_salv_model IMPLEMENTATION.
  METHOD grabe_model.
* Save the model
    lo_model = io_model.
  ENDMETHOD.                    "grabe_model

  METHOD grabe_controller.
* Save the controller
    lo_control = lo_model->r_controller.
  ENDMETHOD.                    "grabe_controller

  METHOD grabe_adapter.
* Save the adapter from controller
    lo_adapter ?= lo_model->r_controller->r_adapter.
  ENDMETHOD.                    "grabe_adapter
ENDCLASS.                    "LCL_SALV_MODEL IMPLEMENTATION

*-----------------------------------------------------------------------
* Event handler for the added buttons
*-----------------------------------------------------------------------
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_user_command
        FOR EVENT added_function
          OF cl_salv_events
          IMPORTING e_salv_function.
ENDCLASS.                    "lcl_event_handler DEFINITION

* Event Handler for the SALV
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD on_user_command.
*    DATA:
*      lo_grid TYPE REF TO cl_gui_alv_grid,
**      lo_full_adapter TYPE REF TO cl_salv_fullscreen_adapter.
*      lo_full_adapter TYPE REF TO cl_salv_grid_adapter.
    DATA:
      ls_layout TYPE lvc_s_layo.

    CASE e_salv_function.
* Make ALV as Editable ALV
      WHEN 'MYFUNCTION'.
** Controller
*        CALL METHOD gr_salv_model->grabe_controller.
** Adapter
*        CALL METHOD gr_salv_model->grabe_adapter.
** Fullscreen Adapter (Down Casting)
*        lo_full_adapter ?= gr_salv_model->lo_adapter.
** Get the Grid
*        lo_grid = lo_full_adapter->get_grid( ).
** Got the Grid ?
*        IF lo_grid IS BOUND.
** Editable ALV
*          ls_layout-edit = 'X'.
** Set the front layout of ALV
*          CALL METHOD lo_grid->set_frontend_layout
*            EXPORTING
*              is_layout = ls_layout.
** Refresh the table
*          CALL METHOD lo_grid->refresh_table_display.
*         ENDIF.

* Editable ALV
        ls_layout-edit = 'X'.
* Set the front layout of ALV
        CALL METHOD gr_alv->set_frontend_layout
          EXPORTING
            is_layout = ls_layout.
* Refresh the table
        CALL METHOD gr_alv->refresh_table_display.
    ENDCASE.
  ENDMETHOD.                    "on_user_command
ENDCLASS.                           "lcl_event_handler IMPLEMENTATION

*-----------------------------------------------------------------------
* Class definitions and method implementation for drag and drop
*-----------------------------------------------------------------------
CLASS lcl_dragdrop DEFINITION.
  PUBLIC SECTION.
    DATA: wa TYPE sflights,
          index TYPE i.   "Index of Line to be moved
ENDCLASS.                    "LCL_DRAGDROP DEFINITION

*-----------------------------------------------------------------------
* Application class definition
*-----------------------------------------------------------------------
CLASS lcl_objdragdropapp DEFINITION.
  PUBLIC SECTION.
    METHODS:
* Handling Event Drag
      handle_alv_drag
        FOR EVENT ondrag
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj,

* Handling event DROP
      handle_alv_drop
        FOR EVENT ondrop
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj.
ENDCLASS.                    "LCL_objdragdropapp DEFINITION

* Application class implementation
CLASS lcl_objdragdropapp IMPLEMENTATION.

* OnDrag event is used to 'fetch' information from the drag source.
  METHOD handle_alv_drag.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop,
      ls_line TYPE sflights.

* Read dragged row
    READ TABLE gt_data INDEX e_row-index INTO ls_line.

* Create and fill dataobject for events ONDROP
    CREATE OBJECT lo_dataobj.

* Remembering row index to move a line
    MOVE e_row-index TO lo_dataobj->index.

* Store the dragged line.
    READ TABLE gt_data INTO lo_dataobj->wa INDEX e_row-index.

* Assigning data object to the refering event parameter
    e_dragdropobj->object = lo_dataobj.
  ENDMETHOD.                    "HANDLE_ALV_DRAG

* Event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop source.
  METHOD handle_alv_drop.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop.
*      lo_grid TYPE REF TO cl_gui_alv_grid,
*      lo_full_adapter TYPE REF TO cl_salv_fullscreen_adapter,
*      ls_layout TYPE lvc_s_layo,
*      ls_stable TYPE lvc_s_stbl.

** Refresh Alv Grid Control without scrolling
*    ls_stable-row = 'X'.
*    ls_stable-col = 'X'.

* Catch-Statement to ensure the drag&drop-Operation is aborted properly.
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      lo_dataobj ?= e_dragdropobj->object.

      DELETE gt_data INDEX lo_dataobj->index.
      INSERT lo_dataobj->wa INTO gt_data INDEX e_row-index.

** Controller
*      CALL METHOD gr_salv_model->grabe_controller.
** Adapter
*      CALL METHOD gr_salv_model->grabe_adapter.
** Fullscreen Adapter (Down Casting)
*      lo_full_adapter ?= gr_salv_model->lo_adapter.
** Get the Grid
*      lo_grid = lo_full_adapter->get_grid( ).
** Got the Grid ?
*      IF lo_grid IS BOUND.
*** Editable ALV
**        CLEAR ls_layout.
**        ls_layout-edit = 'X'.
*** Set the front layout of ALV
**        CALL METHOD lo_grid->set_frontend_layout
**          EXPORTING
**            is_layout = ls_layout.
** refresh the table
*        CALL METHOD lo_grid->refresh_table_display
*          EXPORTING
*            i_soft_refresh = 'X'
*            is_stable      = ls_stable.
*      ENDIF.

      gr_salv->refresh( ).
    ENDCATCH.

    IF sy-subrc <> 0.
* If anything went wrong aborting the drag and drop operation
      CALL METHOD e_dragdropobj->abort.
    ENDIF.
  ENDMETHOD.                    "HANDLE_ALV_DROP
ENDCLASS.                    "LCL_objdragdropapp IMPLEMENTATION

* Start of selection
START-OF-SELECTION.
* test data
  SELECT *
    FROM sflights
    INTO TABLE gt_data
      UP TO 30 ROWS.

  CALL SCREEN 0100 STARTING AT 10 5.

*----------------------------------------------------------------------*
*  MODULE pbo OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  PERFORM pbo.
ENDMODULE.                    "pbo OUTPUT

*----------------------------------------------------------------------*
*  MODULE pai INPUT
*----------------------------------------------------------------------*
MODULE pai INPUT.
  PERFORM pai.
ENDMODULE.                    "pai INPUT

*&---------------------------------------------------------------------*
*&      Form  pbo
*&---------------------------------------------------------------------*
FORM pbo.
*  SET PF-STATUS 'D0100' OF PROGRAM 'SALV_DEMO_TABLE_FORM_EVENTS'.
  SET PF-STATUS 'D0100'.

  IF gr_container IS NOT BOUND.
    IF cl_salv_table=>is_offline( ) EQ if_salv_c_bool_sap=>false.
      CREATE OBJECT gr_container
        EXPORTING
          container_name = 'CONTAINER'.
    ENDIF.

* New ALV Instance
    TRY.
        cl_salv_table=>factory(
          EXPORTING
            r_container    = gr_container
            container_name = 'CONTAINER'
          IMPORTING
            r_salv_table   = gr_salv
          CHANGING
            t_table        = gt_data ).
      CATCH cx_salv_msg.                                "#EC NO_HANDLER
    ENDTRY.

** New ALV Instance
*  TRY.
*      cl_salv_table=>factory(
*        EXPORTING
*          list_display = abap_false
*        IMPORTING
*          r_salv_table = gr_salv
*        CHANGING
*          t_table      = gt_data ).
*    CATCH cx_salv_msg.                                  "#EC NO_HANDLER
*  ENDTRY.

* Activate ALV generic Functions
    DATA:
      lr_functions TYPE REF TO cl_salv_functions_list,
      lv_text TYPE string,
      lv_icon TYPE string.

    lr_functions = gr_salv->get_functions( ).
    lr_functions->set_all( 'X' ).

** Add MYFUNCTION from the report SALV_DEMO_TABLE_EVENTS
*    gr_salv->set_screen_status(
*      pfstatus      =  'SALV_STANDARD'
*      report        =  'SALV_DEMO_TABLE_EVENTS'
*      set_functions = gr_salv->c_functions_all ).

* Include own functions
    TRY.
        lv_text = 'Meine eigene Funktion'.
        lv_icon = icon_complete.
        lr_functions->add_function(
          name     = 'MYFUNCTION'
          icon     = lv_icon
          text     = lv_text
          tooltip  = lv_text
          position = if_salv_c_function_position=>right_of_salv_functions ).
      CATCH cx_salv_wrong_call cx_salv_existing.        "#EC NO_HANDLER
    ENDTRY.

* Set the selection mode of the Popup: multiple or single row selection
    DATA:
      lr_selections TYPE REF TO cl_salv_selections.

    lr_selections = gr_salv->get_selections( ).
    lr_selections->set_selection_mode( if_salv_c_selection_mode=>multiple ).
*  lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

*    gr_salv->set_screen_popup(
*      start_column = 10
*      end_column   = 110
*      start_line   = 2
*      end_line     = 25 ).

* Event handler for the button
    DATA:
      lo_events TYPE REF TO cl_salv_events_table,
      lo_event_h TYPE REF TO lcl_event_handler.

* Event object
    lo_events = gr_salv->get_event( ).

* Event handler
    CREATE OBJECT lo_event_h.

* Setting up the event handler
    SET HANDLER lo_event_h->on_user_command FOR lo_events.

* Get Model Object
    DATA:
      lo_alv_model TYPE REF TO cl_salv_model,
*      lo_full_adapter TYPE REF TO cl_salv_fullscreen_adapter.
      lo_full_adapter TYPE REF TO cl_salv_grid_adapter.

* Narrow casting
    lo_alv_model ?= gr_salv.

* Object for the local inherited class from the CL_SALV_MODEL_LIST
    CREATE OBJECT gr_salv_model.

* Grabe model to use it later
    CALL METHOD gr_salv_model->grabe_model
      EXPORTING
        io_model = lo_alv_model.

* Generate ALV output
* It is required to execute the display method otherwise the adapter
* will not been instantiated when grabbing the alv grid
    gr_salv->display( ).

* Controller
    CALL METHOD gr_salv_model->grabe_controller.

* Adapter
    CALL METHOD gr_salv_model->grabe_adapter.

* Fullscreen Adapter (Down Casting)
    lo_full_adapter ?= gr_salv_model->lo_adapter.

    IF lo_full_adapter IS BOUND.
* Get the Grid
      gr_alv = lo_full_adapter->get_grid( ).
* Got the Grid ?
      IF gr_alv IS BOUND.
* Create the application object to handle the ABAP Objects Events
        CREATE OBJECT gr_dragdropapp.

* Events alv control
* For Dragging
        SET HANDLER gr_dragdropapp->handle_alv_drag FOR gr_alv.
* For Dropping
        SET HANDLER gr_dragdropapp->handle_alv_drop FOR gr_alv.

* Define a drag & Drop behaviour for the whole grid
        CREATE OBJECT gr_dragdropalv.

        gv_effect = cl_dragdrop=>move + cl_dragdrop=>copy.

        CALL METHOD gr_dragdropalv->add
          EXPORTING
            flavor     = 'Line'
            dragsrc    = 'X'
            droptarget = 'X'
            effect     = gv_effect.

* Getting the handle for drag and drop
        CALL METHOD gr_dragdropalv->get_handle
          IMPORTING
            handle = gv_handle_alv.

* Provide handle to alv control to all rows for same drag & drop behaviour
        DATA:
          ls_layout TYPE lvc_s_layo.

        CLEAR ls_layout.
* Editable ALV
*  ls_layout-edit = 'X'.
        ls_layout-zebra = 'X'.
        ls_layout-s_dragdrop-row_ddid = gv_handle_alv.
*        ls_layout-s_dragdrop-cntr_ddid = gv_handle_alv.

* Set the front layout of ALV
        CALL METHOD gr_alv->set_frontend_layout
          EXPORTING
            is_layout = ls_layout.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    "pbo

*&---------------------------------------------------------------------*
*&      Form  pai
*&---------------------------------------------------------------------*
FORM pai.
  CASE gv_okcode.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDW'.
      MESSAGE i000 WITH 'Weiter...'.
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDZ'.
      MESSAGE i000 WITH 'Zurück...'.
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN OTHERS.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDFORM.                    "pai

*** Programmende ***
Gruß Einar

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von black_adept (Top Expert / 4080 / 125 / 934 ) »
Guten Morgen Einar,

schau doch mal ob du mit dem folgenden Coding zurecht kommst.

Du musst allerdings den Screen 9000 irgendwie sinnvoll definieren.

Code: Alles auswählen.

REPORT .


DATA: gt_data TYPE STANDARD TABLE OF sflight WITH NON-UNIQUE DEFAULT KEY,
      go_salv TYPE REF TO cl_salv_table,
      go_grid TYPE REF TO cl_gui_alv_grid,
      ok_code TYPE syucomm.



START-OF-SELECTION.
  SELECT * UP TO 100 ROWS
    INTO TABLE gt_data
    FROM sflight.


END-OF-SELECTION.
  PERFORM create_salv.
  CALL SCREEN 9000 STARTING AT 40 4.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
  SET PF-STATUS '9000'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_9000  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
  CASE ok_code.
    WHEN 'ABBR'
      OR 'EXIT'
      OR 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  CREATE_SALV
*&---------------------------------------------------------------------*
FORM create_salv .
  DATA: ls_child                      LIKE LINE OF cl_gui_container=>screen1->children.

  DATA: lo_salv_functions_list        TYPE REF TO cl_salv_functions_list.
  TRY.
      cl_salv_table=>factory( EXPORTING
                                r_container    = cl_gui_container=>screen1  " 1. Popuplevel vollständig überdecken
                              IMPORTING
                                r_salv_table   = go_salv
                              CHANGING
                                t_table        = gt_data ).
      lo_salv_functions_list = go_salv->get_functions( ).
      lo_salv_functions_list->set_all( ).


      go_salv->display( ).

      READ TABLE cl_gui_container=>screen1->children INDEX 1 INTO ls_child.
* Sinnvoller Test, ob das überhaupt ein Grid ist sollte man hier wohl einbauen - hab ich aber gerade keine Lust dazu
      go_grid ?= ls_child.


      BREAK-POINT.
    CATCH cx_salv_msg .
  ENDTRY.

ENDFORM.                    " CREATE_SALV
live long and prosper
Stefan Schmöcker

email: stefan@schmoecker.de

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo black-adept,
da haben sich wohl unsere Antworten "überholt".

Ich habe Deinen Vorschlag ausprobiert, der ist natürlich wesentlich kürzer.
Und er funktioniert auch.

Aber das geschilderte Problem bleibt trotzdem bestehen, dass D&D erst nach einmaliger Ausführung der Funktion MYFUNCTION funktioniert.

Danke und Gruß
Einar

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von black_adept (Top Expert / 4080 / 125 / 934 ) »
Hallo einar,

wenn du eine erweiterte Version "meines" (kurzen) Vorschlags hast, der D&D realisiert ( von mir aus auch erst nach dem Ausführen deiner MY_FUNCTION ) poste das doch mal.
Ich mache einfach zu wenig mit D&D als dass ich das jetzt so nebenbei einbauen könnte - aber wenn ich sehe wie du es gelöst hast sehe ich ja vielleicht warum es erst einen Klick zu spät funktioniert.
live long and prosper
Stefan Schmöcker

email: stefan@schmoecker.de

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo black-adept,
ich habe das Programm jetzt nochmals kopiert und alle überflüssigen Kommentare entfernt.

-das Dynpro 0100 enthält immer noch nur als einziges Element den Container CONTAINER, obwohl der explizit nirgends verwendet wird, aber ohne funktioniert es nicht
-im Status D0100C habe ich zwei zusätzliche eigene Button "Weiter" und "Zurück" eingebaut, die sieht man dann am unteren Rand des ALV, dort will ich später noch weitere eigene Funktionen integrieren

Wie erstellt man eigentlich einen SAPLINK?

Danke und Gruß
Einar

Code: Alles auswählen.

REPORT zkar_dragdrop_6
       MESSAGE-ID ztass_util.
* Overcome the restriction of the SALV model using the power of the
* Object Oriented ABAP
*
*-----------------------------------------------------------------------
* PROBLEM: Drag und Drop funktioniert erst, wenn die
*          Funktion MYFUNCTION einmal!!! ausgeführt wurde
*-----------------------------------------------------------------------
TYPES:
  ty_t_sflights TYPE STANDARD TABLE OF sflights.

DATA:
  gt_data TYPE ty_t_sflights.

* Class declaration
CLASS:
  lcl_objdragdropapp DEFINITION DEFERRED.

* Data declarations for alv
DATA:
  gr_dragdropapp TYPE REF TO lcl_objdragdropapp,
  gr_alv TYPE REF TO cl_gui_alv_grid,
* Reference variable to CL_DRAGDROP
  gr_dragdropalv TYPE REF TO cl_dragdrop.

* Declarations for handle event
DATA:
  gv_effect TYPE i,
  gv_handle_alv TYPE i,
  gv_okcode TYPE syucomm.

DATA:
  gr_salv TYPE REF TO cl_salv_table.

*-----------------------------------------------------------------------
* Event handler for the added buttons
*-----------------------------------------------------------------------
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_user_command
        FOR EVENT added_function
          OF cl_salv_events
          IMPORTING e_salv_function.
ENDCLASS.                    "lcl_event_handler DEFINITION

* Event Handler for the SALV
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD on_user_command.
    DATA:
      ls_layout TYPE lvc_s_layo.

    CASE e_salv_function.
* Make ALV as Editable ALV
      WHEN 'MYFUNCTION'.
* Get the front layout of ALV
        CALL METHOD gr_alv->get_frontend_layout
          IMPORTING
            es_layout = ls_layout.

        IF ls_layout-edit IS INITIAL.
* Editable ALV
          ls_layout-edit = 'X'.
        ELSE.
* Non-Editable ALV
          CLEAR ls_layout-edit.
        ENDIF.

* Set the front layout of ALV
        CALL METHOD gr_alv->set_frontend_layout
          EXPORTING
            is_layout = ls_layout.
* Refresh the table
        CALL METHOD gr_alv->refresh_table_display.
    ENDCASE.
  ENDMETHOD.                    "on_user_command
ENDCLASS.                           "lcl_event_handler IMPLEMENTATION

*-----------------------------------------------------------------------
* Class definitions and method implementation for drag and drop
*-----------------------------------------------------------------------
CLASS lcl_dragdrop DEFINITION.
  PUBLIC SECTION.
    DATA: wa TYPE sflights,
          index TYPE i.   "Index of Line to be moved
ENDCLASS.                    "LCL_DRAGDROP DEFINITION

*-----------------------------------------------------------------------
* Application class definition
*-----------------------------------------------------------------------
CLASS lcl_objdragdropapp DEFINITION.
  PUBLIC SECTION.
    METHODS:
* Handling Event Drag
      handle_alv_drag
        FOR EVENT ondrag
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj,

* Handling event DROP
      handle_alv_drop
        FOR EVENT ondrop
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj.
ENDCLASS.                    "LCL_objdragdropapp DEFINITION

* Application class implementation
CLASS lcl_objdragdropapp IMPLEMENTATION.

* OnDrag event is used to 'fetch' information from the drag source.
  METHOD handle_alv_drag.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop,
      ls_line TYPE sflights.                                "#EC NEEDED

* Read dragged row
    READ TABLE gt_data INDEX e_row-index INTO ls_line.

* Create and fill dataobject for events ONDROP
    CREATE OBJECT lo_dataobj.

* Remembering row index to move a line
    MOVE e_row-index TO lo_dataobj->index.

* Store the dragged line.
    READ TABLE gt_data INTO lo_dataobj->wa INDEX e_row-index.

* Assigning data object to the refering event parameter
    e_dragdropobj->object = lo_dataobj.
  ENDMETHOD.                    "HANDLE_ALV_DRAG

* Event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop source.
  METHOD handle_alv_drop.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop.

* Catch-Statement to ensure the drag&drop-Operation is aborted properly.
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      lo_dataobj ?= e_dragdropobj->object.

      DELETE gt_data INDEX lo_dataobj->index.
      INSERT lo_dataobj->wa INTO gt_data INDEX e_row-index.

      gr_salv->refresh( ).
    ENDCATCH.

    IF sy-subrc <> 0.
* If anything went wrong aborting the drag and drop operation
      CALL METHOD e_dragdropobj->abort.
    ENDIF.
  ENDMETHOD.                    "HANDLE_ALV_DROP
ENDCLASS.                    "LCL_objdragdropapp IMPLEMENTATION

* Start of selection
START-OF-SELECTION.
* Test data
  SELECT *
    FROM sflights
    INTO TABLE gt_data
      UP TO 30 ROWS.

  CALL SCREEN 0100 STARTING AT  10  5
                   ENDING AT   100 16.
*  CALL SCREEN 0100.

*----------------------------------------------------------------------*
*  MODULE pbo OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  PERFORM pbo.
ENDMODULE.                    "pbo OUTPUT

*----------------------------------------------------------------------*
*  MODULE pai INPUT
*----------------------------------------------------------------------*
MODULE pai INPUT.
  PERFORM pai.
ENDMODULE.                    "pai INPUT

*&---------------------------------------------------------------------*
*&      Form  pbo
*&---------------------------------------------------------------------*
FORM pbo.
  SET PF-STATUS 'D0100C'.

* New ALV Instance
  TRY.
      cl_salv_table=>factory(
        EXPORTING
          list_display   = abap_false
          r_container    = cl_gui_container=>screen1
        IMPORTING
          r_salv_table   = gr_salv
        CHANGING
          t_table        = gt_data ).
    CATCH cx_salv_msg.                                  "#EC NO_HANDLER
  ENDTRY.

* Activate ALV generic Functions
  DATA:
    lr_functions TYPE REF TO cl_salv_functions_list,
    lv_text TYPE string,
    lv_icon TYPE string.

  lr_functions = gr_salv->get_functions( ).
*  lr_functions->set_all( 'X' ).

* Include own functions
  TRY.
      lv_text = 'Meine eigene Funktion'.                    "#EC NOTEXT
      lv_icon = icon_complete.
      lr_functions->add_function(
        name     = 'MYFUNCTION'
        icon     = lv_icon
        text     = lv_text
        tooltip  = lv_text
        position = if_salv_c_function_position=>right_of_salv_functions ).
    CATCH cx_salv_wrong_call cx_salv_existing.          "#EC NO_HANDLER
  ENDTRY.

** Set the selection mode of the Popup: multiple or single row selection
*  DATA:
*    lr_selections TYPE REF TO cl_salv_selections.
*
*  lr_selections = gr_salv->get_selections( ).
*  lr_selections->set_selection_mode( if_salv_c_selection_mode=>multiple ).
**  lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

*    gr_salv->set_screen_popup(
*      start_column = 10
*      end_column   = 110
*      start_line   = 2
*      end_line     = 25 ).

* Event handler for the button
  DATA:
    lo_events TYPE REF TO cl_salv_events_table,
    lo_event_h TYPE REF TO lcl_event_handler.

* Event object
  lo_events = gr_salv->get_event( ).

* Event handler
  CREATE OBJECT lo_event_h.

* Setting up the event handler
  SET HANDLER lo_event_h->on_user_command FOR lo_events.

* Generate ALV output
* It is required to execute the display method otherwise the adapter
* will not been instantiated when grabbing the alv grid
  gr_salv->display( ).

  DATA:
    ls_child LIKE LINE OF cl_gui_container=>screen1->children.

* Variante black-adept
  READ TABLE cl_gui_container=>screen1->children
    INDEX 1 INTO ls_child.

** ToDo: Test auf Grid ?
* Sinnvoller Test, ob das überhaupt ein Grid ist sollte
* man hier wohl einbauen - hab ich aber gerade keine Lust dazu
  gr_alv ?= ls_child.

* Got the Grid ?
  IF gr_alv IS BOUND.
* Create the application object to handle the ABAP Objects Events
    CREATE OBJECT gr_dragdropapp.

* Events alv control
* For Dragging
    SET HANDLER gr_dragdropapp->handle_alv_drag FOR gr_alv.
* For Dropping
    SET HANDLER gr_dragdropapp->handle_alv_drop FOR gr_alv.

* Define a drag & Drop behaviour for the whole grid
    CREATE OBJECT gr_dragdropalv.

    gv_effect = cl_dragdrop=>move + cl_dragdrop=>copy.

    CALL METHOD gr_dragdropalv->add
      EXPORTING
        flavor     = 'Line'                                 "#EC NOTEXT
        dragsrc    = 'X'
        droptarget = 'X'
        effect     = gv_effect.

* Getting the handle for drag and drop
    CALL METHOD gr_dragdropalv->get_handle
      IMPORTING
        handle = gv_handle_alv.

* Provide handle to alv control to all rows for same drag & drop behaviour
    DATA:
      ls_layout TYPE lvc_s_layo.

    CLEAR ls_layout.
*    ls_layout-s_dragdrop-cntr_ddid = gv_handle_alv.
    ls_layout-s_dragdrop-row_ddid = gv_handle_alv.

* Set the front layout of ALV
    CALL METHOD gr_alv->set_frontend_layout
      EXPORTING
        is_layout = ls_layout.
  ENDIF.
ENDFORM.                    "pbo

*&---------------------------------------------------------------------*
*&      Form  pai
*&---------------------------------------------------------------------*
FORM pai.
  CASE gv_okcode.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDW'.
      MESSAGE i000 WITH 'Weiter...'.                        "#EC NOTEXT
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDZ'.
      MESSAGE i000 WITH 'Zurück...'.                        "#EC NOTEXT
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN OTHERS.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDFORM.                    "pai

*** Programmende ***

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von black_adept (Top Expert / 4080 / 125 / 934 ) »
Wirf doch mal ein Refresh hinter das Setzen des D&D Handles

Code: Alles auswählen.

* Set the front layout of ALV
    CALL METHOD gr_alv->set_frontend_layout
      EXPORTING
        is_layout = ls_layout.
    
    
    gr_alv->refresh_table_display( ). " <----  Diese Zeile bitte einfügen
  ENDIF.
ENDFORM.                    "pbo

Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
einar46

live long and prosper
Stefan Schmöcker

email: stefan@schmoecker.de

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo black-adept,
ich habe den Refresh "geworfen" und es funktioniert bestens.
Vielen Dank.
Ich habe jetzt noch zusätzlich den Button MYFUNCTION entfernt.
Wegen der Vollständigkeit habe ich nochmals das Coding angefügt.

Danke und Gruß
Einar

Code: Alles auswählen.

REPORT zkar_dragdrop_6
       MESSAGE-ID ztass_util.

* Test: Drag and Drop in einem ALV

TYPES:
  ty_t_sflights TYPE STANDARD TABLE OF sflights.

* Class declaration
CLASS:
  lcl_objdragdropapp DEFINITION DEFERRED.

DATA:
* Test data
  gt_data TYPE ty_t_sflights,
* Data declarations for alv
  gr_salv TYPE REF TO cl_salv_table,
  gr_alv TYPE REF TO cl_gui_alv_grid,
* Reference variable to CL_DRAGDROP
  gr_dragdropalv TYPE REF TO cl_dragdrop,
  gr_dragdropapp TYPE REF TO lcl_objdragdropapp,
* Declarations for handle event
  gv_effect TYPE i,
  gv_handle_alv TYPE i,
  gv_okcode TYPE syucomm.

*-----------------------------------------------------------------------
* Class definitions and method implementation for drag and drop
*-----------------------------------------------------------------------
CLASS lcl_dragdrop DEFINITION.
  PUBLIC SECTION.
    DATA: wa TYPE sflights,
          index TYPE i.   "Index of Line to be moved
ENDCLASS.                    "LCL_DRAGDROP DEFINITION

*-----------------------------------------------------------------------
* Application class definition
*-----------------------------------------------------------------------
CLASS lcl_objdragdropapp DEFINITION.
  PUBLIC SECTION.
    METHODS:
* Handling Event Drag
      handle_alv_drag
        FOR EVENT ondrag
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj,

* Handling event DROP
      handle_alv_drop
        FOR EVENT ondrop
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj.
ENDCLASS.                    "LCL_objdragdropapp DEFINITION

* Application class implementation
CLASS lcl_objdragdropapp IMPLEMENTATION.

* OnDrag event is used to 'fetch' information from the drag source.
  METHOD handle_alv_drag.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop,
      ls_line TYPE sflights.                                "#EC NEEDED

* Read dragged row
    READ TABLE gt_data INDEX e_row-index INTO ls_line.

* Create and fill dataobject for events ONDROP
    CREATE OBJECT lo_dataobj.

* Remembering row index to move a line
    MOVE e_row-index TO lo_dataobj->index.

* Store the dragged line.
    READ TABLE gt_data INTO lo_dataobj->wa INDEX e_row-index.

* Assigning data object to the refering event parameter
    e_dragdropobj->object = lo_dataobj.
  ENDMETHOD.                    "HANDLE_ALV_DRAG

* Event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop source.
  METHOD handle_alv_drop.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop.

* Catch-Statement to ensure the drag&drop-Operation is aborted properly.
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      lo_dataobj ?= e_dragdropobj->object.

      DELETE gt_data INDEX lo_dataobj->index.
      INSERT lo_dataobj->wa INTO gt_data INDEX e_row-index.

      gr_salv->refresh( ).
    ENDCATCH.

    IF sy-subrc IS NOT INITIAL.
* If anything went wrong aborting the drag and drop operation
      CALL METHOD e_dragdropobj->abort.
    ENDIF.
  ENDMETHOD.                    "HANDLE_ALV_DROP
ENDCLASS.                    "LCL_objdragdropapp IMPLEMENTATION

* Start of selection
START-OF-SELECTION.
* Test data
  SELECT *
    FROM sflights
    INTO TABLE gt_data
      UP TO 30 ROWS.

  CALL SCREEN 0100 STARTING AT  10  5
                   ENDING AT   120 16.

*----------------------------------------------------------------------*
*  MODULE pbo OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  PERFORM pbo.
ENDMODULE.                    "pbo OUTPUT

*----------------------------------------------------------------------*
*  MODULE pai INPUT
*----------------------------------------------------------------------*
MODULE pai INPUT.
  PERFORM pai.
ENDMODULE.                    "pai INPUT

*&---------------------------------------------------------------------*
*&      Form  pbo
*&---------------------------------------------------------------------*
FORM pbo.
  DATA:
    lr_functions TYPE REF TO cl_salv_functions_list,        "#EC NEEDED
    lr_selections TYPE REF TO cl_salv_selections,           "#EC *
    ls_child LIKE LINE OF cl_gui_container=>screen1->children,
    ls_layout TYPE lvc_s_layo.

  SET PF-STATUS 'D0100C'.

* New ALV Instance
  TRY.
      cl_salv_table=>factory(
        EXPORTING
          list_display   = abap_false
          r_container    = cl_gui_container=>screen1
        IMPORTING
          r_salv_table   = gr_salv
        CHANGING
          t_table        = gt_data ).
    CATCH cx_salv_msg.                                  "#EC NO_HANDLER
  ENDTRY.

  lr_functions = gr_salv->get_functions( ).
*  IF lr_functions IS BOUND.
*    lr_functions->set_all( 'X' ).
*  ENDIF.

** ToDo: Ich hätte gern die Markierbarkeit von Zeilen zurück!!!
** Set the selection mode of the Popup: multiple or single row selection
*  lr_selections = gr_salv->get_selections( ).
*  IF lr_selections IS BOUND.
*    lr_selections->set_selection_mode( if_salv_c_selection_mode=>multiple ).
**    lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
*  ENDIF.

* Generate ALV output

* It is required to execute the display method otherwise the adapter
* will not been instantiated when grabbing the alv grid
  gr_salv->display( ).

* Variante black-adept
  READ TABLE cl_gui_container=>screen1->children
    INDEX 1 INTO ls_child.

** ToDo: Test auf Grid!!!
* Sinnvoller Test, ob das überhaupt ein Grid ist
  gr_alv ?= ls_child.

* Got the Grid ?
  IF gr_alv IS BOUND.
* Create the application object to handle the ABAP Objects Events
    CREATE OBJECT gr_dragdropapp.

* Events alv control...

* ...for Dragging
    SET HANDLER gr_dragdropapp->handle_alv_drag FOR gr_alv.
* ...for Dropping
    SET HANDLER gr_dragdropapp->handle_alv_drop FOR gr_alv.

* Define a drag & drop behaviour for the whole grid
    CREATE OBJECT gr_dragdropalv.

    gv_effect = cl_dragdrop=>move + cl_dragdrop=>copy.

    CALL METHOD gr_dragdropalv->add
      EXPORTING
        flavor     = 'Line'                                 "#EC NOTEXT
        dragsrc    = 'X'
        droptarget = 'X'
        effect     = gv_effect.

* Getting the handle for drag and drop
    CALL METHOD gr_dragdropalv->get_handle
      IMPORTING
        handle = gv_handle_alv.

* Provide handle to alv control to all rows for same drag & drop behaviour
    CLEAR ls_layout.
    ls_layout-grid_title = 'Drag and Drop - Test'.          "#EC NOTEXT
    ls_layout-s_dragdrop-row_ddid = gv_handle_alv.

* Set the front layout of ALV
    CALL METHOD gr_alv->set_frontend_layout
      EXPORTING
        is_layout = ls_layout.

* Refresh the ALV
    gr_alv->refresh_table_display( ).
  ENDIF.
ENDFORM.                    "pbo

*&---------------------------------------------------------------------*
*&      Form  pai
*&---------------------------------------------------------------------*
FORM pai.
  CASE gv_okcode.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDW'.
      MESSAGE i000 WITH 'Weiter...'.                        "#EC NOTEXT
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'ZDDZ'.
      MESSAGE i000 WITH 'Zurück...'.                        "#EC NOTEXT
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN OTHERS.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDFORM.                    "pai

*** Programmende ***

Re: Ist Drag&Drop im ALV-Popup-Grid mit CL_SALV_TABLE möglic

Beitrag von einar46 (ForumUser / 33 / 5 / 1 ) »
Hallo,
obwohl das Thema schon als gelöst gemeldet ist, möchte ich wegen der Vollständigkeit nochmals mein Beispiel-Coding posten. Das Coding ist jetzt so erweitert, dass eine beliebige Anzahl von Zeilen per Drag&Drop verschoben werden können.

Code: Alles auswählen.

REPORT zkar_dragdrop_7
       MESSAGE-ID salv_exception.
*=======================================================================
* Test: Drag and Drop of multiple rows in an ALV
*=======================================================================
TYPES:
  tt_sflights TYPE STANDARD TABLE OF sflights.

* Class declaration
CLASS:
  lcl_dragdropobj DEFINITION DEFERRED.

DATA:
* Test data
  gt_datas TYPE tt_sflights,
* Data declarations for ALV
  gr_salv TYPE REF TO cl_salv_table,
  gr_alv TYPE REF TO cl_gui_alv_grid,
* Reference variable to CL_DRAGDROP
  gr_dragdropalv TYPE REF TO cl_dragdrop,
  gr_dragdropobj TYPE REF TO lcl_dragdropobj,
* Ok-Code for dynpro
  gv_okcode TYPE syucomm.

*-----------------------------------------------------------------------
* Class definitions and method implementation for drag and drop
*-----------------------------------------------------------------------
CLASS lcl_dragdrop DEFINITION.
  PUBLIC SECTION.
    DATA:
* Table of data of (m)ultiple (r)ow(s)
      gt_datamrs TYPE tt_sflights,
* Table of (i)ndices of multiple row(s)
      gt_datais TYPE STANDARD TABLE OF sytabix.
ENDCLASS.                    "LCL_DRAGDROP DEFINITION

*-----------------------------------------------------------------------
* Application class definition
*-----------------------------------------------------------------------
CLASS lcl_dragdropobj DEFINITION.
  PUBLIC SECTION.
    METHODS:
* Handling event DRAG
      on_drag
        FOR EVENT ondrag
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj,

* Handling event DROP
      on_drop
        FOR EVENT ondrop
        OF cl_gui_alv_grid
        IMPORTING e_row e_column e_dragdropobj.
ENDCLASS.                    "LCL_DRAGDROPOBJ DEFINITION

*-----------------------------------------------------------------------
* Application class implementation
*-----------------------------------------------------------------------
CLASS lcl_dragdropobj IMPLEMENTATION.

* OnDrag event is used to 'fetch' information from the drag source
  METHOD on_drag.
    DATA:
      lt_index_rows TYPE lvc_t_row,
      ls_index_row TYPE REF TO lvc_s_row,
      lo_dataobj TYPE REF TO lcl_dragdrop,
      ls_data TYPE REF TO sflights.                         "#EC NEEDED

* Drag multiple rows

* Get the selected rows
    CALL METHOD gr_alv->get_selected_rows
      IMPORTING
        et_index_rows = lt_index_rows.

    IF lt_index_rows IS INITIAL.
* No selected row, then we set a selected row
      INSERT INITIAL LINE INTO TABLE lt_index_rows
        REFERENCE INTO ls_index_row.

      IF sy-subrc IS INITIAL.
        ls_index_row->index = e_row-index.
      ENDIF.
    ENDIF.

* Create and fill dataobject for events ONDROP
    CREATE OBJECT lo_dataobj.

    CLEAR lo_dataobj->gt_datamrs.
    CLEAR lo_dataobj->gt_datais.

* Read the dragged rows
    LOOP AT lt_index_rows REFERENCE INTO ls_index_row.
      READ TABLE gt_datas REFERENCE INTO ls_data
        INDEX ls_index_row->index.
      IF sy-subrc IS INITIAL.
* Store the dragged rows and indices
        APPEND ls_data->* TO lo_dataobj->gt_datamrs.
        APPEND ls_index_row->index TO lo_dataobj->gt_datais.
      ENDIF.
    ENDLOOP.

* Assigning data object to the refering event parameter
    e_dragdropobj->object = lo_dataobj.
  ENDMETHOD.                    "ON_DRAG

* Event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop source.
  METHOD on_drop.
    DATA:
      lo_dataobj TYPE REF TO lcl_dragdrop,
      lt_data_olds TYPE tt_sflights,
      ls_data_old TYPE REF TO sflights,
      lt_data_news TYPE tt_sflights,
      ls_data_new TYPE REF TO sflights,
      ls_datamr TYPE REF TO sflights,
      lv_datai TYPE sytabix,
      lv_tabix TYPE sytabix,
      lv_index TYPE sytabix,
      lv_position TYPE i,
      lv_count TYPE i.

* Drop multiple rows
* REMARK:    The selected rows are always positioned
*            behind!!! the target position
* EXCEPTION: When the selected rows should be positioned in front
*            of the first row, then it has to be done in two steps

* Catch-Statement to ensure the drag&drop-Operation is aborted properly
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      lo_dataobj ?= e_dragdropobj->object.

      DESCRIBE TABLE lo_dataobj->gt_datamrs LINES lv_count.
      IF lv_count IS NOT INITIAL.
* Save the old table
        CLEAR lt_data_olds.
        lt_data_olds = gt_datas.

* Check and correct the target position
        lv_position = e_row-index.
        LOOP AT lo_dataobj->gt_datais INTO lv_datai.
          IF lv_datai < e_row-index.
            lv_position = lv_position - 1.
          ENDIF.
        ENDLOOP.

* Delete the selected rows in the old table
        LOOP AT lo_dataobj->gt_datamrs REFERENCE INTO ls_datamr.
          DELETE TABLE lt_data_olds FROM ls_datamr->*.
        ENDLOOP.

* Build the new table
        CLEAR lt_data_news.

* Insert old data only up to the target position
        CLEAR lv_index.
        LOOP AT lt_data_olds REFERENCE INTO ls_data_old.
          lv_tabix = sy-tabix.
          lv_index = lv_index + 1.
          IF lv_index <= lv_position.
            INSERT INITIAL LINE INTO TABLE lt_data_news
              REFERENCE INTO ls_data_new.

            IF sy-subrc IS INITIAL.
              ls_data_new->* = ls_data_old->*.

              DELETE lt_data_olds INDEX lv_tabix.
            ENDIF.
          ENDIF.
        ENDLOOP.

* Insert the selected rows in the new table
        LOOP AT lo_dataobj->gt_datamrs REFERENCE INTO ls_datamr.
          INSERT INITIAL LINE INTO TABLE lt_data_news
            REFERENCE INTO ls_data_new.

          IF sy-subrc IS INITIAL.
            ls_data_new->* = ls_datamr->*.
          ENDIF.
        ENDLOOP.

* Insert the rest of the old table in the new table
        LOOP AT lt_data_olds REFERENCE INTO ls_data_old.
          INSERT INITIAL LINE INTO TABLE lt_data_news
            REFERENCE INTO ls_data_new.

          IF sy-subrc IS INITIAL.
            ls_data_new->* = ls_data_old->*.
          ENDIF.
        ENDLOOP.

        IF lt_data_news IS NOT INITIAL.
          CLEAR gt_datas.
          gt_datas = lt_data_news.
        ENDIF.

* Refresh the ALV
        gr_salv->refresh( ).
      ENDIF.
    ENDCATCH.

* If anything went wrong aborting the drag and drop operation
    IF sy-subrc IS NOT INITIAL.
      CALL METHOD e_dragdropobj->abort.
    ENDIF.
  ENDMETHOD.                    "ON_DROP
ENDCLASS.                    "LCL_DRAGDROPOBJ IMPLEMENTATION

* Start of selection
START-OF-SELECTION.

* Test data
  SELECT *
    FROM sflights
    INTO TABLE gt_datas
      UP TO 30 ROWS.                                    "#EC CI_NOWHERE

END-OF-SELECTION.

* Call the dynpro
* REMARK: The dynpro contains no container and is a normal dynpro!!!
  CALL SCREEN 0100 STARTING AT   5  2
                   ENDING   AT 120 15.

*----------------------------------------------------------------------*
*  MODULE pbo OUTPUT
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
  PERFORM pbo.
ENDMODULE.                    "pbo OUTPUT

*----------------------------------------------------------------------*
*  MODULE pai INPUT
*----------------------------------------------------------------------*
MODULE pai INPUT.
  PERFORM pai.
ENDMODULE.                    "pai INPUT

*----------------------------------------------------------------------*
*       Form  pbo
*----------------------------------------------------------------------*
FORM pbo.
  DATA:
* REMARK: screen1, ...2, ...3 describes the level of an ALV
    ls_child LIKE LINE OF cl_gui_container=>screen1->children,
    ls_layout TYPE lvc_s_layo,
    ls_stable TYPE lvc_s_stbl,
* Declarations for handle event drag and drop
    lv_handle_alv TYPE i,
    lv_effect TYPE i.

* Set status
* REMARK: The status is copied from the program
*         SALV_DEMO_TABLE_FORM_EVENTS and was extended
*         by two buttons ZDDW und ZDDZ.
*         See Form-routine PAI for testing the position of the
*         own buttons.
  SET PF-STATUS 'D0100C'.

* New ALV instance
  TRY.
      cl_salv_table=>factory(
        EXPORTING
          list_display   = abap_false
          r_container    = cl_gui_container=>screen1
        IMPORTING
          r_salv_table   = gr_salv
        CHANGING
          t_table        = gt_datas ).
    CATCH cx_salv_msg.                                  "#EC NO_HANDLER
  ENDTRY.

* Generate ALV output
  gr_salv->display( ).

* Get the reference of the class CL_GUI_ALV_GRID
** (Variant of abapforum-user black-adept)
*  READ TABLE cl_gui_container=>screen1->children
*    INDEX 1 INTO ls_child.
  LOOP AT cl_gui_container=>screen1->children INTO ls_child.
    TRY.
        gr_alv ?= ls_child.
        EXIT.
      CATCH cx_sy_move_cast_error.
        CONTINUE.
    ENDTRY.
  ENDLOOP.

* Got the reference of the grid ?
  IF gr_alv IS BOUND.
* Create the application object to handle the ABAP objects events
    CREATE OBJECT gr_dragdropobj.

* Events ALV control...

* ...for dragging
    SET HANDLER gr_dragdropobj->on_drag FOR gr_alv.
* ...for dropping
    SET HANDLER gr_dragdropobj->on_drop FOR gr_alv.

* Define a drag & drop behaviour for the whole grid
    CREATE OBJECT gr_dragdropalv.

    lv_effect = cl_dragdrop=>move + cl_dragdrop=>copy.

    CALL METHOD gr_dragdropalv->add
      EXPORTING
        flavor     = 'Line'                                 "#EC NOTEXT
        dragsrc    = 'X'
        droptarget = 'X'
        effect     = lv_effect.

* Getting the handle for drag and drop
    CALL METHOD gr_dragdropalv->get_handle
      IMPORTING
        handle = lv_handle_alv.

* Get the old front layout of ALV
    CALL METHOD gr_alv->get_frontend_layout
      IMPORTING
        es_layout = ls_layout.

* Grid title
    ls_layout-grid_title = 'Drag and Drop - Test'.          "#EC NOTEXT
* Small title font
    ls_layout-smalltitle = 'X'.
* Allow to select multiple rows
    ls_layout-sel_mode = 'A'.
* Optimize column width
    ls_layout-cwidth_opt = 'X'.
* Off horizontal grid lines
    ls_layout-no_hgridln = 'X'.
* Zebra crossing
    ls_layout-zebra = 'X'.
* Provide handle to alv control to all rows
* for same drag and drop behaviour
    ls_layout-s_dragdrop-row_ddid = lv_handle_alv.

* Set the new front layout of ALV
    CALL METHOD gr_alv->set_frontend_layout
      EXPORTING
        is_layout = ls_layout.

* Refresh the ALV
    ls_stable-row = 'X'.
    ls_stable-col = 'X'.
    CALL METHOD gr_alv->refresh_table_display
      EXPORTING
        i_soft_refresh = 'X'
        is_stable      = ls_stable.
  ENDIF.
ENDFORM.                    "pbo

*----------------------------------------------------------------------*
*       Form  pai
*----------------------------------------------------------------------*
FORM pai.
  DATA:
    lv_okcode TYPE syucomm.

  lv_okcode = gv_okcode.
  CLEAR gv_okcode.

  CASE lv_okcode.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
* Destroy the references before leaving the ALV
      IF gr_salv IS NOT INITIAL.
        CALL METHOD gr_salv->close_screen.
        FREE gr_salv.
      ENDIF.

      IF gr_alv IS NOT INITIAL.
        CALL METHOD gr_alv->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2.
        CLEAR gr_alv.
      ENDIF.

      LEAVE TO SCREEN 0.
* Only for test to see the position of the button (see status)
    WHEN 'ZDDW'.
* Destroy the references before leaving the ALV
      IF gr_salv IS NOT INITIAL.
        CALL METHOD gr_salv->close_screen.
        FREE gr_salv.
      ENDIF.

      IF gr_alv IS NOT INITIAL.
        CALL METHOD gr_alv->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2.
        CLEAR gr_alv.
      ENDIF.

      MESSAGE i000 WITH 'More...'.                          "#EC NOTEXT

      LEAVE TO SCREEN 0.
* Only for test to see the position of the button (see status)
    WHEN 'ZDDZ'.
* Destroy the references before leaving the ALV
      IF gr_salv IS NOT INITIAL.
        CALL METHOD gr_salv->close_screen.
        FREE gr_salv.
      ENDIF.

      IF gr_alv IS NOT INITIAL.
        CALL METHOD gr_alv->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2.
        CLEAR gr_alv.
      ENDIF.

      MESSAGE i000 WITH 'Back...'.                          "#EC NOTEXT

      LEAVE TO SCREEN 0.
    WHEN OTHERS.
* Destroy the references before leaving the ALV
      IF gr_salv IS NOT INITIAL.
        CALL METHOD gr_salv->close_screen.
        FREE gr_salv.
      ENDIF.

      IF gr_alv IS NOT INITIAL.
        CALL METHOD gr_alv->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2.
        CLEAR gr_alv.
      ENDIF.

      LEAVE TO SCREEN 0.
  ENDCASE.
ENDFORM.                    "pai

*** Program end ***
Gruß einar46

Folgende Benutzer bedankten sich beim Autor einar46 für den Beitrag:
ewx


Seite 1 von 1

Vergleichbare Themen

1
Antw.
3043
Views
SALV-Popup verlassen
von ralf.wenzel » 13.12.2014 17:24 • Verfasst in ABAP Objects®
5
Antw.
5913
Views
Wie kann ich bestimmte Buttons im ALV (SALV,Popup) abfangen?
von einar46 » 23.07.2014 09:12 • Verfasst in ABAP Objects®
2
Antw.
4921
Views
Salv Table - Layouts speichern
von JohnLocklay » 14.06.2019 11:33 • Verfasst in ABAP Objects®
3
Antw.
2727
Views
GUI Status verhindert on click Event des SALV Table
von Pinguincommander » 05.02.2019 09:51 • Verfasst in ABAP® Core
5
Antw.
3499
Views
Kalender-Popup in Grid
von Tom_ » 24.10.2005 13:32 • Verfasst in ABAP® für Anfänger

Über diesen Beitrag


Die Frage ist als "gelöst" markiert. Den entsprechend Beitrag findest du hier.

Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Unbeantwortete Forenbeiträge

aRFC im OO-Kontext
vor 4 Wochen von ralf.wenzel 1 / 1515
Hilfe bei SWEC/SWE2
letzen Monat von retsch 1 / 8128