Monday, February 11, 2008

Translate system message into another language

With the function BAPI_MESSAGE_GETDETAIL it is possible to translate any
system message into another language. This is extremly usefull for the web
when a user needs to get language-dependent messages before he logs on
(the system doesn't know the correct language yet).

Sort mechanism respecting field type

It is often not enough to sort an internal table by text or binary value
but respecting the field type, e.g. a date field. In this case you have to
create a sort table with the sort fields as seperate rows. This small
example illustrates this:

date otab TYPE abap_sortorder_tab.
date oline TYPE abap_sortorder.

oline-descending = 'X'.
oline-name = 'CREATE_DATE'. APPEND oline to otab.
oline-name = 'CREATE_TIME'. APPEND oline to otab.
oline-name = 'CUSTOMER'. APPEND oline to otab.

SORT table_to_sort BY (otab).

Friday, February 8, 2008

Dynamic Code Execution

The following code is the basis for a report to dynamically execute
ABAP-Code at runtime.

*&---------------------------------------------------------------------*
*& Report ZDynamic_Code_Execution
*&---------------------------------------------------------------------*
report ZDynamic_Code_Execution.

types: line(132) type c.
data: it_tline type standard table of tline with header line,
header type thead,
control type itced,
report(30) type c,
itab type standard table of line initial size 500 with header
line,
l_uname like sy-uname.

concatenate 'ZZAB' sy-uname into l_uname.
concatenate 'report' l_uname '.' into itab separated by space.
append itab to itab.

* check if report already exits
select single * from stxh into corresponding fields of header
where tdobject = 'TEXT'
and tdname = l_uname
and tdid = 'ST'
and tdspras = 'D'.

check sy-subrc = 0.

* create table with 132 lines
do 132 times.
append it_tline to it_tline.
enddo.

header-tdobject = 'TEXT'.
header-tdname = l_uname.
header-tdid = 'ST'.
header-tdspras = 'D'.

call function 'SAVE_TEXT'
exporting
header = header
insert = 'X'
savemode_direct = 'X'
tables
lines = it_tline.

commit work.

* read text and create table
call function 'READ_TEXT'
exporting
id = 'ST'
language = 'D'
name = header-tdname
object = 'TEXT'
tables
lines = it_tline.

header-tdlinesize = 132.
control-changemode = 'X'.

call function 'EDIT_TEXT'
exporting
header = header
control = control
tables
lines = it_tline.

loop at it_tline.
write it_tline-tdline to itab.
append itab to itab.
endloop.

* syntax check.
syntax-check for itab message f line g word h
program l_uname.

check sy-subrc = 0.
* create report
insert report l_uname from itab.

* excecute report
submit (l_uname) and return.

* delete report
delete report report.

Function RSDU_EXEC_SQL

Mit Funktionsbaustein RSDU_EXEC_SQL kann ein beliebiges SQL statement
ausgeführt werden. Damit können evtl. vorhandenen Pflegerestriktionen
(Rechteprüfungen) umgangen werden.

Monday, January 21, 2008

Meta-Info for Excel Export

The documentation for the meta information for an Excel export can be
found here:
http://msdn2.microsoft.com/en-us/library/aa155477(office.10).aspx

It describes which xml-tags can be used to define the Excel page settings
for an document, like scaling or page width.