2009 May 05 6:48 PM
I have a dynamic internal table created via
DATA: e_dyntab_tb TYPE lvc_t_fcat,
i_reftab TYPE REF TO data.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = e_dyntab_tb "Pass alv_fcat here
IMPORTING
ep_table = i_reftab.
* Create Dynamic Work Area and assign to FS
ASSIGN i_reftab->* TO <fs_final_itab>. "Assigning the Final Table,
CREATE DATA t_line_reftab LIKE LINE OF <fs_final_itab>.
ASSIGN t_line_reftab->* TO <fs_line_reftab>. "Create a Work Area
e_dyntab_tb contains the structure of lvc_t_fcat and is being populated by:
MOVE: c_matnr TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
MOVE: c_maktx TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
MOVE: c_meins TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
So onu2026
The Class cl_alv_table_create=>create_dynamic_table automatically inherits the data type definition of the field being populated in the e_dyntab_wa;
For instance, matnru2019s data type is character(18) and meinsu2019 data type is unit., etc
PROBLEM:
How can I append a column string header in the fist row of the dynamic internal table ( <fs_final_itab> ) ?
Please take note that the structure of <fs_final_itab> is metadata (different data types) so there will be a type mismatch for moving the word u2018WEEK1u2019 to field MENGE which is one of the data type definition in the structure of <fs_final_itab>.
Edited by: Jaime Cabanban on May 6, 2009 2:03 AM
I have a dynamic internal table created via
DATA: e_dyntab_tb TYPE lvc_t_fcat,
i_reftab TYPE REF TO data.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = e_dyntab_tb "Pass alv_fcat here
IMPORTING
ep_table = i_reftab.
* Create Dynamic Work Area and assign to FS
ASSIGN i_reftab->* TO <fs_final_itab>. "Assigning the Final Table,
CREATE DATA t_line_reftab LIKE LINE OF <fs_final_itab>.
ASSIGN t_line_reftab->* TO <fs_line_reftab>. "Create a Work Area
e_dyntab_tb contains the structure of lvc_t_fcat and is being populated by:
MOVE: c_matnr TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
MOVE: c_maktx TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
MOVE: c_meins TO e_dyntab_wa-fieldname.
APPEND e_dyntab_wa TO e_dyntab_tb.
So onu2026
The Class cl_alv_table_create=>create_dynamic_table automatically inherits the data type definition of the field being populated in the e_dyntab_wa;
For instance, matnru2019s data type is character(18) and meinsu2019 data type is unit., etc
PROBLEM:
How can I append a column string header in the fist row of the dynamic internal table ( <fs_final_itab> ) ?
Please take note that the structure of <fs_final_itab> is metadata (different data types) so there will be a type mismatch for moving the word u2018WEEK1u2019 to field MENGE which is one of the data type definition in the structure of <fs_final_itab>.
Edited by: Jaime Cabanban on May 6, 2009 2:03 AM
2009 May 05 8:27 PM
Hi Jaime,
I think you are mixing things up.
First of all you have to know that we distinguish technical and semantic attirbutes. First ones are used in all programs simply for defining a data object, a structure, a table. These are also visible at domain level in ABAP Dictionary, whereas the latter are available at date element level.
Now how this reflects in your program.
Generally programs usues only technical attributes i.e when you define such structure:
data: begin of my_structure,
molga type T500l-molga,
...
end of my_structure.
As you can see molga here doesn't tell us what is the desciption behind it. It is a type which does the trick. During runtime system checks semantic attributes of T500L-MOLGA (semantic here means its label for example). molga here could be easily changed to my_field but would mean the same as long as the typing wouldn't change (still we would have the same description).
Technical attributes, on the other hand, just describe what is the lenght and type of this field.
When you run the program in debug mode, you can see that no description of the column would be visible. Column would be named molgda not Contry Grouping . It is task of screen processor to get this description once you display your field in ALV or use this field on screen.
Having this knowledge you probably already realized that you can't provide desription of the column in your dynamic table. It will have technical names of fields like C_MATNR, C_MEINS but never 'Material' etc.
This will show up only when this column is used in your ALV.
For this in your fieldcatalog you need to provide a reference to a data element or field of a table from DDIC.
e_dyntab_wa-REF_FIELD = "here provide field name of a DDIC table which you are refering to
e_dyntab_wa-REF_TABLE = "and a DDIC table name
That's all you need. In debugger you will still only see technical description but on the screen, screen processor will pull out the description of column for you.
Regards
Marcin
2009 May 06 5:10 PM
Hi Marcin,
Yes the screen processor will automatically put the description of the column for me in my ALV output.
My scenario is quite unique though,
since I manually remove the SAP standard ALV buttons, I need to add a customize functionality to extract the current ALV output (dynamic), and put into an internal table where it will be use to the functionality of download to file /MS Excel.
So the Algo goes like this:
1. Display ALV output
2. Remove all the SAP standard ALV buttons, replace it with one custom button
3. When the user click this custom button, it will extract all the data of the current ALV output which is dynamic, so the extraction will include the column header description as the first row, then the succeeding rows will the data entries respective to its column header.
At #3, I'm currently stagnant ....
Thanks.
Regards,
Jaime
Edited by: Jaime Cabanban on May 7, 2009 12:10 AM
2009 May 07 12:04 PM
Hi Jaime,
As you noticed before, there will be a type conflict of column header (which is of C type) and its data which are of different types. You have to rewrite data from one dynamic table (having your custom type columns) to another dynamic one which has to be of type C. Otherwise you can't store all those data if one table.
You query is not so trival, but I think this is what you need.
TYPE-POOLS: abap.
"1. --------------- typing (you may also create those typing dynamically but here I used static approach)
"your type (can be dynamic)
TYPES: BEGIN OF t_dyn,
pernr TYPE pa0001-pernr,
begda TYPE pa0001-begda,
END OF t_dyn.
"table type
TYPES: tt_dyn TYPE TABLE OF t_dyn.
"new dyn type
TYPES: BEGIN OF t_new_dyn,
field1 TYPE c LENGTH 60,
field2 TYPE c LENGTH 60,
END OF t_new_dyn.
"table type
TYPES: tt_new_dyn TYPE TABLE OF t_new_dyn.
"2. --------------- references & data objects
DATA: r_dyn_tab TYPE REF TO data,
r_dyn_str TYPE REF TO data,
r_new_dyn_tab TYPE REF TO data,
r_struct TYPE REF TO cl_abap_structdescr, "to describe strcutre
r_elem TYPE REF TO cl_abap_elemdescr. "to describe data object
DATA: dfies_str TYPE dfies,
fields_tab TYPE abap_component_tab,
header TYPE dfies-fieldtext,
index TYPE i.
"3. --------------- dynamic creation
CREATE DATA r_dyn_tab TYPE tt_dyn. "dynamic table
CREATE DATA r_dyn_str TYPE t_dyn. "and dynamic structure like line of dynamic table
CREATE DATA r_new_dyn_tab TYPE tt_new_dyn. "new dynamic table
"4. --------------- getting struture components (to get their header later)
"we will work on strucutre to get its components and describe them, that's why I create also a structure
"describe your structure
r_struct ?= cl_abap_typedescr=>describe_by_data_ref( r_dyn_str ).
"get its components
fields_tab = r_struct->get_components( ).
"field symbols to address references
FIELD-SYMBOLS: <wa_fields> LIKE LINE OF fields_tab,
<new_tab> TYPE tt_new_dyn,
<wa_new_tab> TYPE t_new_dyn,
<new_comp> TYPE ANY. "to address specific field
ASSIGN r_new_dyn_tab->* TO <new_tab>.
APPEND INITIAL LINE TO <new_tab> ASSIGNING <wa_new_tab>.
"<wa_new_tab> now points to first row
BREAK-POINT.
"5. --------------- populating new dyn table with header as first row
LOOP AT fields_tab ASSIGNING <wa_fields>.
index = sy-tabix.
r_elem ?= <wa_fields>-type.
dfies_str = r_elem->get_ddic_field( ).
"here you have header desciption of a column
header = dfies_str-fieldtext.
"assing header to a field
ASSIGN COMPONENT index OF STRUCTURE <wa_new_tab> TO <new_comp>.
IF sy-subrc = 0.
<new_comp> = header.
ENDIF.
ENDLOOP.
"6. ---------------- here you just move entries from r_dyn_tab to r_new_dyn_tab
Regards
Marcin
2009 May 14 1:10 AM
Hi Marcin,
Yes your suggestion makes sense but somehow I was able to manage to define everything as TYPE C and amazingly ABAP can still do accurate arithmetic computation even if all of them are defined as type C.
On your suggestion below, when I'll migrate the dynamic_itab(which is metadata) to dynamic_itab(pure character), an issue will occur on entries with negative number, the - (minus) sign will always appear as it is, so if I'm going to send it to Excel, it is not treated as number but rather as text.
Solution i'm thinking: On the ABAP, search the string for -(minus sign) at the end of every string, if found, put it at the beginning; but this might consume some memory though.
What do you think?
Thanks,
Jaime
2009 Oct 15 1:59 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |