Can I use field symbol in AT events? How?
Hi all,
I want to use field symbol in <b>AT END OF</b> event
Can I use field symbol in such event as it takes table fields only.
Kinldy look in to pseudo:
Loop itab.
AT END OF <FS1>.
ENDAT.
Endloop.
I tried in my program but it's giving me a short dump.
If it is possible to use field symbol in AT events, kindly tell me how..??
Thanks in Advance.
Sagar
Hi,
i don't know your reqirement but it is possible:
DATA: t1(4), t2 TYPE i.
FIELD-GROUPS: header.
INSERT t2 t1 INTO header.
t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 2. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 2. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 1. EXTRACT header.
t1 ='AAAA'. t2 = 3. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.
SORT BY t1 t2.
*Here begins the definition of the field symbols
FIELD-SYMBOLS:
<t1> TYPE ANY,
<t2> TYPE ANY.
ASSIGN t1 TO <t1>.
ASSIGN t2 TO <t2>.</b>
LOOP.
AT FIRST.
WRITE 'Start of LOOP'.
ULINE.
ENDAT.
AT NEW <t1>.
WRITE / ' New T1:'.
ENDAT.
AT NEW <t2>.
WRITE / ' New T2:'.
ENDAT.
WRITE: /14 t1, t2.
AT END OF <t2>.
WRITE / 'End of T2'.
ENDAT.
AT END OF <t1>.
WRITE / 'End of T1'.
ENDAT.
AT LAST.
ULINE.
ENDAT.
ENDLOOP.
Regards,
Gianpietro
Similar Messages
-
Using Field-Symbols in a user exit to change the importing parameter
Please don't ask why but I need to use a user exit, changing the importing parameter. I decided that I could do this using field-symbols.
Please excuse my ignorance but I have never used field symbols for something such as this.
Here is my goal: Loop through an internal table (im_document-item). When I find what I need I want to make a change to this line (not so hard if I am looping into a field symbol) and also append a line to the end of the table im_document-item.
I have the following so far:
DATA: wa_item TYPE accit,
wa_item_out type ACCIT_SUB.
FIELD-SYMBOLS: <document> type acc_document,
<accit> TYPE ACCIT.
LOOP AT im_document-item ASSIGNING <accit> where saknr = '0000211000'.
* Modify the curent line
wa_item = <accit>
* Append a new line into table im_document-item.
ENDLOOP.
How can I use field-symbols to append a line to this table? Please note that the table in question (im_document-item) is an importing only parameter.
Regards,
Davisthat will allow me to append an initial line with <accit> pointing to the line. Therefore I just have to modify <accit> and the new line will then have my changes?
Yep, that is exactly it. So after the APPEND statement, simply fill the fields of the <accit>.
append initial line to im_document-item ASSIGNING <accit>.
<accit>-field1 = 'Blah'.
<accit>-field2 = 'Blah'.
Regards,
Rich Heilman -
How can i write the bellow code using field symbols
data : it_mara type table of mara.
select * from mara
into it_mara.
delete it_mara where matnr = '100-100'
and meins = 'KG'.
if i do the same by using field symbols
i am getting data into <it_mara>
but
delete <it_mara> where matnr = '100-100'
and meins = 'KG'.
is showing syntax error
how to correct the error ?I think, DELETE does not allows to dynamically define the logical expression for the WHERE clausule.
Have you tried by filtering data in SELECT statement??
Something like:
if dataBase = 'MARA'.
append 'MATNR <> '100-100'' to Itab_Where[].
append 'AND MEINS <> 'KG'' to Itab_Where[].
endIf.
select * from (dataBase) where (Itab_Where) into table <my_table>.
this is possible, but I don't know if this fits your requirements. -
Modify DB by single field using Field Symbol
Hi,
please help me ,actually i have not use the field symbol in any object. i have one requirement ,i have to modify the DB by field STATUS using Field symbol ,
I am sending u my code so please help me how can i modify DB using field symbol..
gw_msg3_status1 = k_status1 .
LOOP AT gi_msg3 INTO gs_msg3.
gs_msg3-status = gw_msg3_status1 .
gs_msg3-issue = lw_issuno.
MODIFY gi_msg3 FROM gs_msg3 TRANSPORTING status.
MODIFY gi_msg3 INDEX sy-tabix FROM gs_msg3 TRANSPORTING issue status.
ENDLOOP.
Thanks & Regards,
Meenakshiperform dboperation_table using 'SET' 'BIRTHDT' '=' <fs>.
perform dboperation_table using 'WHERE' 'PARTNER' '=' <fs>
perform dboperation_update using 'BUT000'.
form dboperation_table
using p_type
p_var1
p_var2
p_var3.
data: t_l type cmst_str_data.
data: d_cx_root type ref to cx_root,
d_text type string.
try.
clear t_l.
if p_var3 is not initial.
t_l = p_var3.
condense t_l.
concatenate '''' t_l '''' into t_l.
endif.
concatenate p_var1 p_var2 t_l into t_l
separated by space.
case p_type.
when 'SET'. append t_l to g_s_t.
when 'WHERE'. append t_l to g_w_t.
endcase.
catch cx_root into d_cx_root.
d_text = d_cx_root->get_text( ).
message a398(00) with d_text.
endtry.
endform. "DBOPERATION_table
form dboperation_update
using p_tabname type zdboperation-tabname.
data: tabname type bus_table.
data: d_cx_root type ref to cx_root,
d_text type string.
try.
tabname-tabname = p_tabname.
call function 'ZDBOPERATION_UPDATE'
in update task
exporting
tabname = tabname
tables
where_table = g_w_t
set_table = g_s_t.
catch cx_root into d_cx_root.
d_text = d_cx_root->get_text( ).
message a398(00) with d_text.
endtry.
endform. "DBOPERATION_update
Hope it will help you.
Regards,
Madan. -
Delete row from internal table using field symbol.
Hi friends,
I created dynamic internal table using field symbol. I want to delete some data using where clause.
for example. i want to use like,
DELETE <FS> WHERE KUNNR = WA_KNA1-KUNNR.
Like the above statment it won't work. How i can use delete with where clause in field symbols.
Hope any one can help me.
Thanks and regards
Srikanth. Shi Srikanth,
I think you have to LOOP through the whole internal table and check each line and decide to delete or not:
LOOP at <itab> INTO <wa>.
ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <wa> TO <field>.
CHECK <field> IS ASSIGNED.
IF <field> EQ WA_KNA1-KUNNR.
DELETE ...
ENDIF.
UNASSIGN <field>.
ENDLOOP.
hope this helps
ec -
Problem in using Field Symbols in HIDE statement
Hi All,
I am working in an Upgrade project ( from 4.6B to ECC 5.0 ). In a program I found few warnings on HIDE statement because they have used Field Symbols in HIDE statement.
The warning is " HIDE on a field symbol is dangerous, but the formal parameter "" is not ".
and the piece of code is
SET EXTENDED CHECK OFF.
HIDE: flg_pick_up, <s1>, <s2>, <s3>, <s4>, <s5>, z_feld_ind.
CLEAR flg_pick_up.
SET EXTENDED CHECK ON.
all the field symbols are of type ANY. SO can any one help in removing those warnings.
Please reply me as soon as possible.
With Regards,
Amarnath SinganamalaHi amarnath,
1. Why do u want to remove
the warning ?
2. This warning (and not an error)
is a GENUINE warning,
which the system wants the user to make aware of.
3. By doing some xyz,
even if u may be able to hide the warning,
the warning may be hidden (for display purpose only),
but,
the warning will still be there inside the system.
4. I think u should ignore the warning,
(if there are no other repurcussions).
regards,
amit m. -
can anyone tell me how to use field symbols. What effect it has on performance of a program?
what r its avantages?
iam working on a report where iam facing a lot of problems in performance issue. can anyone tell how field symbols are useful in this regard?
thanx to allCheck the below links
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/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
Effect
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
Effect
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
Effect
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. -
How to use field symbol in select
Hi,
CONCATENATE 'WTG0' LV_MON INTO LV_FNAME.
ASSIGN (LV_FNAME) TO <FS>.
SELECT SINGLE <FS> FROM COSP INTO LV_SAPRST
WHERE OBJNR = LV_OBJ AND GJAHR = LV_YEAR AND WRTTP = '4' AND KSTAR = GT_INOUT-SAKNR
Error message : Unknown column name "<FS>" . field list. . field list. field list.
actually , if i use if command, i can do, but i want to use simple code by fieldsymbol.
is it possible in select command?
Thanks in advance
BenjaminHi
Hope it will help you.
reward if help.
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.
check the below links u will get the answers for your questions
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Syntax Diagram
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Extras:
1. ... TYPE type
2. ... TYPE REF TO cif
3. ... TYPE REF TO DATA
4. ... TYPE LINE OF type
5. ... LIKE s
6. ... LIKE LINE OF s
7. ... TYPE tabkind
8. ... STRUCTURE s DEFAULT wa
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
Effect
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> TYPE ANY.
DATA SFLIGHT_WA TYPE SFLIGHT.
ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... TYPE type
Addition 2
... TYPE REF TO cif
Addition 3
... TYPE REF TO DATA
Addition 4
... TYPE LINE OF type
Addition 5
... LIKE s
Addition 6
... LIKE LINE OF s
Addition 7
... TYPE tabkind
Effect
You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
Effect
Assigns any (internal) field string or structure to the field symbol from the ABAP 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.
Related
ASSIGN, DATA
Additional help
Declaring Field Symbols -
How to use field-symbols in MODIFY ... TRANSPORTING and SORT
Hi,
I need to increase the performance of an abap report using the field-symbols. More exactly the code is the following.
TYPES:
BEGIN OF itab_structure.
INCLUDE STRUCTURE nameofstructure.
TYPES:
RECNO LIKE sy-tabix,
END OF itab_structure.
DATA:
itab TYPE STANDARD TABLE OF itab_structure
WITH HEADER LINE
WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
SORT itab ASCENDING BY f1.
LOOP AT itab WHERE f1 = '10'.
itab-fn= value-n.
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
ENDLOOP.
I need your suggestions in this kind of conversion or solution.
SORT itab ASCENDING BY f1 (<-- I don't know if in this case the better performances should be obtained using field symbols and in which way)
FIELD-SYMBOLS: <fs_itab_line> TYPE LINE OF itab.
LOOP AT itab ASSIGNING <fs_itab_line> WHERE
<fs_itab_line>-f1 = '10'.
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
(I don't know if in this case the better performances should be obtained using field symbols and in which way)
ENDLOOP.
I wish to implement the field symbols or the better performance in terms of execution time in all my abap code, where it is possible.
Any suggestion will be well appreciated.
Thanks in advance for your kind support.
Regards,
GiovanniDear All,
I have appeciated your suggestions and I can conclude these points in my case:
1) The "sort" statement is not optimized in a different way using filed-symbols
2) The loop with "where" condition on a standard table is performed using filed-symbols
But ... my last point to investigate is about the statement MODIFY table TRANSPORTING f1, f2 WHERE conditions.
More exactly, in my code the execution logic of the abap code expects a global modification of the same table at the end of every (primary) loop, using the MODYFY statement.
In other words in my code I can locate two loops on the same table in the following logic:
LOOP AT table1 WHERE f1 = '10'. (#1)
updates to table1
set c1_filed, c2_filed
LOOP AT table1. (#2)
IF f1 = c1_filed AND
f2 = c2_filed.
table1-fx = 'x'.
table1-fy = 'y'.
table1-fz = 'z'.
table1-ft = 't'.
ENDIF.
MODIFY table1.
ENDLOOP. (#2)
ENDLOOP. (#1)
In better way (maybe more fast in terms of execution time) to modify a set of lines (MODIFY...TRANSPORTING...WHERE):
LOOP AT table1 WHERE f1 = '10'.
table1-fx= 'x'.
table1-fy= 'y'.
table1-fz= 'z'.
table1-ft= 't'.
MODIFY itab
TRANSPORTING fx fy fz ft
WHERE f1 = c1_filed AND
f2 = c2_field.
ENDLOOP.
My aim is to use field-symbols everywhere possible for speeding up the execution of my code,by maintaining this logic.
My proposal should be the following but I need your kind opinion.
FIELD-SYMBOLS: <fs_#1_line> TYPE LINE OF table1.
FIELD-SYMBOLS: <fs_#2_line> TYPE LINE OF table1.
LOOP AT table1 WHERE f1 = '10' ASSIGNING <fs_#1_line>. (#1)
updates to table1
set c1_filed, c2_filed
LOOP AT table1 ASSIGNING <fs_#2_line>. (#2)
IF <fs_#2_line>-f1 = c1_filed AND
<fs_#2_line>-f2 = c2_filed.
<fs_#2_line>-fx = 'x'.
<fs_#2_line>-fy = 'y'.
<fs_#2_line>-fz = 'z'.
<fs_#2_line>-ft = 't'.
ENDIF.
ENDLOOP. (#2)
ENDLOOP. (#1)
Your kind support is very important for me.
Thanks in advance.
Regards,
Giovanni -
How to use field symbols in program
how to use field symbols can any one explain with example please..
Regards,
venki...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.
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.
check the below links u will get the answers for your questions
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Syntax Diagram
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Extras:
1. ... TYPE type
2. ... TYPE REF TO cif
3. ... TYPE REF TO DATA
4. ... TYPE LINE OF type
5. ... LIKE s
6. ... LIKE LINE OF s
7. ... TYPE tabkind
8. ... STRUCTURE s DEFAULT wa
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
Effect
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> TYPE ANY.
DATA SFLIGHT_WA TYPE SFLIGHT.
ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... TYPE type
Addition 2
... TYPE REF TO cif
Addition 3
... TYPE REF TO DATA
Addition 4
... TYPE LINE OF type
Addition 5
... LIKE s
Addition 6
... LIKE LINE OF s
Addition 7
... TYPE tabkind
Effect
You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
Effect
Assigns any (internal) field string or structure to the field symbol from the ABAP 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.
<b>Reward points for useful Answers</b>
Regards
Anji -
How to use Field-symbol with dynamic select query
Can anybody tell me, how to use field-symbols in the dynamic select query.
FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.
1. ... typing
2. ... STRUCTURE struc DEFAULT dobj
The FIELD-SYMBOLS statement declares a field symbol <fs>. The name conventions apply to the name fs. 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.
eg.
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: BEGIN OF line,
string1(10) VALUE '0123456789',
string2(10) VALUE 'abcdefghij',
END OF line.
WRITE / line-string1+5.
ASSIGN line-string1+5(*) TO <fs>.
WRITE / <fs>.
output:
56789
56789
reward if helpful
anju -
Re: Problem in ALV reports using Field symbols
Hi Friends,
Can you tell me how to convert a normal report using field symbols into ALV report
can ypu please suggest me any solutions.I am sending the code along with this mail.
Regards,
Dinesh
<b>Coding:</b>
*& Report YSDBTEMP *
REPORT YSDBTEMP .
tables: ekko , ekpo .
TYPE-POOLS: SLIS.
*Internal Table Declaration
data: begin of line ,
ebeln like ekko-ebeln , "Purchasing Document No.
bedat like ekko-bedat , "Purchasing Document Date
matnr like ekpo-matnr , "Material No.
netwr like ekpo-netwr , "Net Order Value in PO Currancy
meins like ekpo-meins , "UOM
change like ekpo-menge ,
end of line .
*Internal table Declaration
DATA: IT_final like table of line with header line.
DATA : FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV with header line.
DATA : V_REPID TYPE SYREPID.
DATA : IT_LISTHEADER TYPE SLIS_T_LISTHEADER.
data : i_layout type slis_layout_alv .
Header for Main Grid Display
data:i_header1 type slis_t_listheader with header line.
Header for Interactive Report Display
data:i_header2 type slis_t_listheader with header line.
*Field Symbol declaration.
FIELD-SYMBOLS: <FS> type any table.
**select option Declaration
selection-screen begin of block block.
select-options: s_ebeln for ekko-ebeln .
selection-screen end of block block .
start-of-selection.
perform get_data.
perform field_cat.
perform layout using i_layout .
perform grid_display .
*& Form get_data
text
--> p1 text
<-- p2 text
FORM get_data .
SELECT EKKO~EBELN
EKKO~BEDAT
EKPO~EBELP
EKPO~MATNR
EKPO~NETWR
EKPO~MEINS
EKPO~MENGE
EKPO~BPRME
INTO CORRESPONDING FIELDS OF table IT_FINAL
FROM EKKO INNER JOIN EKPO ON EKKOEBELN = EKPOEBELN
WHERE EKKO~EBELN IN S_EBELN.
ENDFORM. " get_data
*& Form field_cat
text
--> p1 text
<-- p2 text
FORM field_cat .
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order No'.
fieldcatalog-col_pos = 1.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'BEDAT'.
fieldcatalog-seltext_m = 'Purchasing Document Date'.
fieldcatalog-col_pos = 2.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material No'.
fieldcatalog-col_pos = 3.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Net order'.
fieldcatalog-col_pos = 4.
append fieldcatalog .
clear fieldcatalog.
ENDFORM. " field_cat
*& Form layout
text
-->P_I_LAYOUT text
FORM layout USING P_I_LAYOUT.
i_layout-lights_tabname = 'IT_FINAL'.
i_layout-box_tabname = 'IT_FINAL'.
ENDFORM. " layout
*& Form grid_display
text
--> p1 text
<-- p2 text
FORM grid_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'SET_PO_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = I_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
*IT_EVENTS = I_EVENT[]
TABLES
t_outtab = <fs>.
endform.Hi,
This is one sample program,
Check this.
I hope it is helpful to you.
TABLES : zeastable_02,zeastable_04.
TYPE-POOLS : slis.
TYPES : BEGIN OF fieldst,
name LIKE zeastable_02-name,
znum LIKE zeastable_02-znum,
empno LIKE zeastable_04-empno,
zempsalary LIKE zeastable_04-zempsalary,
END OF fieldst.
DATA itab TYPE TABLE OF fieldst WITH HEADER LINE.
DATA: w_report_id LIKE sy-repid. "Program name
DATA: w_title TYPE lvc_title VALUE 'Assignment 1 in ALV'.
DATA: w_layout TYPE slis_layout_alv. "Layout setup
DATA: w_fieldcat TYPE slis_t_fieldcat_alv. "Field Catlog
START-OF-SELECTION.
SELECT-OPTIONS employee FOR zeastable_04-empno.
SELECT zeastable_02name zeastable_02znum
zeastable_04empno zeastable_04zempsalary
INTO CORRESPONDING FIELDS OF TABLE itab FROM
zeastable_02 INNER JOIN zeastable_04 ON
zeastable_02name = zeastable_04name
WHERE zeastable_04~empno IN employee.
w_report_id = sy-repid.
PERFORM i_layout CHANGING w_layout.
PERFORM i_fieldcat CHANGING w_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'ZEASALV_04'
i_grid_title = w_title
is_layout = w_layout
it_fieldcat = w_fieldcat
i_save = 'A'
TABLES
t_outtab = itab
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.
PERFORM i_layout CHANGING w_layout.
PERFORM i_fieldcat CHANGING w_fieldcat.
*& Form i_layout
text
<--P_W_LAYOUT text
form i_layout changing p_w_layout.
clear w_layout.
w_layout-colwidth_optimize = 'X'.
w_layout-edit = ' '.
endform. " i_layout
*& Form i_fieldcat
text
<--P_W_FEILDCAT text
form i_fieldcat changing p_w_feildcat.
data: l_line_fieldcat type slis_fieldcat_alv.
clear l_line_fieldcat.
l_line_fieldcat-fieldname = 'NAME'.
l_line_fieldcat-ref_tabname = 'itab'.
l_line_fieldcat-seltext_m = 'NAME'.
l_line_fieldcat-key = 'X'.
append l_line_fieldcat to w_fieldcat.
clear l_line_fieldcat.
l_line_fieldcat-fieldname = 'ZNUM'.
l_line_fieldcat-ref_tabname = 'itab'.
l_line_fieldcat-seltext_m = 'NUMBER'.
l_line_fieldcat-key = 'X'.
append l_line_fieldcat to w_fieldcat.
clear l_line_fieldcat.
l_line_fieldcat-fieldname = 'EMPNO'.
l_line_fieldcat-ref_tabname = 'itab'.
l_line_fieldcat-seltext_m = 'EMPLNUM'.
*l_line_fieldcat-key = 'X'.
append l_line_fieldcat to w_fieldcat.
clear l_line_fieldcat.
l_line_fieldcat-fieldname = 'ZEMPSALARY'.
l_line_fieldcat-ref_tabname = 'itab'.
l_line_fieldcat-seltext_m = 'SALARY'.
*l_line_fieldcat-key = 'X'.
append l_line_fieldcat to w_fieldcat.
endform. " i_fieldcat
Reward for useful answers. -
Using field-symbols giving dump " the output area is too small. "
Hi All,
Good Afternoon.
I am creating a report using field-symbols. The purpose is :
"This development involves extracting all the fields and the entire data, of any SAP table, and download it as a ; seperator file."
For this I wrote following code:
*& Report ZTOOL
REPORT ztool1.
Tables***************************************
DATA : i_tab TYPE TABLE OF dfies WITH HEADER LINE.
Variables***************************************
DATA dref TYPE REF TO data.
FIELD-SYMBOLS <ft> TYPE ANY TABLE." with header line.
FIELD-SYMBOLS <fs> TYPE ANY .
DATA: w_heading(5000),
w_line(5000).
CONSTANTS sep TYPE c VALUE ';'.
Selection Screen*********************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS : p_tab LIKE dfies-tabname OBLIGATORY.
PARAMETERS : p_file(100) TYPE c .
PARAMETERS : p_lfile(100) TYPE c .
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
ONLY = ' '
tabname = p_tab
WITHTEXT = 'X'
IMPORTING
HEADER =
RC =
TABLES
fieldtab = i_tab
EXCEPTIONS
internal_error = 1
no_texts_found = 2
table_has_no_fields = 3
table_not_activ = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
SELECT * FROM (p_tab) INTO <fs> .
endselect.
CREATE DATA dref TYPE STANDARD TABLE OF (p_tab).
ENDSELECT.
assign dref to <fs> casting.
ASSIGN dref->* TO <ft>.
SELECT & FROM (p_tab) INTO table <ft>.
OPEN DATASET p_lfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT i_tab.
IF sy-index = 1.
w_heading = i_tab-fieldname.
ELSE.
CONCATENATE w_heading i_tab-fieldname INTO w_heading SEPARATED BY sep.
ENDIF.
ENDLOOP.
TRANSFER w_heading TO p_lfile.
LOOP AT <ft> into <ft>.
clear w_line.
LOOP AT i_tab.
ASSIGN COMPONENT i_tab-fieldname OF STRUCTURE <ft> TO <fs>.
IF sy-index = 1.
w_line = <fs> .
ELSE.
CONCATENATE w_line <fs> into w_line SEPARATED BY sep.
ENDIF.
ENDLOOP.
TRANSFER w_line TO p_file.
ENDLOOP.
The program is executed well till the statement :
SELECT * FROM (p_tab) INTO <fs> .
endselect.
But here it gives the following dump :
"Error analysis
In an Open SQL select, the output area used t
records must be at least as wide as the datab
records are being read.
In this particular case, the database table i
but the output area is only 2 bytes wide."
Can you please help me solve this problem.
Thanks in advance.Hi Abhii,
Both are having the same number of fields.
The only problem is with the data and time (in my scenario). Here, actual length of date is 8 and maximum length is 10. and for time the actual length is 6 and maximum length is 8.
So, my work area it is taking only the actual length but not the maximum length because of this it is going to dump.
Can i have any thing which also considers the maximum length of any field at a domain level so that by work area bytes should match according to the db table byte length.
Thanks
rohith -
HOW CAN I SEND FIELD SYMBOL TO SUBROUTINE
HAI,
HOW CAN I SEND FIELD SYMBOL TO SUBROUTINE
HOW CAN I COME BACK FROM 5TH INTERACTIVE REROT TO 2ND
INTERACTIVE REPORT.
THANK YOU.
ASHOKHi
Write some code in the program to come to 2nd list from 5th list
if sy-lsind = 5.
sy-lsind = 2.
endif.
for field symbols see the doc
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.
check the below links u will get the answers for your questions
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Syntax Diagram
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Extras:
1. ... TYPE type
2. ... TYPE REF TO cif
3. ... TYPE REF TO DATA
4. ... TYPE LINE OF type
5. ... LIKE s
6. ... LIKE LINE OF s
7. ... TYPE tabkind
8. ... STRUCTURE s DEFAULT wa
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
Effect
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> TYPE ANY.
DATA SFLIGHT_WA TYPE SFLIGHT.
ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... TYPE type
Addition 2
... TYPE REF TO cif
Addition 3
... TYPE REF TO DATA
Addition 4
... TYPE LINE OF type
Addition 5
... LIKE s
Addition 6
... LIKE LINE OF s
Addition 7
... TYPE tabkind
Effect
You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
Effect
Assigns any (internal) field string or structure to the field symbol from the ABAP 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.
Related
ASSIGN, DATA
Additional help
Declaring Field Symbols
Reward points if useful
Regards
Anji -
How to code this using FIELD SYMBOL ?
Hello All,
I never used field symbols before and I think this is where I should use field symbols in my program.
I have a selection parameter period (p_period) and based on the p_period value(XX), I need to display the HSLXX, KSLXX from table GLT0 using field symbols. Can anyboby help me?
Thanks,
Chandni ReddyRight, you can use field-symbols, here is a example.
report zrich_0002.
data: xGLT0 type GLT0 .
data: field_name(20) type c.
field-symbols: <fs> .
parameters: p_per(2) type n.
* Read a line from table
select Single * from glt0 into xglt0.
* Build the field name that you want to access
concatenate 'XGLT0-HSL' p_per into field_name.
* Assign it
assign (field_name) to <fs>.
* Write it
write:/ <fs>.
Regards,
Rich Heilman
Maybe you are looking for
-
Blue screen after installing labview 8
I recently installed Labview 8 Professional Dev. Suite on to a Win. XP SP2 system. The image before installation was stable. After the installation and reboot, the system blue screens (I have been unable to read the exact message on the blue screen
-
VL02N Error: Output could not be issued with smartforms
Hi All, Currently I am doing some customization on existing delivery note smartforms LE_SHP_DELNOTE on ECC 6.0. I have copied it from the above smartforms and name it as ZLE_SHP_DELNOTE. Did most of the modification according to the user's format req
-
Hi, Can you please explain me the complete procedure to be followed and precautions to be taken for upgrading SPAU(program,func groups,data elements,tables,structures, etc) objects, SPDD objects and custom objects(programs,func grps etc..) from 4.6c
-
Prerequisites for SAP XI installation?
Hi, Could any one help me out to know the prerequisite for SAP XI installation? Thanks & Regards, Yaseen Mahammad.
-
Hi, I am looking for incorporating deep linking into my site which is developed using Flex2.0 and AS3. I searched in google and found SWFAddress2.0(an open source by Asual). I tried to go through the samples and docs ,but i was not able to find a goo