SAP ABAP - Formatting Data

ABAP offers various types of formatting options to format the output of programs. For example, you can create a list that includes various items in different colors or formatting styles.
The WRITE statement is a formatting statement used to display data on a screen. There are different formatting options for the WRITE statement. The syntax of the WRITE statement is −
WRITE <format> <f> <options>.

In this syntax, <format> represents the output format specification, which can be a forward slash (/) that indicates the display of the output starting from a new line. In addition to the forward slash, the format specification includes a column number and column length. For example, the WRITE/04 (6) statement shows that a new line begins with column 4 and the column length is 6, whereas the WRITE 20 statement shows the current line with column 20. The parameter <f> represents a data variable or numbered text.
The following table describes various clauses used for formatting −
LEFT-JUSTIFIED
Specifies that the output is left-justified.
CENTERED
Denotes that the output is centered.
RIGHT-JUSTIFIED
Specifies that the output is right-justified.
UNDER <g>
The output starts directly under the field <g>.
NO-GAP
Specifies that the blank after field <f> is rejected.
USING EDIT MASK <m>
Denotes the specification of the format template <m>. Using No EDIT Mask: This specifies that the format template specified in the ABAP Dictionary is deactivated.
NO-ZERO
If a field contains only zeroes, then they are replaced by blanks.
Following are the formatting options for Numeric Type fields −
NO-SIGN
Specifies that no leading sign is displayed on the screen.
EXPONENT <e>
Specifies that in type F (the floating point fields), the exponent is defined in <e>.
ROUND <r>
The type P fields (packed numeric data types) are first multiplied by 10**(-r) and then rounded off to an integer value.
CURRENCY <c>
Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX database table.
UNIT <u>
Specifies that the number of decimal places is fixed according to the <u> unit as specified in the T006 database table for type P.
DECIMALS <d>
Specifies that the number of digits <d> must be displayed after the decimal point.
For instance, the following table shows different formatting options for the date fields −
Here, DD stands for the date in two figures, MM stands for the month in two figures, YY stands for the year in two figures, and YYYY stands for the year in four figures.
Let’s take a look at an example of ABAP code that implements some of the above formatting options −
REPORT ZTest123_01.
 
DATA: n(9) TYPE C VALUE 'Tutorials', 
m(5) TYPE C VALUE 'Point'. 

WRITE: n, m. 
WRITE: / n, 
/ m UNDER n. 

WRITE: / n NO-GAP, m. 
DATA time TYPE T VALUE '112538'. 

WRITE: / time, 
/(8) time Using EDIT MASK '__:__:__'.
The above code produces the following output −
Tutorials Point 
Tutorials  
Point 
TutorialsPoint 
112538 
11:25:38


    25 Lectures 
     6 hours 

 Sanjo Thomas

    26 Lectures 
     2 hours 

 Neha Gupta

    30 Lectures 
     2.5 hours 

 Sumit Agarwal

    30 Lectures 
     4 hours 

 Sumit Agarwal

    14 Lectures 
     1.5 hours 

 Neha Malik

    13 Lectures 
     1.5 hours 

 Neha Malik
 Print
 Add Notes
 Bookmark this page