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.





Tuesday, July 9, 2013

SAP Smartforms + Zebra printer = QR codes work

Personally I did some research for myself concerning possibilities to print QR codes within SAP Smartforms. The result was not so happy. There is no direct support from SAP for QRs in Smartforms these days, I mean year 2013.

Possible ways are as follows:

  • The solution from third parties 

  Zebra Designer – NiceLabel software
  http://www.nicelabel.com/products#designer

  • OR ??? ...read below...

QR code printing on Zebra printers

I did many various tests and spend enough time with Zebra support as well. My aim was to avoid any third party tools. Solution is finally no so difficult. The answer is Smartforms "Command node" and ZPL language of Zebra printers. 

Wee need following commands:

  • Position of QR on label
Any ZPL II command inserted into smart form via “command node” is not positioned in the end by smartform's window, but by another ZPL command FO e.g. ‘^FO100,100’.
  • Data - QR content
QR code data must be inserted as command node attribute just by one variable (here e.g. GV_QR_ZPL_CODE). I found this SAP info below and it started to work.
  • Avoid
Although many examples on internet uses starting and ending ZPL commands, but in smart forms you have to avoid of usage such a ZPL sequence ^XA… ^XZ, because it starts new label. It means, QR code is then going to be printed on separate label!


Now put everything together

1. Prepare data for QR in Smartform designer



2. Insert command node, that’s all

It could be placed under MAIN window. I used another window just for imagination of position within designer.




The only limitations is lengh for one Command node content. It is up to 200 characters including ZPL. But for many cases it is sufficient.