ABAP - THE WRITE STATEMENT / FORMATTING DATA.
/** EXPAND VARIABLE IN WRITE STATEMENT **/
DATA number TYPE P VALUE '10'.
WRITE: 'Number is:', number, 'and is printed'
/** SPACES + ALIGNMENT **/
WRITE: /10 'SAP', 20 'ABAP'. /* Adds 10 spaces before 'SAP' (Word 1 starts at space 10)
/* Word 2 is aligned at space 20
WRITE /(10) 'SAP', (20) 'ABAP. /* Adds spaces up to position 10 on word 1, 20 on word2
WRITE /(10) 'SAP' CENTERED. /* Pads the word left/right with spaces, center
WRITE /(10) 'SAP' RIGHT-JUSTIFIED. /* Right justifies the word, add padding (left)
WRITE /(10) 'SAP' LEFT-JUSTIFIED. /* Left justifies the word, add padding (right)
/** SKIP A LINE, X LINES **/
SKIP. /* Skips one line
SKIP 10 /* Skips 10 lines
* The statement ULINE AT 3(10).
* corresponds to WRITE AT 3(10) SY-ULINE.
* Output of a horizontal line along the whole line after the first WRITE output, and two horizontal lines as a part of a frame. */
WRITE 'A text in a frame'.
ULINE.
SKIP.
ULINE AT 10(10).
WRITE: /10 '|', 11(8) 'Text' CENTERED, 19 '|'.
ULINE AT /10(10)
•WRITE <format> <value> <options>
<format>
/p(I)
/ = Line Feed
p = Column Position
I = Output Length
<Value>
Program Field or
Text Literal
<Option>
–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. Note
–NO-GAP – deletes the gaps between consecutively displayed fields
–USING EDIT 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
•There are many other formatting options. Consult the Extended Help text by placing the cursor on the WRITE keyword in the editor and pressing <F1> on the keyboard.
/**COMBINED PRINT STATEMENTS **/
WRITE : / 'Hello',
'World',
'There'.
WRITE: / SY-VLINE, (20) 'SALES-ID' CENTERED,
SY-VLINE, (20) 'PROFIT' CENTERED,
SY-VLINE, (20) 'YEAR' CENTERED.
/** COLUMNIZE WITH USE OF UNDER **/
WRITE: / SY-VLINE, (20) 'SALES-ID' CENTERED, /* Will allign 000x under the three labels
SY-VLINE, (20) 'PROFIT' CENTERED,
SY-VLINE, (20) 'YEAR' CENTERED.
WRITE: /(20) '0001' UNDER 'SALES-ID' CENTERED,
/(20) '0002' UNDER 'PROFIT' CENTERED,
/(20) '0003' UNDER 'YEAR' CENTERED.
/** SPACES + ALIGNMENT **/
WRITE: /10 'SAP', 20 'ABAP'. /* Adds 10 spaces before 'SAP' (Word 1 starts at space 10)
/* Word 2 is aligned at space 20
WRITE /(10) 'SAP', (20) 'ABAP. /* Adds spaces up to position 10 on word 1, 20 on word2
WRITE /(10) 'SAP' CENTERED. /* Pads the word left/right with spaces, center
WRITE /(10) 'SAP' RIGHT-JUSTIFIED. /* Right justifies the word, add padding (left)
WRITE /(10) 'SAP' LEFT-JUSTIFIED. /* Left justifies the word, add padding (right)
/*************************************/
/** SIMPLE **/
WRITE 'HELLO WORLD'. /* Output will have selectable 'Hello World' as a single string
WRITE: 'Hello', 'World'. /* Output will have selectable 'Hello' or 'World'
WRITE: / 'Hello', 'World'. /* Adds a new line before printing
REPORT ZTEE_TAM_PD_TUT1.
****************************************************
****************************************************
****************************************************
* Examples on Write:
* Simple
*
WRITE 'EXAMPLES ON WRITE:'.
ULINE.
*
WRITE / 'HELLO WORLD'.
*
* Split word
WRITE: 'Hello', 'World'.
*
* Split Word - new line
WRITE: / 'Hello', 'World'.
*
* With spacing - Add spaces between the worsd
WRITE: /10 'SAP', 20 'ABAP'.
*
* With space padding to the word
WRITE: /(10) 'SAP', (20) 'ABAP'.
*
* With space padding and alignment
WRITE /(10) 'SAP' CENTERED.
*
* Space padding - Right justified
WRITE /(10) 'SAP' RIGHT-JUSTIFIED.
*
* Space padding - Left justified
WRITE /(10) 'SAP' LEFT-JUSTIFIED.
*
* Careful with padding, it can trim words - assigns space to word before it writes
WRITE: /(10) 'ALTERNATIVELY'.
WRITE: /.
*
* Horizontal lines
WRITE 'A text in a frame'.
ULINE.
SKIP.
ULINE AT 10(10).
WRITE: /10 '|', 11(8) 'Text' CENTERED, 19 '|'.
ULINE AT /10(10).
*
* Skip X lines
SKIP 5.
WRITE: 'AFTER THE LINES'.
*
* VERTICAL SEPARATORS
* Vertical separator is stored in ABAP as an environment variable SY-VLINE
*
*
WRITE: /(10) 'SAP' LEFT-JUSTIFIED, SY-VLINE, (20) 'AFTER SEPARATOR'.
* Adds a vertical line at the end
*
*
DATA number TYPE P VALUE '10'.
WRITE: /(10) 'Number is:', (2) number, (15)'and is printed'.
SKIP 2.
*
* COMBINED PRINT STATEMENT
WRITE : / 'Hello',
'World',
'There'.
WRITE: / SY-VLINE, (20) 'SALES-ID' CENTERED,
SY-VLINE, (20) 'PROFIT' CENTERED,
SY-VLINE, (20) 'YEAR' CENTERED.
*
* COLUMNIZE
WRITE: / SY-VLINE, (20) 'SALES-ID' CENTERED,
SY-VLINE, (20) 'PROFIT' CENTERED,
SY-VLINE, (20) 'YEAR' CENTERED.
WRITE: /(20) '0001' UNDER 'SALES-ID' CENTERED,
(20) '0002' UNDER 'PROFIT' CENTERED,
(20) '0003' UNDER 'YEAR' CENTERED.
1. Simplewrite.abap - Simple write program
2. Writespaces.abap - Write with spaces / padding
3. Writealign.abap - Writh with spaces and aligning
4. Writeverticalsep.abap - Write with vertical line separators
5. Writehorline.abap - Write with horizontal line sseparators
6. Writeskip.abap - Write / Skip one or more lines
7. Writecombined.abap - Combinatory print statement
8. Writecolumnize.abap - Example of columnizing output
9. Writevariablecall.abap - Write with variable expansion
10.Writedocument.abap - Documentation and options for Write
11. Collective.abap - Collective script to display all functions
/** VERTICAL LINE SEPARATORS **/
/* Vertical separator is stored in ABAP as an environment variable SY-VLINE
WRITE /(10) 'SAP' LEFT-JUSTIFIED, SY-VLINE /* Adds a vertical line at the end