Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

about statements

Former Member
0 Kudos
65

what is the diff b/w stmts WRITE 😕 and WRITE /: ?

3 REPLIES 3

Former Member
0 Kudos
35

Hi,

Check the following code

WRITE : / 'Hello',

'Good morning'.

<b>Output:</b>

Hello Good morning

WRITE /: 'Hello',

'Good morning'.

<b>Output:</b>

Hello

Good morning

The difference is in the result.

<b>Reward if helpful.</b>

Former Member
0 Kudos
35

HI,

here

if you write

write:/ 'sflight-carrid','sflight-connid'.

it will print output in new line.

sflight-carrid sflight-connid

if you write

write /: 'sflight-carrid','sflight-connid'.

it will take : as delimeter and print output in new line depending on how many numbr of word you have.

then i will print as

sflight-carrid

sflight-connid

WRITE - Output to a list

Basic form

WRITE f.

Extras:

1. ... AT f (position and length specification, before the field)

2. ... option (formatting option)

3. ... fmt (output format by field)

4. ... AS CHECKBOX (output as checkbox)

5. ... AS SYMBOL (output as symbol)

6. ... AS ICON (output as icon)

7. ... AS LINE (output as line)

8. ...QUICKINFO g(output with quick info)

Effect

Outputs the field f in the correct format for its type to the current list. The field f can be:

a field declared by DATA,

a component of a structure declared by TABLES,

a field symbol ( FIELD-SYMBOLS),

a text literal which is not language-specific

a language-specific text literal (text symbol).

Examples

TABLES SPFLI.

DATA N TYPE I VALUE 123.

...

WRITE N.

WRITE SPFLI-FLTIME.

FIELD-SYMBOLS <CF> TYPE ANY.

ASSIGN 'NEW YORK' TO <CF>.

WRITE <CF>.

WRITE: '---->', SPFLI-DISTANCE.

WRITE: TEXT-001, SPFLI-ARRTIME.

or

WRITE: 'Time:'(001), SPFLI-ARRTIME.

Text symbols can be addressed in two different ways (TEXT-001 or 'Time:'(001)).

Notes

If no explicit position is specified for a field on a new line, it is output on the left (in column 1). Otherwise, output is one column removed from the previously output field. If a field does not fit on one line, a new line is started.

You can perform explicit positioning with a position and length specification (see addition 1) or with ABAP/4 statements (e.g. POSITION). In this case, the field is always output at the defined position, even if the line is not quite long enough for it to fit completely.

If a field is too long to fit completely on the line, the excess characters are truncated.

When you explicitly position fields on a list, you should almost always usie the ... LINE-SIZE addition in the REPORT or NEW-PAGE statement, otherwise the width of the list will depend on the current width of the display window, the font used, and other such factors that can lead to the list display being truncated.

Each field occupies a number of characters in the list. If this number is not explicitly defined (see addition 1), the system uses a type-specific standard length or the output length specified in the ABAP Dictionary.

Type-specific output: (len = field length)

Type Standard output length Output

C , en left-justified

D , , eft-justified

F , 2 right-justified

I , 1 right-justified

N , en left-justified

P , len or 2len+1 right-justified

T , , eft-justified

X , *len left-justified

Numeric fields (types P, I and F) are always output right-justified, but all other types are left-justified; if required, blanks are used for padding. With numeric fields, leading zeros are replaced by blanks. If there is enough space, types P and I have thousands separators. To accommodate the decimal point, the output length of type P fields is 1 byte longer.

System fields that are useful when generating lists are documented in System Fields for Lists.

Please consult Data Area and Modularization Unit Organization documentation as well.

Addition 1

WRITE AT f (position and length specification before the field)

Effect

You can use the position and length specification f to define the precise output position and length of a field. The specification consists of:

Wrong dynamic position specification.

/ New line

p Output position (1-3 character number or variable)

(l) Output length (1-3 character number or variable)

Combinations are possible.

Examples

DATA: WORD(16), VALUE '0123456789ABCDEF',

COL TYPE I VALUE 5,

LEN TYPE I VALUE 10.

WRITE AT / WORD. "new line

WRITE AT 5 WORD. "column 5

WRITE AT (10) WORD. "output length 10

WRITE AT /5(10) WORD. "new line, column 5, length 10

WRITE AT COL WORD. "column = contents of COL

WRITE AT (LEN) WORD. "output length = contents of LEN

WRITE AT /COL(LEN) WORD. "new line, column = contents of COL

"output length = contents of LEN

Notes

The position and length specification must appear before the field.

If the position and length specification contains only constants, you the introductory AT is unnecessary. (In the first four of the above examples, you can therefore omit AT.)

Always write the position and length specification without gaps and in the specified order.

Leave at least one space between the position and length specification and the field name.

For dynamic positioning, see also POSITION.

No output results from positioning to the right of the far right edge of the page.

With explicit column specifications, the field is output from this column, even if it no longer completely fits on the line or overwrites another field.

If the output length is too short, numeric fields (types P, I and F are prefixed with an asterisk ('*'), while all other types are truncated on the right.

If you want the abbreviated output of a variable, you should always use WRITE (10) T100-TEXT rather than WRITE T100-TEXT(10) (sub-field access).

On the one hand, the first form is always allowed and the second form can be forbidden for certain data types (e.g. TYPE P). On the other hand, only the first form guarantees the identity of the variables for GET CURSOR ... FIELD and F1 help.

Addition 2

... option (formatting option)

Effect

You can modify the output of the field f by using one of the special formatting options.

Addition 3

... fmt (output format by field)

Effect

Outputs the field with the specified output formats (color, intensity, ready for input, ...).

You can use the same output options as for FORMAT. If no specifications are made, the field is output with the standard formats or with the format set by a preceding FORMAT statement.

Example

DATA F.

FORMAT INTENSIFIED OFF INPUT.

WRITE F INPUT OFF INVERSE COLOR 3.

Note

The format specifications with WRITE apply only for output of the field f. They modify the currently valid format for this field. This means that, in the above example, the non-highlighted output remains for the field F. When f has been output, the system reverts to the old format.

Addition 4

... AS CHECKBOX (output as checkbox)

WRITE - Output as checkbox

Effect

Outputs the field f as a checkbox. The contents of the first character of f is interpreted as the "status":

' ' = not selected

'X' = selected

The user can change this as required.

Note

To prevent the user changing the contents of the checkbox, you can use the addition ... INPUT OFF. The checkbox is then nothing more than a status display and can only be changed by programming.

In technical terms, a checkbox behaves exactly like an input field with a length of 1 ( FORMAT INPUT).

Examples

DATA: MARKFIELD(1) TYPE C VALUE 'X'.

...

WRITE MARKFIELD AS CHECKBOX. "checkbox selected

MARKFIELD = SPACE.

WRITE MARKFIELD AS CHECKBOX. "deselected

WRITE MARKFIELD AS CHECKBOX INPUT OFF. "deselected, protected

Additional help

List Creation

Addition 5

... AS SYMBOL (output as symbol)

WRITE - Output as symbol

Effect

You can output certain characters as symbols using the addition ... AS SYMBOL. You should only address these characters with their system-defined names. The include <SYMBOL> (or the more comprehensive include <LIST>) contains the relevant identifiers as constants, e.g. SYM_PHONE, SYM_CIRCLE. (List of symbols, Proposals for use).

Example

INCLUDE .

WRITE: / SYM_RIGHT_HAND AS SYMBOL, " output as symbol

'Tip, Note',

SYM_LEFT_HAND AS SYMBOL. " output as symbol

Note

An output length of one character is enough for most symbols, but some (e.g. SYM_FAX) are twice as long.

You can determine the length of a symbol with DESCRIBE FIELD SYM_... OUTPUT-LENGTH ...

Additional help

List Creation

Addition 6

... AS ICON (output as icon)

WRITE - Output as icon

Effect

You can output certain characters as icons using the addition ...AS ICON. You should only address these characters with their system-defined names. The include <ICON> (or the more comprehensive include <LIST>) contains the relevant identifiers as constants, e.g. ICON_OKAY (see List of icons).

Example

INCLUDE .

WRITE: / ICON_OKAY AS ICON, "output as icon

'Text line'.

Note

Although an output length of 2 characters is enough for most icons, some (e.g. the traffic light icons ICON_RED_LIGHT, ...) have a greater output length.

You can determine the length of an icon with DESCRIBE FIELD ICON_... output length ....

You cannot print out all list icons. The printable icons are flagged as such in the 'list of icons' mentioned above.

Additional help

List Creation

Addition 7

... AS LINE (output as line)

WRITE - Output as line

Effect

On list output, automatically links certain characters together to form continuous lines or boxes, if there is no space between them:

vertical lines, output with the system field SY-VLINE or using a field with the contents "|" (vertical line)

horizontal lines, output with the system field SY-ULINE or using a field with at least 2 consecutive minus signs "--".

Exactly how each line segment is output (e.g. whether as straight line, corner, T-piece or cross) depends on the adjoining characters.

A good rule of thumb sipulates that if the cell adjacent to a line character also contains a line character, the missing piece required to form a connection is added. If an adjacent cell does not also contain a line character, the line character is truncated on that side. Line characters standing on their own remain unchanged.

This technique is sufficient to cope with most cases (e.g. tables, boxes, simple hierarchies). However, no matter how carefully you use some empty characters and lines, it is not possible to stop adjacent line characters being joined in an inappropriate way (e.g. very compact hierarchy diagrams, or densely boxes). The solution here is to output the required line segment explicitly using the addition ... AS LINE.

The include <LINE> (or the more comprehensive include <LIST>) contains the relevant identifiers for lines as constants, e.g. LINE_TOP_LEFT_CORNER, LINE_BOTTOM_MIDDLE_CORNER.

Note

Lines cannot have any other display attributes. If attributes such as color ( COLOR), reverse video (INVERSE) or intensified ( INTENSIFIED) are set, these are ignored on output. If the ready for input attribute ( INPUT) is set, the actual characters (minus sign, vertical line) are displayed.

Example

Output two nested corner segments:

INCLUDE .

ULINE /1(50).

WRITE: / SY-VLINE NO-GAP, LINE_TOP_LEFT_CORNER AS LINE.

ULINE 3(48).

WRITE: / SY-VLINE NO-GAP, SY-VLINE NO-GAP.

Additional help

List Creation

Note

General notes on outputting boxes to lists

When you output a list, this is sometimes combined with vertical and horizontal lines to form closed boxes:

Vertical lines are output by the system field SY-VLINE or by a field containing "|" (vertical bar),

Horizontal lines are output by the system field SY-ULINE or by a field containing only "-" (minus sign),

Vertical and horizontal lines converge (without gaps).

Addition 8

... QUICKINFO g

Effect

The field f is displayed with the quick info g: Whenever the mouse pointer is positioned on the output area of f, the contents of g are displayed as an explanatory text on the list (in a small, differently-colored box).

Notes

The quick info can be up to 40 characters long.

g must be a non-numeric field (data type C, N, D, or T).

Quick info is unsuitable for lines, input fields, or checkboxes. Its suitability is also limited for icons that are normally displayed in longer fields (the icon assignment may be inexact).

If two output fields overlap (for example, when one field is placed over another with the POSITION ... statement, the 'bottom' field may not have quick info.

The output length of f must be greater than zero ( f must actually be placed on the list) if you want to use the ... QUICKINFO addition.

Example

INCLUDE .

DATA: INFO(20) VALUE 'Information'.

WRITE: / SY-UNAME QUICKINFO 'User name'.

WRITE: / ICON_INFORMATION AS ICON QUICKINFO info

HOTSPOT COLOR COL_POSITIVE.

*********please reward points if theinformation is helpful to you***********

varma_narayana
Active Contributor
0 Kudos
35

Hi..

If you place the / after : then it will be chained and each field is displayed in a new line.

Otherwise it will generate only one line break by default.

<b>Reward if helpful.</b>