English 中文(简体)
SAP ABAP Tutorial

SAP ABAP Useful Resources

Selected Reading

SAP ABAP - Formatting Data
  • 时间:2024-11-05

SAP ABAP - Formatting Data


Previous Page Next Page  

ABAP offers various types of formatting options to format the output of programs. For example, you can create a pst 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 pne. 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 pne begins with column 4 and the column length is 6, whereas the WRITE 20 statement shows the current pne with column 20. The parameter <f> represents a data variable or numbered text.

The following table describes various clauses used for formatting −

S.No. Clause & Description
1

LEFT-JUSTIFIED

Specifies that the output is left-justified.

2

CENTERED

Denotes that the output is centered.

3

RIGHT-JUSTIFIED

Specifies that the output is right-justified.

4

UNDER <g>

The output starts directly under the field <g>.

5

NO-GAP

Specifies that the blank after field <f> is rejected.

6

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.

7

NO-ZERO

If a field contains only zeroes, then they are replaced by blanks.

Following are the formatting options for Numeric Type fields −

S.No. Clause & Description
1

NO-SIGN

Specifies that no leading sign is displayed on the screen.

2

EXPONENT <e>

Specifies that in type F (the floating point fields), the exponent is defined in <e>.

3

ROUND <r>

The type P fields (packed numeric data types) are first multipped by 10**(-r) and then rounded off to an integer value.

4

CURRENCY <c>

Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX database table.

5

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.

6

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 −

Formatting Option Example
DD/MM/YY 13/01/15
MM/DD/YY 01/13/15
DD/MM/YYYY 13/01/2015
MM/DD/YYYY 01/13/2015
DDMMYY 130115
MMDDYY 011315
YYMMDD 150113

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
Advertisements