Macros,field symbols
Hi All,
Please can you suggest me best sites or any documents to learn more on field symbols and macros in ABAP SAP?
Thanks in advance.
Regds,
Leeza.
For field symbols
<a href="http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html">Use field symbols for better performance in internal tables</a>
<a href="http://www.erpgenie.com/abap/example_code.htm">Example code</a>
For macros
<a href="http://www.howforge.com/how-to-define-macro-in-abap-4">How to define macro in ABAP/4</a>
<a href="http://www.sap-img.com/ab022.htm">Macro in ABAP</a>
Regards
Similar Messages
-
Hi Experts,
I want to assign the fields of a field symbol using a macro because the field names come from a table
the code look like this
DEFINE ASSIGN_VALUE.
&1-&2 = &3.
END-OF-DEFINITION.
ASSIGN_VALUE <RESULT_FIELDS> FIELDNAME FIELDVALUE.
Where FIELDNAME is a CHAR variable containing the name of the field
I get the following error:
E:The data object "<RESULT_FIELDS>" does not have a component called
"FIELDNAME".
The macro and the call to it are located in a method of a class ( end routine of a transformation in BW)
Thanks for your help
ThibaultHi
Welcome to SDN forum
See the doc of MACROS and do accordingly
Macros
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
The following statement block defines a macro macro:
DEFINE makro.
statements
END-OF-DEFINITION.
You must specify complete statements between DEFINE and END-OF-DEFINITION. These statements can contain up to nine placeholders &1, &2,...., &9). You must define the macro before the point in the program at which you want to use it.
Macros do not belong to the definition part of the program. This means that the DEFINE statement block is not interpreted before the processing blocks in the program. At the same time, however, macros are not operational statements that are executed within a processing block at runtime. When the program is generated, macro definitions are not taken into account at the point at which they are defined. For this reason, they do not appear in the overview of the structure of processing logic.
A macro definition inserts a form of shortcut at any point in a program and can be used at any subsequent point in the program. As the programmer, you must ensure that the macro definition occurs in the program before the macro itself is used. Particular care is required if you use both macros and include programs, since not all include programs are included in the syntax check (exception: TOP include).
To use a macro, use the following form:
makro [p1 p2... p9].
When the program is generated, the system replaces the macro by the appropriate statements and the placeholders &1, &2, , &9 by the parameter p1, p2, , p9. You can use macros within macros. However, a macro cannot call itself.
REPORT demo_mod_tech_macros.
DATA: result TYPE i,
n1 TYPE i VALUE 5,
n2 TYPE i VALUE 6.
DEFINE operation.
result = &1 &2 &3.
output &1 &2 &3 result.
END-OF-DEFINITION.
DEFINE output.
write: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
operation 4 + 3.
operation 2 ** 7.
operation n2 - n1.
This produces the following output:
The result of 4 + 3 is 7
The result of 2 ** 7 is 128
The result of N2 - N1 is 1
In this example, the two macros operation and output are defined. output is nested in operation. operation is called three times with different parameters. Note how the placeholders &1, &2,... are replaced in the macros.
The following example shows that a macro definition only works in the program lines following its definition. Do not copy it!
Let us have a look at a program with a subroutine test:
PROGRAM macro_test.
FORM test.
WRITE '...'.
ENDFORM.
We can rewrite the program by introducing a macro macro:
PROGRAM macro_test.
FORM test.
DEFINE macro.
WRITE '...'.
ENDFORM.
END-OF-DEFINITION.
MACRO.
Inserting the macro changes nothing in the generated form of the program. Processing blocks - here a subroutine - are always indivisible. We could also write the program as follows:
PROGRAM macro_test.
DEFINE macro.
WRITE '...'.
ENDFORM.
END-OF-DEFINITION.
FORM test.
MACRO.
The most essential feature of a macro definition is that it should occur before the macro is used.
Macro in ABAP
Macro in ABAP
Submitted by : SAP Basis, ABAP Programming and Other IMG Stuff
http://www.sap-img.com
REPORT ZMACRO.
DATA: RESULT TYPE I,
N1 TYPE I VALUE 5,
N2 TYPE I VALUE 6.
DEFINE OPERATION.
RESULT = &1 &2 &3.
OUTPUT &1 &2 &3 RESULT.
END-OF-DEFINITION.
DEFINE OUTPUT.
WRITE: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
OPERATION 4 + 3.
OPERATION 2 ** 7.
OPERATION N2 - N1.
*-- End of Program
Regards
Anji -
Passing unassigned field symbols to a method
Hello Gurus,
I work with a field symbol in a method and after the work is finished i have to use it i my program that i call the method from.
The problem is that the field symbol gets assigned only in the method so i can`t get the field symbol as a changing parameter in my method because it is not assigned yet.
I thought that i can return the field symbol from the method after it has been assigned, but i don`t know how. The <fs> is a dynamic itab that i created within the method.
Can anyone help please ??Although already answered this code snippet might make it clearer
my_line is your data structure typically an itab structure.
For example
TYPES: BEGIN OF s_elements,
tabname type DD02L-tabname,
tabclass type dd02l-tabclass,
as4user type dd02L-as4user,
as4date type dd02l-as4date,
as4time type DD02l-as4time,
viewed(1) type c.
TYPES: END OF s_elements.
Data: my_line TYPE s_elements.
1) get the structure of your itab automatically so you can build an FCAT simply for any structure without the horrendous usual coding to manipulate and create FCATS.
CALL METHOD me->return_structure
EXPORTING
my_line = my_line.
You need to make a table ZOGT data available in the class definition either as an attribute if you are using the class builder SE24 or as DATA in the relevant class section.
data:
zog LIKE LINE OF lr_rtti_struc->components .
data:
zogt LIKE TABLE OF zog .
method RETURN_STRUCTURE.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( my_line ).
zogt[] = lr_rtti_struc->components.
endmethod.
Your structure details are now in table zogt.
Use this to build an FCAT.
CALL METHOD me->create_dynamic_fcat
IMPORTING
it_fldcat = it_fldcat.
method CREATE_DYNAMIC_FCAT.
LOOP AT zogt INTO zog.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
APPEND wa_it_fldcat TO it_fldcat .
ENDLOOP.
endmethod.
Now having got your FCAT you can build your dynamic table.
CALL METHOD me->create_dynamic_table
EXPORTING
it_fldcat = it_fldcat
IMPORTING
dy_table = dy_table.
(dy_table is defined as ref to data)
method CREATE_DYNAMIC_TABLE.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
endmethod.
Now populate your dynamic table as per sample code here
field_symbols:
<dyn_table> TYPE STANDARD TABLE.
<dyn_wa>.
data: dy_line TYPE REF TO data.
FORM populate_dynamic_itab.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
SELECT *
FROM DD02L
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
WHERE TABNAME LIKE 'ZHR%'.
ENDFORM.
Now you can display your grid and process your data.
CALL METHOD z_object->display_grid
EXPORTING
g_outtab = <dyn_table>
g_fldcat = it_fldcat
i_gridtitle = i_gridtitle
i_edit = i_edit
i_zebra = i_zebra
CHANGING
it_fldcat = it_fldcat
gt_outtab = <dyn_table>.
In the Method
method DISPLAY_GRID.
GET REFERENCE OF g_outtab INTO g_outtab1.
GET REFERENCE OF g_fldcat INTO g_fldcat1.
struct_grid_lset-edit = i_edit. "To enable editing
struct_grid_LSET-zebra = i_zebra.
struct_grid_lset-grid_title = i_gridtitle.
struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
struct_grid_lset-stylefname = 'CELLTAB'.
CALL METHOD grid1->set_ready_for_input
EXPORTING
i_ready_for_input = '1'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = it_fldcat.
ENDMETHOD.
You can even easily code your own column names if you so wish in the application program.
Before calling the method that displays the grid encode the following macro.
DEFINE col_name.
read table it_fldcat into wa_it_fldcat index &1.
wa_it_fldcat-coltext = &2.
wa_it_fldcat-outputlen = &3.
modify it_fldcat from wa_it_fldcat index &1.
END-OF-DEFINITION.
Then have a subroutine in your application code something like this
Form name_columns.
Here before displaying you can change the field catalog to
adjust your own column names.
*col_name col-nr 'your name' output length.
col_name 1 'Table name' 30.
col_name 2 'Table class' 12.
col_name 3 'Changed By' 12.
col_name 4 ' On' 12.
col_name 5 ' At' 8.
col_name 6 'Act' 3.
i_gridtitle = 'HR ESS / ITS ZHR Tables - Double click to display'.
i_zebra = 'X'.
i_edit = ' '.
endform.
Hope this clears it up a bit.
Once you get this stuff working you can re-use 99% of the code for almost any structure making the whole process of OO ALV grid applications really simple.
Yoy only need as well a standard dynpro with a custom container on it (se51).
Cheers
jimbo -
Hi Experts,
whats the usage of fieldsymbols is smartforms?can any one explain why will use and how it help full in smartforms?
Thanks ,Hi,
Field Symbols in smartforms can declare in Global definitions .Under the Field Symbol Tab.
The main use of Field Symbol is Like pointers in C.
If we want to modify the table or variable or assiging to the total table or u want to create dynamic internal table or for macros.
Regards,
Shiva. -
Internal table to field symbol
hi all,
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.
*data : dyn_itab2 type ANY table.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c.
selection-screen end of block b1.
start-of-selection.
BREAK-POINT.
perform get_structure.
perform create_dynamic_itab.
perform get_data.
PERFORM OUTPUT.
*perform write_out.
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.
*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.
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.
here i want to assighn the structure of dy_table to internal atble.
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.
Select Data from table.
select * into table <dyN_table> UP TO 10 ROWS
from (p_table).
endform.
Write out data from table.
FORM OUTPUT.
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.
how can i achieve this one.
regards
sivaHi,
Check this Code ...
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <fs_field> .
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <fs_field>.
ELSE.
WRITE: <fs_field>.
ENDIF.
ENDDO.
ENDLOOP.
For reference check below code
DATA: it_fieldcat TYPE lvc_t_fcat . " Field catalog
DATA: wa_fieldcat LIKE LINE OF it_fieldcat. " Field catalog
DATA: it_dyn_table TYPE REF TO data, " Dynamic table
it_wa_dyn_table TYPE REF TO data. " Dynamic table
* Field sysmbols Begin with <fs> *
FIELD-SYMBOLS: <fs_dyn_table> TYPE STANDARD TABLE, " Dynamic tbale
<fs_dyn_table_temp> TYPE ANY , " Dynamic tbale
<fs_field> TYPE ANY , " Temp field for data assignment
<fs_field_temp> TYPE ANY . " Temp field for data assignment
* Macro *
* Macro Defination
* Building field catalog using macro defination
DEFINE m_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-scrtext_l = &2.
wa_fieldcat-coltext = &2.
wa_fieldcat-no_zero = &3.
wa_fieldcat-hotspot = &4.
wa_fieldcat-outputlen = &5.
wa_fieldcat-emphasize = &6.
* Appending workarea to internal table
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
END-OF-DEFINITION.
*& Form f005_prepare_field_catalog
* text
form f005_prepare_field_catalog .
REFRESH: it_fieldcat.
* Build the field catalog
m_fieldcat text-007 text-008 c_blank c_blank c_30 c_blank.
m_fieldcat text-009 text-010 c_blank c_blank c_30 c_blank.
SORT it_final_temp BY equnr point.
SORT it_final BY equnr point psort idate.
w_date1 = so_date-low.
* Loop to generate grid column at run time
* Loop - Till the lower date not equal to higer date
WHILE so_date-high GE w_date1.
* Changing date into actual date format using edit mask
WRITE w_date1 TO w_var4 USING EDIT MASK '__-__-____'.
m_fieldcat w_var4 w_var4 c_flag c_blank c_12 c_blank.
w_date1 = w_date1 + c_count.
CLEAR w_var4.
ENDWHILE.
*& Form f007_create_dynamic_table
* text: Create dynamic table
form f007_create_dynamic_table .
* Call method to create dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = it_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 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.
SORT it_final_temp BY equnr point.
SORT it_final BY equnr point psort idate.
ASSIGN it_dyn_table->* TO <fs_dyn_table>.
CREATE DATA it_wa_dyn_table LIKE LINE OF <fs_dyn_table>.
ASSIGN it_wa_dyn_table->* TO <fs_dyn_table_temp>.
IF it_final_temp IS NOT INITIAL.
LOOP AT it_final_temp INTO wa_final_temp.
* Assign equipment number and it's field data to field symbols (Dynamic table)
* Assign field name to field symbol
ASSIGN text-007 TO <fs_field_temp>.
* Assign component name and it's value to dynamic table
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
* Assign equipment number value to field symbol
<fs_field> = wa_final_temp-equnr.
* Assign Short Description and it's field data to field symbols (Dynamic table)
* Assign field name to field symbol
ASSIGN text-009 TO <fs_field_temp>.
* Assign component name and it's value to dynamic table
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
* Assign short description value to field symbol
<fs_field> = wa_final_temp-psort.
* Loop to assign value of run time generated column.
IF it_final IS NOT INITIAL.
LOOP AT it_final INTO wa_final WHERE equnr = wa_final_temp-equnr
AND point = wa_final_temp-point.
w_date1 = wa_final-idate.
WRITE w_date1 TO w_var4 USING EDIT MASK '__-__-____'.
ASSIGN w_var4 TO <fs_field_temp>.
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
<fs_field> = wa_final-cdiff.
CLEAR: wa_final, w_var4, w_date1.
ENDLOOP.
ENDIF.
CLEAR: wa_final_temp.
* Assign field symbol temporary table to final dynamic table
APPEND <fs_dyn_table_temp> TO <fs_dyn_table>.
CLEAR: <fs_dyn_table_temp>.
ENDLOOP.
ENDIF.
endform. " f007_create_dynamic_table -
In webdynpro ,Passing field symbols as values to class methods
Hi
Please tell me the ways of accessing database in webdynpro abap(not directly). I am calling Class method for accessing database. As currently I am directly accessing database in my webdynpro application. I have created a class and method for the same.
In my method I want to use select statement which will return table with values to webdynpro application. So for select statement(Calling Method) I need to use my field symbol values as where in clause .
Could anyone please help with example code?
Thanks,
Ujjwaldata: in_line type ref to data.
CREATE DATA in_line LIKE LINE OF <dyn_tab>.
ASSIGN in_line->* TO <dyn_wa>.
You can create a data reference and assign it to a field symbol and change the values. direclty passing field symbols is not possible.
Abhi -
How to revert back a SAP NOTE? Dump- Field symbol has not yet been assigned
Hi Experts,
We r getting dump(cause: Field symbol has not yet been assigned) in production for ABUMN tx, so, when debugged, it came to know that, the Field symbol is coming from REUSE_ALV_LIST_DISPLAY!!
So, for some reason the system message text is not getting output in ALV-->Dump!!
So, found a NOTE causing this problem!!
So, pls. let me know that, How to revert back this/any SAP NOTE? pls. in detail steps wise!!
thanq
Edited by: Srinivas on Jan 24, 2008 4:32 PMHi
In SNOTE tcode, select the Note that you implemented and click on 'RESET SAP Note Implementation'
shylesh -
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 -
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 -
"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! -
Error while trying to run Bex Query -------- Field symbol is not assigned.
Hello Every body,
I am facing the following error after giving some value in Selection screen and trying to run the Bex Query
ERROR : Field symbol is not assigned.
Thanks in advance,
Praveencan u plz give details of variables, what it is build on and the value u r inputing,
also is thr any dump.
double click on the error message it shows u. it will give u the detailed error message. post that too -
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 -
How can i concatenate single quote to a field symbol
hi
i have a senario where i have to concatenate a single quote (') to the field symbol. it is simple but i' m not able to do that.
concatenate ''' <f> ''' into lv_f.
CONCATENATE lv_condition_temp lv_f INTO
lv_condition_temp
SEPARATED BY space.
this is the code which i used. could someone help me in solving this...
thanks & regards,
subha....hi
i tried using the following code
data : lv_text(10) type c.
concatenate ''' <f> ''' into lv_text.
it is giving me a spelling or incorrect comma error.
thanks & regards,
subhashini. -
Field symbol with top of page in reuse_alv_list
When using the top_of_page in REUSE_ALV_LIST_DISPLAY
I had in the old programm reference to values in the outtab for the header in the new programm I use dynamic tables and I wonder how to add those values in a header.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = h_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
* i_structure_name = 'ZDOORBEL_ALV'
* IT_EVENTS = TEVENTS
is_layout = slayout
it_fieldcat = it_fieldcat[]
it_sort = tsort[]
i_save = a_save
is_variant = variant
TABLES
t_outtab = <ta_output>
in my top_of_page I try to read the current row of <ta_output> but I have no clue on how to do it. I gives the error that there is no workarea assigned to <ta_output>
anybody knows how to read the current line of <ta_output> in top_of_page ?
kind regards
arthur de smidtI have
* fieldsymbols voor dynamische ALV tabel
FIELD-SYMBOLS: <ta_output> TYPE table ,
<ta_color> TYPE table,
<l_line> TYPE ANY,
<wa_output> type any,
<wa> TYPE ANY,
<l_field> TYPE ANY,
<fs> TYPE ty_pernrs.
FORM top_of_page.
CREATE DATA new_line LIKE LINE OF <ta_output>.
ASSIGN new_line->* TO <wa_output>.
read table <ta_output> assigning <wa_output> index sy-tabix.
if ra_pernr = 'X'.
if <wa_output>-week = space or <wa_output>-pernr = '00000000'.
but still it says that the
The data object "<WA_OUTPUT>" has no structure and therefore no
component called "WEEK" . .
Edited by: A. de Smidt on Jun 26, 2008 11:07 AM
Maybe you are looking for
-
i have a mac pro. when i try to connet to a vedio call. the call doesnt connet. the person on the other side can see me but i cant see them. i updated the new version for adobe flash. but the camra stiil doesnt work.
-
How do I import a CSV. contacts file to outlook using Mozilla Firefox?
I need to import a CSV. file containing my contacts to outlook mail using the mozilla firefox browser but there is no option for importing and exporting.
-
Selection Screen Validation In ABAP Queries
Hello all, I have created a selection screen field in the Infoset by EXTRAS --> Create Field. Now i want the values entered in this field at the selection screen to be available at the event Record Processing. The values entered at the select
-
Upgraded to Maps 2.o and now problems
I used to be able to download the maps over WLAN for Bosnia and Herzegovina on my previous version of Nokia Maps, now I can only download the maps for the countries that have the Navigation feature... And I am stuck with minimal map information for B
-
Help needed with certificates for RDS Host servers
Hi, We currently have 4 RD Session-Host servers in our network. All four servers are member of a TS farm. We also have a TS Gatway server. I managed to give the TSGW server a certificate but I need your support on this on the RDS servers. What happen