Saving and restoring selected radio buttons on selection screen

Sometimes it's useful to save and restore the selection of user's parameters, after the program was started newly. For many parameters it can be achieved with construction PARAMETERS ... MEMORY ID which stores the values of parameters as SPA/GPA in the SAP Memory. The MEMORY ID addition is not allowed for radio buttons, so here is a small example how you can code it by yourself.
PARAMETERS:
  p1 RADIOBUTTON GROUP rg1,
  p2 RADIOBUTTON GROUP rg1,
  p3 RADIOBUTTON GROUP rg1.

AT SELECTION-SCREEN OUTPUT.

  DATA:
    lv_rg1(2) TYPE c.

* Restore selected radio button as SPA/GPA parameter in SAP memory 
* and set its value
  GET PARAMETER ID 'RG1' FIELD lv_rg1.

  IF lv_rg1 = 'P1'.
    p1 = 'X'.   p2 = ''.   p3 = ''.
  ELSEIF lv_rg1 = 'P2'.
    p1 = ''.    p2 = 'X'.  p3 = ''.
  ELSEIF lv_rg1 = 'P3'.
    p1 = ''.    p2 = ''.   p3 = 'X'.
  ENDIF.

START-OF-SELECTION.

* Save selected radio button as SPA/GPA parameter in SAP memory
  IF     p1 = 'X'.
    SET PARAMETER ID 'RG1' FIELD 'P1'.
  ELSEIF p2 = 'X'.
    SET PARAMETER ID 'RG1' FIELD 'P2'.
  ELSEIF p3 = 'X'.
    SET PARAMETER ID 'RG1' FIELD 'P3'.
  ENDIF.

  WRITE: / 'p1', p1.
  WRITE: / 'p2', p2.
  WRITE: / 'p3', p3.
See other related notes in my infodepot:
Tabbed block at selection screen - returning to previous selected tabstrip 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) 2011 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.