08-20-2007 10:42 AM
Hello experts,
I have several similar ODSs objects, i would like to read their content (export paramater = structure of the ODS), but i don't want to create the function for every ODS. Is it possible set up export parameter as dynamic or do you have another solution ?
Thanks for advice in advance
Martin
08-20-2007 11:30 AM
declare the import parameter as type ref to DATA
in the program calling the FM first fill this itab with data .
data: itab type <ODSNAMETABLENAME> .
data: odstab type ref to data .
*fill data to itab
get reference of itab into odstab .
now pass this odstab to the FM import parameter (which of type ref to data)
in this approach only the program which is calling the FM whould know the odstable name in design time. this can also be avoided by dynamically creating the itab.
within the FM code you can have the following code to convert the type ref to DATA vairalbe to a itab.
field-symbols: <outtab> type any table .
assign var->* to <outtab> . (where var is the import parameter name which is of type ref to DATA)
Hope this is clear.
Sorry, didnt read the question carefully and missed that you want it as export parameter. you can use similar approach for export param as well
Regards
Raja
Message was edited by:
Durairaj Athavan Raja
08-20-2007 11:30 AM
declare the import parameter as type ref to DATA
in the program calling the FM first fill this itab with data .
data: itab type <ODSNAMETABLENAME> .
data: odstab type ref to data .
*fill data to itab
get reference of itab into odstab .
now pass this odstab to the FM import parameter (which of type ref to data)
in this approach only the program which is calling the FM whould know the odstable name in design time. this can also be avoided by dynamically creating the itab.
within the FM code you can have the following code to convert the type ref to DATA vairalbe to a itab.
field-symbols: <outtab> type any table .
assign var->* to <outtab> . (where var is the import parameter name which is of type ref to DATA)
Hope this is clear.
Sorry, didnt read the question carefully and missed that you want it as export parameter. you can use similar approach for export param as well
Regards
Raja
Message was edited by:
Durairaj Athavan Raja
08-20-2007 1:21 PM
Thanks for help, but i am not sure if i understand that correctly.The structure of the ODSs tables are different, how could i set up export parameter. ?
My example :
import parameter = typ_table
export parameter = e_result
program = if typ_table = 'A' - > table = 'AAA'
else typ_table = 'B' - > table = 'BBB' .....
select * from (table) INTO CORRESPONDING FIELDS OF e_result
the structure of the table (e_result) is different
Is it possible to solve that by your solution ?
Thanks
08-23-2007 6:42 AM
Hi try this solution.
import parameter = typ_table type char30
export parameter = e_result type table
****Function module code******
FUNCTION ZZZZZ.
*"----
""Local interface:
*" IMPORTING
*" REFERENCE(TYP_TABLE) TYPE CHAR20
*" EXPORTING
*" REFERENCE(E_RESULT) TYPE TABLE
*"----
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
DATA : itab1 TYPE REF TO data.
FIELD-SYMBOLS : <lt_result> TYPE STANDARD TABLE.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( typ_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = itab1.
ASSIGN itab1->* TO <lt_result>.
DATA: l_rec_d TYPE REF TO data.
FIELD-SYMBOLS: <l_rec>.
CREATE DATA: l_rec_d LIKE LINE OF <lt_result>.
ASSIGN l_rec_d->* TO <l_rec>.
SELECT * FROM (itab) INTO corresponding fields of TABLE <lt_result>.
LOOP AT <lt_result> INTO <l_rec>.
INSERT <l_rec> INTO TABLE e_result.
ENDLOOP.
ENDFUNCTION.
**************************************
If your query is answered close the thread and reward points.
Cheers
Shafiq
08-24-2007 2:03 PM
Hi,
thanks a lot, but I have one small problem.
I received an error if i use some Key Figure (e.g. 0ACC_QTY) in the table - error icompatible fields.
I can see in the table definition length(17) and decim. places 3 for KF, but in the line of program (debug) , i see
xfc-intlen = xdetails-length. - > 9
xfc-decimals = xdetails-decimals.- > 3
Do you have any idea ?
Thanks Martin
08-20-2007 11:55 AM
Hi
You can try the following approach.
Lets assume your ODS structure which bring the data is XTH_DATA.
***Creating Dynamic internal table of type XTH_DATA.***
DATA : LT_RESULT_D TYPE REF TO DATA.
**If the incoming table is hashed type**
FIELD-SYMBOLS : <LT_RESULT> TYPE HASHED TABLE. "
CREATE DATA: LT_RESULT_D LIKE XTH_DATA.
**Creating Dynamic work area**
DATA: L_REC_D TYPE REF TO DATA.
FIELD-SYMBOLS: <L_REC> TYPE ANY.
CREATE DATA: L_REC_D LIKE LINE OF XTH_DATA.
ASSIGN:
LT_RESULT_D->* TO <LT_RESULT>,
L_REC_D->* TO <L_REC>.
In addition, we also should create field symbols for every***
field which will be used directly in the further code.***
FIELD-SYMBOLS : <CALMONTH2> TYPE /BI0/OICALMONTH2 .
LOOP AT XTH_DATA ASSIGNING <L_REC>.
ASSIGN COMPONENT :
'S_CHAS-0CALMONTH2' OF STRUCTURE <L_REC> TO <CALMONTH2>.
IF <CALMONTH2> = '02' .
INSERT <L_REC> INTO TABLE <LT_RESULT>.
ENDIF.
ENDLOOP.
If it solves ur query kindly close the thread and award points.
Cheers
Shafiq