2023 Sep 15 11:35 AM
I have written an SAP ABAP programme to manage favourites. Via the selection screen, a user can save a report with a name as a favourite among the favourites. A report can also be assigned to a folder if it was previously created in SAP via GUI. The user can do this by using the transaction code `/n` and then right clicking on 'Favourites' -> 'Insert Folder'.
Now most things work, there is just one minor problem. When I create the first reports in the favourites folder by my program, and then create a folder by SAP GUI, the value of the column 'menu_level' of the two entries is set to '2'. However, this should be `1` because the folder and the report shortcut are in the root folder, i.e. in the first level.
This does not happen when I start to create a folder and then add the reports with my program. The menu_level remains correct with the value '1'.
Does anyone have an idea what the problem is and how I can fix it?
Here is my current, complete code:
```
REPORT z_report_fav.
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.
```SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S32 { color: #3399FF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }
2023 Sep 15 11:36 AM
Hello Fritz,
Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers, as it provides tips for preparing questions that draw responses from our members.
Feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will also help you when preparing questions for the community.
By adding a picture to your profile you encourage your readers to respond.
Kind regards,
Anne
2023 Sep 15 2:03 PM
As far as I remember, I had to manage other tables for favorites (I think there was an OSS note on copying favorites between users, and a treatment to avoid buffering?
2023 Sep 15 5:17 PM
Please edit your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!
PS: my poor eyes won't read it how it's currently formatted.