DATA(lv_string) = |My string I want to convert to xstring.|.
TRY.
DATA(lv_xstring) = cl_abap_codepage=>convert_to( lv_string ).
DATA(lv_string_decoded) = cl_abap_codepage=>convert_from( lv_xstring ).
WRITE: / lv_string,
/ lv_xstring,
/ lv_string_decoded.
CATCH cx_root INTO DATA(e).
WRITE: / e->get_text( ).
ENDTRY.
Tag: abap
[ABAP] Filter table using VALUE FOR
DATA(lt_result) = VALUE z_type( FOR line IN lt_table
WHERE ( value IN lr_values )
( field = ls_line-value ) ).
[ABAP] Selection Screen Tabbed Block
SELECTION-SCREEN BEGIN OF BLOCK bl4 WITH FRAME TITLE TEXT-t01.
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 10 LINES.
SELECTION-SCREEN TAB (15) tbl_tab1 USER-COMMAND tab1 DEFAULT SCREEN 1001.
SELECTION-SCREEN TAB (15) tbl_tab2 USER-COMMAND tab2 DEFAULT SCREEN 1002.
SELECTION-SCREEN TAB (15) tbl_tab3 USER-COMMAND tab3 DEFAULT SCREEN 1003.
SELECTION-SCREEN END OF BLOCK tbl.
SELECTION-SCREEN END OF BLOCK bl4.
* Subscreen 1001 Tab1
SELECTION-SCREEN BEGIN OF SCREEN 1001 AS SUBSCREEN.
PARAMETERS p_bool1 TYPE abap_bool AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1001.
* Subscreen 1002 Tab2
SELECTION-SCREEN BEGIN OF SCREEN 1002 AS SUBSCREEN.
PARAMETERS p_btp1 TYPE flag RADIOBUTTON GROUP rbg DEFAULT 'X'.
PARAMETERS p_btp2 TYPE flag RADIOBUTTON GROUP rbg.
PARAMETERS p_btp3 TYPE flag RADIOBUTTON GROUP rbg.
SELECTION-SCREEN END OF SCREEN 1002.
* Subscreen 1003 Tab3
SELECTION-SCREEN BEGIN OF SCREEN 1003 AS SUBSCREEN.
PARAMETERS p_bool2 TYPE flag AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1003.
INITIALIZATION.
" provide tab names
tbl_tab1 = 'Tab1'.
tbl_tab2 = 'Tab2'.
tbl_tab3 = 'Tab3'.
" set active tab (activetab value must be in uppercase)
tbl-activetab = 'TAB2'.
tbl-dynnr = 1002.
tbl-prog = sy-repid.
AT SELECTION-SCREEN.
" click on tabstrip event
CASE sy-ucomm.
WHEN 'TAB1'.
MESSAGE 'TAB1' TYPE 'S'.
WHEN 'TAB2'.
MESSAGE 'TAB2' TYPE 'S'.
WHEN 'TAB3'.
MESSAGE 'TAB3' TYPE 'S'.
ENDCASE.
[ABAP] Replace unusual characters with ordinary characters in a String
DATA(unusual) = 'á Ă é Ä Ö Ü ä ö ü ß'.
DATA(pretty) = VALUE string( ).
CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
intext = unusual
IMPORTING
outtext = pretty.
WRITE / unusual.
WRITE / pretty. "a A e Ae Oe Ue ae oe ue ss
[ABAP] Display Table data as HTML
REPORT z_table_to_html.
TRY.
SELECT * FROM sflight INTO TABLE @DATA(flights) UP TO 100 ROWS.
cl_demo_output=>write_data( flights ).
DATA(lv_html) = cl_demo_output=>get( ).
cl_abap_browser=>show_html( title = 'Flights'
html_string = lv_html
container = cl_gui_container=>default_screen ).
" force cl_gui_container=>default_screen
WRITE: space.
CATCH cx_root INTO DATA(e).
WRITE: / e->get_text( ).
ENDTRY.
[ABAP] Get URL for BSP Page
cl_http_ext_webapp=>create_url_for_bsp_application( EXPORTING bsp_application = bsp_application " Name der BSP Applikation
bsp_start_page = bsp_start_page " Startseite der BSP Applikation
bsp_start_parameters = bsp_start_parameters " Startparameter der BSP Applikation
IMPORTING abs_url = DATA(lv_absolute_url ). " Absolute URL (Protokol, Host, Port, ...) der BSP Applikation
[ABAP] Display PDF in HTML Control
DATA lt_data TYPE STANDARD TABLE OF x255.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring "pdf data
TABLES
binary_tab = lt_data.
DATA(o_html) = NEW cl_gui_html_viewer( parent = o_parent ).
* URL zu HTML holen
DATA: lv_url TYPE swk_url.
o_html->load_data( EXPORTING type = 'BIN'
subtype = 'PDF'
IMPORTING assigned_url = lv_url
CHANGING data_table = lt_data ).
* HTML anzeigen
o_html->show_url( lv_url ).
[ABAP] OData – Request Parameter
You can access the request parameter from anywhere in the *_DPC_EXT class via:
mr_request_details->parameters
[ABAP] Convert table of strings to a single string
DATA(lv_string) = REDUCE #( INIT str = || FOR line IN table_of_strings NEXT str = str && line).
[ABAP] Create ToC for a given transport, release it and download it as ZIP
Related Reports:
https://nocin.eu/abap-download-transport-as-zip/
https://nocin.eu/abap-import-transport-from-zip/
*&---------------------------------------------------------------------*
*& Report Z_ZIP_TOC
*&---------------------------------------------------------------------*
*& For the givin transport, this report creates a transport of copies (ToC),
*& releases it, and then download the ToC as ZIP file to your filesystem.
*& The given request can be in sate unreleased!
*&---------------------------------------------------------------------*
REPORT Z_ZIP_TOC.
INITIALIZATION.
SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE TEXT-t01.
PARAMETERS p_trkorr LIKE e070-trkorr OBLIGATORY.
PARAMETERS p_ttext TYPE as4text.
SELECTION-SCREEN END OF BLOCK bl01.
SELECTION-SCREEN BEGIN OF BLOCK bl02 WITH FRAME TITLE TEXT-t02.
PARAMETERS p_sapdir TYPE string LOWER CASE OBLIGATORY DEFAULT '/usr/sap/trans/'.
PARAMETERS p_lcldir TYPE string LOWER CASE OBLIGATORY DEFAULT 'C:\temp\'.
SELECTION-SCREEN END OF BLOCK bl02.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_trkorr.
CALL FUNCTION 'TR_F4_REQUESTS'
EXPORTING
iv_trkorr_pattern = p_trkorr
IMPORTING
ev_selected_request = p_trkorr.
START-OF-SELECTION.
" Read description of provided transport
DATA ls_request TYPE trwbo_request.
CALL FUNCTION 'TR_READ_REQUEST'
EXPORTING
iv_read_e07t = 'X'
iv_trkorr = p_trkorr
CHANGING
cs_request = ls_request
EXCEPTIONS
error_occured = 1
no_authorization = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'Could not read Transport description' TYPE 'E'.
ENDIF.
" Read all objects for provided transport
DATA: lt_objects TYPE tr_objects,
lt_keys TYPE tr_keys.
CALL FUNCTION 'TR_GET_OBJECTS_OF_REQ_AN_TASKS'
EXPORTING
is_request_header = VALUE trwbo_request_header( trkorr = p_trkorr )
iv_condense_objectlist = 'X'
IMPORTING
et_objects = lt_objects
et_keys = lt_keys
EXCEPTIONS
invalid_input = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Could not read Transport objects' TYPE 'E'.
ENDIF.
" Create new ToC
DATA ls_request_header TYPE trwbo_request_header.
CALL FUNCTION 'TR_INSERT_REQUEST_WITH_TASKS'
EXPORTING
iv_type = 'T'
iv_text = COND as4text( WHEN p_ttext IS INITIAL THEN ls_request-h-as4text
ELSE p_ttext )
iv_owner = sy-uname
iv_target = 'DUM'
IMPORTING
es_request_header = ls_request_header
EXCEPTIONS
insert_failed = 1
enqueue_failed = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'Transport creation failed' TYPE 'E'.
ENDIF.
DATA(lv_trkorr_toc) = ls_request_header-trkorr.
" Add all object to the new ToC
CALL FUNCTION 'TRINT_APPEND_COMM'
EXPORTING
wi_exclusive = 'X'
wi_sel_e071 = 'X'
wi_sel_e071k = 'X'
wi_trkorr = lv_trkorr_toc
TABLES
wt_e071 = lt_objects
wt_e071k = lt_keys
EXCEPTIONS
e071k_append_error = 1
e071_append_error = 2
trkorr_empty = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE 'Could not append objects to ToC' TYPE 'E'.
ENDIF.
" Release ToC Transport
DATA lt_messages TYPE ctsgerrmsgs.
CALL FUNCTION 'TRINT_RELEASE_REQUEST'
EXPORTING
iv_trkorr = lv_trkorr_toc
* IV_DIALOG = 'X'
* IV_AS_BACKGROUND_JOB = ' '
* IV_SUCCESS_MESSAGE = 'X'
* IV_WITHOUT_OBJECTS_CHECK = ' '
* IV_CALLED_BY_ADT = ' '
* IV_CALLED_BY_PERFORCE = ' '
* IV_WITHOUT_DOCU = ' '
iv_without_locking = 'X'
* IV_DISPLAY_EXPORT_LOG = 'X'
* IV_IGNORE_WARNINGS = ' '
* IV_SIMULATION = ' '
IMPORTING
et_messages = lt_messages
EXCEPTIONS
cts_initialization_failure = 1
enqueue_failed = 2
no_authorization = 3
invalid_request = 4
request_already_released = 5
repeat_too_early = 6
object_lock_error = 7
object_check_error = 8
docu_missing = 9
db_access_error = 10
action_aborted_by_user = 11
export_failed = 12
execute_objects_check = 13
release_in_bg_mode = 14
release_in_bg_mode_w_objchk = 15
error_in_export_methods = 16
object_lang_error = 17
OTHERS = 18.
IF sy-subrc <> 0.
MESSAGE 'Could not release ToC' TYPE 'E'.
cl_demo_output=>display( lt_messages ).
ENDIF.
" Download released ToC as ZIP
DATA lv_xcontent_k TYPE xstring.
DATA lv_xcontent_r TYPE xstring.
DATA(lv_transdir_k) = |{ p_sapdir }cofiles/K{ lv_trkorr_toc+4 }.{ lv_trkorr_toc(3) }|.
DATA(lv_transdir_r) = |{ p_sapdir }data/R{ lv_trkorr_toc+4 }.{ lv_trkorr_toc(3) }|.
TRY.
" K
OPEN DATASET lv_transdir_k FOR INPUT IN BINARY MODE.
READ DATASET lv_transdir_k INTO lv_xcontent_k.
CLOSE DATASET lv_transdir_k.
" R
OPEN DATASET lv_transdir_r FOR INPUT IN BINARY MODE.
READ DATASET lv_transdir_r INTO lv_xcontent_r.
CLOSE DATASET lv_transdir_r.
" Add to ZIP
DATA(lo_zipper) = NEW cl_abap_zip( ).
lo_zipper->add( name = |K{ lv_trkorr_toc+4 }.{ lv_trkorr_toc(3) }|
content = lv_xcontent_k ).
lo_zipper->add( name = |R{ lv_trkorr_toc+4 }.{ lv_trkorr_toc(3) }|
content = lv_xcontent_r ).
" Download ZIP
DATA(lv_xzip) = lo_zipper->save( ).
" Convert to raw data
DATA(lt_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_xzip ).
" Set zip filename
DATA(lv_zip_name) = COND #( WHEN p_ttext IS INITIAL THEN |{ ls_request-h-as4text }_{ lv_trkorr_toc }|
ELSE |{ p_ttext }_{ lv_trkorr_toc }| ).
" Replace every character that is not [a-zA-Z0-9_] with '_'.
REPLACE ALL OCCURRENCES OF REGEX '[^\w]+' IN lv_zip_name WITH '_'.
cl_gui_frontend_services=>gui_download( EXPORTING filename = p_lcldir && lv_zip_name && '.zip'
filetype = 'BIN'
CHANGING data_tab = lt_data ).
CATCH cx_root INTO DATA(e_text).
MESSAGE e_text->get_text( ) TYPE 'E'.
ENDTRY.
MESSAGE |{ lv_zip_name }.zip created and downloaded to { p_lcldir }| TYPE 'S'.