2008 May 21 1:30 PM
Hi all,
Following is my requirement,
user can enter any table name in screen, as soon as he enters all entries in the that table should be displayed in alv grid ...
i think here i need to implement dynamic alv... so please can anyne help me to do the same ... i have never used it
its urgent
thanks i advance
Amruta
Hi all,
Following is my requirement,
user can enter any table name in screen, as soon as he enters all entries in the that table should be displayed in alv grid ...
i think here i need to implement dynamic alv... so please can anyne help me to do the same ... i have never used it
its urgent
thanks i advance
Amruta
2008 May 21 1:33 PM
Hi,
AS : Dynamic ALV generation with data
stored in a table,DB table as input.
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.Output:
Regards,
Jagadish
2008 May 21 1:37 PM
Hi,
Check the code below:
REPORT ZYKTEST3 .
DATA: d_ref TYPE REF TO data,
d_ref2 TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat.
TYPES: tabname LIKE dcobjdef-name ,
fieldname LIKE dcobjdef-name,
desc LIKE dntab-fieldtext.
PARAMETER: p_tablen TYPE tabname. ----> Input table field
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE dntab.
DATA: END OF itab.
FIELD-SYMBOLS : <f_fs> TYPE table,
<f_fs1> TYPE table,
<f_fs2> TYPE ANY,
<f_fs3> TYPE ANY,
<f_fs4> type any,
<f_field> TYPE ANY.
REFRESH itab.
CALL FUNCTION 'NAMETAB_GET' ----------> Fetches the fields
EXPORTING
langu = sy-langu
tabname = p_tablen
TABLES
nametab = itab
EXCEPTIONS
no_texts_found = 1.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
ls_alv_cat-seltext = itab-fieldtext.
ls_alv_cat-reptext = itab-fieldtext.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
internal table build
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = d_ref.
ASSIGN d_ref->* TO <f_fs>. ----> Dynamic table creation with fields of the table
DATA: l_field TYPE fieldname,
l_field1 type fieldname.
SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.
"Fetching of the data from the table
* Here you can call the ALV Grid
LOOP AT <f_fs> ASSIGNING <f_fs2>.
Here u can check the validations and process
ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.
ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
IF sy-subrc = 0.
MOVE <f_fs3> TO l_field.
MOVE <f_fs4> TO l_field1.
WRITE:/1 l_field(20),
22 l_field1(10).
ENDIF.
ENDLOOP.
Regards
Kannaiah
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |