‎2008 Jun 26 1:11 PM
Hi,
I am working on an a alv report.In the selection screen,if the fiscal period is input based on that the dates have to be calculated and have to be displayed as column headers in the o/p.This colum is dynamic and will change based on the values given in the selection screen.Now I need to populate the values for these dates under the corresponding columns respectively.
Can anyone tell me how can I achieve this?
Regards,
Hema
‎2008 Jun 26 1:13 PM
hi check this..
REPORT Z_DYNALV .
*Type pools declaration for ALV
TYPE-POOLS: SLIS. " ALV Global Types*data declaration for dynamic internal table and alv
DATA: L_STRUCTURE TYPE REF TO DATA,
L_TABLE TYPE REF TO DATA,
STRUC_DESC TYPE REF TO CL_ABAP_STRUCTDESCR,
LT_LAYOUT TYPE SLIS_LAYOUT_ALV,
LS_LVC_FIELDCATALOGUE TYPE LVC_S_FCAT,
LT_LVC_FIELDCATALOGUE TYPE LVC_T_FCAT,
LS_FIELDCATALOGUE TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCATALOGUE TYPE SLIS_T_FIELDCAT_ALV.
*field symbols declaration
FIELD-SYMBOLS :
<IT_TABLE> TYPE STANDARD TABLE,
<DYN_STR> TYPE ANY,
<STR_COMP> TYPE ABAP_COMPDESCR.
*declarations for grid title
DATA : T1(30),
T2(10),
T3(50).
*selection screen declaration for table input
PARAMETERS : P_TABLE LIKE DD02L-TABNAME.
*initialization event
INITIALIZATION.
*start of selection event
START-OF-SELECTION.
*texts for grid title
T1 = 'Dynamic ALV display for table'.
T2 = P_TABLE. CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.
Dynamic creation of a structure
CREATE DATA L_STRUCTURE TYPE (P_TABLE).
ASSIGN L_STRUCTURE->* TO <DYN_STR>.
Fields Structure
STRUC_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).
LOOP AT STRUC_DESC->COMPONENTS ASSIGNING <STR_COMP>.
Build Fieldcatalog
LS_LVC_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.
LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.
APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.
Build Fieldcatalog
LS_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.
LS_FIELDCATALOGUE-REF_TABNAME = P_TABLE.
APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.
ENDLOOP.
Create internal table dynamic
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE
IMPORTING
EP_TABLE = L_TABLE.
ASSIGN L_TABLE->* TO <IT_TABLE>.
Read data from the table selected.
SELECT * FROM (P_TABLE)
INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.
ALV Layout
LT_LAYOUT-ZEBRA = 'X'.
LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LT_LAYOUT-WINDOW_TITLEBAR = T3.
*ALV output
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = LT_LAYOUT
IT_FIELDCAT = LT_FIELDCATALOGUE
TABLES
T_OUTTAB = <IT_TABLE>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
‎2008 Jun 26 1:15 PM
Hi,
Refer to the code in the following code.
http://saptechnical.com/Tutorials/ALV/DynamicALV/Demo.htm
It may be useful ..
Regards,
Jaya Vani
‎2008 Jun 26 1:15 PM
check this.. sample code..
REPORT ztest_dynamic_code.
TYPES: BEGIN OF ty_data,
abc(3),
xyz(3),
pqr(3),
item1,
item2,
item3,
item4,
item5,
item6,
item7,
item8,
item9,
END OF ty_data.
DATA: BEGIN OF it_tab OCCURS 0,
abc(3),
xyz(3),
pqr(3),
item,
END OF it_tab.
DATA: it_fieldcatalog TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.
DATA: i_dyntab TYPE REF TO data. " To create dyn.Itab
DATA:
w_dref TYPE REF TO data,
ind(2) TYPE n,
w_data TYPE REF TO data,
w_text(5),
w_grid TYPE REF TO cl_gui_alv_grid.
DATA: grid TYPE REF TO cl_gui_alv_grid,
cont TYPE REF TO cl_gui_custom_container.
FIELD-SYMBOLS: <t_itab> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,<fs> TYPE ANY.
DATA: in TYPE i.
*Data population
it_tab-abc = 'ABC'.
it_tab-xyz = 'XYZ'.
it_tab-pqr = 'PQR'.
DO 9 TIMES.
in = in + 1.
it_tab-item = in.
APPEND it_tab.
ENDDO.
*Field cat population.
wa_fieldcat-fieldname = 'ABC'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'abc'.
APPEND wa_fieldcat TO it_fieldcatalog.
wa_fieldcat-fieldname = 'XYZ'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'XYZ'.
APPEND wa_fieldcat TO it_fieldcatalog.
wa_fieldcat-fieldname = 'PQR'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'pqr'.
APPEND wa_fieldcat TO it_fieldcatalog.
ind = 1.
DO 9 TIMES.
CONCATENATE 'ITEM' ind INTO wa_fieldcat-fieldname.
CONCATENATE 'ITEM' ind INTO wa_fieldcat-coltext.
wa_fieldcat-outputlen = 1.
APPEND wa_fieldcat TO it_fieldcatalog.
CLEAR wa_fieldcat .
ind = ind + 1.
ENDDO.
*-Dynamic Table creation
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = i_dyntab.
ASSIGN i_dyntab->* TO <t_itab>.
CREATE DATA w_data LIKE LINE OF <t_itab>.
ASSIGN w_data->* TO <fs_wa>.
SORT it_tab BY abc xyz pqr.
CLEAR ind.
ind = 4.
*-Final Internal table as per Requirement
LOOP AT it_tab.
ASSIGN COMPONENT 1 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-abc.
ASSIGN COMPONENT 2 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-xyz.
UNASSIGN <fs>.
ASSIGN COMPONENT 3 OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-pqr.
UNASSIGN <fs>.
ASSIGN COMPONENT ind OF STRUCTURE <fs_wa> TO <fs>.
<fs> = it_tab-item.
UNASSIGN <fs>.
ind = ind + 1.
AT END OF pqr.
APPEND <fs_wa> TO <t_itab>.
ind = 4.
CLEAR <fs_wa>.
ENDAT.
ENDLOOP.
*-Display
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
DATA: layout TYPE lvc_s_layo.
CREATE OBJECT cont
EXPORTING
container_name = 'CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT grid
EXPORTING
i_parent = cont
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
grid->set_table_for_first_display(
EXPORTING
is_layout = layout
CHANGING
it_outtab = <t_itab>
it_fieldcatalog = it_fieldcatalog
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
).
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT