Friday, July 19, 2013

Function modules reading user parameters



There exist a lot of various function modules reading user parameters. So what is useful? I found two of them most useful.

SUSR_GET_USER_DEFAULTS

Returns standard user SAP attributes as user's date format, language, printers etc.

Sample usage:

* Data for user parameter
  DATAlt_users LIKE usdef OCCURS WITH HEADER LINE.
  DATAls_users TYPE usdef.

* Get standard SAP user defaults - due to printer settings
  CALL FUNCTION 'SUSR_GET_USER_DEFAULTS'
    TABLES
      users  lt_users
    EXCEPTIONS
      OTHERS 0.

  READ TABLE lt_users INDEX INTO ls_users.
  " set printer
  IF sy-subrc EQ AND ls_users-spdb 'G' ).
    gs_control_structure-spdb 'X'.
  ENDIF.

There is an example of returned content for FM SUSR_GET_USER_DEFAULTS.





SUSR_USER_PARAMETERS_GET

It gives internal table filled with pairs - Id of parameter (parid) and it's value (parva). Here we speak about custom user parameters set in TPARA table (maintained via SM30).


Insert new user parmeter

transaction SM30, table TPARA



Reading of user parameter



* Get user's custom printing setting
  DATAlt_user_params TYPE ustyp_t_parameters,
              ls_user_param  LIKE LINE OF lt_user_params,
              lv_user TYPE usr02-bname.

* Name of searched parameter id (parid)
  CONSTANTScv_print_colli_usr_param TYPE string VALUE '/YourNameSpace/HU035_P_COLLI'. 


  MOVE sy-uname TO lv_user.

  " get custom user default parameters
  CALL FUNCTION 'SUSR_USER_PARAMETERS_GET'
    EXPORTING
      user_name       lv_user
    TABLES
      user_parameters lt_user_params.

  READ TABLE lt_user_params INTO ls_user_param WITH KEY parid cv_print_colli_usr_param.

  " set checkbox by user parameter
  IF ls_user_param-parva EQ abap_true.
    d1000-printbox 'X'.
  ENDIF.


There is an example of returned content for FM SUSR_USER_PARAMETERS_GET.





No comments:

Post a Comment