Passing field symbol value to a variable
Hi All,
I have a value in Field Symbol declared as <FS-STATUS> TYPE STANDARD TABLE.
I want to use the value <fs-status> -low in a case statement.
For this i think i have to pass the <fs-status> -low into a variable and then use in case statement.
Can anyone explain how to pass values in field symbol to variable? Or if this is not possible is there any other solution.
Thanks in advance.
Hi ,
I have give some code sample ; just check ..
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c VALUE 'X',
END OF line.
FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.
WRITE: <fs>-col1, <fs>-col2.
Or u can check this link :
http://www.erpgenie.com/abaptips/content/view/401/62/
Similar Messages
-
Reg Field-Symbol value trasfer into variable
Hi,
I'm using one FIELD-SYMBOL in one of my program. I used this to catch Hotspot Fields in List Report. It catches that required field of BELNR.
I read the Click event through that FIELD-SYMBOL. Now I used
DATA: HOTSPOT(18) , "VALUE 'Document No',
F(18), OFF TYPE I, LIN TYPE I, VAL(40), LEN TYPE I.
FIELD-SYMBOLS <FS>.
ASSIGN HOTSPOT TO <FS>.
WRITE <FS> HOTSPOT COLOR 3 INVERSE ON.
AT LINE-SELECTION.
*WINDOW STARTING AT 5 6 ENDING AT 45 20.
GET CURSOR FIELD F OFFSET OFF
LINE LIN
VALUE VAL
LENGTH LEN.
data: click_item type bsid-belnr.
move val to click_item.
It moves the value into CLICK_ITEM variable. But when I try to run SELECT query with condition BELNR = CLICK_ITEM, query gives no result.
Can you please point out my fault?
Thanks.
Kumar saurav.Try using Conversion Routine before the Select Query.
DATA : T_BELNR TYPE BSID_BELNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = CLICK_ITEM
IMPORTING
OUTPUT = T_BELNR
and pass T_BELNR to the where condition.
Hope this helps. -
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 -
Field symbols values passing as parameter to Methods
Hi ,
Can we pass fields symbols as parameter to methods ? I want to use field symbols values in my where in clause in methods, thereafter I want to pass my internal table to calling method.
Thanks,
UjjwalHi,
I have create an class in which have I have create a method to written a select query to extract value from a table. The table name is passed by user. the select used is:
select * from (tab) into CORRESPONDING FIELDS OF TABLE data.
this method has 2 parameter:
tab of type sting (importing).
data of type ANY TABLE (exporting).
and i am using the following code to get the data:
data: itab TYPE TABLE OF t578w.
field-SYMBOLS <ab> TYPE any.
ASSIGN 'T578W' to <ab>.
CALL METHOD Z_GET_TABLE_DATA=>GET_TABLE " Z_GET_TABLE_DATA is the class name & GET_TABLE is method name
EXPORTING
tab = <ab>
IMPORTING
data = itab.
You can code in similar way.
I hope it helps.
Regards
Arjun
Edited by: Arjun Thakur on Apr 23, 2009 3:16 PM -
Passing Field Symbols in subroutines
Hi all,
Can any body tell me how to pass field symbols in a suboutine and will that effect orignal value of that symbl if i change it in subroutine.
Any Help will be awarded.
<b>Sachin</b>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 -
Hi Friends,
In my FM, i want to pass field symbol back to my main program for further use. How can i achieve the same.
In my source code section of FM,
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<fs_col1>,<fs_col2>.
DATA : t_newtable TYPE REF TO data,t_newline TYPE REF TO data,t_fldcat TYPE lvc_t_fcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN t_newtable->* TO <t_dyntable>.
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
i want to pass <t_dyntable> back to my prg but i am not getting how to pass it and where to write it.
Please guide me.
Thanks and Regards,
GauravHi Naimesh,
Thanks for the reply.
Finally i understood what you guys wanted me to do.I did exactly the same but the problem remains the same.
when my control get back to subroutine it works fine, i mean upto
ASSIGN r_dyntab->* TO <t_dyntable>
,it works fine.But when the control gets over from FM and process the next statement
clear <t_dyntable>.
then the <t_dyntable> says it is not yet assigned. I want to access <t_dyntable> as main dynamic table for further process.
i have added code for your reference.
Thanks and Regards,
Gaurav
Report Zcallingprg.
DATA : t_newtable TYPE REF TO data,t_newline TYPE REF TO data,t_fldcat TYPE lvc_t_fcat.
DATA : wa_it_fldcat TYPE lvc_s_fcat,wa_colno(2) TYPE n,wa_flname(5) TYPE c,G_DISCONT.
data : num2(2).
DATA: rest TYPE i.
DATA: task(8) TYPE c value '1'.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<fs_col1>,<fs_col2>.
DO 100 TIMES.
rest = sy-index MOD 36.
IF rest = 0.
task = task + 1.
ENDIF.
CALL FUNCTION 'ZTEST_NEW_TASK' STARTING NEW TASK task
EXPORTING
num2 = 2.
ENDDO.
clear <t_dyntable>.
FORM get_dyn_tab CHANGING r_dyntab TYPE REF TO data.
ASSIGN r_dyntab->* TO <t_dyntable>.
ENDFORM.
code of FM
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = r_newtab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
*ASSIGN r_newtab->* TO <t_dyntable>.
PERFORM get_dyn_tab(ztemp5) USING r_newtab. -
ABAP field symbols and PERL reference variables to unnamed arrays.
Rob -
Please do NOT delete this post even though it contains this link:
ABAP field symbols and PERL reference variables to unnamed arrays.
to a question I posted in the Scripting Languages forum.
It's a question that should be of interest to ABAP programmers, and they may miss if they don't frequent the SL forum ...
Thanks for your forbearance here (in advance, of course) ...
Best
djh
Edited by: Rob Burbank on Jul 11, 2011 1:26 PMIf interested, please reply in the original thread. We don't want multiple conversations at cross purposes do we?
Rob -
How to Pass dashboard prompt value to RPD variable??
Hi Experts,
I am creating RPD variable with below query in initialization block
SELECT extract(month from Max(report_date)) from xyz_date_dim where report_id=14 and year=:YEAR
I am having YEAR prompt in dashboard..from this RPD variable i want to get MAX(month) from selected year in dashboard.Here my problem is unable to pass selected YEAR to RPD Initialization block.
I read some threads we can pass user selected values to session variables. If possible can any one help me how to pass variable to achieve my requirement.
can any one help me in this....
Thanks,
KSS.So you want to pick a month in a dashboard prompt and have the answers report filter for that month, and return results for that month, month -1, month -2 etc etc.
If so try the following, lets assume your measure is simply called 'count'
in the BMM you have measure 'count' with aggregation set.
Create a new measure in the BMM called 'count MAGO' or whatever you want (this will be month -1)
in the logical forumula for that column, use the AGO function, syntax would be AGO(count measure,<time dimension.Month>, -1) - this function is found under the 'Time Series Functions' category.
repeat steps to create 'count 2MAGO' and use -2 in the AGO function to take off 2 months.
Repeat for however many Mth Ago's you want.
Then in answers, simply use is prompted on your month fied to filter the report for the relative month, select your 'count', 'count MAGO', 'Count 2MAGO' etc, the measure will be calculated for prior months relative to your filtered month.
Sorted? -
How to check the length of a field symbol value
hi all,
i have a problem with string function, i have assined table fields to a field symbol in a loop i want check the length of the assigned fields symbol value in every loop . i have written like ,,,,,len = strlen( <fs>). then i am getting the length of the field label what i ahve assigned to fiels symbol not the field value lenght ,
please advise me on this,
thanks,
sreI think you're on the right track. This should work:
data: len type i.
data: begin of itab OCCURS 1,
a type string value '1',
b type string value '12',
c type string value '123',
end of itab.
FIELD-SYMBOLS: <fs> type ANY.
do 3 times.
assign component sy-index of STRUCTURE itab to <fs>.
len = strlen( <fs> ).
enddo. -
Passing internal tabel values to a variable
Hi experts,
I wanna pass the values of an internal table eg itab to a variable of character type of lenth 1000. the values in itab are of different types.
plz suggest me how solve this.
regards,
alson.Hi..,
use the field-symbols....
(This code is for an itab which contains more than one field... )
<b>
data:
w_line(1000),
w_field(40) type c.
table to hold all the records resulted from concatenating fields....
data
t_file like standard table
of w_line
initial size 0.
field-symbols <fs>.
loop at itab into wa_itab.
do.
assign component sy-index of structure wa_itab to <fs>.
if sy-subrc ne 0.
exit.
endif.
w_field = <fs>.
condense w_field no-gaps.
if sy-index eq 1.
w_line = w_field.
else.
concatenate w_line ' ' w_field into w_line.
endif. " If sy-index eq 1.
enddo. " Do.
append w_line to t_file.
endloop.
</b>
if u have itab onli with one field
then...
<b>data:
w_line(1000),
w_field(40) type c.
loop at itab.
w_field = itab-field.
concatenate w_line w_field into w_line.
endloop.</b>
reward if it helps u..
sai ramesh -
How to pass field symbol as parameter to a method
Hi,
I have a field symbol of type table,also i have a method with parameter (say vbeln), i need to pass the range value in <fs> as the parametrs to the method.,
How can I acheive this,
A code snippet eill help me a lot.,
Thank you.
Arjun.GHi,
Example code :
field-symbols : <fs> type table.
CALL METHOD cl_gui_frontend_services=>gui_upload
CHANGING
data_tab = <fs>
* EXCEPTIONS
* file_open_error = 1
* file_read_error = 2
* no_batch = 3
* gui_refuse_filetransfer = 4
* invalid_type = 5
* no_authority = 6
* unknown_error = 7
* bad_data_format = 8
* header_not_allowed = 9
* separator_not_allowed = 10
* header_too_long = 11
* unknown_dp_error = 12
* access_denied = 13
* dp_out_of_memory = 14
* disk_full = 15
* dp_timeout = 16
* not_supported_by_gui = 17
* error_no_gui = 18
* others = 19
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Remember : parameter should be of type standard table.
Regards,
Mohaiyuddin -
Pls help...How to pass a executed value to a variable?
hi everyone im new here..
ok im having prob in passing the executed value of a string into a variable for me to manupulate the value. sample codes as below :
declare @Str varchar(500)
declare @Str1 varchar(50)
declare @Int varchar(50)
declare @Str2 varchar(50)
set @Str1 = 'where ET.isVerified = 1'
set @Str = 'select sum(ET.Sundries+ET.Entertainment+ET.BalReimbursement+ET.Fee+ET.TrainerCharges+ET.SeminarPack+ET.Food+ET.Accomodation+ET.Flight) from ExpensesTransactions ET ' + @Str1
EXEC(@Str)
Answer : 16935.00
so now i want to pass the output(Answer) into a variable so that i can insert the value into a table. anyone can help me in this thing . thank you so much..
regards
-nash-hi Jurek
thanx for ur help dude, i change as what u said but i got this error msg "Incorrect syntax near '@Answer'"
declare @Str varchar(500)
declare @Str1 varchar(50)
declare @Int varchar(50)
declare @Str2 varchar(50)
declare @Answer varchar(50)
set @Str1 = 'where ET.isVerified = 1'
set @Str = ' BEGIN select sum(....) INTO @Answer From ExpensesTransactions ET ' + @Str1 + ' END;'
EXEC(@Str)
print @Answer
but then i change the script abit to 'Begin select....' + @Answer + ' From ..' + @Str1 + 'END;'...this time i got no error msg but there is no value in variable @Answer...
thanx everyone
- nash - -
How i pass table column value to string variable or return to java applete
Hi Master,
How do I pass a table column value into string variable. See my code below:
import java.sql.*;
public class Waheed {
public Waheed() {
public static void main (String args [])
String s = "9 23 45.4 56.7";
System.out.println ("going for connection");
// DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@fahim:1521:aamir","muhammad","mfa786");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select accid from accbal");
System.out.println ("going for connection");
while (rset.next())
s= rset.getString("accid"); this line give me error
System.out.println (rset.getString("accid"));
System.out.println (s);
catch(Exception e){
e.printStackTrace();
This line give me an error:
s= rset.getString("accid");
s is string variable
Plese give me an idea how I can pass accid in s variable.
Thanks.
AamirSee the code sample in the following thread (try using upeercase).
JDBC connection
Kuassi -
How to pass field symbol or table from one view to another view in abap web dynpro?
I am creating an Inbound Outbound ALV report in ABAP Web Dynpro. However at selection-screen I have select options and fetching is done at view2. Problem is we can pass parameter using inbound outbound parameters but how to pass internal table or field-symbols from one view to another view? I made use of Assistance Class too but its not very clear to me. Please give me some example or code to sort this problem out.
I am creating an Inbound Outbound ALV report in ABAP Web Dynpro. However at selection-screen I have select options and fetching is done at view2. Problem is we can pass parameter using inbound outbound parameters but how to pass internal table or field-symbols from one view to another view? I made use of Assistance Class too but its not very clear to me. Please give me some example or code to sort this problem out.
-
Problem with field-symbol values not updating
H i ,
I have following piece of code :
Assigning Dynamic Table to Field Symbol
ASSIGN ist_dyn_table->* TO <gs_dyn_table>.
* Creating Structure for dynamic table
CREATE DATA gs_dyn_line LIKE LINE OF <gs_dyn_table>.
* Creating line type for the Dynamic Values
ASSIGN gs_dyn_line->* TO <gs_line>.
* Populating values in the dynamic table
LOOP AT ist_pwcl_main INTO wa_pwcl_main.
ASSIGN COMPONENT gc_fld_werks OF STRUCTURE <gs_line> TO <gs_field>.
1 IF sy-subrc EQ 0.
2 <gs_field> = wa_pwcl_main-werks.
3 ENDIF.
5 IF <gs_field> IS ASSIGNED.
6 <gs_field> = wa_pwcl_main-vbeln.
ENDIF.
7 IF <gs_field> IS ASSIGNED.
8 <gs_field> = wa_pwcl_main-posnr.
ENDIF.
IF <gs_field> IS ASSIGNED.
<gs_field> = wa_pwcl_main-quant.
ENDIF.
on debugging at line 2 <gs_filed> contains the value of werks .
but at line 6 <gs_field> contains value of vbeln as 0 and at 8 of posnr as 0 .
What can be the problem ? Other values are getting assigned properly .
Plz help ...
Regards .Hi,
Assigning Dynamic Table to Field Symbol
ASSIGN ist_dyn_table->* TO <gs_dyn_table>.
Creating Structure for dynamic table
CREATE DATA gs_dyn_line LIKE LINE OF <gs_dyn_table>.
Creating line type for the Dynamic Values
ASSIGN gs_dyn_line->* TO <gs_line>.
Populating values in the dynamic table
LOOP AT ist_pwcl_main INTO wa_pwcl_main.
ASSIGN COMPONENT gc_fld_werks OF STRUCTURE <gs_line> TO <gs_field>.
1 IF sy-subrc EQ 0.
2 <gs_field> = wa_pwcl_main-werks.
3 ENDIF.
5 IF <gs_field> IS ASSIGNED.
6 <gs_field> = wa_pwcl_main-vbeln.
ENDIF.
7 IF <gs_field> IS ASSIGNED.
8 <gs_field> = wa_pwcl_main-posnr.
ENDIF.
IF <gs_field> IS ASSIGNED.
<gs_field> = wa_pwcl_main-quant.
ENDIF.
Based on your coding above, <gs_field> has been assigned with data type 'WERKS' (i'd assume component gc_fld_werks found from structure <gs_line> is a plant typed), which is a CHAR(4) data type.
Meaning, if <gs_field> is assigned with Plant type value, e.g. <gs_field> = '1000', field symbol <gs_field> will contain 4 character only.
At line 6, if wa_pwcl_main-vbeln = '0000201000', <gs_field> is only capturing '0000' only. This is also happened to line 8.
However, it looks like that <gs_field> is getting over-write if ASSIGNED statement returns SY-SUBRC = 0.
Hope this helps.
Regards,
Patrick
Maybe you are looking for
-
I'm using an older Microsoft Work version, is that the issue
-
Is macbook easy to use for that with the special programs ? And if it is which one of the available macbook is better ? Concerning ram, storage, size ... Please i want a detailed answer to help me chose well. I know macbook is the best in quality and
-
How to Display Current Quarter results in WebI report?
Hi Guys, I have a requirement where a WebI report should open up on current quarter basis by default. I have checked the refresh on Open in the document properties.What changes or formulae do I need to make/create in order to open the report with cur
-
How export data in Excel From Visual Composer
Hay everybody, I would like to export my data result from Visual Composer to Excel. I've tried with an export data buton, but the exported file has a very bad format in Excel. I've tried an hyperlink buton which contain the Reptname data of the query
-
Unable to find redemption code for creative cloud
I was running trial for illustrator and photoshop then decided to join adobe cloud membership. However, my softwares will asked for serial number even after i signed in I realised my problem was that I didn't activate my membership through redemption