Code: Alles auswählen.
TYPE-POOLS: vrm.
DATA: ls_smen_buffc TYPE smen_buffc,
lv_max_object_id TYPE smen_buffc-object_id,
lv_max_sort_order TYPE smen_buffc-sort_order,
lt_folders TYPE TABLE OF smen_buffc,
ls_folder TYPE smen_buffc,
lt_vrm_values TYPE vrm_values,
ls_vrm_value TYPE LINE OF vrm_values.
CLASS lcl_menu_level DEFINITION.
PUBLIC SECTION.
METHODS: get_menu_level IMPORTING parent_id TYPE smen_buffc-parent_id
RETURNING VALUE(menu_level) TYPE i.
ENDCLASS.
CLASS lcl_menu_level IMPLEMENTATION.
METHOD get_menu_level.
DATA lv_parent_id TYPE smen_buffc-parent_id.
lv_parent_id = parent_id.
menu_level = 1.
WHILE lv_parent_id <> 1.
SELECT SINGLE parent_id INTO lv_parent_id FROM smen_buffc WHERE object_id = lv_parent_id.
IF sy-subrc = 0.
menu_level = menu_level + 1.
ELSE.
EXIT.
ENDIF.
ENDWHILE.
ENDMETHOD.
ENDCLASS.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_user TYPE sy-uname DEFAULT sy-uname,
p_report TYPE extdreport OBLIGATORY,
p_desc TYPE char100sm OBLIGATORY,
p_folder TYPE smen_buffc-text AS LISTBOX VISIBLE LENGTH 30.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
SELECT * FROM smen_buffc INTO TABLE lt_folders WHERE uname = p_user AND reporttype = space.
LOOP AT lt_folders INTO ls_folder.
ls_vrm_value-key = ls_folder-object_id.
ls_vrm_value-text = ls_folder-text.
APPEND ls_vrm_value TO lt_vrm_values.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_FOLDER'
values = lt_vrm_values.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_USER'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
DATA: lo_menu_level TYPE REF TO lcl_menu_level.
CREATE OBJECT lo_menu_level.
ls_smen_buffc-uname = p_user.
ls_smen_buffc-report = p_report.
ls_smen_buffc-text = p_desc.
ls_smen_buffc-reporttype = 'RE'.
SELECT MAX( object_id ) INTO lv_max_object_id FROM smen_buffc WHERE uname = p_user.
IF sy-subrc <> 0.
lv_max_object_id = 0.
ENDIF.
IF p_folder IS INITIAL.
ls_smen_buffc-parent_id = 1.
ELSE.
ls_smen_buffc-parent_id = p_folder.
ENDIF.
ls_smen_buffc-menu_level = lo_menu_level->get_menu_level( ls_smen_buffc-parent_id ).
SELECT MAX( sort_order ) INTO lv_max_sort_order FROM smen_buffc WHERE uname = p_user AND parent_id = ls_smen_buffc-parent_id.
IF sy-subrc <> 0.
lv_max_sort_order = 0.
ENDIF.
ls_smen_buffc-object_id = lv_max_object_id + 1.
ls_smen_buffc-sort_order = lv_max_sort_order + 10.
INSERT INTO smen_buffc VALUES ls_smen_buffc.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
MESSAGE 'Der Favorit wurde erfolgreich erstellt.' TYPE 'S'.
ELSE.
MESSAGE 'Fehler beim Einfügen der Daten.' TYPE 'E'.
ENDIF.
Code: Alles auswählen.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_FOLDER'
values = VALUE vrm_values( FOR <zeile> IN lt_folders ( key = <zeile>-object_id
text = <zeile>-text ).
Code: Alles auswählen.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_FOLDER'
values = CORRESPONDING vrm_values( lt_folders MAPPING key = object_id ).