### Example Usage of CL_ABAP_CORRESPONDING Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENCL_ABAP_CORRESPONDING_3.html A basic setup example defining source and destination structures for use with the mapping class. ```ABAP FINAL(out) = cl_demo_output=>new( ). DATA: BEGIN OF struct1, a1 TYPE string VALUE 'a1', a2 TYPE string VALUE 'a2', a3 TYPE string VALUE ' ', a4 TYPE string VALUE 'a4', END OF struct1, BEGIN OF struct2, b1 TYPE string VALUE 'b1', b2 TYPE string VALUE 'b2', b3 TYPE string VALUE 'b3', b4 TYPE string VALUE 'b4', END OF struct2. ``` -------------------------------- ### Forward Loop with Key/Value Pairs and Subconditions Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENITAB_WHERE_OPTIMIZATION.html This example shows a forward loop using a key. The starting point is determined by key/value pairs, and the loop continues as long as subconditions for these pairs are fulfilled. ```ABAP TYPES: BEGIN OF line, a TYPE i, b TYPE i, c TYPE i, d TYPE i, END OF line. DATA itab TYPE STANDARD TABLE OF line WITH UNIQUE SORTED KEY key COMPONENTS a b c. LOOP AT itab USING KEY key ASSIGNING FIELD-SYMBOL() WHERE a = 0 AND b >= 0 AND b < 5 AND c > 2. ... ENDLOOP. ``` -------------------------------- ### Dynamic GET PERMISSIONS Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_PERMISSIONS_DYN.html Demonstrates the dynamic form of the GET PERMISSIONS statement for checking access restrictions on data fields. Requires setup of permission table components. ```abap "Root entity components for perm_tab. DATA: lt_perm_key_root TYPE TABLE FOR PERMISSIONS KEY demo_managed_root_3, ls_perm_req_root TYPE STRUCTURE FOR PERMISSIONS REQUEST demo_managed_root_3, ls_perm_res_root TYPE STRUCTURE FOR PERMISSIONS RESULT demo_managed_root_3. lt_perm_key_root = VALUE #( ( %key-key_field = 5 ) ( %key-key_field = 6 ) ). ls_perm_req_root = VALUE #( %field-data_field1_root = if_abap_behv=>mk-on %field-data_field2_root = if_abap_behv=>mk-on ). ls_perm_res_root = VALUE #( ). ``` -------------------------------- ### Set File Pointer and Read Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPSET_DATASET.html This example demonstrates opening a file for output, writing lines, setting the file pointer to the beginning, reading data, and then setting the file pointer to the end of the file. ```abap DATA: file TYPE string VALUE 'test1.dat', pos TYPE i, text TYPE string. OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH SMART LINEFEED MESSAGE FINAL(msg). TRANSFER: 'Line1' TO file, 'Line2' TO file, 'Line3' TO file. SET DATASET file POSITION 0. READ DATASET file INTO text. SET DATASET file POSITION END OF FILE. ``` -------------------------------- ### HIERARCHY_ANCESTORS Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSELECT_HIERARCHY_NODE_NAVIS.html Selects all ancestor nodes of specified start nodes, including the start nodes themselves. It also returns the distance from each ancestor to its start node. ```ABAP SELECT FROM HIERARCHY_ANCESTORS( SOURCE HIERARCHY( SOURCE demo_cds_simple_tree_source CHILD TO PARENT ASSOCIATION _tree START WHERE id = 1 SIBLINGS ORDER BY id ASCENDING ) START WHERE id = @id ) FIELDS id, parent_id, hierarchy_rank, hierarchy_level, hierarchy_tree_size, hierarchy_distance INTO TABLE @FINAL(ancestors). ``` -------------------------------- ### Create Directory and Upload File on Presentation Server Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenfrontend_files.html This example demonstrates how to write to and read from a file on a presentation server using MS Windows. It includes logic to create the directory if it doesn't exist and checks for SAP GUI availability to prevent runtime errors. ```ABAP DATA gui TYPE c LENGTH 1. CALL FUNCTION 'GUI_IS_AVAILABLE' IMPORTING return = gui. IF gui IS INITIAL. RETURN. ENDIF. FINAL(dir) = `C:\temp\my_temp\`. FINAL(name) = `myfile.dat`. IF cl_gui_frontend_services=>directory_exist( dir ) = abap_false. DATA rc TYPE i. cl_gui_frontend_services=>directory_create( EXPORTING directory = dir ). ENDIF. ``` -------------------------------- ### Example: File and Directory Operations Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenfrontend_files.html Demonstrates how to check for directory existence, create a directory if it doesn't exist, and perform file operations (upload/download) using CL_GUI_FRONTEND_SERVICES. This example specifically shows writing to and reading from a file on a Windows presentation server. ```ABAP DATA gui TYPE c LENGTH 1. CALL FUNCTION 'GUI_IS_AVAILABLE' IMPORTING return = gui. IF gui IS INITIAL. RETURN. ENDIF. FINAL(dir) = `C:\temp\my_temp\\`. FINAL(name) = `myfile.dat`. IF cl_gui_frontend_services=>directory_exist( dir ) = abap_false. DATA rc TYPE i. cl_gui_frontend_services=>directory_create( EXPORTING directory = dir IMPORTING rc = rc ). IF rc <> 0. " Handle error: Directory creation failed RETURN. ENDIF. ENDIF. " Example of writing to a file (GUI_DOWNLOAD would be used here) " Example of reading from a file (GUI_UPLOAD would be used here) " Note: The provided snippet is incomplete for full upload/download demonstration. ``` -------------------------------- ### HIERARCHY_DESCENDANTS Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSELECT_HIERARCHY_NODE_NAVIS.html Selects all descendant nodes of specified start nodes, including the start nodes themselves. It also returns the distance from each descendant to its start node. ```ABAP FINAL(id) = 6. SELECT FROM HIERARCHY_DESCENDANTS( SOURCE HIERARCHY( SOURCE demo_cds_simple_tree_source CHILD TO PARENT ASSOCIATION _tree START WHERE id = 1 SIBLINGS ORDER BY id ASCENDING ) START WHERE id = @id ) FIELDS id, parent_id, hierarchy_rank, hierarchy_level, hierarchy_tree_size, hierarchy_distance INTO TABLE @FINAL(descendants). ``` -------------------------------- ### File Upload and Download Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENFRONTEND_FILES.html Demonstrates writing to and reading from a file on a presentation server using MS Windows. It includes directory creation and a check for SAP GUI availability to prevent runtime errors. ```ABAP DATA gui TYPE c LENGTH 1. CALL FUNCTION 'GUI_IS_AVAILABLE' IMPORTING return = gui. IF gui IS INITIAL. RETURN. ENDIF. FINAL(dir) = `C:\temp\my_temp\`. FINAL(name) = `myfile.dat`. IF cl_gui_frontend_services=>directory_exist( dir ) = abap_false. DATA rc TYPE i. cl_gui_frontend_services=>directory_create( EXPORTING directory = dir ). ENDIF. ``` -------------------------------- ### Example: Get and Restore Locale Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_LOCALE.html This example demonstrates how to determine the current text environment language using GET LOCALE and restore it after a change using SET LOCALE. Note that the COUNTRY and MODIFIER additions are obsolete. ```ABAP DATA: lang TYPE tcp0c-langu, dummy TYPE string ##needed. GET LOCALE LANGUAGE lang COUNTRY dummy MODIFIER dummy. SET LOCALE LANGUAGE ... ... SET LOCALE LANGUAGE lang. ``` -------------------------------- ### Recommended: Dynamic Component Assignment with (name) Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPAT_ITAB_OBSOLETE.html This example shows the modern and recommended way to dynamically specify a component for AT NEW using parentheses `(name)`. This syntax is preferred over the older method. ```ABAP name = 'COL1'. LOOP AT itab INTO wa. AT NEW (name). ... ENDAT. ENDLOOP. ``` -------------------------------- ### Example of SET RUN TIME CLOCK RESOLUTION with GET RUN TIME Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPSET_RUN_TIME_CLOCK_RESOLUTION.html This example demonstrates how to use SET RUN TIME CLOCK RESOLUTION LOW before executing GET RUN TIME to measure the duration of a one-second wait. ```ABAP FINAL(out) = cl_demo_output=>new( ). SET RUN TIME CLOCK RESOLUTION LOW. GET RUN TIME FIELD FINAL(t1). wait UP TO 1 SECONDS. GET RUN TIME FIELD FINAL(t2). out->write( t2 - t1 ). out->display( ). ``` -------------------------------- ### Open Text File for Output (Good Example) Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENCODEPAGE_FILE_GUIDL.html This example shows the recommended way to open a text file for output by explicitly specifying the UTF-8 code page and including the byte order mark. This ensures proper handling of international characters and clear file identification. ```ABAP OPEN DATASET dset FOR OUTPUT IN TEXT MODE ENCODING UTF-8 WITH BYTE-ORDER MARK. ``` -------------------------------- ### Include Program for GET LFA1 Event Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENLDB_PROGRAM_EXAMPLE.html Handles the GET event for the LFA1 node in a logical database. It includes commented-out examples for selecting data and a PUT statement to make the data available. ```ABAP *----------------------------------------------------------* * Call event GET LFA1 *----------------------------------------------------------* FORM PUT_LFA1. * SELECT * FROM LFA1 * INTO LFA1 * INTO TABLE ? (choose one!) * WHERE LIFNR = ?. PUT LFA1. * ENDSELECT. ENDFORM. "PUT_LFA1 *----------------------------------------------------------* * Authority Check for node LFA1 *----------------------------------------------------------* * FORM AUTHORITY_CHECK_LFA1. * AUTHORITY-CHECK ... * ENDFORM. ``` -------------------------------- ### Recommended Use of START-OF-SELECTION Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPSTART-OF-SELECTION.html This example demonstrates the recommended way to use START-OF-SELECTION by calling a dedicated method for functionality instead of implementing it directly within the event block. ```ABAP REPORT ... CLASS cls DEFINITION. PUBLIC SECTION. CLASS-METHODS main. ENDCLASS. CLASS cls IMPLEMENTATION. METHOD main. ... ENDMETHOD. ENDCLASS. START-OF-SELECTION. cls=>main( ). ``` -------------------------------- ### Declare Binary Floating Point Number Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSELECT_NUMERIC_TYPE_GUIDL.html This example shows the declaration of a binary floating point number with an assigned start value. Note the actual start value due to binary representation. ```ABAP DATA number TYPE f VALUE '0.815'. ``` -------------------------------- ### ABAP Example: Program-driven List Creation with SET USER-COMMAND Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPSET_USER-COMMAND.html Demonstrates program-driven creation of a basic list and detail lists, including displaying a search dialog and using SET CURSOR to enable the _PICK_ function code. This example shows how to chain SET USER-COMMAND statements to navigate between different list levels and trigger events. ```abap START-OF-SELECTION. SET USER-COMMAND 'MYCOMM'. WRITE 'Basic List'. AT USER-COMMAND. CASE sy-ucomm. WHEN 'MYCOMM'. WRITE 'Details List from USER-COMMAND,'. WRITE: 'SY-LSIND', sy-lsind. SET CURSOR LINE 1. SET USER-COMMAND 'PICK'. ENDCASE. AT LINE-SELECTION. WRITE 'Details List from LINE-SELECTION,'. WRITE: 'SY-LSIND', sy-lsind. ``` -------------------------------- ### Hierarchy Navigator HIERARCHY_ANCESTORS_AGGREGATE Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENHIER_ANCS_AGG_ABEXA.html Demonstrates the usage of the HIERARCHY_ANCESTORS_AGGREGATE function. The example shows how to retrieve paths from a start node to specified hierarchy nodes and highlights the aggregated paths using STRING_AGG. ```ABAP * Public class definition CLASS cl_demo_hrrchy_ancestors_agg DEFINITION INHERITING FROM cl_demo_classrun PUBLIC CREATE PUBLIC. PUBLIC SECTION. METHODS main REDEFINITION. PRIVATE SECTION. METHODS fill_table. ENDCLASS. * Public class implementation CLASS cl_demo_hrrchy_ancestors_agg IMPLEMENTATION. METHOD main. DATA(start_id) = 'A '. DATA(end_id1) = 'F1'. DATA(end_id2) = 'D2'. cl_demo_input=>new( )->add_field( CHANGING field = start_id )->add_field( CHANGING field = end_id1 )->add_field( CHANGING field = end_id2 )->display( NEW cl_demo_hrrchy_ancestors_agg( ) ). ENDMETHOD. METHOD fill_table. ENDMETHOD. ENDCLASS. ``` -------------------------------- ### Get Current Time into a Variable (ABAP) Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_TIME.html This example shows how to use the GET TIME statement with the FIELD addition to store the current time in a variable named 'time'. It then calculates the difference between this time and sy-uzeit. ```ABAP FINAL(out) = cl_demo_output=>new( ). GET TIME. DO 5000000 TIMES. ENDDO. GET TIME FIELD FINAL(time). out->write( time - sy-uzeit ). out->display( ). ``` -------------------------------- ### Dynamic Selection Screen with Select-Options Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSEL_SCREEN_SEL_OPT_ABEXA.html This example demonstrates how to dynamically create a selection screen based on user input for table and column names. It shows how to populate and display select-options, including handling multiple selections. ```ABAP REPORT demo_sel_screen_select_options. CLASS start DEFINITION. PUBLIC SECTION. CLASS-DATA name(80) TYPE c. CLASS-METHODS main. ENDCLASS. SELECTION-SCREEN BEGIN OF SCREEN 100. PARAMETERS: dbtab TYPE c LENGTH 30 DEFAULT 'SFLIGHT', column TYPE c LENGTH 30 DEFAULT 'CARRID'. SELECTION-SCREEN END OF SCREEN 100. SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW. SELECT-OPTIONS selcrit FOR (start=>name). SELECTION-SCREEN END OF SCREEN 500. START-OF-SELECTION. start=>main( ). CLASS start IMPLEMENTATION. ENDCLASS. ``` -------------------------------- ### ABAP GET PERMISSIONS ONLY GLOBAL Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_PERMISSIONS_ONLY_CLAUSE.html Demonstrates the 'ONLY GLOBAL' variant of the GET PERMISSIONS statement to include global authorization, global, and static feature control. The 'FROM keys' addition is not permitted with this variant. ```ABAP DATA: request TYPE STRUCTURE FOR PERMISSIONS REQUEST demo_managed_root_3. request = VALUE #( %create = if_abap_behv=>mk-on %update = if_abap_behv=>mk-on %delete = if_abap_behv=>mk-on %field-key_field = if_abap_behv=>mk-on %field-data_field1_root = if_abap_behv=>mk-on %field-data_field2_root = if_abap_behv=>mk-on %field-data_field3_root = if_abap_behv=>mk-on %field-data_field4_root = if_abap_behv=>mk-on ). GET PERMISSIONS ONLY GLOBAL ENTITY demo_managed_root_3 REQUEST request ``` -------------------------------- ### Program Calls Filling the Selection Screen Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapsubmit_interface.html This example demonstrates calling a program and filling its selection screen with data. It illustrates how parameters and selection criteria can be supplied programmatically. ```ABAP SUBMIT (progname) WITH SELECTION-TABLE seltab WITH p1 = val1 WITH selcrit1 BETWEEN l1 AND h1 WITH selcrit2 LIKE lt_range WITHOUT LIST TRANSFER USER sy-uname. ``` -------------------------------- ### ABAP GET PERMISSIONS ONLY INSTANCE FEATURES Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_PERMISSIONS_ONLY_CLAUSE.html Illustrates the 'ONLY INSTANCE FEATURES' variant of the GET PERMISSIONS statement in an unmanaged RAP BO. This is used to determine if a calculation is permissible, for instance, to prevent division by zero. ```ABAP GET PERMISSIONS ONLY INSTANCE FEATURES ``` -------------------------------- ### Create and Execute Prepared Statement with ADBC Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENADBC_SQL_PREPARED_ABEXA.html This example demonstrates creating a query as a prepared statement and executing it with different parameters. Parameters and results are collected in internal tables to avoid work process switching. ```ABAP CLASS cl_demo_adbc_prepared_stmnt DEFINITION INHERITING FROM cl_demo_classrun PUBLIC CREATE PUBLIC. PUBLIC SECTION. METHODS main REDEFINITION. PRIVATE SECTION. DATA: BEGIN OF result_line, carrid TYPE sflight-carrid, connid TYPE sflight-connid, END OF result_line, result_tab LIKE TABLE OF result_line. ENDCLASS. CLASS cl_demo_adbc_prepared_stmnt IMPLEMENTATION. METHOD main. DATA: sql TYPE REF TO cl_sql_prepared_statement, cols TYPE adbc_column_tab, ``` -------------------------------- ### Terminate GET sbook Event Block with STOP Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPSTOP.html This example demonstrates terminating the GET sbook event block of a logical database after a maximum number of postings have been issued, branching to END-OF-SELECTION. Ensure the program context allows the use of STOP. ```ABAP FINAL(out) = cl_demo_output=>new( ). nODES: sflight, sbook. DATA: bookings TYPE i, max TYPE i VALUE 100. GET sflight. out->next_section( |{ sflight-carrid } | && |{ sflight-connid } | && |{ sflight-fldate }| ). GET sbook. bookings += 1. out->write( |{ sbook-bookid } | && ``` -------------------------------- ### Retrieving Cursor Offset with GET CURSOR OFFSET DISPLAY Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPGET_CURSOR_LIST_FIELD.html Use OFFSET without an addition or with DISPLAY to get the cursor's position within the output area. Counting starts at 0. The target variable must be of type i. ```ABAP GET CURSOR FIELD f OFFSET off. ``` ```ABAP GET CURSOR FIELD f DISPLAY OFFSET off. ``` -------------------------------- ### Enable Input Field and Evaluate Selection Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapformat.html This example demonstrates how to make a list area ready for input and how to evaluate user input when a specific hotspot is selected. Ensure SET BLANK LINES ON is used if input fields might contain only blanks. ```ABAP DATA: input_field TYPE c LENGTH 100, line_num TYPE i. START-OF-SELECTION. WRITE 'Input text:'. SET BLANK LINES ON. FORMAT INPUT. WRITE / input_field. FORMAT INPUT OFF. WRITE / '>>> OK <<<' COLOR 5 HOTSPOT. AT LINE-SELECTION. IF sy-lisel = '>>> OK <<<'. line_num = sy-lilli - 1. READ LINE line_num FIELD VALUE input_field. WRITE: 'The input was:', הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה ``` -------------------------------- ### Example: Export and Import Data Cluster Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPIMPORT_INTERNAL.html Demonstrates exporting a data cluster to a database table and then importing it back. This example uses a subroutine to handle the import process. ```ABAP TABLES demo_indx_table. DATA demo_indx_tab TYPE TABLE OF demo_indx_table. SELECT * FROM sflight INTO TABLE @DATA(sflight_tab). EXPORT sflight_tab TO DATABASE demo_indx_table(fl) ID 'FLIGHTS' USING demo_indx_table_export. ... demo_indx_table-srtf2 = 0. IMPORT sflight_tab FROM DATABASE demo_indx_table(fl) ID 'FLIGHTS' USING demo_indx_table_import. ``` -------------------------------- ### Demonstrate GET RUN TIME FIELD Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENGET_RUN_TIME_ABEXA.html This example demonstrates the usage of the GET RUN TIME FIELD statement to measure the runtime of different code segments. It compares the runtime of an empty segment, reading an entire database table, and reading specific columns from a table. ```ABAP CLASS cl_demo_get_run_time DEFINITION INHERITING FROM cl_demo_classrun PUBLIC CREATE PUBLIC. PUBLIC SECTION. METHODS main REDEFINITION. ENDCLASS. CLASS cl_demo_get_run_time IMPLEMENTATION. METHOD main. DATA: t1 TYPE i, t2 TYPE i, t TYPE p DECIMALS 2. DATA n TYPE i VALUE 5. cl_demo_input=>new( )->request( EXPORTING text = 'Number of measurements' CHANGING field = n ). GET RUN TIME FIELD t1. LOOP n TIMES. " Empty code segment ENDLOOP. GET RUN TIME FIELD t2. t = ( t2 - t1 ) / n * 1000. cl_demo_output=>display( | Offset of runtime measurement: { t } microseconds| ). GET RUN TIME FIELD t1. LOOP n TIMES. SELECT * FROM sbook. ENDLOOP. GET RUN TIME FIELD t2. t = ( t2 - t1 ) / n * 1000. cl_demo_output=>display( | Runtime for reading all columns: { t } microseconds| ). GET RUN TIME FIELD t1. LOOP n TIMES. SELECT carrid, connid FROM sbook. ENDLOOP. GET RUN TIME FIELD t2. t = ( t2 - t1 ) / n * 1000. cl_demo_output=>display( | Runtime for reading specific columns: { t } microseconds| ). ENDMETHOD. ENDCLASS. ``` -------------------------------- ### Switching Program to Unicode Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapinsert_report.html This example demonstrates how to switch a program to Unicode by modifying its source code. It reads the program into an internal table, modifies it, and then overwrites the source code. ```ABAP DATA: itab TYPE TABLE OF string, prog TYPE sy-repid, uc TYPE trdir-uccheck. FIELD-SYMBOLS TYPE string. prog = ... SELECT SINGLE uccheck FROM trdir WHERE name = @prog AND uccheck = ' ' INTO (@uc). IF sy-subrc = 0. READ REPORT prog INTO itab. LOOP AT itab ASSIGNING . * Code to modify the source code lines goes here ENDLOOP. INSERT REPORT prog FROM itab. ENDIF. ``` -------------------------------- ### Hierarchy Generator with Interval Start Condition Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSELECT_HIERARCHY_GEN_ASSOC.html Generates an SQL hierarchy where root nodes are selected based on an interval condition. All descendant nodes of the selected root nodes are included. This example uses the `HIERARCHY` generator with a `START WHERE` clause to filter nodes by an ID range. ```ABAP FINAL(from) = 'A '. FINAL(to) = 'B '. SELECT FROM HIERARCHY( SOURCE demo_cds_parent_child_source CHILD TO PARENT ASSOCIATION _relat START WHERE id BETWEEN @from AND @to SIBLINGS ORDER BY parent MULTIPLE PARENTS ALLOWED CYCLES BREAKUP ) FIELDS id, parent INTO TABLE @FINAL(asql_result). ``` -------------------------------- ### ABAP tt:value Formatting Examples Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENST_FORMAT_OPTION_ABEXA.html Illustrates the use of tt:value with different format options for various ABAP data types, including timestamps, GUIDs, dates, and numeric values. These examples show how to specify formatting for both XML and JSON output, with special considerations for OData. ```ABAP ``` -------------------------------- ### Populating an Internal Table with LINES OF Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENVALUE_CONSTRUCTOR_PARAMS_LSPC.html Illustrates the creation of an internal table with an elementary line type. It shows how to initialize the table with an initial line, a specific value, and then append multiple lines from another internal table using the LINES OF addition. ```ABAP FINAL(out) = cl_demo_output=>new( ). TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY. FINAL(jtab) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ). FINAL(itab) = VALUE t_itab( ( ) ( 1 ) ( 2 ) ( LINES OF jtab ) ). out->write( itab ). out->display( ). ``` -------------------------------- ### Declare Decimal Floating Point Number Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENSELECT_NUMERIC_TYPE_GUIDL.html This example demonstrates the declaration of a decimal floating point number using the decfloat34 type, assigning a precise start value. ```ABAP DATA number TYPE decfloat34 VALUE '0.815' ``` -------------------------------- ### ALV List Output Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENLIST_GUIDL.html This example demonstrates generating ALV lists, which are the recommended replacement for classic lists in application programs. ALV lists offer the same content and functions as classic lists but with modern UI technologies. ```ABAP REPORT demo_alv_reporting. ``` -------------------------------- ### ABAP Example: Index Lines for Square Numbers Archiving Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPPRINT-CONTROL.html This example shows how to create index lines (DAIN and DKEY) for archiving a list of square numbers. It demonstrates setting up DKEY lines and then using PRINT-CONTROL INDEX-LINE to insert them, enabling search functionality in the archived spool list. ```ABAP PARAMETERS number TYPE i. DATA: index TYPE i, square TYPE decfloat16, numb TYPE i, num TYPE c LENGTH 4, dkey TYPE c LENGTH 100, dain TYPE c LENGTH 100. dkey = 'DKEYIndex'. dkey+44 = '0'. dkey+47 = '3'. PRINT-CONTROL INDEX-LINE dkey. CLEAR dkey. DO 100 TIMES. index = sy-index. square = index ** 2. numb = index. num = numb. dain = 'DAIN'. dain+44 = '0'. dain+47 = '3'. dain+50 = num. PRINT-CONTROL INDEX-LINE dain. CLEAR dain. ENDDO. ``` -------------------------------- ### ABAP Auto Daemon Class Implementation Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABENABAP_AUTO_DAEMON_ABEXA.html Implements the methods for the automatically started ABAP daemon class. This includes the setup and teardown methods, and the redefinition of the main method. ```ABAP * Public class implementation CLASS cl_demo_abap_auto_daemon IMPLEMENTATION. METHOD main. הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` -------------------------------- ### Dynamic Structure Component Access Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenstructure_component_selector.html Demonstrates calling the `CL_DEMO_STRUCT_COMP=>GET` method to access structure components dynamically by name. This is useful when the component to access is determined at runtime. ```ABAP SELECT SINGLE FROM scarr FIELDS carrid, carrname, currcode, url WHERE carrid = 'LH' INTO @FINAL(scarr). FINAL(out) = cl_demo_output=>new( ). out->next_section( cl_demo_struct_comp=>get( struct = scarr comp = 'CARRID' ) ). ``` -------------------------------- ### Mesh Path Syntax Example Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenmesh_path.html Illustrates the general syntax for specifying a mesh path, including root node and association specifications. ```ABAP ... {mesh-|-|mesh_ref->}rnode_associ[ ...] _assoc1[ ... ]_assoc2[ ... ] ... ``` -------------------------------- ### Example: Export and Import Source: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABAPEXPORT_DATA_CLUSTER.html Demonstrates exporting an internal table to a database table and then importing it back. ```APIDOC ## Example: Export and Import ### Description This example shows how to export an internal table to a DDIC database table `DEMO_INDX_BLOB` and then import the content from the data cluster to another internal table. ### Method EXPORT, IMPORT ### Endpoint N/A (ABAP statement) ### Parameters N/A ### Request Example ```abap FINAL(out) = cl_demo_output=>new( ). SELECT * FROM scarr INTO TABLE @FINAL(itab). EXPORT scarr = itab TO DATABASE demo_indx_blob(sc) ID 'DEMO'. DATA jtab LIKE itab. IMPORT scarr = jtab FROM DATABASE demo_indx_blob(sc) ID 'DEMO'. out->write( jtab ). out->display( ). ``` ### Response #### Success Response (200) N/A (ABAP statement) #### Response Example ```abap " The 'out' object will display the imported data. ``` ```