Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Here comes the definition of a simple data structure used in our ALV grid:
1. TYPES:
2. BEGIN OF gty_data,
3. matnr TYPE matnr,
4. plant TYPE werks_d,
5. END OF gty_data.
There are actually several types of objects that can be added to the toolbar:
Value Constant Meaning
0 cntb_btype_button Button (normal)
1 cntb_btype_dropdown Pushbutton with menu
2 cntb_btype_menu Menu
3 cntb_btype_sep Seperator
4 cntb_btype_group Pushbutton group
5 cntb_btype_check Checkbox
6 Menu entry
1. METHOD my_toolbar_handler.
2. data:
3. ls_button type stb_button.
4.
5. ls_button-butn_type = 0. "Button
6. ls_button-function = mc_functions-import_clipboard.
7. ls_button-icon = '@48@'. "Import icon
8. ls_button-text = 'Import Clipboard'.
9.
10. INSERT ls_button into e_object->mt_toolbar INDEX 1.
11. ENDMETHOD.
Method which handles user-click on the custom toolbar button:
1. METHOD my_user_command_handler.
2. CASE e_ucomm.
3. WHEN mc_functions-import_clipboard.
4. me->import_clipboard( ).
5. ENDCASE.
6.
7. * We need to refresh grid with updated data
8. IF mo_data_grid IS NOT INITIAL.
9. mo_data_grid->refresh_table_display( ).
10. ENDIF.
11. ENDMETHOD.
1. METHOD import_clipboard.
2. DATA:
3. ls_data type gty_data,
4. lt_clipdata TYPE STANDARD TABLE OF char255,
5. ls_clipdata type char255,
6. lt_record TYPE STANDARD TABLE OF char255,
7. ls_record type char255,
8. lv_clip_len TYPE i.
9.
10. CONSTANTS: c_tab TYPE c VALUE cl_bcs_convert=>gc_tab.
11.
12. cl_gui_frontend_services=>clipboard_import(
13. IMPORTING
14. data = lt_clipdata
15. length = lv_clip_len
16. EXCEPTIONS
17. cntl_error = 1
18. error_no_gui = 2
19. not_supported_by_gui = 3
20. OTHERS = 4 ).
21. IF sy-subrc NE 0.
22. MESSAGE 'Error while importing data from clipboard' TYPE 'I'.
23. RETURN.
24. ENDIF.
25.
26. LOOP AT lt_clipdata INTO ls_clipdata.
27. * Split data to respective fields
28. SPLIT ls_clipdata AT c_tab
29. INTO TABLE lt_record.
30.
31. * Populate data into the ls_data structure
32. CLEAR ls_data.
33.
34. "reading MATNR
35. READ TABLE lt_record INTO ls_record INDEX 1.
36. IF sy-subrc = 0.
37. ls_data-matnr = ls_record.
38. ENDIF.
39.
40. "reading PLANT
41. READ TABLE lt_record INTO ls_record INDEX 2.
42. IF sy-subrc = 0.
43. ls_data-plant = ls_record.
44. ENDIF.
45.
46. * Populate the ALV data table
47. IF ls_data IS NOT INITIAL.
48. APPEND ls_data TO mt_data.
49. ENDIF.
50. ENDLOOP.
51. ENDMETHOD.
1. METHOD show_grid.
2. DATA:
3. ls_layout TYPE lvc_s_layo.
4.
5. IF mo_data_grid IS INITIAL.
6. CREATE OBJECT mo_data_grid
7. EXPORTING
8. i_parent = cl_gui_container=>screen0
9. i_appl_events = abap_true.
10.
11. ls_layout-sel_mode = 'A'.
12. ls_layout-no_rowmark = abap_false.
13.
14. build_fieldcat( ).
15.
16. * !!! Handlers registration !!!
17. SET HANDLER my_toolbar_handler FOR mo_data_grid.
18. SET HANDLER my_user_command_handler FOR mo_data_grid.
19.
20. mo_data_grid->set_table_for_first_display(
21. EXPORTING
22. is_layout = ls_layout
23. CHANGING
24. it_fieldcatalog = mt_fieldcat
25. it_outtab = mt_data ).
26. ENDIF.
27. ENDMETHOD.
1. DATA:
2. gr_grid TYPE REF TO lcl_demo.
3.
4. START-OF-SELECTION.
5. CALL SCREEN 100.
6.
7. MODULE pbo OUTPUT.
8. CREATE OBJECT gr_grid.
9. gr_grid->show_grid( ).
10. ENDMODULE.
To show you a real example I prepared few lines in Excel:
After running the ABAP report (code above) I got this screen: