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: 

What we can do with field symbols,

Former Member
0 Kudos

Hi all,

I need to learn what we can do with field symbols.

I have seen that we can assign data to them and later use the data, but how I can do I do not know.

Thanks.

Deniz.

7 REPLIES 7

Former Member
0 Kudos

Hi Deniz,

U can use field symbols like internal table.

Field symobls stores data dynamically like pointers in C language.

Generally while creating routines and userexits. People will use them for

capturing runtime data available in that transactions.

Assign points if useful.

Former Member
0 Kudos

Hi

Field-Symbols are place holders for existing fields.

A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.

Field-Symbols are like Pointers in Programming language ‘ C ‘.

Syntax check is not effective.

Syntax :

Data : v1(4) value ‘abcd’.

Field-symbols <fs>.

Assign v1 to <fs>.

Write:/ <fs>.

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

DO 4 TIMES.

LINE-COL1 = SY-INDEX.

LINE-COL2 = SY-INDEX ** 2.

APPEND LINE TO ITAB.

ENDDO.

READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.

<FS>-COL2 = 100.

READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.

DELETE ITAB INDEX 3.

IF <FS> IS ASSIGNED.

WRITE '<FS> is assigned!'.

ENDIF.

LOOP AT ITAB ASSIGNING <FS>.

WRITE: / <FS>-COL1, <FS>-COL2.

ENDLOOP.

The output is:

1 1

2 100

4 16

Check the below Links :

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm

http://www.erpgenie.com/abap/code/chap2401.txt

http://help.sap.com/saphelp_nw04/helpdata/en/16/0dce0a0cf711d3b9360000e8353423/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3930358411d1829f0000e829fbfe/content.htm

Regards

Pavan

Former Member
0 Kudos

Field-symbol is like pointer in C. Field-symbols has some unique features. Most usefulls are :

1. You can modify the table directly. Do not need a modify statement.

2. You can access (read/write) the variable/internal table of other program.

3. You can access a perticular field of a structure mentioning the element no.

etc.

Former Member
0 Kudos

HI,

The FIELD-SYMBOLS statement declares a field symbol <name>. The naming conventions apply to the name 'name'. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.

After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.

You can use the addition typing to type the field symbol. The syntax of typing is described under Typing. The typing specifies which memory areas can be assigned to the field symbol and in which operand positions it can be used.

FIELD-SYMBOLS <scarr1> type scarr

or <scarr1> like line of scarr

or <scarr1> type any.

The first example shows the obsolete usage of the addition STRUCTURE.

DATA wa1 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr1> STRUCTURE scarr DEFAULT wa1.

<scarr1>-carrid = '...'.

and can access them using <scarr1>-fieldname for any computation and display purposes.

Regards

Gururaj

Reward if useful

Former Member
0 Kudos

well,

field symbols act just like pointers, they store the refrence of data and not the data itself.

There are variety of applications for field symbols as explained in previous replies. I will explain a typical scenario in which only field symbol can help.

<b>Scenario:</b> You want to cocatenate all the fields in an internal table having 200 fields and u eant to write to a file.

LOOP AT t_mat.

w_cnt = 1.

DO.

ASSIGN COMPONENT w_cnt OF STRUCTURE t_mat TO <fl>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

if w_cnt EQ 1.

t_data-lines = <fl>.

endif.

IF NOT <fl> IS INITIAL.

CONCATENATE t_data-lines <fl> INTO t_data-lines

SEPARATED BY c_tild.

ENDIF.

w_cnt = w_cnt + 1.

ENDDO.

APPEND t_data.

ENDLOOP.

now t_data contains all the 200 fileds of t_mat internal table conacteanted with tild

*reward if helped*

varma_narayana
Active Contributor
0 Kudos

Hi Deniz..

Field symbols provides the Flexibility to develop Dynamic applications. For Eg Creating an internal table dynamically.

Check this sample program:

**Dynamic internal Table Upload from Excel Sheet**

PARAMETERS: FILENAME LIKE RLGRAP-FILENAME OBLIGATORY,

HEADER AS CHECKBOX.

FIELD-SYMBOLS: <F>,

<TAB> TYPE STANDARD TABLE,

<WA>.

TYPE-POOLS: SLIS.

DATA: INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE,

FCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_FIELDCAT TYPE LVC_T_FCAT.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

MASK = '*.xls'

STATIC = 'X'

CHANGING

FILE_NAME = FILENAME.

START-OF-SELECTION.

PERFORM GET-SPREADSHEET.

PERFORM BUILD-FIELD-CATALOG.

PERFORM CREATE-DATA-TABLE.

PERFORM FILL-DATA-TABLE.

PERFORM GRID-DISPLAY.

----


  • FORM get-spreadsheet *

----


  • ........ *

----


FORM GET-SPREADSHEET.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = FILENAME

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 256

I_END_ROW = 65000

TABLES

INTERN = INTERN

EXCEPTIONS

OTHERS = 3.

ENDFORM.

----


  • FORM build-field-catalog *

----


  • ........ *

----


FORM BUILD-FIELD-CATALOG.

DATA: IS_FIELDCAT LIKE LINE OF IT_FIELDCAT,

WCAT LIKE LINE OF FCAT,

INDEX(3) TYPE N,

MAXCOL LIKE INTERN-COL.

  • find the last column used

LOOP AT INTERN.

IF INTERN-COL > MAXCOL.

MAXCOL = INTERN-COL.

ENDIF.

ENDLOOP.

  • build field catalog for each column for dynamic table

DO MAXCOL TIMES.

IS_FIELDCAT-INTTYPE = 'C'.

IS_FIELDCAT-INTLEN = '50'.

IF HEADER = 'X'.

READ TABLE INTERN WITH KEY ROW = 1 COL = SY-INDEX.

IF SY-SUBRC = 0.

IS_FIELDCAT-FIELDNAME = INTERN-VALUE.

CONDENSE IS_FIELDCAT-FIELDNAME NO-GAPS. "just in case

TRANSLATE IS_FIELDCAT-FIELDNAME TO UPPER CASE.

ENDIF.

ENDIF.

IF SY-SUBRC > 0 OR HEADER <> 'X'.

INDEX = SY-INDEX.

CONCATENATE 'FLD_' INDEX INTO IS_FIELDCAT-FIELDNAME.

ENDIF.

APPEND IS_FIELDCAT TO IT_FIELDCAT.

  • field catalog for alv grid

WCAT-COL_POS = SY-INDEX.

WCAT-FIELDNAME = IS_FIELDCAT-FIELDNAME.

WCAT-SELTEXT_S = IS_FIELDCAT-FIELDNAME.

APPEND WCAT TO FCAT.

ENDDO.

ENDFORM.

----


  • FORM CREATE-DATA-TABLE *

----


  • ........ *

----


FORM CREATE-DATA-TABLE.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FIELDCAT

IMPORTING

EP_TABLE = NEW_TABLE.

ASSIGN NEW_TABLE->* TO <TAB>.

CREATE DATA NEW_LINE LIKE LINE OF <TAB>.

ASSIGN NEW_LINE->* TO <WA>.

ENDFORM.

----


  • FORM fill-data-table *

----


  • ........ *

----


FORM FILL-DATA-TABLE.

CLEAR <WA>.

LOOP AT INTERN.

IF HEADER = 'X' AND INTERN-ROW = 1.

ELSE.

AT NEW ROW.

IF NOT <WA> IS INITIAL.

APPEND <WA> TO <TAB>.

CLEAR <WA>.

ENDIF.

ENDAT.

ASSIGN COMPONENT INTERN-COL OF STRUCTURE <WA> TO <F>.

<F> = INTERN-VALUE.

ENDIF.

ENDLOOP.

IF NOT <WA> IS INITIAL.

APPEND <WA> TO <TAB>.

ENDIF.

ENDFORM.

----


  • FORM GRID-DISPLAY *

----


  • ........ *

----


FORM GRID-DISPLAY.

DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.

LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LAYOUT-ZEBRA = 'X'.

LAYOUT-DETAIL_POPUP = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FCAT[]

TABLES

T_OUTTAB = <TAB>.

ENFORM.

<b>reward if Helpful</b>