¡Caminando hacia el éxito!

Aprende en Comunidad

Avalados por :

Todo sobre el símbolo de campo: ventajas, uso y significado

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 17 Vistas
0
Cargando...

Hola,

Necesito saber qué es un símbolo de campo, cuáles son sus ventajas y dónde debe ser utilizado.

Saludos,

Anitha

Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

4 Respuestas

0
Cargando...

Hola Anitha,

FIELD-SYMBOLS <fs>.

Declara un campo simbólico con el nombre <fs>. En tiempo de ejecución, puedes asignarle un campo concreto usando la instrucción ASSIGN. Cualquier operación que realices luego usando el símbolo de campo afectará directamente al campo al que está asignado.

Ventaja:

-


La principal ventaja es al procesar los registros en una tabla interna y añadirlos a otra tabla interna.

Simplemente asigna los valores directamente al campo simbólico y no es necesario utilizar append.

Esto aumenta el rendimiento del programa.

Saludos,

Srikanth.

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

hi anitha,

<b>Field Symbols</b>

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.

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.

<b>Field symbols provide greater flexibility when you address data objects:</b>

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.

<b>example:</b>

REPORT demo_field_symbols_stat_assign .

FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i.

DATA: text(20) TYPE c VALUE 'Hello, how are you?',

num TYPE i VALUE 5,

BEGIN OF line1,

col1 TYPE f VALUE '1.1e+10',

col2 TYPE i VALUE '1234',

END OF line1,

line2 LIKE line1.

ASSIGN text TO <f1>.

ASSIGN num TO <f2>.

DESCRIBE FIELD <f1> LENGTH <f2>.

WRITE: / <f1>, 'has length', num.

ASSIGN line1 TO <f1>.

ASSIGN line2-col2 TO <f2>.

MOVE <f1> TO line2.

ASSIGN 'LINE2-COL2 =' TO <f1>.

WRITE: / <f1>, <f2>.

The output is:

Hello, how are you? has length 20

LINE-COL2 = 1,234

The example declares two field symbols <F1> and <F2>. <F2> has the type I, which means that only type I fields may be assigned to it. <F1> and <F2> both point to different fields during the program.

<
Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Hola,

Los símbolos de campo son como punteros a otros campos. No ocupan ninguna memoria física, sino que solo apuntan a su contenido. Un símbolo de campo puede apuntar a cualquier objeto de datos y hacer que el programa sea eficiente. Consulte la siguiente Ayuda de SAP.

Saludos,

Suresh Datti

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

hi anitha,

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.

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.

example:

REPORT demo_field_symbols_stat_assign .

FIELD-SYMBOLS: TYPE ANY, TYPE i.

DATA: text(20) TYPE c VALUE 'Hello, how are you?',

num TYPE i VALUE 5,

BEGIN OF line1,

col1 TYPE f VALUE '1.1e+10',

col2 TYPE i VALUE '1234',

END OF line1,

line2 LIKE line1.

ASSIGN text TO .

ASSIGN num TO .

DESCRIBE FIELD LENGTH .

WRITE: / , 'has length', num.

ASSIGN line1 TO .

ASSIGN line2-col2 TO .

MOVE TO line2.

ASSIGN 'LINE2-COL2 =' TO .

WRITE: / , .

The output is:

Hello, how are you? has length 20

LINE-COL2 = 1,234

The example declares two field symbols and . has the type I, which means that only type I fields may be assigned to it. and both point to different fields during the program.

Message was edited by: Ashok Kumar Prithiviraj

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?