Summary -

In this topic, we described about the below sections -

Genrally, the reports are made with clear indentation, alignment and formatting of information. To create a report programmatically, the indentation, alignment and formatting of information should be handled through programming.

ABAP provides various formatting options to create the report with all the above. WRITE statement is a formatting statement to display the data in the format prescribed.

WRITE Statement -

The WRITE statement prepares the content by using predefined formats or formatting using explicit options. The WRITE statement primarily designed for formatting data for output purposes but not for internal processing.

Consecutive WRITE statements writes the output data on the same output line. When the line is full, the output continuously writing to the next line.

Syntax -

WRITE {[AT] [/] [Starting-position][Length]} 
		variable/field 
      	[UNDER variable/field] 
      	[NO-GAP] 
      	[internal_format_options] 
      	[external_format_options] 
      	[list_elements] 
      	[QUICKINFO info].

OptionDescription
ATOutput starting position and length defines after AT.
/(Line Feed)Indicates the output should start at new line.
Starting-position Column Position.
LengthOutput Length.
UNDER fieldOutput directly starts under the field.
NO-GAPSpecifies the blank after field is not valid or rejected.
internal_format_optionsSpecifies the format options that are used internally to format the data before displaying the output.

Below are the list of internal format options.
  • LEFT-JUSTIFIED|CENTERED|RIGHT-JUSTIFIED
  • UNDER [f]
  • NO-GAP
  • USING { {NO EDIT MASK}|{EDIT MASK mask} }
  • NO-ZERO
  • NO-GROUPING
  • NO-SIGN
  • CURRENCY cur
  • DECIMALS dec
  • ROUND scale
  • UNIT unit
  • TIME ZONE tz
  • DD/MM/YY | MM/DD/YY | DD/MM/YYYY | MM/DD/YYYY | DDMMYY | MMDDYY | YYMMDD
We will discuss all the options in the Internal_format_options table below.
External_format_optionsSpecifies the format options that applies externally while displaying the output.
Below are the list of external format options -
[COLOR {[=]{color [ON]}|OFF}|{= col}] 
[INTENSIFIED [{ON|OFF}|{= flag}]] 
[INVERSE     [{ON|OFF}|{= flag}]] 
[HOTSPOT     [{ON|OFF}|{= flag}]] 
[INPUT       [{ON|OFF}|{= flag}]] 
[FRAMES      [{ON|OFF}|{= flag}]] 
[RESET]
List_elementsSpecifies the special list elements. Below are the list elements.
  • AS CHECKBOX
  • AS ICON
  • AS SYMBOL
  • AS LINE
QUICKINFO infoSpecifies the tooltip associated with output.
The info is of 80 characters length.

Internal_format_options -

Specifies the format options that are used internally to format the data before displaying the output. Following table describes all internal format options.

OptionDescriptionApplicable data typesRestricted format options along with
LEFT-JUSTIFIEDSpecifies the output is left justifiedAll
CENTEREDSpecifies the output is centredAll
RIGHT-JUSTIFIEDSpecifies the output is right justifiedAll
UNDER [f1]Specifies the output starts immediately under field f1All
NO-GAPSpecifies the blank after the field f1 is rejected or restricted
USING NO EDIT MASKSwitches off/deactivates the format template specified in ABAP dictionaryC, String
USING EDIT MASK maskOverrides the format template with mask specifiedC, String
NO-ZEROIf the field/variable contains zeroes, those are replaced with spacesC, N, StringENVIRONMENT TIME FORMAT, TIME ZONE
NO-GROUPINGSuppresses the thousand separatorsI,PENVIRONMENT TIME FORMAT, TIME ZONE
NO-SIGN Suppresses the signI,P,FENVIRONMENT TIME FORMAT, TIME ZONE
CURRENCY [c] Determines the currency-dependent decimal places according to the currency [c] value
currency [c] value is stored in the TCURX database table
I,P,FENVIRONMENT TIME FORMAT, TIME ZONE
DECIMALS [d]Specifies the number of decimals [d] displayed after the decimal pointI,P,FENVIRONMENT TIME FORMAT, TIME ZONE, UNIT
ROUND [r]Multiplied by 10**(-r) and rounded to the integer valuePENVIRONMENT TIME FORMAT, TIME ZONE, UNIT
UNIT [u]Number of decimal places fixed according to [u]. Database table T006 to determine the number of decimal places. PDECIMALS, ROUND, STYLE, ENVIRONMENT TIME FORMAT, and TIME ZONE.
TIME ZONE [tz]Used to display the timestamp in the local time zone [tz] configured in the user preferences TIMESTAMP, TIMESTAMPLCURRENCY, DECIMALS, ENVIRONMENT TIME FORMAT, EXPONENT, NO-GROUPING, NO-SIGN, NO-ZERO, ROUND, STYLE, or UNIT
DD/MM/YY
MM/DD/YY
DD/MM/YYYY
MM/DD/YYYY
DDMMYY
MMDDYY
YYMMDD
Used to specify the format of date displayDATE

Example -

Below example shows WRITE operations in ABAP application program.


Code -

*&---------------------------------------------------------------------*
*& Report  Z_WRITE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*

REPORT  Z_WRITE.

* Declaring required variables
DATA: W_DATE1 TYPE D,
      W_TIME1 TYPE T,
      W_TEXT1(10) TYPE C VALUE 'SAP ABAP',
      W_TEXT2(10) TYPE C VALUE 'Tutorial'.

* Assigning system date to W_DATE1
W_DATE1 = SY-DATUM.
WRITE: / 'Current Date: ', W_DATE1 DD/MM/YYYY.

* Assigning system time to W_TIME1
W_TIME1 = SY-UZEIT.
WRITE /(60) W_TIME1 USING EDIT MASK 'Current time: __:__:__'.

*Displaying using UNDER from 10th line
WRITE: /10 W_TEXT1,/ W_TEXT2 UNDER W_TEXT1.


Output -

Write statement example output

Explaining Example -

In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.

W_DATE1 = SY-DATUM, assigns system date SY-DATUM to W_DATE1. W_TIME1 = SY-UZEIT, assigns system time SY-UZEIT to W_TIME1.

WRITE: /10 W_TEXT1,/ W_TEXT2 UNDER W_TEXT1, start displaying the W_TEXT1 value from 11th column and also displays the W_TEXT2 under W_TEXT1 from where exactly W_TEXT1 started.