Sunday, November 25, 2007

Check user roles

For checking if a user has a specific role the function
SRM_VE_GET_USER_ROLES can be of great help. The following code gives an
example of its use:

DATA lt_roles TYPE STANDARD TABLE OF str_agrs.

* Einlesen aller Rollen eines Users
CALL FUNCTION 'SRM_VE_GET_USER_ROLES'
EXPORTING
user_name = im_user
time_dependent = im_time_dependent
TABLES
activity_groups_users = lt_roles
EXCEPTIONS
no_activity_groups_available = 1
OTHERS = 2.

IF sy-subrc <> 0.
EXIT.
ENDIF.

SORT lt_roles BY agr_name.

* versuche, die benötigte Rolle zu finden
READ TABLE lt_roles WITH KEY agr_name = im_role_to_check
TRANSPORTING NO FIELDS BINARY SEARCH.

Conversion of date

The SAP standard class CL_RS_TIME_SERVICE offers a lot of methods for the
conversion of date values/formats.

Convert date from internal to external format

The function CONVERSION_EXIT_PDATE_OUTPUT should be used to convert a date
from its internal to external format. It automatically takes the user's
date type for the external format (i.e. 20071013 -> 10/13/2007).

data: lv_date_im TYPE d,
lv_date_ex(10).
lv_date_im = xyz-Datum.

CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'
EXPORTING
INPUT = lv_date_im
IMPORTING
OUTPUT = lv_date_ex.

xyz-Datum = lv_date_ex.

Friday, November 23, 2007

Eval Formula

The function eval_formula offers the possibility to easily evaluate a
formula and automatically calculate the result. If used inside a report
program the formula can even contain variables which are replaced within a
sub-routine. The following code gives a little how-to-use example:

CALL FUNCTION 'EVAL_FORMULA'
EXPORTING
FORMULA = 'A+B'
PROGRAM = 'ZSB_TEST'
ROUTINE = 'GET_VAR'
IMPORTING
VALUE = e_value

FORM get_var USING value(name)
CHANGING value(value)
value(subrc).
CASE name.
WHEN 'A'.
value = 13.
WHEN 'B'.
value = 13.
WHEN OTHERS.
value = 0.
ENDCASE.
ENDFORM.

Create offset date

Using the function SALP_CALC_DATE it is possible to calculate any date
with a specific offset, i.e. to get the date 2 year, 3 months and 5 days
in the future. So this function is extremely useful because you can ignore
even/odd months or leap years.

Monday, November 19, 2007

Scaling of Excel export page

After exporting a website into an Excel page it might happen that not the
whole content fits on a print sheet. Therefor a possible solution is the
scaling of the page. This can easily be done with extra header information
in the website like the following:

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<style>
@page { margin:.90in .70in .70in .70in;
mso-header-margin:.49in;
mso-footer-margin:.49in; }
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:WorksheetOptions>
<x:DefaultColWidth>10</x:DefaultColWidth>
<x:Print>
<x:ValidPrinterInfo/>
<x:PaperSizeIndex>9</x:PaperSizeIndex>
<x:Scale>80</x:Scale>
<x:HorizontalResolution>600</x:HorizontalResolution>
<x:VerticalResolution>600</x:VerticalResolution>
</x:Print>
<x:Selected/>
<x:DoNotDisplayGridlines/>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>

Important is the tag <x:Scale>. Also interesting is the tag
<DoNotDisplayGridlines> which suppresses the table/line borders.

Sunday, November 4, 2007

Start Info

I opened this blog to document all the interesting facts, infos, tricks, tipps, hacks and mics stuff that crosses my way. Currently I work as a SAP consultant/developer so it will be mostly blogs about SAP things that I'm going to post over the next weeks, months, years, decades (well, maybe not that long).