You are on page 1of 21

B1 - 1

Week 2 :
Simple Output Statements
B1 - 2

The ABAP WRITE Statement


WRITE ‘********************’.
SKIP 2.
WRITE: ‘The date today is:’, SY-DATUM,
‘The current time is:’, SY-UZEIT.
SKIP.
Notice that there is an
WRITE ‘********************’. automatic space between
<program title> the fields written to the list. 1
--------------------------------------------------------------------------------
********************

The date today is: 12/30/1996 The current time is: 12:32:06

********************
B1 - 3

Notes
 The WRITE statement outputs the contents of a field or constant in a
format consistent with the data type.
 Successive WRITE statements output data on the same output line.
When the line is full, output continues on the next line.
 The SKIP <n> statement creates <n> blank lines.
 Normally, ABAP produces two standard header lines for each page.
The date and page number are displayed on the first header line
along with the program title. The second header line is an underline.
The date does not display until the report is printed.
 Many system fields are available in an ABAP program. These system
fields are defined in the ABAP Dictionary structure SYST. To
reference system fields in a program, use SY-<field name>. For
example, SY-DATUM indicates the current date and SY-UZEIT
indicates the current time.
- You can use many methods to view the system ABAP Dictionary
B1 - 4

ABAP Format Specifications


WRITE 10 ‘***** City of Philadelphia *****’.
SKIP 2.
WRITE: 10 ‘Ticket Date’, SY-DATUM.
WRITE: /10 ‘Ticket Time’, SY-UZEIT.
ULINE /10(60). …or use NEW-LINE
SKIP 2.
WRITE 10 ‘***** Department of Public Safety *****’.
***** City of Philadelphia *****

Ticket Date 01/01/1997


Ticket Time 18:01:00
-----------------------------------------------------

***** Department of Public Safety *****


B1 - 5

Notes
 ABAP provides many methods for formatting data.
 You can specify when to start a new line of output, start columns,
and/or output length with the following statement:
 WRITE /<pos(len)> . . .
- The forward slash (/) in the WRITE statement will start the output
on a new line.
- NEW-LINE new line, corresponds to "/" in the WRITE statement.

 The ULINE statement creates an underline.


- You can specify the exact location for an underline by referencing a
line feed, position, and/or length with the following statement:
- ULINE /<pos(len)>
B1 - 6

ABAP Format Options


WRITE 10 ‘***** City of Philadelphia *****’.
SKIP 2.
WRITE: 10 ‘Ticket Date’, 25 SY-DATUM,
/10 ‘Ticket Time’, SY-UZEIT UNDER SY-DATUM.
ULINE /10(60).
SKIP 2.
WRITE 10 ‘***** Department of Public Safety *****’.
***** City of Philadelphia *****

Ticket Date 01/01/1997


Ticket Time 18:01:00
------------------------------------------------------------

***** Department of Public Safety *****


B1 - 7

Notes
 The UNDER addition to the WRITE statement allows you to specify a
field to be printed in the same start column (left justified) directly
beneath a field which has already been output.

 You must still code an explicit line feed (with a forward slash) to move
to the next line. The UNDER addition does not act as a line feed.

 Note :
 The values of sy-datum and sy-uzeit are set at the beginning of
program execution and do not change until the program ends. If you
need access to the most current date and time during execution of a
long-running pro-gram, use the statement get time. It updates the
values of sy-datum and sy-uzeit to reflect the current date and time.
B1 - 8

WRITE Statement Extended Syntax

WRITE <format> <value> <options> .


<format>
/p(I)
/ = Line Feed <value>
p = Column Position
I = Output Length
Program Field or <options>
Text Literal

Format Options
B1 - 9

Notes
 The sequence for the format specification of the WRITE statement
must be followed precisely if more than one specification is used.
 Formatting options include:
- LEFT-JUSTIFIED - Output will start at left margin

- RIGHT-JUSTIFIED - Output will start an appropriate distance from


the right margin
- CENTERED - Output will be centered on the line.

- NO-GAP - deletes the gaps between consecutively displayed fields

- USING EDIT MASK <mask> - specifies a format template

- USING NO EDIT MASK - switches off any format template


specified in the ABAP Dictionary
- NO-ZERO - replaces leading zeros with blanks; if the contents of a
field are equal to zero the output consists entirely of blanks
B1 - 10

Notes
 DD/MM/YY Overrides the date formatting rule defined at the User
profile level.
 CURRENCY <key> Formats currency fields based on rules defined
in table TCURX.
 UNIT <key> determines the number of decimal places for quantities
in the list output. The specified key is used to read the number of
decimal places in table T006.
 UNDER <g> The output begins at the column in which field <g> was
output.
B1 - 11

NEW-PAGE Statement
WRITE ‘***** City of Philadelphia *****’.
SKIP.
WRITE: / ‘Ticket Date’, 15 SY-DATUM.
WRITE: / ‘Ticket Time’, 15 SY-UZEIT.
SKIP.
WRITE ‘***** Department of Public Safety *****’.
NEW-PAGE.
WRITE: ‘Comments:’. <program title> 1
--------------------------------------------------------------------------------------
***** City of Philadelphia *****
Ticket Date 01/01/1997
Ticket Time 18:01:00

***** Department of Public Safety *****

<program title> 2
---------------------------------------------------------------------------------------
Comments:
B1 - 12

Notes
 The NEW-PAGE statement starts a new page.
 This statement will not create an empty page.

 NEW-LINE Creates a line break and is the equivalent of "/" in a


WRITE statement.

 SKIP <n> blank lines are output.


B1 - 13

Exercises

 << Exercise 10.15 >>


 << Exercise 14.1 >> •After coding, we will save
and generate. During
 << Exercise 14.2 >> generation, the system
 << Exercise 14.3 >> creates a Run Time object.
 << Exercise 14.4 >> When we execute, the
system executes this Run
 << Exercise 14.5 >> Time Object.
 << Exercise 14.6 >>

 << Exercise 14.14 >>


B1 - 14

Commonly Used System Variables


Name Description

sy-datum Current date

sy-uzeit Current time

sy-uname Current user id

sy-subrc Last return code

sy-mandt Logon client

sy-pagno Current output page number

sy-colno / sy- Current output column / row number


srows
B1 - 15

Notes
 The values of sy-datum and sy-uzeit are set at the beginning of
program execution and do not change until the program ends. If you
need access to the most current date and time during execution of a
long-running pro-gram, use the statement get time. It updates the
values of sy-datum and sy-uzeit to reflect the current date and time.
B1 - 16

Commonly Used System Variables


Name Description

sy-linno Current output list line number


sy-vline Vertical line
sy-uline Horizontal line
sy-repid Current report name
sy-cprog Main program name
sy-tcode Current transaction code
sy-dbcnt Within a select, contains the current iteration counter.
After the endselect, contains number of rows that match
the where clause.

 << Exercise 9.1 >>


B1 - 17

System Fields in List Creation


B1 - 18

Notes
 During generation of a list, the ABAP runtime system fills the following
system fields:

 SY-LINCT Number of lines from REPORT statement (LINE-


COUNT)
 SY-LINSZ Line width from REPORT statement (LINE-SIZE)
 SY-SROWS Number of lines in the display window
 SY-SCOLS Number of columns in the display window
 SY-PAGNO Page number of the current page
 SY-LINNO Line number of the current line of the current page
(SY-PAGNO)
 SY-COLNO Column number of the current column

 During generation of the list, the system fills the last three system
fields continuously.
B1 - 19

Setting the List Format


B1 - 20

Notes
 The default report line width is 83 columns. To override these defaults,
use the additions LINE-SIZE <columns> and LINE-COUNT
<lines_per_page> on the REPORT statement. Note that the values for
lines per page and column width must be numbers and not data object
names.

 You can override the default values for each list buffer by using the NEW-
PAGE LINE-SIZE <columns> and/or LINE-COUNT <lines-per-page>. To
return to the default values set <lines> and/or <columns> to zero.

 The use of LINE-COUNT <lines_per_page>(<footer_lines>) indicates that


the page has a fixed number of lines, part of which is reserved for use at
the END-OF-PAGE event.

 The number of lines per page includes headings, detail, and footer lines.
If the value of <lines_per_page> is less than the actual lines on the page,
the report will terminate.
Thank you

You might also like