Tuesday, March 11, 2014

ABAP change PNP LDB select options behaviour SELECT_OPTIONS_RESTRICT



Hi Folks,
this time i needed to change a select option from the PNP logical data base.
Normally you can change things from the HR report class. But some things you cannot.
For example i want to select only one person in an Hr report with the PNP logical database.
I could have used no-interval if it were a select option defined by me in my program.
But it is defined in the PNP LDB so i cannot access its coding.

Luckily enough there is a function module called SELECT_OPTIONS_RESTRICT
that allow to change parameters and select options from both the LDB and the current program.
Here a coding example and below the result.

INITIALIZATION.

* Include des Typepools SSCR
  TYPE-POOLS sscr.
* define objects for restriction
  DATA restrict TYPE sscr_restrict.
* helpobject to fill restriction
  DATA opt_list TYPE sscr_opt_list.
  DATA ass TYPE sscr_ass.

* EQ: only EQ allowed
  CLEAR opt_list.
  MOVE 'ONLY_EQ' TO opt_list-name.
  MOVE 'X' TO: opt_list-options-eq.
  APPEND opt_list TO restrict-opt_list_tab.

* options you want to allow
  CLEAR ass.
  MOVE: 'S' TO ass-kind,
  'PNPPERNR' TO ass-name,
  'I'  TO ass-sg_main,
  'N'  TO ass-sg_addy, "removes the interval selections
  'ONLY_EQ' TO ass-op_main.
  APPEND ass TO restrict-ass_tab.

* Eingrenzung der möglichen Selektionsoptionen
  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
*     PROGRAM                =
      restriction            = restrict
*     DB                     = ' '
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9
    . " Punkt
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF. " sy-subrc <> 0 - CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'


And here the result.
 
 
Enjoy!