Skip to content

Instantly share code, notes, and snippets.

@sandraros
sandraros / vba_word_tabs_to_spaces_or_markdown
Last active January 19, 2019 19:51
VBA macro to paste into MS Word, which converts text lines with tab characters representing tables into tables without tab, but instead with values right-padded with spaces (markdown version too) so that to fit perfectly for usage of HTML <pre>...</pre>
Rem 1) select the text lines representing a table whose columns are separated by the tab character
Rem 2) run this macro
Rem 3) result: the tab characters are replaced by two or more space characters such a way each column
Rem has the same number of characters
Rem 4) you may then copy/paste those text lines inside HTML <pre>...</pre> it will look like a table
Sub tabs_to_spaces()
Dim par As Paragraph
Dim pars() As Paragraph
Dim arr(50) As Integer ' 50 tabs maximum per line
@sandraros
sandraros / mass_reading_stxl.abap
Last active October 13, 2024 15:50
Bulk reading long texts in SAP R/3 & S/4 (tables STXH and STXL) with very good performance
* Improvement of code at https://blogs.sap.com/2014/02/25/alternative-to-readtext-function-module/comment-page-1/#comment-4121
* including Kenneth proposal at https://blogs.sap.com/2014/02/25/alternative-to-readtext-function-module/comment-page-1/#comment-452639
*
* Create your own class implementing LIF_PROCESSOR to process each text extracted.
* Two demo classes are provided: LCL_WRITER (active) and LCL_VERIFIER (if you want to test).
*
* Note: you won't need this code if you have the newest standard function modules READ_MULTIPLE_TEXTS and READ_TEXT_TABLE installed in
* your system (cf note 2261311 – Function module for reading multiple SAPscript texts -> https://launchpad.support.sap.com/#/notes/2261311/E )
REPORT zdemo.
@sandraros
sandraros / test_of_cl_http_utility_unescape_url.abap
Last active August 17, 2020 14:00
Test class to verify the behavior of cl_http_utility=>unescape_url, that all escaped characters (from %00 to %EF%BF%BF which are equivalent to U+0000 to U+FFFF) are unescaped correctly, and more...
* SUMMARY OF SPECIFIC BEHAVIORS:
*
* input string (formatted as string template) returned string (formatted as string template)
* ------------------------------------------- -----------------------------------------
* any string containing %00 return empty string
* unencoded null character null character returned unchanged
* A%0AB A\nB
* A%0DB A\rB
* A%B return empty string
* A+B A B
@sandraros
sandraros / zcl_abapgit_user_exit.clas.abap
Created November 2, 2019 09:53
Example implementation for custom_deserialize_abap_clif (https://github.com/larshp/abapGit/pull/2987)
CLASS zcl_abapgit_user_exit DEFINITION PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES zif_abapgit_exit.
ENDCLASS.
CLASS zcl_abapgit_user_exit IMPLEMENTATION.
METHOD zif_abapgit_exit~custom_deserialize_abap_clif.
DATA: lo_deserializer TYPE REF TO zcl_abapgit_oo_deserializer.
CLASS ltc_main DEFINITION
FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
CONSTANTS iterations TYPE i VALUE 50000.
DATA: sflight_s TYPE STANDARD TABLE OF sflight.
METHODS setup.
METHODS reference_into FOR TESTING.
METHODS assigning FOR TESTING.
@sandraros
sandraros / gist:ed2808ce00af79e0762b08d9f4514942
Created February 27, 2021 13:05
Test of ABAP method skip_non_xml_characters in if_ixml_ostream
REPORT.
DATA l_string TYPE string.
DATA character2 TYPE string.
data(vietnamese) = 'ớắ'.
data(emoji) = '🦀🦀🤙🤙🤙🌎🌍🌏'.
PERFORM get_characters_unicode_range USING '0000' 'FFFF' CHANGING l_string.
DATA(off) = 0.
data(xml_characters) = ``.
data(non_xml_characters) = ``.
WHILE off < strlen( l_string ).
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS at_selection_screen_output.
METHODS at_selection_screen_exit.
METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.
PRIVATE SECTION.
DATA o_html TYPE REF TO cl_gui_html_viewer.
ENDCLASS.
@sandraros
sandraros / gist:9282da1c7c39c944a87d843e49508651
Last active February 26, 2023 12:18
ABAP: check if pretty printer was applied (NB: default list of programs defined for https://github.com/abap2xlsx)
REPORT.
SELECT-OPTIONS s_prog FOR sy-repid.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (64) label_1.
PARAMETERS prog_bef TYPE syrepid DEFAULT 'ZTEMPORARY'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (64) label_2.
PARAMETERS prog_aft TYPE syrepid DEFAULT 'ZTEMPORARY2'.
SELECTION-SCREEN END OF LINE.
*Version of code from blog post, adapted to work/compile with 7.40+, and no need to create ddic structure ZDEBUGGER_SCRIPTING_S
*https://blogs.sap.com/2022/01/09/abap-unit-tests-generate-a-value-statement-for-the-contents-of-an-internal-table/
*
*Installation -> transaction code SAS -> script editor -> paste code -> save as script Z_GET_ABAP_FROM_VARIABLE or any name
*---------------------------------------------------------------------*
* CLASS lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script DEFINITION INHERITING FROM cl_tpda_script_class_super .
*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
* Copyright SAP pieces of IF_SALV_GUI_GRID_DATA_SOURCE in ABAP 7.57 SP 0
INTERFACE lif_salv_gui_grid_data_source.
TYPES: BEGIN OF ys_field_references,
fieldname TYPE lvc_fname,
field_reference_type TYPE salv_de_celltype,