2007 Dec 11 6:09 AM
Hi all.
How can i assign all value of internal table to field symbols.
How it is beneficial in performance tunning???
2007 Dec 11 6:17 AM
Hi,
this is the code for creating the internal table using field symbols.
plzz reward points if it is helpful.
REPORT ZREPORT_TEST.
tYPE-POOLS SLIS.
**
DATA:
BEGIN OF T_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
END OF T_MARC.
**
**SELECT MATNR WERKS
FROM MARC
INTO TABLE T_MARC UP TO 10 ROWS.
**
**DATA:
T_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
T_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
**
**data: NEW_table type ref to data.
**data: new_line type ref to data.
**
**FIELD-SYMBOLS: <l_table> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
**
**T_FIELDCAT-FIELDNAME = 'MATNR'.
**T_FIELDCAT-REF_TABLE = 'MARC'.
**APPEND T_FIELDCAT.
**
**T_FIELDCAT-FIELDNAME = 'WERKS'.
**T_FIELDCAT-REF_TABLE = 'MARC'.
**APPEND T_FIELDCAT.
**
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = T_FIELDCAT[]
importing
ep_table = NEW_table .
**
*ASSIGN new_table-> TO <l_table>.
**CREATE DATA new_line LIKE LINE OF <l_table>.
*ASSIGN new_line-> TO <l_line>.
**
**ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '12345'.
**ASSIGN COMPONENT 'WERKS' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '1000'.
**APPEND <L_LINE> TO <L_TABLE>.
**
**ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '52349'.
**ASSIGN COMPONENT 'WERKS' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '2000'.
**APPEND <L_LINE> TO <L_TABLE>.
**
***LOOP AT <L_TABLE> INTO <L_LINE>.
***WRITE: / <L_LINE>.
***ENDLOOP.
**
**LOOP AT T_FIELDCAT.
**T_FCAT-FIELDNAME = T_FIELDCAT-FIELDNAME.
**T_FCAT-REF_TABNAME = T_FIELDCAT-REF_TABLE.
**APPEND T_FCAT.
**ENDLOOP.
**
**CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_FCAT[]
TABLES
t_outtab = <l_table>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
**IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
**ENDIF.
plzzzz reward points if it helps
Hi all.
How can i assign all value of internal table to field symbols.
How it is beneficial in performance tunning???
2007 Dec 11 6:17 AM
Hi,
this is the code for creating the internal table using field symbols.
plzz reward points if it is helpful.
REPORT ZREPORT_TEST.
tYPE-POOLS SLIS.
**
DATA:
BEGIN OF T_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
END OF T_MARC.
**
**SELECT MATNR WERKS
FROM MARC
INTO TABLE T_MARC UP TO 10 ROWS.
**
**DATA:
T_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
T_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
**
**data: NEW_table type ref to data.
**data: new_line type ref to data.
**
**FIELD-SYMBOLS: <l_table> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
**
**T_FIELDCAT-FIELDNAME = 'MATNR'.
**T_FIELDCAT-REF_TABLE = 'MARC'.
**APPEND T_FIELDCAT.
**
**T_FIELDCAT-FIELDNAME = 'WERKS'.
**T_FIELDCAT-REF_TABLE = 'MARC'.
**APPEND T_FIELDCAT.
**
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = T_FIELDCAT[]
importing
ep_table = NEW_table .
**
*ASSIGN new_table-> TO <l_table>.
**CREATE DATA new_line LIKE LINE OF <l_table>.
*ASSIGN new_line-> TO <l_line>.
**
**ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '12345'.
**ASSIGN COMPONENT 'WERKS' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '1000'.
**APPEND <L_LINE> TO <L_TABLE>.
**
**ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '52349'.
**ASSIGN COMPONENT 'WERKS' OF STRUCTURE <l_line> TO <l_field>.
**<L_FIELD> = '2000'.
**APPEND <L_LINE> TO <L_TABLE>.
**
***LOOP AT <L_TABLE> INTO <L_LINE>.
***WRITE: / <L_LINE>.
***ENDLOOP.
**
**LOOP AT T_FIELDCAT.
**T_FCAT-FIELDNAME = T_FIELDCAT-FIELDNAME.
**T_FCAT-REF_TABNAME = T_FIELDCAT-REF_TABLE.
**APPEND T_FCAT.
**ENDLOOP.
**
**CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_FCAT[]
TABLES
t_outtab = <l_table>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
**IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
**ENDIF.
plzzzz reward points if it helps
2007 Dec 11 6:18 AM
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). 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.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb38c8358411d1829f0000e829fbfe/content.htm
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Additions
1. ... STRUCTURE s DEFAULT wa
2. ... TYPE t
3. ... TYPE LINE OF t
4. ... LIKE s
5. ... LIKE LINE OF s
This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN . All operations performed with the field symbol then directly affect the field assigned to it.
You can only use one of the additions.
Example
Output aircraft type from the table SFLIGHT using a field symbol:
FIELD-SYMBOLS <PT>.
TABLES SFLIGHT.
...
ASSIGN SFLIGHT-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... STRUCTURE s DEFAULT wa
Assigns any (internal) field string or structure to the field symbol from the ABAP/4 Dictionary ( s ). All fields of the structure can be addressed by name: <fs>-fieldname . The structured field symbol points initially to the work area wa specified after DEFAULT .
The work area wa must be at least as long as the structure s . If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.
Example
Address components of the flight bookings table SBOOK using a field symbol:
DATA SBOOK_WA LIKE SBOOK.
FIELD-SYMBOLS <SB> STRUCTURE SBOOK
DEFAULT SBOOK_WA.
...
WRITE: <SB>-BOOKID, <SB>-FLDATE.
Addition 2
... TYPE t
Addition 3
... TYPE LINE OF t
Addition 4
... LIKE s
Addition 5
... LIKE LINE OF s
You can use additions 2 to 5 to type field symbols in the same way as FORM parameters (see also Type assignment of subroutine parameters). ASSIGN performs the same type checks as with USING parameters of FORM s.
Related ASSIGN , DATA
2007 Dec 11 6:19 AM
Below is the usage where in u can use field symbol to access int table.
Below example concatenates all fields of itab t_lineitems into a single value and stores in another itab t_data.
There is nothing beneficial to performance when using FS.
hope this helps
Loop at t_lineitems.
w_cnt = 1.
DO.
ASSIGN COMPONENT w_cnt OF STRUCTURE t_lineitems TO <fl>.
IF sy-subrc <> 0.
EXIT.
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.
2007 Dec 11 6:19 AM
hi dude,
<b>i think following will help u.</b>
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.
From Performance point of View.
When you read from an internal table, there are no overheads for copying the table line to the work area. When you change an internal table with the MODIFY statement, you must first fill a work area with values, and then assign them to the internal table. If you work with field symbols instead, you do not have this overhead. This can improve performance if you have large or complex internal tables. It also makes it easier to process nested internal tables.
<b> if useful reward me with points</b>
2007 Dec 11 6:21 AM
Hi,
Just go through this.
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.
-
-
Static ASSIGN
If you already know the name of the field that you want to assign to the field symbol when you write a program, use the static ASSIGN statement:
ASSIGN both point to different fields during the program.
-
-
Dynamic ASSIGN
If you do not know the name of the field that you want to assign to the field symbol when you write a program, you can use a dynamic ASSIGN statement:
ASSIGN (.
ENDIF.
ENDFORM.
The output looks something like this:
02.06.1998
hope this helps.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |