‎2012 Nov 12 8:20 AM
Hi Everybody;
I want to learn that how to create a dynamic alv . Maybe you can give me examples about that.
The outline which i want to create will be like at the below.
| a | b | c | d | e | f | g | h | e | f | g | h |
|---|---|---|---|---|---|---|---|---|---|---|---|
You can see the dynamic columns " e,f,g,h " will be repeat. These columns will be dynamic.If you give me an example which resemble of my outline .I can complete the ALV report.Thanks.
Take it easy.
‎2012 Nov 12 10:19 AM
Hi,
I also mention the usage of cl_alv_table_create=>create_dynamic_table as
a second option look at program BCALV_TABLE_CREATE.
7 or 8 times is not a large number.
In the sample I sent I am duplicating tp_frag_xx 8 times.
You cannot have the same name appear more then once so
the addition of "RENAMING WITH SUFFIX" is used.
Please create a program with the data definition .
Add some lines to this table:
DATA: st_line_1 LIKE LINE OF it_line_1 .
FIELD-SYMBOLS: <st_frag_xx> TYPE tp_frag_xx .
DATA: n2 TYPE n LENGTH 2 .
DATA: fieldname TYPE fieldname .
DO 8 TIMES .
CLEAR st_line_1 .
n2 = sy-index .
CONCATENATE 'FRAG_' n2 INTO fieldname .
ASSIGN COMPONENT fieldname OF STRUCTURE st_line_1 TO <st_frag_xx> .
<st_frag_xx>-e = 'X' .
APPEND st_line_1 TO it_line_1 .
ENDDO .
and use debug to learn about the structure of the table.
‎2012 Nov 12 9:08 AM
Hi,
Asuming you are using cl_gui_alv_grid .
Two options:
1. Create as many entries of tp_frag_xx as you will need.
Expose or hide those sets of fields using the field catalog.
*----------------------------------------------------------------------*
TYPES: BEGIN OF tp_frag_fx .
TYPES: a TYPE c ,
b TYPE c ,
c TYPE c ,
d TYPE c .
TYPES: END OF tp_frag_fx .
*----------------------------------------------------------------------*
TYPES: BEGIN OF tp_frag_xx .
TYPES: e TYPE c ,
f TYPE c ,
g TYPE c ,
h TYPE c .
TYPES: END OF tp_frag_xx .
*----------------------------------------------------------------------*
TYPES: BEGIN OF tp_line_1 .
INCLUDE TYPE tp_frag_fx AS frag_fx RENAMING WITH SUFFIX _fx .
INCLUDE TYPE tp_frag_xx AS frag_01 RENAMING WITH SUFFIX _01 .
INCLUDE TYPE tp_frag_xx AS frag_02 RENAMING WITH SUFFIX _02 .
INCLUDE TYPE tp_frag_xx AS frag_03 RENAMING WITH SUFFIX _03 .
INCLUDE TYPE tp_frag_xx AS frag_04 RENAMING WITH SUFFIX _04 .
INCLUDE TYPE tp_frag_xx AS frag_05 RENAMING WITH SUFFIX _05 .
INCLUDE TYPE tp_frag_xx AS frag_06 RENAMING WITH SUFFIX _06 .
INCLUDE TYPE tp_frag_xx AS frag_07 RENAMING WITH SUFFIX _07 .
INCLUDE TYPE tp_frag_xx AS frag_08 RENAMING WITH SUFFIX _08 .
TYPES: END OF tp_line_1 .
TYPES: tp_line_1_tab TYPE TABLE OF tp_line_1 .
DATA: it_line_1 TYPE tp_line_1_tab .
This is how it how a single line looks in debug:
2. Consider using cl_alv_table_create=>create_dynamic_table.
‎2012 Nov 12 9:44 AM
Eitan Rosenberg thanks for your helpful answer but the dynamic columns will repeat many times maybe 7 or 8 times so;do you have any other idea?
‎2012 Nov 12 9:59 AM
I have done this kind of development.
I can't give you entire source code, but following are steps.
1. I hope you know how many times it would reoccur before displaying final table.
2. Create a field catlog based on your required table structure.
3. Use below code to create a dynamic table structure.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcat
IMPORTING
ep_table = lt_result.
ASSIGN lt_result->* TO <fs_result>.
CREATE DATA lwa_result LIKE LINE OF <fs_result>.
ASSIGN lwa_result->* TO <wa_result>.
(Google with method name if you get stuck)
4. Fill the table which is directed with field symbol using your logic.
5. Display the ALV using REUSE_ALV_GRID_DISPLAY with <FS_RESULT> as internal table and lt_fieldcat as fieldcatlog.
Let me know if you face any errors.
If you are stuck at 1st step itself, then I am sorry, cant help you.
‎2012 Nov 12 10:19 AM
Hi,
I also mention the usage of cl_alv_table_create=>create_dynamic_table as
a second option look at program BCALV_TABLE_CREATE.
7 or 8 times is not a large number.
In the sample I sent I am duplicating tp_frag_xx 8 times.
You cannot have the same name appear more then once so
the addition of "RENAMING WITH SUFFIX" is used.
Please create a program with the data definition .
Add some lines to this table:
DATA: st_line_1 LIKE LINE OF it_line_1 .
FIELD-SYMBOLS: <st_frag_xx> TYPE tp_frag_xx .
DATA: n2 TYPE n LENGTH 2 .
DATA: fieldname TYPE fieldname .
DO 8 TIMES .
CLEAR st_line_1 .
n2 = sy-index .
CONCATENATE 'FRAG_' n2 INTO fieldname .
ASSIGN COMPONENT fieldname OF STRUCTURE st_line_1 TO <st_frag_xx> .
<st_frag_xx>-e = 'X' .
APPEND st_line_1 TO it_line_1 .
ENDDO .
and use debug to learn about the structure of the table.
‎2012 Nov 12 12:19 PM
Thanks for your clues .I will try to use all of your recommendations.If i get any error i will inform to you about the problem.
Regards.