toffler
toffler

Reputation: 1233

BACK Button ends Transaction, but should go back to selection screen

I want to use an ALV grid with a selection screen but without adding additional dynpros and PAI PBO Modules, like shown in this Example.

Everything works fine, but I can't go back from ALV to selection screen since the report gets terminated.

For my understanding, I need to adapt this part of code. If I don't call the function RS_SET_SELSCREEN_STATUS, I can go back to selection screen, but the F8 button is showing during the ALV Screen.

* Drucktastenleiste: Button "Ausführen (F8)" entfernen
    DATA: it_exclude_btn TYPE STANDARD TABLE OF rsexfcode WITH DEFAULT KEY.
    it_exclude_btn = VALUE #( ( fcode = 'ONLI' ) ).
 
    CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
      EXPORTING
        p_status  = '%_00' " akt. Standard-PF-Status des Dypro 2000
      TABLES
        p_exclude = it_exclude_btn.
 
* leere SAP-Toolbar ausblenden
    cl_abap_list_layout=>suppress_toolbar( ).
 
* Focus auf ALV setzen
    cl_gui_alv_grid=>set_focus( control = o_alv ).
 
* Flag für Screen-Status auf ALV-Anzeige setzen
    gv_screen_status = 'IN_ALV'.
  ENDIF.

Please help me to make the Back Button work in ALV view.


EDIT: You can test the behaviour using the code below:

PARAMETERS dummy1.
SELECTION-SCREEN BEGIN OF SCREEN 2000.
  PARAMETERS dummy2.
SELECTION-SCREEN END OF SCREEN 2000.

AT SELECTION-SCREEN OUTPUT.
  IF sy-dynnr = '2000'.
    DATA it_exclude_btn TYPE STANDARD TABLE OF rsexfcode WITH DEFAULT KEY.
    CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
      EXPORTING
        p_status  = '%_00' " wrong one: back will leave program
      TABLES
        p_exclude = it_exclude_btn.
  ENDIF.

START-OF-SELECTION.
  CALL SELECTION-SCREEN 2000.
  ASSERT 1 = 1. " Debug helper to set a break-point / never reached

Upvotes: 0

Views: 579

Answers (2)

Sandra Rossi
Sandra Rossi

Reputation: 13628

The reason why leaving the Selection Screen 2000 doesn't make your return to the previous default Selection Screen (1000) is that you have assigned the incorrect GUI Status %_00 (of the Kernel program RSSYSTDB) to the screen 2000, which is the standard one assigned to the default Selection Screen (1000). Hence, the ABAP kernel thinks that Back is pressed on the main Selection Screen and exits the program.

More specifically, it's the value of the Function Code which is tested by the kernel: in the GUI Status %_00, the Back button corresponds to the function code E, so if you create a custom GUI Status with a button assigned to the function code E, pressing this button will also leave the program.

Solution: for a selection screen called with CALL SELECTION-SCREEN, the default standard GUI Status %_CS is used, so your custom GUI Status should use its Function Codes (CBAC for the Back button), and the default Selection Screen 1000 will then be displayed (in debug, you will see that the ABAP statement after CALL SELECTION-SCREEN 2000 is executed, which was not the case with %_00, and so it will return to the main Selection Screen).

So, one solution is the below one (Edit: adding CRET to exclude F8), but you may choose other solutions now that you understand what the original issue was.

    it_exclude_btn = VALUE #( ( fcode = 'CRET' ) ).
    CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
      EXPORTING
        p_status  = '%_CS'
      TABLES
        p_exclude = it_exclude_btn.

As one can see, F8 is assigned to CRET in the GUI Status %_CS of RSSYSTDB:

%_CS of RSSYSTDB

The issue is not related to ALV, it's a pure selection screen issue. Here is the minimal code to reproduce the issue (the code doesn't continue after CALL SELECTION-SCREEN 2000 after Back has been pressed):

PARAMETERS dummy1.
SELECTION-SCREEN BEGIN OF SCREEN 2000.
  PARAMETERS dummy2.
SELECTION-SCREEN END OF SCREEN 2000.

AT SELECTION-SCREEN OUTPUT.
  IF sy-dynnr = '2000'.
    DATA it_exclude_btn TYPE STANDARD TABLE OF rsexfcode WITH DEFAULT KEY.
    CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
      EXPORTING
        p_status  = '%_00' " wrong one: back will leave program
      TABLES
        p_exclude = it_exclude_btn.
  ENDIF.

START-OF-SELECTION.
  CALL SELECTION-SCREEN 2000.
  ASSERT 1 = 1. " Debug helper to set a break-point / never reached

For information, here are the GUI statuses and their main buttons/function codes, depending on the exact context how the selection screen is called (see table legend (*)):

Function SUBMIT (**) CALL SELECTION-SCREEN
... (full screen)
CALL SELECTION-SCREEN
... AS WINDOW (popup)
SUBMIT ... VIA JOB
... (before job is created)
GUI status %_00 %_CS %_CSP %_JB
Enter <empty> <empty> NONE <empty>
Save variant SPOS SPOS SPOS SPOS
Get variant (E) GET GET GET GET
Execute ONLI CRET CRET N/A
Execute and print PRIN N/A N/A N/A
Execute in background SJOB N/A N/A N/A
Exit (E) ENDE CEND N/A ENDE
Cancel (E) ECAN CCAN CCAN ECAN
Back (E) E CBAC N/A E
Schedule in job N/A N/A N/A JOBS

(*) Legend: "(E)" if a function is of type Exit, i.e. triggers AT SELECTION-SCREEN ON EXIT-COMMAND (others trigger AT SELECTION-SCREEN), "" means that pressing Enter corresponds to an empty function code, "N/A" means that the function is not available.

(**) Either SUBMIT without extension, or default selection screen 1000 exists and is shown, or SUBMIT ... USING SELECTION-SCREEN <number> ..., or Transaction Code calling an Executable Program (type 1)

Note that in Selection Screens, if needed to test the function code, the field sscrfields-ucomm should be used as shown in the example below (NB: in Dynpro programming, SY-UCOMM is always to be avoided; complete path: Home > ABAP_PLATFORM_NEW > Classic Screen Programming > General Dynpros > Processing Screens > User Actions on Screens > Reading Function Code):

REPORT ... " or FUNCTION-POOL ...
...
TABLES sscrfields. " mandatory
...
AT SELECTION-SCREEN.
  CASE sy-dynnr.
    WHEN '1000'.
      CASE sscrfields-ucomm.
        WHEN 'ONLI'.
          ...
      ENDCASE.
  ENDCASE.
...
AT SELECTION-SCREEN ON EXIT-COMMAND.
  CASE sy-dynnr.
    WHEN '2000'.
      CASE sscrfields-ucomm.
        WHEN 'CBAC'.
          ...
      ENDCASE.
  ENDCASE.
...

Upvotes: 2

AlexSchell
AlexSchell

Reputation: 1722

To achieve the desired behavior, add the AT ... ON EXIT-COMMAND event.

You can insert the following code almost anywhere, for example place it before AT SELECTION-SCREEN OUTPUT.:

...
AT SELECTION-SCREEN ON EXIT-COMMAND.
  CASE sy-dynnr.
    WHEN '1000'.
      LEAVE PROGRAM.
    WHEN '2000'.
      LEAVE TO SCREEN 0.
  ENDCASE.
...

Upvotes: 1

Related Questions