06-27-2014 9:23 AM
Hi guys,
The method create_dynamic_table from cl_alv_table_create has as exporting parameter a fielcatalog table. I want to insert a table type in this table, basically the field INTTYPE from LVC_S_FCAT can do that if u put the value 'h' in it. But I notice, that in method implementations all the cases are considered:
C | Character String |
N | Character String with Digits Only |
D | Date (Date: YYYYMMDD) |
T | Time (Time: HHMMSS) |
X | Byte Sequence (heXadecimal) |
I | Integer number (4-byte integer with sign) |
b | 1-byte integer, integer number <= 254 |
s | 2-byte integer, only for length field before LCHR or LRAW |
P | Packed number |
F | Floating point number to accuracy of 8 bytes |
and other, but not 'h'.
Does anybody knows how create a dynamic table with a table type inside ? The table type has the structure from data dictionary lvc_t_scol.
Ionut.
06-29-2014 6:50 AM
Hi Ionut,
I had come across such a requirement recently, My requirement was to add a cell coloring field(type internal table) for ALV.
I solved this by the below code.. This is very easy....
CLEAR gwa_fldcat_2.
gwa_fldcat_2-fieldname = 'TCOLOR'.
gwa_fldcat_2-tech = abap_true. " Technical Field
gwa_fldcat_2-ref_field = 'SCOL'. " A Field in /BEV2/ED_DETAILS_MATBEL_ALV.SCOL type LVC_T_SCOL(Table Type).
gwa_fldcat_2-ref_table = '/BEV2/ED_DETAILS_MATBEL_ALV'. " A Structure
APPEND gwa_fldcat_2 TO git_fldcat_2.
The Field TCOLOR accrue the type of field SCOL in /BEV2/ED_DETAILS_MATBEL_ALV.
Regards
Sreekanth
06-27-2014 9:48 AM
Alternate & better option to create dynamic table is using RTTS class, search for the class cl_abap_tabledescr in SCN you will find many documents.
Thanks,
Sharath
06-27-2014 11:40 AM
Hi,
I search in SCN but I didn't find nothing like that, in fact, I found a similar question with no answer.
I use cl_abap_tabledescr. This is the code and it is working.:
FORM create_dynamic_tables USING wa.
DATA: ref_table_des TYPE REF TO cl_abap_structdescr,
ref_table_alv TYPE REF TO cl_abap_structdescr,
lt_details TYPE abap_compdescr_tab,
ls_field_catalog TYPE lvc_s_fcat,
ls_details TYPE abap_compdescr,
ls_dynline TYPE REF TO data,
lt_dyntable TYPE REF TO data,
l_tabix TYPE i,
l_tabix_cf TYPE i,
l_tabname TYPE dd03l-tabname,
l_decimals TYPE dd03l-decimals,
l_intlen TYPE dd03l-intlen.
REFRESH lt_details.
ref_table_alv ?=
cl_abap_typedescr=>describe_by_data( wa ).
lt_details[] = ref_table_alv->components[].
CLEAR l_tabix.
LOOP AT lt_details INTO ls_details.
CLEAR ls_field_catalog.
ADD 1 TO l_tabix.
CLEAR ls_field_catalog.
MOVE: ls_details-name TO ls_field_catalog-fieldname,
ls_details-type_kind TO ls_field_catalog-inttype,
ls_details-decimals TO ls_field_catalog-decimals,
ls_details-length TO ls_field_catalog-dd_outlen.
CASE ls_details-name.
WHEN 'PASTRTERM' OR 'PAENDTERM' OR 'ENSTEHDAT'
OR 'PRUEFLOS' OR 'LOSMENGE' OR 'MENGENEINH'
OR 'ART' OR 'HERKUNFT' OR 'SLWBEZ'
OR 'MATNR' OR 'SELWERKS' OR 'CHARG'
OR 'KTEXTLOS' OR 'KTEXTMAT' OR 'SELWERK'.
MOVE 'QALS' TO: l_tabname,
ls_field_catalog-tabname.
PERFORM select_text USING ls_field_catalog-scrtext_s
ls_field_catalog-scrtext_m
ls_field_catalog-scrtext_l
ls_field_catalog-reptext
ls_field_catalog-rollname
ls_field_catalog-domname
l_tabname
ls_details-name.
.....
......
ENDCASE.
MOVE l_tabix TO ls_field_catalog-col_pos.
ls_field_catalog-no_merging = ''.
APPEND ls_field_catalog TO gt_alv_s_fcat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_alv_s_fcat
IMPORTING
ep_table = gt_dyntab.
ASSIGN gt_dyntab->* TO <dyn_table_output>.
CREATE DATA ls_dynline LIKE LINE OF <dyn_table_output>.
ASSIGN ls_dynline->* TO <dyn_wa_output>.
Now, i want to put a table type in <dyn_table_output>..
Ionut.
06-27-2014 1:45 PM
cl_alv_table_create=>create_dynamic_table( ) is no longer recommended to build dynamic tables.
RTTC classes are very intuitive and quite easy to maintain.
BR,
Suhas
06-27-2014 2:51 PM
In staid of gwa_struct_field-type = cl_abap_elemdescr=>get_c( 10 ).
I need gwa_struct_field-type = cl_abap_elemdescr=>get_h ????.
I now that I can create with CL_ABAP_STRUCTDESCR=>CREATE ( ... ) but how I insert a table type ? Not a char of 10 ?
I know this cases:
* WHEN 'STRING'. ls_typ = cl_abap_elemdescr=>get_string( ).
* WHEN 'XSTRING'. ls_typ = cl_abap_elemdescr=>get_xstring( ).
* WHEN 'I'. ls_typ = cl_abap_elemdescr=>get_i( ).
* WHEN 'F'. ls_typ = cl_abap_elemdescr=>get_f( ).
* WHEN 'D'. ls_typ = cl_abap_elemdescr=>get_d( ).
* WHEN 'T'. ls_typ = cl_abap_elemdescr=>get_t( ).
* WHEN 'C'. ls_typ = cl_abap_elemdescr=>get_c( p_length = ls_details-length ).
* WHEN 'N'. ls_typ = cl_abap_elemdescr=>get_n( p_length = ls_details-length ).
* WHEN 'X'. ls_typ = cl_abap_elemdescr=>get_x( p_length = ls_details-length ).
* WHEN 'P'. ls_typ = cl_abap_elemdescr=>get_p( p_length = ls_details-length p_decimals = ls_details-decimals ).
Where is table type ?
Ionut.
06-27-2014 3:29 PM
That is what i have mentioned:
* f3 TYPE flighttab
gwa_struct_field-name = `F3`.
gwa_struct_field-type ?= cl_abap_typedescr=>describe_by_name( `FLIGHTTAB` ).
APPEND gwa_struct_field TO gt_struct_fields.
CLEAR gwa_struct_field.
FLIGHTTAB is a table type. Did you even see it?
06-29-2014 6:32 AM
Hi,
31.* Use the structure object to build the table
32. goref_table = cl_abap_tabledescr=>get(
33. cl_abap_structdescr=>get( gt_struct_fields )
34. ).
On what release are you ?
I am using cl_abap_tabledescr=>create
Regards.
06-29-2014 9:45 AM
On what release are you ?
I am working with ABAP release 740 (SP02).
The GET( ) methods have been part of the ABAP release 7.0 EhP2 - ABAP Keyword Documentation .
If you are on the relevant ABAP release then i think you should use GET( ) and not CREATE( ). Here's the reason why - .
BR,
Suhas
06-29-2014 11:08 AM
I am not there yet .
I do have a question:
DATA: it_component TYPE abap_component_tab .
DATA: st_component LIKE LINE OF it_component .
st_component-name = 'PAYMENTSUM'.
st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_SUM' ).
* I like the headings...
* Is it possible at this point to change the length of the field ?
APPEND st_component TO it_component .
Regards.
06-30-2014 10:11 AM
Hello Eitan,
Sorry for the late reply
* I like the headings...
* Is it possible at this point to change the length of the field ?
I don't understand what do you mean? Can you please explain in detail?
BR,
Suhas
06-30-2014 10:39 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 and the rest of the gang .
In this program I used cl_alv_table_create=>create_dynamic_table .
Now I want to move to RTTS.
Since I am using lvc_s_fcat I was able to increase the field size when using SQL sum function.
The original definition of "Weight of Luggage" (S_LUGWEIGH) is quite small to be a target of sum but using this trick I can have this:
How I can do this with RTTS ? I want to modify the result of cl_abap_elemdescr=>describe_by_name( 'S_LUGWEIGH' ).
Regards.
06-30-2014 11:30 AM
Ahh, gotcha.
I think you can change the value of the attribute LENGTH for "S_LUGWEIGH" RTTI object. I have never tried it, but worth a shot!
The attribute is public, read-only so cannot be changed. My bad
BR,
Suhas
06-30-2014 11:36 AM
06-29-2014 6:50 AM
Hi Ionut,
I had come across such a requirement recently, My requirement was to add a cell coloring field(type internal table) for ALV.
I solved this by the below code.. This is very easy....
CLEAR gwa_fldcat_2.
gwa_fldcat_2-fieldname = 'TCOLOR'.
gwa_fldcat_2-tech = abap_true. " Technical Field
gwa_fldcat_2-ref_field = 'SCOL'. " A Field in /BEV2/ED_DETAILS_MATBEL_ALV.SCOL type LVC_T_SCOL(Table Type).
gwa_fldcat_2-ref_table = '/BEV2/ED_DETAILS_MATBEL_ALV'. " A Structure
APPEND gwa_fldcat_2 TO git_fldcat_2.
The Field TCOLOR accrue the type of field SCOL in /BEV2/ED_DETAILS_MATBEL_ALV.
Regards
Sreekanth
06-30-2014 7:36 AM