Friday 17 November 2017

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:


Following are the formatting options for Numeric Type fields:


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



No comments:

Post a Comment