07-01-2014 7:21 AM
Hi,
Some time ago I wrote this program http://scn.sap.com/community/abap/blog/2013/12/26/sdbadbc--the-program
that utilize cl_sql_connection .
In this program I used cl_alv_table_create=>create_dynamic_table .
Now I want to move to RTTC.
I ran into a problem represented in "Y_R_EITAN_TEST_04_07" .
REPORT Y_R_EITAN_TEST_04_07 .
*----------------------------------------------------------------------*
START-OF-SELECTION .
PERFORM at_start_of_selection .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM at_start_of_selection .
PERFORM test_08 .
ENDFORM . "at_start_of_selection
*----------------------------------------------------------------------*
FORM test_08 .
* Hard coded structure .
* If I will use this table with CL_SALV_TABLE I will not get the standard headings
TYPES: BEGIN OF tp_sum_1 .
TYPES: carrid TYPE sbook-carrid ,
luggweight TYPE p DECIMALS 4 .
TYPES: END OF tp_sum_1 .
data: it_sum_1 TYPE TABLE OF tp_sum_1 .
SELECT carrid SUM( luggweight ) AS luggweight
INTO CORRESPONDING FIELDS OF TABLE it_sum_1
FROM sbook
GROUP BY
carrid .
* it_sum_1 looks ok .
BREAK-POINT .
DATA: it_component TYPE cl_abap_structdescr=>component_table .
DATA: st_component LIKE LINE OF it_component .
DATA: ob_abap_structdescr TYPE REF TO cl_abap_structdescr,
ob_abap_tabledescr TYPE REF TO cl_abap_tabledescr .
st_component-name = 'CARRID'.
st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_CARR_ID' ).
APPEND st_component TO it_component .
st_component-name = 'LUGGWEIGHT'.
st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_LUGWEIGH' ).
* At this point I want to increase the size of LUGGWEIGHT so I can use it as
* a target to SQL sum function .
* The equivalent of using :
* cl_alv_table_create=>create_dynamic_table
* lvc_t_fcat-intlen = 12 ."Hope that this is enough....
* lvc_t_fcat-inttype = 'P' .
APPEND st_component TO it_component .
DATA: r_data_tab TYPE REF TO data,
r_data_str TYPE REF TO data.
TRY.
ob_abap_structdescr = cl_abap_structdescr=>create( it_component ).
CATCH cx_sy_struct_creation .
ENDTRY.
TRY.
ob_abap_tabledescr = cl_abap_tabledescr=>create( ob_abap_structdescr ).
CATCH cx_sy_table_creation .
ENDTRY.
CREATE DATA: r_data_tab TYPE HANDLE ob_abap_tabledescr ,
r_data_str TYPE HANDLE ob_abap_structdescr .
FIELD-SYMBOLS: <it_data> TYPE INDEX TABLE,
<st_data> TYPE ANY.
ASSIGN: r_data_tab->* TO <it_data> ,
r_data_str->* TO <st_data> .
* I get a dump here...
SELECT carrid SUM( luggweight ) AS luggweight
INTO CORRESPONDING FIELDS OF TABLE <it_data>
FROM sbook
GROUP BY
carrid .
BREAK-POINT .
ENDFORM . "test_08
07-01-2014 9:57 AM
Regards,
Philip.
07-01-2014 9:57 AM
Regards,
Philip.
07-01-2014 10:06 AM
Hi ,
I know that the field is no big enough.
I want to learn how I can increase the field size using RTTC .
Regards.
07-01-2014 11:08 AM
Hi Eitan Rosenberg ,
st_component-type = cl_abap_elemdescr=>get_p(
p_length = 8
p_decimals = 5 ).
Regards,
Philip.
07-01-2014 11:16 AM
Hello Philip,
I think why Eitan wanted to use the data element(S_LUGWEIGH) instead of directly typing the field is that he wanted to use the field labels
BR,
Suhas
07-01-2014 11:27 AM
But there is one commented part in his code which goes like this.
"
* At this point I want to increase the size of LUGGWEIGHT so I can use it as
* a target to SQL sum function .
* The equivalent of using :
* cl_alv_table_create=>create_dynamic_table
* lvc_t_fcat-intlen = 12 ."Hope that this is enough....
* lvc_t_fcat-inttype = 'P' .
"
From this I am deciphering that he is also looking for giving out the ways to give type and length explicitly. Correct me If I am wrong.
Regards,
Philip.
07-01-2014 11:44 AM
07-01-2014 11:46 AM
I meant to overide the result of:
st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_LUGWEIGH' ).
Regards.
07-01-2014 10:12 AM
Hello Eitan,
This is a classical mistake. I don't remember the rules but i know where to find them
I hope these will provide you with better insight.
Edit 11:19:
I was wrong yesterday, the attribute LENGTH is public-read only so you cannot (& should not) change the value. I would rather create a custom data element and define the length accordingly.
BR,
Suhas