Application Development and Automation 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: 
Read only

field symbol

Former Member
0 Likes
939

how we use field symol.

field symbol : <fs> type any

.field symbol type any with good ex. if possible

how we use field symol.

field symbol : <fs> type any

.field symbol type any with good ex. if possible

7 REPLIES 7
Read only

Former Member
0 Likes
909

Hi

simple example

field-symbols: <fs>.

data: begin of it_vbrp,

vbeln like vbrp-vbeln,

posnr like vbrp-posnr,

brgew like vbrp-brgew,

ntgew like vbrp-ntgew,

end of it_vbrp.

data: begin of it_vbrp2,

vbeln like vbrp-vbeln,

posnr like vbrp-posnr,

brgew like vbrp-brgew,

  • ntgew like vbrp-ntgew,

end of it_vbrp2.

select vbeln

posnr

brgew

ntgew

from vbrp

into corresponding fields of it_vbrp

where vbeln between '0090059462' and '0090060327'.

assign it_vbrp to <fs>.

write:/ <fs>.

move <fs> to it_vbrp2.

clear <fs>.

endselect.

Read only

Former Member
0 Likes
909

Refer to the below related threads

Read only

Former Member
0 Likes
909

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.

Read only

Former Member
0 Likes
909

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?

*&#61558; Field symbols use the memory to directly access the data from the internal table.

&#61558; We do not pass the data to the header and from where we read the data which takes more time.

&#61558; 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.

Hope this material helps u

Reward if useful ,

Shankar GJ

Read only

Former Member
0 Likes
909

Hi

Check this Basic Program For Field Symbols..

DATA: BEGIN OF line,

col1(1) TYPE c,

col2(1) TYPE c VALUE 'X',

END OF line.

FIELD-SYMBOLS <fs> LIKE line.

ASSIGN line TO <fs>.

MOVE <fs>-col2 TO <fs>-col1.

WRITE: <fs>-col1, <fs>-col2.

Thanks

Praveen

Read only

Former Member
0 Likes
909

Hi,

Please refer the code below:


REPORT demo_field_symbols_casting.

TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.

FIELD-SYMBOLS <fs> TYPE any.

ASSIGN sy-datum TO <fs> CASTING.

WRITE / sy-datum.
SKIP.
WRITE: / <fs>-year , / <fs>-month, / <fs>-day.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
909

Hi,

Please refer the code below:


REPORT demo_field_symbols_casting.

TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.

FIELD-SYMBOLS <fs> TYPE any.

ASSIGN sy-datum TO <fs> CASTING.

WRITE / sy-datum.
SKIP.
WRITE: / <fs>-year , / <fs>-month, / <fs>-day.

Thanks,

Sriram Ponna.