Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

I want to use RTTC but.....

rosenberg_eitan
Active Contributor
0 Kudos

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

1 ACCEPTED SOLUTION

philipdavy
Contributor
0 Kudos

Hi     

 

  •    I did some research on your problem. It may be a unicode issue. The length is calculated in terms of bytes rather than in characters. That is the reason why you are getting a dumb on your select statement. While debugging I found out that the your  'luggweight'  is of type P(5) Decimals (4) which may not be adequate enough. There are some similar problems posted.
  • Please refer to that,

.

Regards,

Philip.

8 REPLIES 8

philipdavy
Contributor
0 Kudos

Hi     

 

  •    I did some research on your problem. It may be a unicode issue. The length is calculated in terms of bytes rather than in characters. That is the reason why you are getting a dumb on your select statement. While debugging I found out that the your  'luggweight'  is of type P(5) Decimals (4) which may not be adequate enough. There are some similar problems posted.
  • Please refer to that,

.

Regards,

Philip.

0 Kudos

Hi ,

I know that the field is no big enough.

I want to learn how I can increase the field size using RTTC .

Regards.

0 Kudos

Hi Eitan Rosenberg   ,

  • This solution is just to avoid the dump you are facing. (Not a classical solution )
  • If you know the length and type of the variable or (at least a guesstimate so that the target field will be superfluous *in terms of length* ).


  st_component-type = cl_abap_elemdescr=>get_p(

                       p_length   = 8

                       p_decimals = 5 ).

Regards,

Philip.

0 Kudos

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

0 Kudos

Yes , You are right.

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.

0 Kudos

If you can throw in also the labels...

0 Kudos

I meant to overide the result of:

st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_LUGWEIGH' ).

Regards.

SuhaSaha
Advisor
Advisor
0 Kudos

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