Help Library Program

ZTS_LIB_BASIC_01_WRITE

*&---------------------------------------------------------------------*
*& Report ZTS_LIB_BASIC_01_WRITE
*&
*&---------------------------------------------------------------------*
*& Description:
*& Demonstration of WRITE statement
*&
*& Technical description:
*& - Hello World basic output using non-translatable and translatable
*& technique
*& - Changing background color using FORMAT COLOR statement
*& - Using additional frequently used WRITE options
*& - Displaying system variables
*& - Displaying icons
*&
*& More Information:
*& - http://help.sap.com/saphelp_470/helpdata/en/9f/db9e2335c111d1829f0000e829fbfe/content.htm
*&
*&---------------------------------------------------------------------*
*& Change log:
*& Date Author Action
*&
*&
*&---------------------------------------------------------------------*

REPORT zts_lib_basic_01_write.

*-----------------------------------*
* DECLARATIONS
DATA:
gv_hello_world_string TYPE string VALUE 'Hello World - String Variable',
gv_hello_world_char TYPE c LENGTH 50 VALUE 'Hello World - Character Variable',
gv_under_string TYPE string VALUE 'Hello World'.

*-----------------------------------*
* MAIN LOGIC

*------------------------*
* Hello World

" Non-translatable way
" Output "Hello World" using hardcoded text
WRITE 'hello world - Hardcoded'.

" Output "Hello World" using hardcoded text in new line
WRITE / 'Hello world - Hardcoded Text in New Line'.

" Output "Hello World" using chained hardcoded text
WRITE :/ 'Hello', 'world', '- Chained Hardcoded Text in New Line'.

" Output "Hello World" using string variable with default value
WRITE :/ gv_hello_world_string.

" Output "Hello World" using character variable with defined text
WRITE :/ gv_hello_world_char.

" Translatable way
" Output "Hello World" using Text Element. In case that there is no text
" element defined in the system, does not display anything
WRITE: / TEXT-001. "Hello World - Text Element Example 1

" Output "Hello World" using Text Element. In case that there is no text
" element defined in the system, SAP uses at least hardcoded string
WRITE: / 'Hello World - Text Element Example 2'(002).

" See what happens when Text element is not defined in both cases

SKIP. "Skip one line (New Line)
ULINE. "create horizontal line

 

*------------------------*
* Background color

format color = col_heading.
WRITE: / 'Background Colour Formatting'. skip.
FORMAT COLOR = col_background.

" { 0 | COL_BACKGROUND } 0 GUI-specific
" Changing BG color can be written both ways
FORMAT COLOR = col_background.
FORMAT COLOR = 0.
write: / '{ 0 | COL_BACKGROUND } 0 GUI-specific'.

" { 1 | COL_HEADING } 1 Gray-blue
FORMAT COLOR = col_background.
FORMAT COLOR = 1.
write: / '{ 1 | COL_HEADING } 1 Gray-blue'.

" { 2 | COL_NORMAL } 2 Light gray
FORMAT COLOR = col_background.
FORMAT COLOR = 2.
write: / '{ 2 | COL_NORMAL } 2 Light gray'.

" { 3 | COL_TOTAL } 3 Yellow
FORMAT COLOR = col_background.
FORMAT COLOR = 3.
write: / '{ 3 | COL_TOTAL } 3 Yellow'.

" { 4 | COL_KEY } 4 Blue-green
FORMAT COLOR = col_background.
FORMAT COLOR = 4.
write: / '{ 4 | COL_KEY } 4 Blue-green'.

" { 5 | COL_POSITIVE } 5 Green
FORMAT COLOR = col_background.
FORMAT COLOR = 5.
write: / '{ 5 | COL_POSITIVE } 5 Green'.

" { 6 | COL_NEGATIVE } 6 Red
FORMAT COLOR = col_background.
FORMAT COLOR = 6.
write: / '{ 6 | COL_NEGATIVE } 6 Red'.

" { 7 | COL_GROUP } 7 Violet
FORMAT COLOR = col_background.
FORMAT COLOR = 7.
write: / '{ 7 | COL_GROUP } 7 Violet'.

SKIP. "Skip one line (New Line)
ULINE. "create horizontal line
FORMAT COLOR = 0.

*------------------------*
* Additional WRITE options
format color = col_heading.
WRITE: / 'Additional WRITE options'. skip.
FORMAT COLOR = col_background.

WRITE: / 'WRITE {[AT] [/][pos][(len|*|**)]} dobj [UNDER other_dobj] [NO-GAP]'.

" Display string starting from position 20

write:/, 20 gv_under_string.
*write:/, 20 'Hello World'.

" Display string starting from position of 'Hello World' string
write: / 'Hello World using UNDER statement to align text under previous text' UNDER gv_under_string.

" Display 16 characters long string starting from position 20 -> Output: "WRITE /20(16)"He"
WRITE: /(16) 'This is a very veery very long string' under gv_under_string.

" Display part of string variable; Starting from position 14, displaying 10 characters
write: / gv_hello_world_string+14(10) under gv_under_string.

" Display part of character variable; Starting from position 14, displaying 10 characters
write: / gv_hello_world_char+14(10) under gv_under_string.

SKIP. "Skip one line (New Line)
ULINE. "create horizontal line
*------------------------*
* Icons

format color = col_heading.
WRITE: / 'Icons'. skip.
FORMAT COLOR = col_background.

" Lets display some icons
write: / icon_green_light, icon_yellow_light, icon_red_light.

" Icons can be used in text as well
write: / icon_green_light, 'Everything went well'.

WRITE: / 'All icons can be displayed in "SHOWICON" report'.

SKIP. "Skip one line (New Line)
ULINE. "create horizontal line

*------------------------*
* System variables
format color = col_heading.
WRITE: / 'System variables'. skip.
FORMAT COLOR = col_background.

write: / 'System Language: ', sy-langu. "System language
write: / 'Username: ', sy-uname. "Username
write: / 'Date: ', sy-datum. "Date
write: / 'Time: ', sy-uzeit. "Time
write: / 'Program Name: ', sy-cprog. "Program Name
write: / 'System Name: ', sy-sysid. "System Name
write: / 'Client: ', sy-mandt. "Client

" Formatting is done using "UNDER" statement which aligns printed word under defined text string

" For more information use: https://help.sap.com/saphelp_46c/helpdata/en/7b/fb96c8882811d295a90000e8353423/content.htm

SKIP.
ULINE.

WRITE: / 'Use F3 keyboard shortcut to get back.'.