🚀PROMO #PLANCARRERA2024 - 🔥Bonificaciones, Precios Congelados y Cuotas

 X 

✒️ABAP Los Field Symbols

ABAP Los Field Symbols

ABAP Los Field Symbols

Field Symbols

A Field Symbol is an ABAP statement that allows dynamic handling of program data during runtime. In contrast to static data access, where we need to specify the name of an object to perform actions on it, Field Symbols enable access to and passing of data whose names and attributes are unknown until runtime.

Field Symbols can be considered symbolic names for data, as when used, the system works with the content of the assigned data, not the Field Symbol itself. Field Symbols do not physically reserve space for a field but rather "point" to its content. A Field Symbol can point to any data object.

Field Symbols provide great flexibility because:

  • For processing parts of fields, they allow dynamic specification of offset and displacement.
  • They can be forced to take different technical attributes of the assigned field.

Most errors in using Field Symbols are detected only at runtime, making them more challenging to identify. Therefore, Field Symbols should only be used when conventional ABAP statements cannot achieve the same result.

Declaration of a Field Symbol

To use a Field Symbol in an ABAP program, two simple steps must be taken:

  • Declare the Field Symbol.
  • Assign the data object to the Field Symbol.

The syntax for declaring a Field Symbol is:

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

  • If no type is specified, the Field Symbol can contain any data, adopting all technical attributes of the field.
  • If a type is specified, the system checks compatibility between the Field Symbol and the associated field at runtime.

Generic data types for a Field Symbol include:

  • TYPE ANY or unspecified: Accepts all data object types.
  • TYPE C, I, N, P, or X: Accepts only specified data types, adopting length and decimals.
  • TYPE TABLE: Checks if the field is a standard table, inheriting all attributes.
  • TYPE ANY TABLE: Checks if the field is an internal table, inheriting all table attributes.
  • TYPE INDEX TABLE: Checks if the field is an indexed table, inheriting all table attributes.
  • TYPE STANDARD TABLE: Checks if the field is a standard table, inheriting all table attributes.
  • TYPE SORTED TABLE: Checks if the field is a sorted table, inheriting all table attributes.
  • TYPE HASHED TABLE: Checks if the field is a hashed table, inheriting all table attributes.

FIELD-SYMBOLS <fs> TYPE i.

Data Assignment to a Field Symbol

In an ABAP program, data objects can be assigned to Field Symbols at any time, allowing various objects to be assigned to a single Field Symbol. Data assignment to a Field Symbol is done using the ASSIGN statement. The assignment is static since we know the field name we want to assign to the Field Symbol.

The syntax for the ASSIGN statement is:

ASSIGN <field> TO <fs>.

Where <field> is the assigned field and <fs> is the Field Symbol name. After assigning a data object to a Field Symbol, changes in the Field Symbol value also update the corresponding data object value.

DATA: lv_value TYPE i.
FIELD-SYMBOLS <fs> TYPE i.

lv_value = 42.
ASSIGN lv_value TO <fs>.

WRITE: / 'Field Symbol Value:', <fs>. " 42

<fs> = 10.

WRITE: / 'Field Symbol Value:', <fs>. " 10
WRITE: / 'Variable Value:', lv_value. " 10

Using Field Symbols with Structures

Instead of using a structure or work area, we can read a record from an internal table using a Field Symbol. A Field Symbol can be declared in conjunction with an internal table, eliminating the need for declaring a structure or work area. The same Field Symbol can be used to update the internal table.

Considerations

  • Modifying any structure field in the Field Symbol updates the corresponding field in the internal table.
  • No need for the MODIFY statement, as the Field Symbol directly references the internal table row, making processing faster compared to using a work area or structure.

DATA: it_mara TYPE STANDARD TABLE OF mara.
FIELD-SYMBOLS: <fs_mara> TYPE mara.

READ TABLE it_mara ASSIGNING <fs_mara> WITH KEY matnr = 'MAT1'.

SELECT * FROM mara UP TO 5 ROWS INTO TABLE it_mara.

* Before modification
LOOP AT it_mara ASSIGNING <fs_mara>.
WRITE:/ 'MATNR:', <fs_mara>-matnr, 'MATK1:', <fs_mara>-matkl.
ENDLOOP.
ULINE.
LOOP AT it_mara ASSIGNING <fs_mara>.
<fs_mara>-matkl = 'DEMO'.
ENDLOOP.
ULINE.
* After modification
LOOP AT it_mara ASSIGNING <fs_mara>.
WRITE:/ 'MATNR:', <fs_mara>-matnr, 'MATK1:', <fs_mara>-matkl.
ENDLOOP.

Using Field Symbols for Dynamic SELECT Statement

Field Symbols can be used for dynamic SELECT statements on SAP database tables. This allows creating an ABAP program with a parameter for the desired database table name. Depending on user input, the program can either download table records to a file or upload them to memory for processing.

* Dynamic reference to create a new table structure
CREATE DATA dtable TYPE (tabname).
ASSIGN dtable->* TO <fs_itable>.

* Fetch the data from the selected table
SELECT *
FROM (tabname) UP TO 3 ROWS
INTO <fs_itable>.
ENDSELECT.

E.g 1

*&---------------------------------------------------------------------*
*& Report ZTEST_ABAP_JEGA_25
*&---------------------------------------------------------------------*
*& This report demonstrates dynamic selection and display of data from
*& different tables based on user selection.
*&---------------------------------------------------------------------*
REPORT ztest_abap_jega_25.

CONSTANTS: c_x(1) TYPE c VALUE 'X'.

DATA: dtable TYPE REF TO data, " Reference to dynamic data
tabname TYPE tabname. " Table name for dynamic selection

FIELD-SYMBOLS: <fs_itable> TYPE any, " Field symbol for table row
<fs_value> TYPE any. " Field symbol for row value

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t01.
PARAMETERS: p_eban RADIOBUTTON GROUP rad1, " Radio button for table EBAN
p_mara RADIOBUTTON GROUP rad1, " Radio button for table MARA
p_vbak RADIOBUTTON GROUP rad1. " Radio button for table VBAK
SELECTION-SCREEN END OF BLOCK b1.

*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
CLEAR tabname.
* Determine table name based on user selection
IF p_eban EQ c_x.
tabname = 'EBAN'. " Selected table is EBAN
ELSEIF p_mara EQ c_x.
tabname = 'MARA'. " Selected table is MARA
ELSEIF p_vbak EQ c_x.
tabname = 'VBAK'. " Selected table is VBAK
ENDIF.

PERFORM select_data. " Perform data selection
PERFORM display_data. " Perform data display

*---------------------------------------------------------------------*
* Form: SELECT_DATA
*---------------------------------------------------------------------*
*& This form selects data from the dynamically determined table
*---------------------------------------------------------------------*
FORM select_data.
* Dynamic reference to create a new table structure
CREATE DATA dtable TYPE (tabname).
ASSIGN dtable->* TO <fs_itable>.

* Fetch the data from the selected table
SELECT *
FROM (tabname) UP TO 3 ROWS
INTO <fs_itable>.
ENDSELECT.
ENDFORM. " SELECT_DATA

*---------------------------------------------------------------------*
* Form: DISPLAY_DATA
*---------------------------------------------------------------------*
*& This form displays the selected data
*---------------------------------------------------------------------*
FORM display_data.
ULINE.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_itable> TO <fs_value>.
IF sy-subrc <> 0.
EXIT. " No more data
ENDIF.
WRITE:/ sy-index, ' ' , <fs_value> , ' - '.
ENDDO.
ENDFORM. " DISPLAY_DATA

E.g 2

DATA: it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.

FIELD-SYMBOLS: <fs_it_mara> TYPE mara,
<fs_value> TYPE any.

SELECT * FROM mara UP TO 10 ROWS INTO TABLE it_mara.

* Iterating the internal table
LOOP AT it_mara ASSIGNING <fs_it_mara>.

ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_it_mara> TO <fs_value>.
IF sy-subrc = 0.
WRITE: / <fs_value>.
ENDIF.

ASSIGN COMPONENT 'MTART' OF STRUCTURE <fs_it_mara> TO <fs_value>.
IF sy-subrc = 0.
WRITE: / <fs_value>.
ENDIF.
ULINE.
ENDLOOP.


 

 

 


Sobre el autor

Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.

SAP Master

Jaime Eduardo Gomez Arango

Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C

✒️Autor de: 102 Publicaciones Académicas

🎓Cursando Actualmente: Consultor ABAP Nivel Avanzado

🎓Egresado del módulo:

Disponibilidad Laboral: FullTime

Presentación:

Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.

Certificación Académica de Jaime Gomez

✒️+Comunidad Académica CVOSOFT

Continúe aprendiendo sobre el tema "Los Field Symbols" de la mano de nuestros alumnos.

SAP Master

FIELD SYMBOLS. Es un tipo de sentencia abap que nos permite trabajar con los datos de los programas en forma dinamica en tiempo de ejecusión.Los field symbols nos permiten acceder y pasar datos cuyos nombres y atributos no conocemos, hasta el momento de la ejecusión. DECLARACION DE UN FIELD SYMBOLS. utilizaremos la siguiente sintaxis: FIELD-SYMBOLS <fs> [<TYPE> estructure <s> DEFAULT <was>] ASIGNACION DE DATOS A UN FIELD SYMBOLS. Utilizamos la sentencia ASSIGN, utilizaremos la siguiente sintaxis: ASSIGN <f> TO <FS>

Acceder a esta publicación

Creado y Compartido por: Maria Ysabel Colina De Magdaleno

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

1. Field Symbols Tipo de sentencia ABAP que se usar para trabajar datos de forma dinamica en tiempo de ejecuciòn. Pero no son muy flexibles por lo siguiente: - Si quieres procesar te permite especificar el offset y desplazarlo de forma dinàmica. - Se puede usar el Field Symbol para tomar atributos tecnicos. Solo se debe usar los Field Symbols cuando no se pueda llegar a los resultado usando las sentencias convencionales de ABAP. 2. Declaraciòn de un Field Symbol la sintaxis es: FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>]. 3. Asignaciòn de datos a un Field Symbols Se usa la sentencia ASSIGN de siguiente manera: ASSIGN <f> TO <FS>.

Acceder a esta publicación

Creado y Compartido por: Daniel Arias Sarmiento

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

Field Symbols Sentencia ABAP que nos permite trabajar con los datos de los programas en forma dinámica en tiempo de ejecución. Se concideran como nombres simbolicos de lso datos ya que cuando se utilizan, el sistema trabaja con el contenido de los datos y no con el del Field Symbols.(Es un tipo de variable) FIELD-SYMBOLS( fs)[(type) STRUCTURE (s) DEFAULT (wa)] cuando asignamos un dato al field symbol este hereda los atributos tecnicos del dato. Para asignar datos a un FIELD symbol se uda la sentencia ASSIGN, y la asignacion es estatica LA mayoria de los errores con los field symnbols son detectados en tiempo de ejecucion, esto hace que sean dificiles de detectar.

Acceder a esta publicación

Creado y Compartido por: Carolina Sanchez

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

Tratamiento de Archivos y Field Symbols Que son los Field Symbols: Field Symbol, es un tipo de sentencia ABAP que nos permite trabajar con los datos de los programas en forma dinamica en tiempo de ejecucion. Los Field Symbol nos proveen de gran flexibilidad debido a que: Si queremos procesar partes de campos, nos permiten especificar el offset y el desplazamiento de un campo en forma dinamica. Se puede forzar a un field symbol para que tome diferentes atributos tecnicos que los del campo asignado a el. Declaracion de un Field Symbol: Usaremos la siguiente sintaxis: FIELD-SYMBOLS <FS>[<type>|STRUCTURE <s> DEFAULT <wa>]. Asignacion de dato a un Field Symbol: Para asignarle datos usaremos la sentencia ASSIGN.

Acceder a esta publicación

Creado y Compartido por: Juan Fernando Guerra Mata / Disponibilidad Laboral: FullTime

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

1 - Qué son los Field Symbols?. FIELD SYMBOL: Sentencia ABAP para acceder a los datos de los programas en forma dinámica en tiempo de ejecución. Los FIELD SYMBOLS proveen gran flexibilidad debido a que: Si queremos procesar partes de campos, nos permiten especificar el offset y el desplazamiento de un campo en forma dinámica. Se puede forzar a un Field Symbols para que tome diferentes atributos técnicos que los del campo asignado a el. Offset: Es cuando separamos un campo en varios strings, y cada string se considera una dato independiente. Solo debemos utilizar Field Symbols cuando no podemos llegar al mismo resultado con las sentencias ABAP convencionales, ya que como los errores se detecan en...

Acceder a esta publicación

Creado y Compartido por: Calixto Gutiérrez

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

FIELD SYMBOL Sentencia abap que permite trabajar con datos de los programas en forma dinámica en tiempo de ejecución. Se declaran de la siguiente manera: FIELD-SYMBOLS <>[<type> |STRUCTURE <s> DEFAULT <wa>]. Si no se espefica un tipo a un field symbol este puede contener cualquier dato. Cuando se asigna un dato al field symbols este hereda los atributos técnicos del dato. Para asignar datos a un field symbol utilizamos la sentencia assign. ASSIGN <f> TO <FS>

Acceder a esta publicación

Creado y Compartido por: Alberth Julian Bolanos Bravo

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

que son los field Symbols es un tipo de sentencia abap que nos permite trabajar con los datos de los programas en forma dinamica en tiempo de ejecucion. al contrario de lo que sucede con el acceso estatico de los datos, donde necesitamos especificar el nombre de un objeto para poder hacer algo con el, los Field Symbols nos permite acceder y pasar datos cuyos nombres y atributos no conocemos hasta el momento de la ejecucion. se puede considerar a los field symbols como nombres simbolicos de los datos, ya que cuando se utilizan, el sistema trabaja con el contenido de los datos asignados y no con el contenido del field symbol. los field symbols nos proveen de gran flexibilidad debido a que: si queremos procesar partes de campos, nos permite especificar...

Acceder a esta publicación

Creado y Compartido por: Oscar Sebastian Caicedo Carlier / Disponibilidad Laboral: PartTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

TRATAMIENTO DE ARCHIVOS Y FIELD SYMBOLS QUE ES UN FILED SYMBOL es un tipo de sentencia ABAP que nos permite trabajar con los datos de los programas en forma dinamica en tiempo de ejecucion nombres simbolicos de los datos este nos permite especificar el offset y el desplazamiento en forma dinamica DECLARACION DE UN FIELD SYMBOL FIELD-SYMBOLS <FS> [<TYPE> |STRUCTURE <s> DEFAULT <wa>]. ASIGNACION DE DATOS para asignar datos aun field symbols utilizamos la sentencia ASSIGN la asignacion que utilizamos es estatica ya que sabemos el nombre del campo que queremos asignar ASSIGN <f> to <FS>

Acceder a esta publicación

Creado y Compartido por: Andres Felipe Escobar Lopez

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

1|QUE SON LOS FIELD SYMBOLS ES UN TIPO DE SENTENCIA ABAP QUE NOS PERMITE TRABAJAR CON LOS DATOS DE LOS PROGRAMAS EN UNA FORMA DINAMICA DE TIEMPO DE EJECUCION. LOS FIELD SYMBOL NOS PERMITEN ACCEDER Y PASAR DATOS CUYOS NOMBRES Y ATRIBUTO NO CONOCEMOS HASTA EL MOMENTO DE LA EJECUCION. LOS FIELD SYMBOL NOS PROVEEN DE GRAN FLEXIBILIDAD DEBIDO A QUE : SI QUEREMOS PROCESAR PARTES DE CAMPOS, NOS PERMITE ESPECIFICAR EL OFFSET Y EL DESPLAZAMIENTO DE UN CAMPO EN FORMA DINAMICA SE PUEDE FORZAR A UN FIEL SYMBOL PARA QUE TOME DIFERENTES ATRIBUTOS TECNICOS QUE LOS DEL CAMPOS ASIGNADO 2| DECLARACION DE UN FIELD SYMBOL SINTAXIS FIELD-SYMBOLS <FS> [<TYPE>|STRUCTURE <S> DEFAULT <WA>] SI NO ESPECIFICAMOS UN TIPO A UN FIELD SYMBOL ESTE PUEDE...

Acceder a esta publicación

Creado y Compartido por: Luis Eugenio Leyva Orozco

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

FIELD SYMBOLS Es un tipode sentencia ABAP que nos permite trabajar con los datos de los programas en forma dinamica en tiempo de ejecucion. Si queremos procesar partes de campos, nos permiten especificar el offset y el desplazamiento de un campo en forma dinamica, Se puede forzar a un FIELD Symbol para que tome diferentes atributos tecnicos que los campos asignados a el. La mayoria de los errores que comentamos en su utilizacion, lo detectaremos recien en tiempo de ejecucion. Lo cual lo hace mas dificil de detectar. Declaracion de un FIELDSYMBOL. FIELD-SYMBOLS nombre TYPE estructura. Si no especificamos un tipo de un FIELD SYMBOLS este puede contener cualquier dato. Cuando le asignamos un dato, este hereda los atributos...

Acceder a esta publicación

Creado y Compartido por: Jessica Daiana Garcete Paez / Disponibilidad Laboral: PartTime + Carta Presentación

 


 

👌Genial!, estos fueron los últimos artículos sobre más de 79.000 publicaciones académicas abiertas, libres y gratuitas compartidas con la comunidad, para acceder a ellas le dejamos el enlace a CVOPEN ACADEMY.

Buscador de Publicaciones:

 


 

No sea Juan... Solo podrá llegar alto si realiza su formación con los mejores!