Field-Symbols as Method Parameter
Hi all,
is there a way to create a field symbol within a method and export this field-symbol directly as a method parameter?
The problem is that we can't pass a field symbol as method parameter unless it's assigned, but we would like to assign the field symbol within a method and give the result back to the calling program.
We have managed to create a field symbol within the method and give back the result as a reference (we used the type ANY).
We would like to pass the result field-symbol directly as a Method parameter.
Any ideas?
Best regards Dominik
Hi all,
thanks for you help. I managed to do the method calls with reference parameters but I'd like to do it with fieldsymbols instead.
Your suggentions for field-symbold worked, but I could use them only with primitive datatypes.
In my requirements the table must be created within the method, so the caller doesn't know the tablestructure.
If a dummy table is assigned to the field-symbol before the call, the error "Two internal tables are neither compatible nor convertible" is produced.
Is there a solution?
Thanks in advance
Dominik
class ZZX0_CL_TEST definition
public
final
create public .
public section.
class-methods FIELD_SYMBOLS_TAB_TEST
changing
!FS type ANY .
METHOD FIELD_SYMBOLS_TAB_TEST .
DATA: it_t000 TYPE TABLE OF t000.
FIELD-SYMBOLS <field_symbol> TYPE ANY TABLE.
ASSIGN it_t000 TO <field_symbol>.
fs = <field_symbol>.
EXIT.
ENDMETHOD.
REPORT zzx0_mini.
DATA: it_mara TYPE TABLE OF mara.
START-OF-SELECTION.
* Tabellen test
FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
ASSIGN it_mara TO <fs>.
* ASSIGN it_t000 TO <fs>.
CALL METHOD zzx0_cl_test=>field_symbols_tab_test
CHANGING
fs = <fs>.
EXIT.
Similar Messages
-
Field symbol as import parameter in class method ???
Hi everyone,
is it possible to pass a field symbol as an import parameter to a method in a class? If yes, how do I define the data type of the import parameter? I'm trying to work with field symbols as the program doesn't know what kind of structure the program parameter p_srcdso has. Coding example would be something like this:
PARAMETERS: p_srcdso TYPE rsdodsobject DEFAULT '/BIC/AKVI0001'.
DATA: lr_srcpkg TYPE REF TO data.
FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE.
CREATE DATA lr_srcpkg TYPE TABLE OF (p_srcdso).
ASSIGN lr_srcpkg->* TO <fs_table>.
SELECT *
FROM (p_srcdso)
INTO TABLE <fs_table>.
CALL METHOD cl_ref->create_somethign
EXPORTING
i_source_package = <fs_table>.
Thanks,
AlexHalo Alexander,
You can use TYPE REF TO DATA( say the parameter name is i_data) as the importing parameter of the method create_somethign and inside the method you need to dereference it using data reference variable again.
data: dref type ref to data.
field-symbols: <fs_table> type table.
create data dref like i_data.
assign dref->* to <fs_table>.
Regards
Arshad -
Using field symbol on export parameter
HI All,
I am using this logic In few methods of mine and I wonder if there is option the create one method
and every time that I need it just call it.
The issue is that <lt_output> is not assign yet (this need to happen in the method itself )so And I need to export it
and if I am creating method with exporting field type any I put the field symbol there I am getting dump.
Any idea ?
ASSIGN COMPONENT lv_table_out
OF STRUCTURE is_response TO <lt_output>.
IF sy-subrc <> 0.
READ TABLE it_map INTO ls_map INDEX 1.
lv_out = ls_map-left.
ASSIGN COMPONENT lv_out
OF STRUCTURE is_response TO <lt_output>.
ENDIF.
Best regards
JoyHi,
Ok, then you will have to use a data object to reference your field symbol and use a returning parameter I guess:
DATA: lo_data TYPE REF TO data.
FIELD-SYMBOLS: <lt_output> TYPE ANY.
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: get RETURNING value(r_val) TYPE REF TO data.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD get.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN COMPONENT 1 OF STRUCTURE is_response TO <fs>.
GET REFERENCE OF <fs> INTO r_val.
ENDMETHOD. "get
ENDCLASS.
START-OF-SELECTION.
lo_data = lcl_main=>get( ).
ASSIGN lo_data->* TO <lt_output>.
Kr,
m.
Edited by: Manu D'Haeyer on Oct 5, 2011 2:42 PM -
Hi all,
i'm working with classes and interfaces.i have a class and some methods in it.in one of the method i create a new transaction number and this transaction number should be stored in some structures.there are 6 structures.in OO Abap internal table with header line is not allowed. so i have declared like this
WA_ZHEADER TYPE table of ZTMW_HEADER_COM initial size 0
and i am using field symbols as header
field-symbols : <fs1_header> type ztmw_header_com
and then I am Assigning it
<fs1_header>-transaction_num = transaction_num.
assign wa_zheader to <fs1_header> casting.
append <fs1_header> to wa_zheader.
this is how i tried to store the transaction number into the structure(Ztmw_header_com)
but i'm getting the following error
"<FS1_HEADER>" and "WA_ZHEADER" contain references, internal tables, or strings. In the current statement, these must occur at the same offset
position and they must be compatible.
Please help me to resolve this.
Rgds,
PrajithHi there. I think you need to move the casting statement before you assign the transaction number. So the code would be:
WA_ZHEADER TYPE table of ZTMW_HEADER_COM initial size 0
and i am using field symbols as header
field-symbols : <fs1_header> type ztmw_header_com
and then I am Assigning it
assign wa_zheader to <fs1_header> casting.
<fs1_header>-transaction_num = transaction_num.
append <fs1_header> to wa_zheader.
I hope this helps.
- April King -
Using field symbols in method issue
HI All
I created a method as follows and the problem is that when i enter
to the method the i have dump since the field symbol is not
assigned
there is a nice way that i can by-pass this issue ,
the reason that i created a method for that is that
i need to do this operation several of time in my code
The signature
LS_TARGET_STR Importing Type Z_ATTR_STRUCT
ES_ATTR Exporting Type ANY
THe code
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>.
Regards
Alex
Edited by: Alex Dean on Nov 21, 2010 5:13 PMHI Matt
The value of the field is acatully data (this part working Ok)
and after the assign the sybrc = 0.
the problem is with the statment
es_attr = <ls_attr>.
The statment is
DATA: lr_struct TYPE REF TO data.
con_types(
EXPORTING
ls_target_str = ls_target_node-data-attribute_struct " Name of Attribute Structure of Node Entity
IMPORTING
es_attr = lr_struct
And the signature is
LS_TARGET_STR Importing Type Z_ATTR_STRUCT
ES_ATTR Exporting Type ANY
The code of convert types is
FIELD-SYMBOLS <ls_attr> TYPE any.
DATA lo_attr TYPE REF TO data.
CREATE DATA lo_attr TYPE (ls_target_str).
ASSIGN lo_attr->* TO <ls_attr>.
es_attr = <ls_attr>.
***********This is the place that i am
getting the dump . with -> es_attr = <ls_attr>
maybe its becouse that lr_struct is defiend type ref to data .
How can i solve this issue ?
Thanks,
Regards
Alex
Edited by: Alex Dean on Nov 22, 2010 9:36 AM -
Field-symbols as parameters to the method of a class
Hi All,
I am having an doubt regarding the field-symbols.Can we pass the field-symbols as a parameter to the method of a class.If yes can anyone tell me how to do this. Before posting I have searched regarding it in google but I did not find any better solution.Though I have seen some examples regarding the passing of field symbols as a parameter those scenarios does not match with my report as my report varies dynamically based on selection criteria.
Below is the snippet of my code regarding the passing of field-symbols as a parameter.
methods: final_data importing <fs_h_line>TYPE any
<fs_h> TYPE STANDARD TABLE
exporting <fs_f_line> TYPE any
<fs_f> TYPE STANDARD TABLE,
CALL METHOD l_obj->final_data exporting <fs_h_line> = <fs_header_line>
<fs_h> = <fs_header>
importing <fs_f_line> = <fs_final_line>
<fs_f> = <fs_final>.
With the above code I am getting an error.Check whether it is correct or not.If not suggest the solution to resolve the issue.
Regards,
Chakradhar.Hi
Maybe if you change this code below to field-symbol, it can work:
DATA: tl_header_csv TYPE STANDARD TABLE OF yol_header_arquivo,
tl_csv_aux TYPE textline_t .
DATA: wl_header_csv LIKE LINE OF tl_header_csv.
converter_csv_al11_itab( EXPORTING im_t_csv = tl_csv_aux
IMPORTING ex_w_sap = wl_header_csv
CHANGING ex_t_sap = tl_header_csv ).
METHOD converter_csv_al11_itab.
IM_T_CSV Importing Type TEXTLINE_T
EX_W_SAP Exporting Type ANY
EX_T_SAP Changing Type STANDARD TABLE -
Is it possible to declare field symbols inside classes?
Thanks in advance.
Hema
Moderator message: please search for information and try yourself before asking.
Edited by: Thomas Zloch on Dec 23, 2010 10:55 AMHi Hemalatha,
We can use Field Symbols in classes.
local field_symbols within methods are allowed.
you can only use field-symbols within method (locally), not as direct class attribute (globally).
U can check with this sample code.
Sample code is given below:
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS m1 IMPORTING oref TYPE REF TO object attr TYPE string.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
FIELD-SYMBOLS <attr> TYPE ANY.
ASSIGN oref->(attr) TO <attr>.
WRITE <attr> ...
ENDMETHOD.
ENDCLASS.
I hope u got this ..... -
Problem trying to create FIELD SYMBOLS in BADI.
Hi guys!
I'm trying to create a Field Symbol in method CHECK of BADI me_process_req_cust (well, I'm working on a Z implementation).
The problem is that I'm trying to create a FIELD SYMBOL and when I check the syntaxsis, I receive the next error:
Clase ZCL_IM_MM_PURREQ_UPDATE,Método IF_EX_ME_PROCESS_REQ_CUST~CHECK
Names may only consist of the characters "A-Z", "0-9" and "_". In
addition, they may not begin with a number.
This is the code:
FIELD-SYMBOLS: <sy-mereq> TYPE mereq3328-afnam.
Any idea????
Thanks in advance!
BetHi Silveria,
The problem lies in
FIELD-SYMBOLS: <sy-mereq> TYPE mereq3328-afnam.
instead of that it should be something like this
FIELD-SYMBOLS: <sy_mereq> TYPE mereq3328-afnam.
With your code you will be getting a syntax error saying sy-mereq is not defined,as it will be looking for the mereq in the system fields.
Regards
Abhinab Mishra -
How to move a dynamic variable to a FIELD-SYMBOL
Hello:
i would like to ask a favor i have been trying to move a dynamic variable to a FIELD-SYMBOL but, when i compile the programm it send a error message that say 'error with assign'.
The FS is declared like this
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, <dyn_wa>.
and then there is a PERFORM that send a dynamic varible and then this variable is asigned to the <dyn_table> and after of this one variable is created like this CREATE DATA wa_dynamic LIKE LINE OF <dyn_table>.
and finalilly there is a sentences where i trying to send the wa_dynamic to the <dyn_wa>.
here is where the error appear.
if you have any tips for this problem i will appreciate.
thanks a lot
Definition of FS
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, <dyn_wa>.
PERFORM
Create dynamic internal table and Assign it to Field Symbol
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = it_dynamic.
ASSIGN it_dynamic->* TO <dyn_table>.
Create dynamic work area and assign to FS
CREATE DATA wa_dynamic LIKE LINE OF <dyn_table>.
ASSIGN wa_dynamic->* TO <dyn_wa>. "HERE IS THE PROBLEMHow is wa_dynamic defined?
data: wa_dynamic type ref to data.
Regards,
Rich Heilman -
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 -
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 -
Is it possible to pass a field symbol as parameter from any method of view?
Hi
Is it possible to pass a field symbol as an importing parameter to teh globally declared attribute??While it is true that you can pass field symbols, they must be fully typed at the time you pass them and they will be passed by value, not by reference. If you want to pass generically typed variables use a data reference (TYPE REF TO) instead.
-
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 -
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 -
Using Field-Symbols in a user exit to change the importing parameter
Please don't ask why but I need to use a user exit, changing the importing parameter. I decided that I could do this using field-symbols.
Please excuse my ignorance but I have never used field symbols for something such as this.
Here is my goal: Loop through an internal table (im_document-item). When I find what I need I want to make a change to this line (not so hard if I am looping into a field symbol) and also append a line to the end of the table im_document-item.
I have the following so far:
DATA: wa_item TYPE accit,
wa_item_out type ACCIT_SUB.
FIELD-SYMBOLS: <document> type acc_document,
<accit> TYPE ACCIT.
LOOP AT im_document-item ASSIGNING <accit> where saknr = '0000211000'.
* Modify the curent line
wa_item = <accit>
* Append a new line into table im_document-item.
ENDLOOP.
How can I use field-symbols to append a line to this table? Please note that the table in question (im_document-item) is an importing only parameter.
Regards,
Davisthat will allow me to append an initial line with <accit> pointing to the line. Therefore I just have to modify <accit> and the new line will then have my changes?
Yep, that is exactly it. So after the APPEND statement, simply fill the fields of the <accit>.
append initial line to im_document-item ASSIGNING <accit>.
<accit>-field1 = 'Blah'.
<accit>-field2 = 'Blah'.
Regards,
Rich Heilman
Maybe you are looking for
-
HP Pavilion P7-1154, 2nd DVI port not detected
I have a P7-1154 with 2 DVI-D ports. I had a Dell desktop monitor attached via DVI on one port and my HDTV attached on the second port via HDMI adapter. I had video output to BOTH ports, but output to the 2nd port stopped working. There is no proble
-
Passing data values to all the view without inbound plugin
Hi Experts , I am in a complex situation. Scenario is as below. I have 4 views say A, B, C, D when user click Continue on view A he goes on B and so on... Most of the Context created are in COMPONENT CONTROLLER and is being used in Views . This is al
-
Add stroke to placed jpg image
CS3 - have a placed JPG in my illustr document. Can I stroke this box? I don't want to add the stroke to my orig JPG file, I want to stroke to box in illustr. I add the stroke and it doesn't apply, appears to be there in all the boxes, black stroke,
-
MacBook Air and Harmony Remote
I recently purchased a Harmony 900 remote and am trying to configure it on my MacBook air. Harmony admits that there are communication problems with their remotes and Snow Leopard Mac. Their work around is to go to network settings and specifically c
-
Hi How can u make a JSP output while its doing its processing and not ouput after its done all its processing. For example, a jsp reads/accesses a db. The JSP contains a for loop which ouputs data. A statement in the for loop makes a table row. I wan