Formatting Data

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].

Option Description
AT Output starting position and length defines after AT.
/(Line Feed) Indicates the output should start at new line.
Starting-position Column Position.
Length Output Length.
UNDER field Output directly starts under the field.
NO-GAP Specifies the blank after field is not valid or rejected.
internal_format_options Specifies 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_options Specifies 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_elements Specifies the special list elements.
Below are the list elements.

  • AS CHECKBOX
  • AS ICON
  • AS SYMBOL
  • AS LINE
QUICKINFO info Specifies 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.

Option Description Applicable data types Restricted format options along with
LEFT-JUSTIFIED Specifies the output is left justified All
CENTERED Specifies the output is centred All
RIGHT-JUSTIFIED Specifies the output is right justified All
UNDER [f1] Specifies the output starts immediately under field f1 All
NO-GAP Specifies the blank after the field f1 is rejected or restricted
USING NO EDIT MASK Switches off/deactivates the format template specified in ABAP dictionary C, String
USING EDIT MASK mask Overrides the format template with mask specified C, String
NO-ZERO If the field/variable contains zeroes, those are replaced with spaces C, N, String ENVIRONMENT TIME FORMAT,
TIME ZONE
NO-GROUPING Suppresses the thousand separators I,P ENVIRONMENT TIME FORMAT,
TIME ZONE
NO-SIGN Suppresses the sign I,P,F ENVIRONMENT 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,F ENVIRONMENT TIME FORMAT,
TIME ZONE
DECIMALS [d] Specifies the number of decimals [d] displayed after the decimal point I,P,F ENVIRONMENT TIME FORMAT,
TIME ZONE,
UNIT
ROUND [r] Multiplied by 10**(-r) and rounded to the integer value P ENVIRONMENT 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.
P DECIMALS, 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,
TIMESTAMPL
CURRENCY, 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 display DATE

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.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *