SAP has different number to indicate character encoding for UTF-8 and UTF-16. SAP call it code page number. UTF-8 is using number 4110 and UTF-16 is using number 4102.
*Note: 4103, 4104 and 4105 also are Unicode code page, you can see it in table "TCP00".
For example:
If we want to export an Excel file by using "GUI_DOWNLOAD" with encoding "UTF-16", then at the Exporting parameter "CODEPAGE", pass the value "4102" then the file will be export with UTF-16 encoding.
We can find all the code page that supported by SAP in table "TCP00".
A blog which created by Edison to keep information about his research regarding SAP for future reference.
Thursday, June 9, 2011
Wednesday, June 8, 2011
How to get the Year, Month and Day different between two dates?
Sometime we need to know the different between two dates, for example, Employment Period.
Example, James joined the company on 15.01.2001 and resigned on 28.03.2011, how long had James worked in the company? The employment period for James should be 10 Years, 2 Months and 14 Days.
How we going to get this? Function module "HR_GET_TIME_BETWEEN_DATES" will do this for you.
Figure 1:
Example, James joined the company on 15.01.2001 and resigned on 28.03.2011, how long had James worked in the company? The employment period for James should be 10 Years, 2 Months and 14 Days.
How we going to get this? Function module "HR_GET_TIME_BETWEEN_DATES" will do this for you.
Figure 1:
Thursday, June 2, 2011
ABAP Report: Formatted Excel Output File
The source is from "http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/13092".
The XML part looks complicated initially, but after get familiar with the TAGs, I able to write XML easily. I love this:-)
Sample ABAP Program:
The XML part looks complicated initially, but after get familiar with the TAGs, I able to write XML easily. I love this:-)
Sample ABAP Program:
REPORT zedi_excel_xml.
TYPES: BEGIN OF ty_emp,
pernr TYPE persno,
ename TYPE emnam,
END OF ty_emp.
DATA: itab TYPE STANDARD TABLE OF ty_emp,
la_tab LIKE LINE OF itab,
xmlstr TYPE string.
START-OF-SELECTION.
*---------
* Test table
*---------
SELECT pernr ename FROM pa0001 INTO TABLE itab UP TO 30 ROWS.
*---------
* Get the XML data excel
*---------
CALL TRANSFORMATION zedi_excel_xml
SOURCE table = itab
RESULT XML xmlstr.
*---------
* Download the file
*---------
* Fill the table
DATA: xml_table TYPE STANDARD TABLE OF string.
APPEND xmlstr TO xml_table.
DATA: window_title TYPE string,
fullpath TYPE string,
path TYPE string,
user_action TYPE i,
default_extension TYPE string,
default_file_name TYPE string,
file_filter TYPE string,
filename TYPE string,
initialpath TYPE string.
* File selection
MOVE '.XLS' TO default_extension.
MOVE 'XLS files (*.XLS)|*.XLS' TO file_filter.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = default_extension
default_file_name = default_file_name
file_filter = file_filter
initial_directory = initialpath
CHANGING
filename = filename
path = path
fullpath = fullpath
user_action = user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* download file
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = fullpath
filetype = 'ASC'
TABLES
data_tab = xml_table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
TYPES: BEGIN OF ty_emp,
pernr TYPE persno,
ename TYPE emnam,
END OF ty_emp.
DATA: itab TYPE STANDARD TABLE OF ty_emp,
la_tab LIKE LINE OF itab,
xmlstr TYPE string.
START-OF-SELECTION.
*---------
* Test table
*---------
SELECT pernr ename FROM pa0001 INTO TABLE itab UP TO 30 ROWS.
*---------
* Get the XML data excel
*---------
CALL TRANSFORMATION zedi_excel_xml
SOURCE table = itab
RESULT XML xmlstr.
*---------
* Download the file
*---------
* Fill the table
DATA: xml_table TYPE STANDARD TABLE OF string.
APPEND xmlstr TO xml_table.
DATA: window_title TYPE string,
fullpath TYPE string,
path TYPE string,
user_action TYPE i,
default_extension TYPE string,
default_file_name TYPE string,
file_filter TYPE string,
filename TYPE string,
initialpath TYPE string.
* File selection
MOVE '.XLS' TO default_extension.
MOVE 'XLS files (*.XLS)|*.XLS' TO file_filter.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = default_extension
default_file_name = default_file_name
file_filter = file_filter
initial_directory = initialpath
CHANGING
filename = filename
path = path
fullpath = fullpath
user_action = user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* download file
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = fullpath
filetype = 'ASC'
TABLES
data_tab = xml_table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Sample XML Transformation
Subscribe to:
Posts (Atom)