Tabbed block at selection screen - returning to previous selected tabstrip

The ABAP processor transfers back the content of input fields (parameters and select-options) after returning to selection screen, so the user has the same status as by the previous selection.
The exception is the active tabstrib in the tabbed block - after returning to the selection screen, system always shows the first tabstrip.
There are at least two solutions to change this behavior:
  1. use the additional hidden parameters and their transfer mechanism, which is missing for tabstrip, or
  2. save and the restore the last active tabstrip in memory (export/import).
I prefer the first scenario. In this scenario the program starts with default tabstrip and in the second one the program starts with last selected tabstrip.

What is the problem with the second export/import scenario?
It is a bit difficult/impossible to implement, because there is no event, which is fired exactly once at the start of the report (the event LOAD-OF-PROGRAM is not fired once per report call, it's fired before processing the selection screen, also when you leaved list and the selection screen will be displayed once again). So there is no good place to code your default tabstrip selection. There is also no event, which is called after the end of the program, where you could delete or free the exported memory variables.
Here the complete example for the first scenario:
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 15 LINES.
SELECTION-SCREEN TAB (15) tbl_tab1 USER-COMMAND tab1 DEFAULT SCREEN 9001.
SELECTION-SCREEN TAB (15) tbl_tab2 USER-COMMAND tab2 DEFAULT SCREEN 9002.
SELECTION-SCREEN END OF BLOCK tbl.

SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
PARAMETERS: pa_test.
SELECTION-SCREEN END OF SCREEN 9001.

SELECTION-SCREEN BEGIN OF SCREEN 9002 AS SUBSCREEN.
SELECTION-SCREEN END OF SCREEN 9002.

PARAMETERS:
* Hidden parameters to store the last selected tab strip
  pa_dynnr LIKE tbl-dynnr NO-DISPLAY,
  pa_acttb LIKE tbl-activetab NO-DISPLAY.

INITIALIZATION.
* Descriptions of the tab strips
  tbl_tab1 = 'First tab'.
  tbl_tab2 = 'Second tab'.

AT SELECTION-SCREEN OUTPUT. " PBO
* if the last choice is saved
  IF NOT pa_dynnr IS INITIAL.
*   activate the last choice
    tbl-dynnr     = pa_dynnr.
    tbl-activetab = pa_acttb.
*   clear the saved choice to make it only once
    pa_dynnr = ''.
    pa_acttb = ''.
  ENDIF.

AT SELECTION-SCREEN. " PAI
* if the list is started (F8)
  IF sy-ucomm = 'ONLI'.
*   save the last choice
    pa_dynnr = tbl-dynnr.
    pa_acttb = tbl-activetab.
  ENDIF.

START-OF-SELECTION.

  WRITE: / tabstrip_tbl-activetab. " show which tabstrip is active
Here the differences to check the second scenario:
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 15 LINES.
...

INITIALIZATION.

* To return to the previous selected tab strip
  IMPORT tbl-dynnr FROM MEMORY ID 'TabStripScreen' .
  IMPORT tbl-activetab FROM MEMORY ID 'TabStripActive'.

START-OF-SELECTION.

* To return to the previous selected tab strip
  EXPORT tbl-dynnr TO MEMORY ID 'TabStripScreen'.
  EXPORT tbl-activetab TO MEMORY ID 'TabStripActive'.
See other related notes in my infodepot:
Saving and restoring selected radio buttons on selection screen Selection Screen with Push Button
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2010 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.