SAP READ REPORT ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for READ_REPORT

READ REPORT

Short Reference
• READ REPORT ABAP Statement
• INTO READ REPORT


ABAP Syntax READ REPORT prog INTO itab [MAXIMUM WIDTH INTO
wid].

ABAP Addition
... MAXIMUM WIDTH INTO wid

What does it do? This statement reads the source code of the program specified in prog from the repository and copies its lines into the internal table itab. The previous content of itab is deleted. If the program cannot be loaded, the content of itab remains unchanged.

prog expects a flat character-like data object, which contains the name of the program to be read; the name is not case-sensitive. The internal table itab must be a standard table without secondary table keys with a character-like row type. When the row length of the internal table is fixed, it must be long enough for the longest program line. Program lines that are too long raise a catchable exception. In the case of the row type string, the length of each row is dictated by the length of the imported program line. An empty program line produces an empty string.

System Fields sy-subrcMeaning 0The program was imported. 4The specified program was not found in the repository. 8The specified program is a system program protected against read access.

Latest notes:A precise working knowledge of the programs' structures and names is vital if the statement READ REPORT is used for programs organized in a master program ABAP Code Snippet were created in ABAP Workbench. The names of the master programs for class pools and function groups do not match the names of the global class or function group (see statements CLASS-POOL and FUNCTION-POOL).
• MAXIMUM WIDTH INTO READ REPORT

ABAP Addition

What does it do? If the addition MAXIMUM WIDTH is used, the number of characters of the longest imported source code line is assigned to the variable wid (expects the data type i).



Example ABAP Coding
After a program is imported into an internal table
source, a dedicated line is replaced by different source code from another internal table insertion. After a syntax check, a subroutine pool is generated from the modified program. The required security checks are indicated by comments. DATA:
template TYPE c LENGTH 30,
generated TYPE c LENGTH 30,
source TYPE TABLE OF string,
insertion TYPE TABLE OF string,
idx TYPE i,
mess TYPE string,
lin TYPE i,
wrd TYPE string.

template = '...'.

'Authority checks
...

READ REPORT template INTO source.

IF sy-subrc <(><<)>> 0.
RETURN.
ENDIF.

'Fill insertion
...

FIND '* insertion' IN TABLE source MATCH LINE idx.
DELETE source • idx.
INSERT LINES OF insertion INTO source • idx.

SYNTAX-CHECK FOR source MESSAGE mess LINE lin WORD wrd
PROGRAM template.
...

'Security checks
...

GENERATE SUBROUTINE POOL source NAME generated.

'Execution
...



Example ABAP Coding
See also Program
Generation.



Runtime Exceptions

Catchable Exceptions
CX_SY_READ_SRC_LINE_TOO_LONG
Reason for error:
At least one line of the source code is longer than the rows of the internal table itab.
Runtime error:
READ_REPORT_LINE_TOO_LONG

Return to menu