2016 Sep 13 10:29 AM
Hi experts,
i have read many blogs to display data through tables parameters in function module .
My problem is, i am not able to display the data using internal dynamic table .i have return the code in the source tab and want to display the output data to tables parameters by using the Declared table in tables parameters. how to declare the table in table parameter. Please provide me the solution. i have tried in many ways.
Thanks & Regards
kesav
2016 Sep 13 10:43 AM
Hi,
if you are having dynamic internal table then you can use Exporting or Tables with specifying giving table type.
thank you!!
Hi experts,
i have read many blogs to display data through tables parameters in function module .
My problem is, i am not able to display the data using internal dynamic table .i have return the code in the source tab and want to display the output data to tables parameters by using the Declared table in tables parameters. how to declare the table in table parameter. Please provide me the solution. i have tried in many ways.
Thanks & Regards
kesav
2016 Sep 13 10:43 AM
Hi,
if you are having dynamic internal table then you can use Exporting or Tables with specifying giving table type.
thank you!!
2016 Sep 13 10:58 AM
Hi Chintu adi,
Thanks for your prompt reply .
The requirement is : import parameters will pick any executable program and the output of that should be displayed using export or table parameters .
My code is working fine till it gets data to dynamic internal table .
I am unable to pass my dynamic internal table data to export or table parameters .
please find the code for your reference and provide me solution how should be pass data to export or tables parameters.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_PROGRAMNAME) TYPE SY-REPID
*" VALUE(IM_SELTAB) TYPE RSPARAMS_TT
*" EXPORTING
*" REFERENCE(E_INTERNAL_TABLE)
*" TABLES
*" T_TABLES
*"----------------------------------------------------------------------
DATA : lr_pay_data TYPE REF TO data,
wa_alv_data TYPE REF TO data.
FIELD-SYMBOLS <infty_tab_wa> TYPE c.
FIELD-SYMBOLS : <work_tab> TYPE table,
<wa_work_tab> TYPE any,
<fs> TYPE any.
DATA : l_string TYPE string.
DATA: it_comp TYPE TABLE OF rstrucinfo,
go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gt_comp TYPE abap_compdescr_tab,
gs_comp TYPE abap_compdescr.
* Start of Changes added by Hareendra for dynamic creation of fieldcat
FIELD-SYMBOLS: <t_dyntable> TYPE INDEX TABLE, " Dynamic internal table name
<fs_dyntable> TYPE any, " “ Field symbol to create work area
<fs_fldval> TYPE any. "“ Field symbol to assign values
*Field symbol declaration
##NEEDED
FIELD-SYMBOLS: <fs_t_header> TYPE STANDARD TABLE,
<fs_t_item> TYPE STANDARD TABLE.
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_output TYPE REF TO data,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(3) TYPE n,
wa_flname(10) TYPE c,
it_alv_data TYPE REF TO data.
DATA: lr_data_descr TYPE REF TO cl_abap_datadescr,
lr_data_line_descr TYPE REF TO cl_abap_datadescr,
lr_data TYPE REF TO data , "##NEEDED
lr_data_line TYPE REF TO data, "##NEEDED
gs_metadata TYPE cl_salv_bs_runtime_info=>s_type_metadata.
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: l_index(3) TYPE c.
* Create fields .
DO 199 TIMES.
CLEAR wa_it_fldcat.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
break c839746.
ASSIGN t_newtable->* TO <t_dyntable>.
* Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
* CREATE DATA lr_pay_data LIKE et_alv_data[].
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_true
data = abap_true ).
SUBMIT (im_programname) WITH SELECTION-TABLE im_seltab AND RETURN.
TRY.
CALL METHOD cl_salv_bs_runtime_info=>get_data_ref
IMPORTING
r_data = lr_pay_data.
ASSIGN lr_pay_data->* TO <fs_dyntable>.
CATCH cx_salv_bs_sc_runtime_info .
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
**************
data : lo_itab type ref to cl_abap_tabledescr,
lo_line TYPE REF TO cl_abap_datadescr,
lo_struct TYPE REF TO cl_abap_structdescr.
lo_itab ?= cl_abap_typedescr=>describe_by_Data( <fs_dyntable> ).
lo_line = lo_itab->get_table_line_type( ).
if lo_line->kind = cl_abap_typedescr=>kind_struct.
lo_struct ?= lo_line.
FIELD-SYMBOLS <wa> like line of lo_struct->components.
DATA: IT_FIELDCAT1 TYPE LVC_T_FCAT,
wa_FIELDCAT1 LIKE LINE OF IT_FIELDCAT1.
LOOP AT lo_Struct->components ASSIGNING <wa>.
wa_fieldcat1-fieldname = <wa>-name.
wa_fieldcat1-inttype = <wa>-type_kind." 'C'.
wa_fieldcat1-outputlen = <wa>-length."'10'.
wa_fieldcat1-coltext = <wa>-name."'My Field 1'.
wa_fieldcat1-seltext = wa_fieldcat1-coltext.
APPEND wa_fieldcat1 to it_fieldcat1.
clear : wa_fieldcat1.
endloop.
DATA: NEW_TABLE1 TYPE REF TO DATA.
DATA: NEW_LINE1 TYPE REF TO DATA.
* it should be standard table otherwise it will not work
FIELD-SYMBOLS: <L_TABLE1> TYPE STANDARD TABLE,
<L_LINE1> TYPE ANY,
<L_FIELD1> TYPE ANY,
<w_field> TYPE ANY.
* Create a new DYNAMIC INT TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT1
IMPORTING
EP_TABLE = NEW_TABLE1.
ASSIGN NEW_TABLE1->* TO <L_TABLE1>.
CREATE DATA NEW_LINE1 LIKE LINE OF <L_TABLE1>.
*CREATE DATA E_INTERNAL_TABLE LIKE LINE OF <L_TABLE1>.
ASSIGN NEW_LINE1->* TO <L_LINE1>.
LOOP AT lo_Struct->components ASSIGNING <wa>.
ASSIGN COMPONENT <wa>-name OF STRUCTURE <L_LINE1> TO <w_field>.
<w_field> = 'XXXX'.
APPEND <L_line1> TO <L_TABLE1>.
endloop.
i want to pass <L_TABLE1> to export or table parameters.
Thanks & Regards
kesav
2016 Sep 13 11:07 AM
Did you consider using generic type "TABLE" for your exporting parameter? And of course you can use a data reference (TYPE REF TO DATA).
2016 Sep 13 11:12 AM
Hi Andre ,
Thanks for prompt reply .
if i use TYPE REF TO DATA , not able to test the FM.
For your Reference please find the code.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_PROGRAMNAME) TYPE SY-REPID
*" VALUE(IM_SELTAB) TYPE RSPARAMS_TT
*" EXPORTING
*" REFERENCE(E_INTERNAL_TABLE)
*" TABLES
*" T_TABLES
*"----------------------------------------------------------------------
DATA : lr_pay_data TYPE REF TO data,
wa_alv_data TYPE REF TO data.
FIELD-SYMBOLS <infty_tab_wa> TYPE c.
FIELD-SYMBOLS : <work_tab> TYPE table,
<wa_work_tab> TYPE any,
<fs> TYPE any.
DATA : l_string TYPE string.
DATA: it_comp TYPE TABLE OF rstrucinfo,
go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gt_comp TYPE abap_compdescr_tab,
gs_comp TYPE abap_compdescr.
* Start of Changes added by Hareendra for dynamic creation of fieldcat
FIELD-SYMBOLS: <t_dyntable> TYPE INDEX TABLE, " Dynamic internal table name
<fs_dyntable> TYPE any, " “ Field symbol to create work area
<fs_fldval> TYPE any. "“ Field symbol to assign values
*Field symbol declaration
##NEEDED
FIELD-SYMBOLS: <fs_t_header> TYPE STANDARD TABLE,
<fs_t_item> TYPE STANDARD TABLE.
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_output TYPE REF TO data,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(3) TYPE n,
wa_flname(10) TYPE c,
it_alv_data TYPE REF TO data.
DATA: lr_data_descr TYPE REF TO cl_abap_datadescr,
lr_data_line_descr TYPE REF TO cl_abap_datadescr,
lr_data TYPE REF TO data , "##NEEDED
lr_data_line TYPE REF TO data, "##NEEDED
gs_metadata TYPE cl_salv_bs_runtime_info=>s_type_metadata.
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: l_index(3) TYPE c.
* Create fields .
DO 199 TIMES.
CLEAR wa_it_fldcat.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
break c839746.
ASSIGN t_newtable->* TO <t_dyntable>.
* Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
* CREATE DATA lr_pay_data LIKE et_alv_data[].
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_true
data = abap_true ).
SUBMIT (im_programname) WITH SELECTION-TABLE im_seltab AND RETURN.
TRY.
CALL METHOD cl_salv_bs_runtime_info=>get_data_ref
IMPORTING
r_data = lr_pay_data.
ASSIGN lr_pay_data->* TO <fs_dyntable>.
CATCH cx_salv_bs_sc_runtime_info .
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
**************
data : lo_itab type ref to cl_abap_tabledescr,
lo_line TYPE REF TO cl_abap_datadescr,
lo_struct TYPE REF TO cl_abap_structdescr.
lo_itab ?= cl_abap_typedescr=>describe_by_Data( <fs_dyntable> ).
lo_line = lo_itab->get_table_line_type( ).
if lo_line->kind = cl_abap_typedescr=>kind_struct.
lo_struct ?= lo_line.
FIELD-SYMBOLS <wa> like line of lo_struct->components.
DATA: IT_FIELDCAT1 TYPE LVC_T_FCAT,
wa_FIELDCAT1 LIKE LINE OF IT_FIELDCAT1.
LOOP AT lo_Struct->components ASSIGNING <wa>.
wa_fieldcat1-fieldname = <wa>-name.
wa_fieldcat1-inttype = <wa>-type_kind." 'C'.
wa_fieldcat1-outputlen = <wa>-length."'10'.
wa_fieldcat1-coltext = <wa>-name."'My Field 1'.
wa_fieldcat1-seltext = wa_fieldcat1-coltext.
APPEND wa_fieldcat1 to it_fieldcat1.
clear : wa_fieldcat1.
endloop.
DATA: NEW_TABLE1 TYPE REF TO DATA.
DATA: NEW_LINE1 TYPE REF TO DATA.
* it should be standard table otherwise it will not work
FIELD-SYMBOLS: <L_TABLE1> TYPE STANDARD TABLE,
<L_LINE1> TYPE ANY,
<L_FIELD1> TYPE ANY,
<w_field> TYPE ANY.
* Create a new DYNAMIC INT TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT1
IMPORTING
EP_TABLE = NEW_TABLE1.
ASSIGN NEW_TABLE1->* TO <L_TABLE1>.
CREATE DATA NEW_LINE1 LIKE LINE OF <L_TABLE1>.
*CREATE DATA E_INTERNAL_TABLE LIKE LINE OF <L_TABLE1>.
ASSIGN NEW_LINE1->* TO <L_LINE1>.
LOOP AT lo_Struct->components ASSIGNING <wa>.
ASSIGN COMPONENT <wa>-name OF STRUCTURE <L_LINE1> TO <w_field>.
<w_field> = 'XXXX'.
APPEND <L_line1> TO <L_TABLE1>.
endloop.
i want to pass <L_TABLE1> to export or table parameters.
Thanks & Regards
kesav.
2016 Sep 13 11:23 AM
Yes you won't be able to test the FM through the standard test frame (SM37) if you use a generic type in the FMs Interface.
But that is no problem. Just write your own test program to call the FM.
And as the type of your exporting parameter just use the generic type "STANDARD TABLE". The assignment from your local field-symbol <L_TABLE1> of generic type "STANDARD TABLE" to an Exporting Parameter of generic type "STANDARD TABLE" will always work.
2016 Sep 13 12:34 PM
Hi Andre,
I followed your steps, code works with no syntax and no errors while executing but no data moves from <L_TABLE1> to export parameter.
i Used 3 types to move data , just for your reference .
e_internal_table = <L_TABLE1>.
e_internal_table = <L_TABLE1>[].
MOVE-CORRESPONDING <L_TABLE1> to e_internal_table .
This way its not working. Please suggest me.
Thanks & Regards
Kesav
2016 Sep 13 1:10 PM
Please note that when you call the FM, the generic type "TABLE" of formal parameter "e_internal_table" gets replaced with the type of the actual parameter you assigned to it.
That means that you have to know the type of the table when you call the FM.
If this is not possible, than you have to export a data reference and dereference it after calling the FM.
When I look at your code I assume that you want an FM that can give back a table of a type that is unknown in the moment you call the FM. In this case data reference is your way to go.
2016 Sep 13 2:15 PM
Hi Andre,
Thanks for Understanding and reply.
Can you please share me the coding. i will be thank full to you.
I tried & could not reach to the proper output.
Thanks & Regards
Kesav
2016 Sep 13 2:35 PM
This is your FM
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_PROGRAMNAME) TYPE SY-REPID
*" VALUE(IM_SELTAB) TYPE RSPARAMS_TT
*" EXPORTING
*" REFERENCE(ER_DATA) TYPE REF TO DATA
*"----------------------------------------------------------------------
.... YOUR CODE....
* last line of your code
GET REFERENCE OF <l_table1> INTO er_data.
This is a snippet of the calling program
DATA: lr_data TYPE REF TO data.
FIELD-SYMBOLS: <lt_any> TYPE STANDARD TABLE.
CALL FUNCTION '...YOUR FM...'
IMPORTING
er_data = lr_data.
ASSIGN lr_data->* TO <lt_any>.
This is a very basic work with field symbols and data references. I would recommend that you have a close look at the documentations to learn about these topics.
2016 Sep 13 2:51 PM
Hi Andre ,
Thank you so much for your remarkable effort.
Thanks & regards
Kesav