Looping a Field symbol.
Hi,
Can someone explain what to me what the following statement means?
Data: i_tab TYPE STANDARD TABLE.
I looked it up and and it says that it is an ABAP built in type which is generic, but i fail to understand its usage.
And here is my scenario.
Field-symbols: <IT_DETAILS > TYPE STANDARD TABLE,
<lines> TYPE (Transparent dictionary table)
LOOP AT <lt_details> ASSIGNING <lines>.
move <lines>-field to l_variable.
Endloop
Upon execution, I get a dump at the Loop statement saying that there is an 'ASSIGN_TYPE_CONFLICT'.You attempted to assign a field to a typed field symbol,but the field does not have the required type.
How to correct the error
Adapt the type of the field symbol to the type of the field or use an
untyped field symbol or use the "CASTING" addition.
Can someone explain the correct way to type the field symbol and implement the loop construct?
Any help will be highly appreciated
Hello,
Can you tell us the type of the variable l_variable?
Example:
FIELD-SYMBOLS: <pos_data> TYPE ANY,
<gt_pos_data> TYPE table.
DATA : lt_csks LIKE gt_csks WITH HEADER LINE.
LOOP AT <gt_pos_data> ASSIGNING <pos_data>.
MOVE-CORRESPONDING <pos_data> TO lt_csks.
ENDLOOP.
Similar Messages
-
Loop at field-symbol (any table) into string ?
Hi Everyone,
I need little help, I have a requirement to extract table content with columns names as the header.
After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through
a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can
write to the file.
REPORT zlab_tbl_export.
DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
DATA v_file(100) VALUE 'c:\sap_export.txt'.
DATA line(1000).
DATA: o_data TYPE REF TO data.
CREATE DATA o_data TYPE TABLE OF (table_name).
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN o_data->* TO <table>.
SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
>>>>>>> LOOP at <table> into line. >>>>>>>>>>>> " Here the code breaks and fail
TRANSFER line to v_file.
WRITE :/ line.
ENDLOOP.
CLOSE DATASET v_file.
Exception Message
|Error analysis |
| You attempted to move one data object to another. |
| This is not possible here because the conversion of a data object |
| of type "v" to type "C" is not supported. |
| |
| List of internal ABAP types: |
| |
| C Text (Character) |
| N Numerical text |
| D Date (YYYYMMDD) |
| T Time (HHMMSS) |
| X Hexadecimal |
| I Integer |
| P Packed number |
| F Floating point number |
| |
| h Internal table |
| r Object reference |
| l Data reference |
| g String of type C |
| y String of type X |
| s 2-byte integer with plus/minus sign |
| b 1-byte integer without plus/minus sign |
| u Structure (flat structure) |
| v Structure (deep structure) |Hi Everyone, I need little help, I have a requirement to extract table content with columns names as the header. After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can write to the file.
thie is the code
REPORT zlab_tbl_export.
DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
DATA v_file(100) VALUE 'c:\sap_export.txt'.
DATA line(1000).
DATA: o_data TYPE REF TO data.
CREATE DATA o_data TYPE TABLE OF (table_name).
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN o_data->* TO <table>.
SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP at <table> into line. " Fail here
TRANSFER line to v_file.
WRITE :/ line.
ENDLOOP.
CLOSE DATASET v_file.
and this is the exception:
Error analysis
You attempted to move one data object to another.
This is not possible here because the conversion of a data object
of type v to type C is not supported.
Edited by: Misbah on Jan 7, 2010 11:50 PM -
Hi friends,
I have to populate(Display) the data using field symol.
I am providing my code:
data: o_ref type ref to data.
field-symbols: <Lt_table> type standard table.
parameters: p_tab type tabname.
start-of-selection.
create data o_ref type table of (p_tab).
assign o_ref->* to <lt_table>.
select * into table <lt_table> from (p_tab).
I am unable to papulate the data.please help me out.
thanks,
satyaREPORT z_dynamic.
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
* FORM get_structure *
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM.
* FORM create_dynamic_itab *
FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM.
* FORM get_data *
FORM get_data.
* Select Data from table.
SELECT * INTO TABLE <dyn_table>
FROM (p_table).
ENDFORM.
* FORM write_out *
FORM write_out.
* Write out data from table.
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <dyn_field>.
ELSE.
WRITE: <dyn_field>.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. -
Can limit loop on FIELD-SYMBOLS list ?
i have loop ....
LOOP AT <GT_TABLE> ASSIGNING <DYN_TABLE1> .
i want to do
LOOP AT <GT_TABLE> ASSIGNING <DYN_TABLE1> where
but i get message that the 'LOOP .. WHERE'
Have to be statically definehi Dakota,
the WHERE won't work here. The reason is the actual structure of <DY_TABLE1> only determined at runtime.
The workaround is that when you are in the LOOP already, you have to ASSIGN fields of the dynamic structure (ASSIGN COMPONENT ...) than you can decide if you need that record or not, if not than CONTINUE...
hope this helps
ec -
How to use different field symbols to append data in a loop
Hi experts!
I have to loop over a itab and I want to save different into one table.
See my code below:
DATA: l_hours TYPE i,
grfk_ok_code TYPE sy-ucomm,
grfk_values TYPE TABLE OF GPRVAL WITH HEADER LINE,
grfk_coltxt TYPE TABLE OF GPRTXT WITH HEADER LINE,
wa_ztab TYPE zqm_chq_prueflos,
l_index TYPE n,
l_field TYPE string,
l_line_check TYPE string
FIELD-SYMBOLS:
<fs_0102> TYPE ANY,
<fs_0304> TYPE ANY,
<fs_0506> TYPE ANY,
<fs_grenze> TYPE ANY
REFRESH: grfk_values.
CLEAR: l_hours.
LOOP AT ztab INTO wa_ztab.
AT NEW qase_serialnr.
CLEAR: l_line_check.
IF wa_ztab-qase_serialnr CS '-01'
OR wa_ztab-qase_serialnr CS '-02'.
grfk_values-rowtxt = 'gelötet'.
l_line_check = '0102'.
ELSEIF wa_ztab-qase_serialnr CS '-03'
OR wa_ztab-qase_serialnr CS '-04'.
grfk_values-rowtxt = 'geglüht'.
l_line_check = '0304'.
ELSEIF wa_ztab-qase_serialnr CS '-05'
OR wa_ztab-qase_serialnr CS '-06'.
grfk_values-rowtxt = 'unbehandelt'.
l_line_check = '0506'.
ELSE.
grfk_values-rowtxt = 'serialnr_wrong'.
ENDIF.
ENDAT.
***---------------------------------------------------->
AT NEW qapp_usern1.
* X-axis: values are:0,50,100,...,400
grfk_coltxt-coltxt = wa_ztab-qapp_usern1.
SHIFT grfk_coltxt-coltxt LEFT DELETING LEADING '0'.
APPEND grfk_coltxt.
UNASSIGN <fs_grenze>.
CLEAR: l_index, l_field.
l_index = sy-tabix.
CONCATENATE 'grfk_values-val' l_index INTO l_field.
ASSIGN (l_field) TO <fs_grenze>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
<fs_grenze> = 10.
APPEND grfk_values.
ENDAT.
IF l_line_check = '0102'.
UNASSIGN <fs_0102>.
CLEAR: l_index, l_field.
l_index = sy-tabix.
CONCATENATE 'grfk_values-val' l_index INTO l_field.
ASSIGN (l_field) TO <fs_0102>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
<fs_0102> = wa_ztab-cf_dgp.
ELSEIF l_line_check = '0304'.
UNASSIGN <fs_0304>.
CLEAR: l_index, l_field.
l_index = sy-tabix.
CONCATENATE 'grfk_values-val' l_index INTO l_field.
ASSIGN (l_field) TO <fs_0304>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
<fs_0304> = wa_ztab-cf_dgp.
ELSEIF l_line_check = '0506'.
UNASSIGN <fs_0506>.
CLEAR: l_index, l_field.
l_index = sy-tabix.
CONCATENATE 'grfk_values-val' l_index INTO l_field.
ASSIGN (l_field) TO <fs_0506>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
<fs_0506> = wa_ztab-cf_dgp.
ENDIF.
ENDLOOP.
My goal should be to fill the graphic with 4 Lines:
1 is boarderline.
2-3 are the lines with the looped values in "ztab"
Do I have to use references to write the values in into different rows of internal table "grfk_values"????
With this code I want to fill the itab which I need for the GFW_PRES_SHOW function.
The table I have to commit has the following structure:
-rowtxt
-val1
-val2
-val31
EDIT:
My current output are 2 lines the first has value 0 for each point and the second shows the correct values... The boarder which always should have value 10 is completly not shown.hopen this will help
report zrich_0001 .
data: begin of itab1 occurs 0,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of itab1.
data: begin of itab2 occurs 0,
flda(10) type c,
fldb(10) type c,
fldc(10) type c,
end of itab2.
field-symbols: <fs_table> type table,
<fs_wa>,
<fs>.
data: mod_field(10) type c.
itab1-fld1 = '1'. itab1-fld2 = '2'. itab1-fld3 = '3'. append itab1.
itab1-fld1 = '4'. itab1-fld2 = '5'. itab1-fld3 = '6'. append itab1.
itab2-flda = 'A'. itab2-fldb = 'B'. itab2-fldc = 'C'. append itab2.
itab2-flda = 'D'. itab2-fldb = 'E'. itab2-fldc = 'F'. append itab2.
assign itab1[] to <fs_table>.
assign itab1 to <fs_wa>.
mod_field = 'FLD2'.
perform modify_table.
perform write_table.
assign itab2[] to <fs_table>.
assign itab2 to <fs_wa>.
mod_field = 'FLDC'.
perform modify_table.
perform write_table.
FORM modify_table *
form modify_table.
loop at <fs_table> into <fs_wa>.
assign component mod_field of structure <fs_wa> to <fs>.
<fs> = 'Modified'.
modify <fs_table> from <fs_wa>.
endloop.
endform.
FORM write_table *
form write_table.
loop at <fs_table> into <fs_wa>.
do.
assign component sy-index of structure <fs_wa> to <fs>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <fs>.
else.
write: <fs>.
endif.
enddo.
endloop.
endform.
regards
navjot
reward points if helpfull -
Hi,
I need to change this code using Field symbols. Can anybody help me?
DATA: i_history TYPE STANDARD TABLE OF mmreq_history INITIAL SIZE 0,
wa_history TYPE mmreq_history,
l_menge LIKE eban-menge.
LOOP AT i_history INTO wa_history.
IF wa_history-bstyp EQ dc_plan.
ADD wa_history-menge TO l_menge.
ELSEIF wa_history-bstyp EQ dc_abierto.
CLEAR: wa_history-menge, wa_history-meins.
SELECT SINGLE ktmng meins
FROM ekpo
INTO (wa_history-menge, wa_history-meins)
WHERE ebeln EQ wa_history-ebeln
AND ebelp EQ wa_history-ebelp.
MODIFY i_history FROM wa_history.
ADD wa_history-menge TO l_menge.
ENDIF.
ENDLOOP.
Thanks!!!
CarlesHi
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 -
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. -
Field symbols and READ TABLE with system code 4
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RTHai Rob
Go through the following Code
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
Thanks & regards
Sreenivasulu P -
"Read table" and field symbols
Hello all,
I have a (hopefully simple) question. Let's suppose I want to do the following:
loop at itab1 assigning <fs1>.
read table itab2 assigning <fs2> with table key <fs1>-field1.
if sy-subrc eq 0.
move <fs2>-field1 to ls_out-field1.
endif.
read table itab3 assigning <fs3> with table key <fs1>-field2.
if sy-subrc eq 0.
move <fs3>-field1 to ls_out-field2.
endif.
endloop.
It's also possible to do the following instead:
loop at itab1 assigning <fs1>.
unassign: <fs2>,
<fs3>.
read table itab2 assigning <fs2> with table key <fs1>-field1.
read table itab3 assigning <fs3> with table key <fs1>-field2.
if <fs2> is assigned.
move <fs2>-field1 to ls_out-field1.
endif.
if <fs3> is assigned.
move <fs3>-field1 to ls_out-field2.
endif.
endloop.
My question is: is it "better" to check sy-subrc after each read, and then do a move statement within that if statement, or is it better to check whether the field symbol is assigned each time I want to fill in a field and read everything at the same time?
I'm only really concerned about the case where you don't want to drop out of the loop after the read (so if the read fails you just don't fill any data in). I'm also discounting potential human error (otherwise the sy-subrc method wins hands-down).Just to close this one (albeit somewhat belatedly). I asked Harry Dietz (the ABAP Performance blogging fella) what he would suggest, and he says sy-subrc all the way. Checking that an integer is zero is considerably faster than checking for the assignment, or otherwise, of a field symbol. Furthermore, whilst the field symbol method has the potential to be faster than the sy-subrc method given some compiler optimizations, unfortunately these optimizations don't exist in the ABAP compiler - they're there in the Java compiler though! Shame really. Apparently the ABAP compiler is a pretty simple beast.
Anyway - thanks Harry for clearing this one up! -
Field symbol has not yet been assigned. ???
Dear Experts ,
W hen i tried to execute my program this error appears :
Short text
Field symbol has not yet been assigned.
What happened?
Error in the ABAP Application Program
The current ABAP program "SAPLSLVC" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
You attempted to access an unassigned field symbol
(data segment 32821).
This error may occur if
- You address a typed field symbol before it has been set with
ASSIGN
- You address a field symbol that pointed to the line of an
internal table that was deleted
- You address a field symbol that was previously reset using
UNASSIGN or that pointed to a local field that no
longer exists
- You address a global function interface, although the
respective function module is not active - that is, is
not in the list of active calls. The list of active calls
can be taken from this short dump.
and Here is my CODE :
*& Report ZPO
Report ZPO1.
type-pools slis.
PARAMETERS : PO_Doc like EKBE-EBELN DEFAULT '4800000007'.
PARAMETERS : Plant TYPE WERKS DEFAULT '1000'.
PARAMETERS : PO_ORG TYPE EKORG DEFAULT ''.
data TtlS type mara-wesch .
data TtlH type mara-wesch .
data Ttl type mara-wesch .
data ZEKBE type TABLE OF EKBE.
data ZEKBER type EKBE.
data ZEKPO type TABLE OF EKPO.
data ZEKPOR type EKPO.
data ZEKKOR TYPE EKKO.
data ZNAME1F type LFA1-LIFNR.
data ZWGBEZF TYPE T023T-WGBEZ.
data i type n.
data counter type n.
types : begin of SBAGDS,
Serial Type n, "Purchase Order
EBELN like EKKO-EBELN, "Purchase Order
MATNR like EKPO-MATNR, "Material
TXZ01 like EKPO-TXZ01, "Short Text
MATKL like EKPO-MATKL, "Material Group
WGBEZ like T023T-WGBEZ, "Material Group Desc"
SUBMI like EKKO-SUBMI, "GPM
CHARG like EKBE-CHARG, "Batch
LIFNR like EKKO-LIFNR, "Vendor
NAME1 like LFA1-NAME1, "Vendor Name
RECV like mara-wesch, "Received Quantity
REVR like mara-wesch, "Reversed Quantity
DELV like mara-wesch, "Delivered Quantity
end of SBAGDS .
DATA : BAGDS TYPE SBAGDS OCCURS 0 WITH HEADER LINE.
data Struc like BAGDS.
data: gr_table like BAGDS OCCURS 0 WITH HEADER LINE.
data: gt_fieldcat type slis_t_fieldcat_alv, gt_outtab type SBAGDS occurs 0 with header line.
INITIALIZATION.
i = 0.
counter = 0 .
perform field_cat_init using gt_fieldcat[].
FORM field_cat_init using rt_fieldcat type slis_t_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv,
pos type i value 1.
clear LS_FIELDCAT.
*Column 1
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'Serial'.
ls_fieldcat-SELTEXT_L = 'Serial'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 2
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'EBELN'.
ls_fieldcat-SELTEXT_L = 'Purchase Order'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 3
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-SELTEXT_L = 'Material'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 4
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'TXZ01'.
ls_fieldcat-SELTEXT_L = 'Short Text'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 5
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MATKL'.
ls_fieldcat-SELTEXT_L = 'Material Group'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 6
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'WGBEZ'.
ls_fieldcat-SELTEXT_L = 'Material Group Desc'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 7
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'SUBMI'.
ls_fieldcat-SELTEXT_L = 'GPM'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 8
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'CHARG'.
ls_fieldcat-SELTEXT_L = 'Batch'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 9
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'LIFNR'.
ls_fieldcat-SELTEXT_L = 'Vendor'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 10
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'NAME1'.
ls_fieldcat-SELTEXT_L = 'Vendor Name'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 11
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'RECV'.
ls_fieldcat-SELTEXT_L = 'Received Quantity'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 12
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'REVR'.
ls_fieldcat-SELTEXT_L = 'Reversed Quantity'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
*Column 13
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'DELV'.
ls_fieldcat-SELTEXT_L = 'Delivered Quantity'.
ls_fieldcat-DDICTXT = 'L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
pos = pos + 1.
endform.
START-OF-SELECTION.
select SINGLE * from EKKO into ZEKKOR where EBELN = PO_DOC.
select SINGLE * from EKPO into ZEKPOR where EBELN = PO_DOC.
select SINGLE NAME1 from LFA1 into ZNAME1F where LIFNR = ZEKKOR-LIFNR.
* ' Buliding Structure
Struc-EBELN = ZEKPOR-EBELN.
Struc-SUBMI = ZEKKOR-SUBMI.
Struc-LIFNR = ZEKKOR-LIFNR.
Struc-Name1 = ZNAME1F.
select * from EKPO into TABLE ZEKPO where EBELN = PO_Doc and WERKS = plant.
LOOP at ZEKPO into ZEKPOR.
select SINGLE WGBEZ from T023T into ZWGBEZF WHERE MATKL = ZEKPOR-MATKL .
counter = counter + 1.
* ' Buliding Structure
Struc-Serial = counter.
Struc-MATNR = ZEKPOR-MATNR.
Struc-TXZ01 = ZEKPOR-TXZ01.
Struc-MATKL = ZEKPOR-MATKL.
Struc-WGBEZ = ZWGBEZF.
* Calcualting Debit transactions from PO History
select * from EKBE into table ZEKBE where EBELN = PO_Doc and MATNR = ZEKPOR-MATNR and EBELP = ZEKPOR-EBELP and BWART NOT LIKE '' and SHKZG = 'S'.
LOOP AT ZEKBE INTO ZEKBER.
TtlS = TtlS + ZEKBER-MENGE.
ENDLOOP.
* ' Buliding Structure
Struc-CHARG = ZEKBER-CHARG.
Struc-RECV = TtlS.
Ttl = TtlS.
clear TtlS.
* Calcualting Credit transactions from PO History
select * from EKBE into table ZEKBE where EBELN = PO_Doc and MATNR = ZEKPOR-MATNR and EBELP = ZEKPOR-EBELP and BWART NOT LIKE '' and SHKZG = 'H'.
LOOP AT ZEKBE INTO ZEKBER.
TtlH = TtlH + ZEKBER-MENGE.
ENDLOOP.
* ' Buliding Structure
Struc-REVR = TtlH.
* Calculating Total Delivered
Ttl = Ttl - TtlH.
clear TtlH.
* ' Buliding Structure
Struc-DELV = Ttl.
clear Ttl.
* Writtng ITAB
APPEND Struc to BAGDS.
ENDLOOP.
* Reading ITAB
* WRITE : / , 'ITAB Begin : ' .
* loop at BAGDS into Struc.
* counter = counter + 1.
* write : /,'Serial : ',counter.
* write : / ,'PO : ',Struc-EBELN.
* write : / ,'Vendor : ',Struc-LIFNR.
* write : / ,'Vendor Name : ',Struc-NAME1.
* write : / ,'Material : ',Struc-MATNR.
* write : /,'Short Text: ',Struc-TXZ01.
* write : / ,'Model : ',Struc-MATKL.
* write : / ,'Model Desc : ',Struc-WGBEZ.
* write : /,'GPM : ',Struc-SUBMI.
* write : /,'Lot : ',Struc-CHARG.
* write : /,'Received : ',Struc-RECV.
* write : /,'Reversed : ',Struc-REVR.
* write : /,'Delivered : ',Struc-DELV,/,/,/.
* ENDLOOP.
* Call ALV Grid Viewer
*BREAK-POINT.
gr_Table[] = BAGDS[].
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SBAGDS'
IT_FIELDCAT = gt_fieldcat[]
TABLES
T_OUTTAB = gr_Table.
Please Advise
Edited by: Sap Sap on Jul 27, 2009 12:18 PM
Edited by: Sap Sap on Jul 27, 2009 12:22 PM
Edited by: Sap Sap on Jul 27, 2009 12:22 PMHi,
The problem seems to be in your ALV grid display.
The reason must be your field catalog.
Just check your fieldcatalog.
The value in the fieldname field of the fieldcatalog should be same as the fieldname in your internal table and should be in capital letters.
Probably you must have mistyped some field.
Kinldy check.
Regards,
Ankur Parab -
Field-symbols v/s Object references in OO-ABAP
Hi,
can anyone please tell me what is the difference between using field-symbols and object references in OO ABAP? Is there a specific need for field-symbols now that we have references?
Thanks.
Shakul.Hi ,
Please note that both Field symbols & Object References are different .
You can use Field symbols during the following situations
1) When you want to modify the value of internal table, the field symbol would be useful since you do not have to use any Modify statement as in case of work area. The Field symbol works as a pointer and any changes to the field symbol will directly affect the value of the internal table
2) Make sure that you do not reassign the field symbol within a Loop iteration
3) Field symbols are useful when you work with dynamic internal tables ( tables whose structure is determined during run time)
4) After Read an internal table ( Read itab...) into a Field symbol, make sure you do a Sy-subrc check or check if the field symbol is assigned.IF not this will give you a run time error
You can use Object References while creating an object to a class. They are instances of a class.
Thanks,
Chakram Govindarajan -
ALV report with internal in field symbol
Hi Shifu ABAP,
I have ALV report.
My problem is when I tried to do sum using the sum icon. I got a message 'desired operation cannot be performed for column 'Dignostic delay'. Is it because I used field symbol, then when I clicked on the column it didn't recorgnise the field.
FYI.
1)The internal table for my ALV report is stored in field symbol.
2)I dont have a problem to display the report.
3)I had to set 'do_sum' at ALV field category, still doesn't work
My source code to define ALV category.
loop at i_qpcd into wa_qpcd.
CLEAR ls_fieldcat2.
ls_fieldcat2-col_pos = pos2.
ls_fieldcat2-fieldname = wa_qpcd-code.
ls_fieldcat2-reptext_ddic = wa_qpcd-desc.
ls_fieldcat2-just = 'C'.
ls_fieldcat2-do_sum = 'X'.
APPEND ls_fieldcat2 TO gt_fieldcat2.
endloop.
My source code call the ALV FM
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'ZMPMR001_Q1OOT'
i_callback_pf_status_set = 'PF_STATUS_SET'
is_layout = ls_layout
it_fieldcat = gt_fieldcat2[]
is_print = ls_print
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.
Thanks a lot in advance for your attention.my situation is like this, declare the internal tble
1) data : begin of itab occurs 0,
code like qpcd-code,
desc like QPCT-KURZTEXT,
end of itab.
2) populate the itab like this
code desc
01 desc 1
02 desc 2
03 desc 3
3) take the selected record converted it into new dynamic internal table using field symbol declare as table, now the component of this new table are 01, 02 and 03.
4) populate the new table with some data, so technically my new table structure will be like this
01 02 03
1 0 1
0 0 3
2 2 2
5) display the new table in ALV report, in ALV I tried to sum-up each of column.
6) Question : HOW can I convert the componet 01, 02 and 03 as an integer/numeric field.
Regards
Nislina -
Right way to declare field symbols
i am new to field symbols, pls help
i want to know which is the right way of declaration ?
types: begin of typ_tab,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
end of typ_tab.
data: itab type standard table of typ_tab,
wa type typ_tab.
field-symbols: <f_t> type standard table,
<f_w> type any, or <f_w> like line of typ_tab, ??
<f_s> type any.
select vbeln posnr ....... into itab......
assign itab to <f_t>.
assign wa to <f_w>.
loop at <f_t> assigning <f_w>.
assign component 'vbeln' of structure <f_w> to <f_s>.
write : / <f_s>.
endloop.
OR
loop at itab assigning <f_w>.
write: / <f_w>-vbeln.
endloop.
r these 2 statements correctt ? if so then which one to use, pls show with an example. wats the diff btwn above 2 types of looping statements ? how to use read statement on this ?Hello Saurajit,
Both the way are correct. And it depends on the requirement, which one to use.
<f_w> TYPE ty_tab - is TYPED field symbol - if you know TYPE before runtime you can use this. It will just work like a static work area.
<f_w> TYPE any - is not TYPED and structure of this field symbol is defined during runtime using ASSIGN statement. And fields of the structure is read by ASSIGN COMPONENT <<field name>> statement. -
Field-Symbols: How to retrieve data into an internal table from FS
Hello All,
I am working on field symbols.I have declared the field symbols as shown.
FIELD-SYMBOLS: <gt_pos_data> TYPE table,
<wa_pos_data> like <gt_pos_data>.
Data: Begin of itab occurs 0,
field1(5) type c,
field2(10)_type c,
end of itab.
The FS <gt_pos_data> has 100 fields but I need to move only two fields from this FS to my internal table itab.I am doing the following.
loop at <gt_pos_data> assigning <wa_pos_data>.
itab-field1 = <wa_pos_data>-field1.
itab-field2 = <wa_pos_data>-field2.
append itab.
clear itab.
endloop.
But it is giving me an error saying "<wa_pos_data> is a table without header line and therefore has no componet FIELD1".How to achieve this requirement?
Thanks in advance
Sandeep<wa_pos_data> should be defined LIKE LINE OF <gt_pos_data>, but it will still have no structure, so you need to assign a field symbol to the component as well.
FIELD-SYMBOLS: <gt_pos_data> TYPE table,
<wa_pos_data> like LINE OF <gt_pos_data>,
<field> type any.
Data: Begin of itab occurs 0,
field1(5) type c,
field2(10)_type c,
end of itab.
loop at <gt_pos_data> assigning <wa_pos_data>.
assign componet 'FIELD1' of structure <wa_pos_data> to <field>.
if sy-subrc = 0.
itab-field1 = <field>.
endif.
assign componet 'FIELD2' of structure <wa_pos_data> to <field>.
if sy-subrc = 0.
itab-field2 = <field>.
endif.
append itab.
clear itab.
endloop.
Regards,
Rich Heilman -
Assigning a value to a field-symbol (workarea of type any)
Dear forumers,
I'm having a bit of difficulty in assigning a value to a field-symbol (it should be treated as a workarea of type any), but I'm given a syntax error instead:-
The data object "<LFS_WORKAREA>" has no structure and therefore no component called "LFMON".
What could have gone wrong and how may I resolve this (I must have missed something out)? I will still need <LFS_WORKAREA> to be defined as TYPE ANY.
Please help. I'd appreciate any inputs at all. Thanks.
*& Form FORMAT_POST_PERIOD
* Subroutine to format the posting period data
* --> PI_MBEW Material valuation data (internal table)
FORM format_post_period CHANGING pi_mbew TYPE ANY TABLE.
" Create local field symbols
FIELD-SYMBOLS:
<lfs_workarea> TYPE ANY,
<lfs_lfmon> TYPE ckmlcr-poper.
" Create local variables
DATA: lv_index TYPE sy-tabix.
DATA: lv_lfmon TYPE ckmlcr-poper.
" Format posting periods
LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
lv_index = sy-tabix.
ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
PERFORM convert_lfmon USING <lfs_lfmon>
CHANGING lv_lfmon.
MOVE lv_lfmon TO <lfs_workarea>-lfmon. " the syntax error occurs here :(
MODIFY pi_mbew FROM <lfs_workarea>
INDEX lv_index
TRANSPORTING lfmon.
CLEAR: <lfs_workarea>,
<lfs_lfmon>
lv_lfmon,
lv_index.
ENDLOOP.
ENDFORM. " FORMAT_POST_PERIODMost of us aren't in it for the points in any case...
For your solution you've redundant code:
*& Form FORMAT_POST_PERIOD
* Subroutine to format the posting period data
* --> PI_MBEW Material valuation data (internal table)
FORM format_post_period CHANGING pi_mbew TYPE ANY TABLE.
FIELD-SYMBOLS:
<lfs_workarea> TYPE ANY,
<lfs_lfmon> TYPE ckmlcr-poper.
DATA: lv_lfmon TYPE ckmlcr-poper.
* DATA: lo_workarea TYPE REF TO data. "<--Not needed, because the LOOP AT ASSIGNING below does the work
* CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
* ASSIGN lo_workarea->* TO <lfs_workarea>.
LOOP AT pi_mbew ASSIGNING <lfs_workarea>.
ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
PERFORM convert_lfmon USING <lfs_lfmon>
CHANGING lv_lfmon.
<lfs_lfmon> = lv_lfmon.
CLEAR lv_lfmon.
ENDLOOP.
ENDFORM. " FORMAT_POST_PERIOD
Here's a couple of more efficient solutions, using LOOP AT INTO.
FORM format_post_period CHANGING pi_mbew TYPE INDEX TABLE. " <-- Table type a little more specific
"<--now you can use index operations
FIELD-SYMBOLS:
<lfs_workarea> TYPE ANY,
<lfs_lfmon> TYPE ckmlcr-poper.
DATA: lv_lfmon TYPE ckmlcr-poper,
lv_index TYPE sytabix.
DATA: lo_workarea TYPE REF TO data.
CREATE DATA lo_workarea LIKE LINE OF pi_mbew.
ASSIGN lo_workarea->* TO <lfs_workarea>.
ASSIGN COMPONENT 'LFMON' OF STRUCTURE <lfs_workarea> TO <lfs_lfmon>.
LOOP AT pi_mbew INTO <lfs_workarea>.
lv_index = sy-tabix.
PERFORM convert_lfmon USING <lfs_lfmon>
CHANGING lv_lfmon.
<lfs_lfmon> = lv_lfmon.
MODIFY pi_mbew FROM <lfs_workarea>
INDEX lv_index. " <--INDEX TABLE, so this is permitted.
CLEAR lv_lfmon.
ENDLOOP.
ENDFORM. " FORMAT_POST_PERIOD
Maybe you are looking for
-
Need to create new users in Office 365 with custom attributes from a csv file
I am exporting users from an active directory environment and then deleting them from AD. They are Alumni and will no longer be in AD. I have a csv file with the following fields that I need to use to create new Alumni email boxes in Office 365 for.
-
Framerate problem after burning PAL Blu-ray
Hi folks, bit of a rookie here. Usually try to work my way around things but this is a new area for me and I'm a little stumped! Basically I'm using Encore CS5 to burn a Blu-ray from footage rendered from Final Cut. The footage is from a Sony HDV cam
-
Can you add iDVD markers to a 1 hour movie - in iDVD?
I have a 1 hour movie that I want to add markers points in iDVD 7. Can it be done? Regards Guy
-
Any ideas on what to do, I have restarted my laptop several times. Your help would be greatly appreciated, Jay
-
I restored my outlook data from my hard drive. All my contacts have been restored to backup in contacts but cannot be accessed when creating mail. If I try to access the main folders, all of which are there, I get a fail message saying that an outloo