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: 

field symbol & work area

Former Member
0 Kudos

hi everybody,

can anybody tell me that what is the difference between field symbol and work area and when to use field symbol and when to use work area.

Thanks and Regards.

noor

8 REPLIES 8

Former Member
0 Kudos

Hi,

Field-Symbols holds the internal address of an ABAP variable, like pointers in C++.

Refer theard

https://forums.sdn.sap.com/click.jspa?searchID=12231864&messageID=3414602

Regards

Kiran Sure

0 Kudos

Field-symbols are not POINTERS.

Extract from help.sap.com

Field symbols are similar to de-referenced pointers in the C programming language (that is, pointers to which the content operator * is applied). In ABAP, data references represent a real equivalent to pointers in the sense of variables that contain a memory address and can be used without the contents operator.

http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi Mohd,

Definition and Features of Field Symbols:

1. Field symbols are placeholders for other fields.

2. They do not physically reserve space for a field, but point

to its contents.

3. A field symbol can point to any data object.

4. The data object to which a field symbol points is assigned

to it after it has been declared in the program.

5. Field symbols are similar to dereferenced pointers in C.

Field symbols provide greater flexibility when you address data objects:

Advantages:

1. If you want to process sections of fields, you can specify the offset and length of the field dynamically.

2. You can assign one field symbol to another, which allows you to address parts of fields.

3. Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.

4. You can also force a field symbol to take different technical attributes from those of the field assigned to it.

Definition Syntax:

FIELD-SYMBOLS <FS1> STRUCTURE <str1> DEFAULT <wa1>.

eg1: FIELD-SYMBOLS <fs1> TYPE ANY TABLE.

eg2: FIELD-SYMBOLS<fs2> STRUCTURE line1 DEFAULT wa2.

ASSIGN wa TO <fs1>.

Former Member
0 Kudos

hi,

Work area : While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line

data: wa_itab like itab. " explicit work area for itab

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.

You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.

Field symbols provide greater flexibility when you address data objects:

If you want to process sections of fields, you can specify the offset and length of the field dynamically.

You can assign one field symbol to another, which allows you to address parts of fields.

Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.

You can also force a field symbol to take different technical attributes from those of the field assigned to it.

The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements

To declare a field symbol, use the statement

FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].

For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.

pls reward if helpful.

Regars,

Rajyalakshmi.

Former Member
0 Kudos

hi,

Field Symbols

Field symbols do not physically reserve space for a field, but point to its contents. A The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field symbols offer functionality similar to pointers in other programming languages. It does not occupy memory for the data object, it points to the object that has been assigned to the field symbol. You use the assign command to relate to the data object. After the assign operation you can work with field symbol in the same way as with the object itself.

You define the field symbol as: field-symbols <fs>.

Consider this:

field-symbol <fs>.

data field value 'X'.

asssign field to <fs>.

The field symbol <fs> now inherits all the properties from the assigned field, and you can work with the field symbol in the same way as with the field itself.

Simple program.

data: letter(10) .

field-symbols: <fs> type any.

assign letter to <fs> type 'X'.

write <fs>.

Simple program.

TYPES: BEGIN OF NAME,

NEXTNAME(10),

FIRSTNAME(10),

LASTNAME(10),

END OF NAME.

FIELD-SYMBOLS <F> TYPE NAME.

DATA: LINE(30).

LINE = 'JOHN SMITH SHRI'.

ASSIGN LINE TO <F> CASTING.

WRITE: / 'Lastname:', <F>-LASTNAME,

'Firstname:', <F>-FIRSTNAME,

'Nextname :', <F>-NEXTNAME.

Why We Use Field Symbols?

 Field symbols use the memory to directly access the data from the internal table.

 We do not pass the data to the header and from where we read the data which takes more time.

 As a result Field Symbol is similar to a Pointer in C-Language. We can directly get the data from the memory which is very convenient.

Typing Field Symbols

TYPES Check for data object

Type ANY All types of data object are accepted

Type C,N,P,X. Only data objects with type C, N, P, or X are accepted.

Type Table The system checks whether the data object is an internal table .

Type Index Table The system checks whether the data object is an index table (standard or sorted table).

Type Standard Table The system checks whether the data object is a standard internal table.

workarea::

WORK AREAS

Work areas are single rows of data.

It should have the same format as any of the internal tables.

It is used to process the data in an internal table one line at a time.

Internal Tables with Header Line : Here the system automatically creates the work area. The work area has the same data type as internal table. This work area is called the HEADER line. It is here that all the changes or any of the action on the contents of the table are done. As a result of this, records can be directly inserted into the table or accessed from the internal table directly.

Internal Tables without Header Line : Here there is no work area associated with the table. Work area is to be explicitly specified when we need to access such tables. Hence these tables cannot be accessed directly.

You access internal tables line by line. You must use a work area as an interface for transferring data to and from the table.

When you read data from an internal table, the contents of the addressed table line overwrite the contents of the work area.

When you write data to an internal table, you must first enter the data in the work area from which the system can transfer the data to the internal table.

do reward if helpful

preet

Former Member
0 Kudos

Hi

Field symbols-

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program. Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs. Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied).

Declaring Field Symbols

To declare a field symbol, use the statement

FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].

For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.

Generic Type Specification

Typing Check for data object

No type specification

TYPE ANY All types of data object are accepted. The field symbol adopts all of the attributes of the data object.

TYPE C, N, P, or X Only data objects with type C, N, P, or X are accepted. The field symbol adopts the field length and DECIMALS specification (type P) of the data object.

TYPE TABLE The system checks whether the data object is a standard internal table. This is a shortened form of TYPE STANDARD TABLE (see below).

TYPE ANY TABLE The system checks whether the data object is an internal table. The field symbol inherits all of the attributes (line type, table type, key) from the data object.

TYPE INDEX TABLE The system checks whether the data object is an index table (standard or sorted table). The field symbol inherits all of the attributes (line type, table type, key) from the data object.

TYPE STANDARD TABLE The system checks whether the data object is a standard internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.

TYPE SORTED TABLE The system checks whether the actual parameter is a sorted internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.

TYPE HASHED TABLE The system checks whether the actual parameter is a hashed internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.

TYPES: BEGIN OF line,

col1 TYPE c,

col2 TYPE c,

END OF line.

DATA: wa TYPE line,

itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,

key(4) TYPE c VALUE 'COL1'.

FIELD-SYMBOLS <fs> TYPE ANY TABLE.

ASSIGN itab TO <fs>.

READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.

Assigning Field Symbols

Instead of using the names of data objects, you can also assign field symbols to field symbols in all variants of the ASSIGN statement.

ASSIGN <FS1>[+<o>][(<l>)] TO <FS2>. in a static ASSIGN and:

ASSIGN [TABLE FIELD] (<f>) TO <FS2>. in a dynamic ASSIGN,

Thanks.

reward points if useful

Former Member
0 Kudos

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects. (For more information, see Data References).

All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.

You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.

Field symbols provide greater flexibility when you address data objects:

If you want to process sections of fields, you can specify the offset and length of the field dynamically.

You can assign one field symbol to another, which allows you to address parts of fields.

Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.

You can also force a field symbol to take different technical attributes from those of the field assigned to it.

The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.

For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.

Field Symbol <MARK>

Use

The field symbol gets the selection status of the records of the internal table TOTAL.

You can get the possible values via constants.

WORK AREAS

- Work areas are single rows of data.

- It should have the same format as any of the internal tables.

- It is used to process the data in an internal table one line at a time.

There are two types of internal tables.

Internal tables with HEADER line and the other

Internal tables without HEADER line.

With Header line

- System automatically creates a work area for the internal table.

- Work area has same data type as internal table.

- Work area is called the header line.

Without Header line

- Internal tables without header line do not have a work area.

- Work area to be explicitly defined to access such internal tables.

REWARD IF USEFUL

Former Member
0 Kudos

field symbol

Field Symbols

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects. (For more information, see Data References).

All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.

You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.

Field symbols provide greater flexibility when you address data objects:

• If you want to process sections of fields, you can specify the offset and length of the field dynamically.

• You can assign one field symbol to another, which allows you to address parts of fields.

• Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.

• You can also force a field symbol to take different technical attributes from those of the field assigned to it.

The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.

For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.

*REPORT.

&----


*& Chapter 24: Using Field Symbols for variable parts of fields

&----


REPORT CHAP2402.

DATA: EXTERNAL_RECORD(4000),

POSITION TYPE I,

LENGTH TYPE N.

FIELD-SYMBOLS <ENTRY>.

EXTERNAL_RECORD = '0005Smith0007Edwards0005Young'.

DO.

LENGTH = EXTERNAL_RECORD+POSITION(4).

IF LENGTH = 0.

EXIT.

ENDIF.

ADD 4 TO POSITION.

ASSIGN EXTERNAL_RECORD+POSITION(LENGTH) TO <ENTRY>.

WRITE <ENTRY>.

ADD LENGTH TO POSITION.

IF POSITION >= 4000.

EXIT.

ENDIF.

ENDDO.

&----


*& Chapter 24: Using Field Symbols for components of a structure

&----


REPORT CHAP2403.

  • Table work area for later use

TABLES CUSTOMERS.

  • Defining a Field Symbol

FIELD-SYMBOLS <OUTPUT>.

  • Displaying all fields of all table entries

SELECT * FROM CUSTOMERS.

NEW-LINE.

DO.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE CUSTOMERS TO <OUTPUT>.

IF SY-SUBRC 0.

EXIT.

ENDIF.

WRITE <OUTPUT>.

ENDDO.

ENDSELECT.

work area

Work Areas: For a better performance it is preferible using internal declared structures in your program named work areas, instead of declaring tables with header lines. This will allow you to use sometimes the same one-record structure for more than one internal table. Use work areas for inserting and updating records. It folows a simple code sample, as in complement to last item's code:

DATA: internal_table TYPE STANDARD TABLE OF table_struc.

DATA: work_area_table TYPE table_struct.

  • ...

APPEND work_area_table TO internal_table.

  • ...

INSERT work_area_table INTO internal_table.

  • ...

MODIFY internal_table FROM work_area_table.

Thanks,

Anon