‎2008 Mar 04 4:57 AM
HI
I have a parameter screen where i enter the name of any table.
Now i create a dynamic internal table to fetch the data in the table in it.
Till this i have done but now i need to display the dynamic data in ALV output.
So i need to create a ALV with dynamic columns -- I think based on the table i have input.
Kindly help mehow to do it..
Thanks
‎2008 Mar 04 6:23 AM
‎2008 Mar 04 5:11 AM
Hi,
Following report is the sample report for Dynaimc alv report.
REPORT YMS_DYNAMICALV.
TYPE-POOLS: SLIS.
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>.
DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FLDCAT TYPE LVC_T_FCAT.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FLDS(5) TYPE C.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
build the dynamic internal table
PERFORM BUILD_DYN_ITAB.
write 5 records to the alv grid
DO 5 TIMES.
PERFORM BUILD_REPORT.
ENDDO.
call the alv grid.
PERFORM CALL_ALV.
************************************************************************
Build_dyn_itab
************************************************************************
FORM BUILD_DYN_ITAB.
DATA: NEW_TABLE TYPE REF TO DATA,
NEW_LINE TYPE REF TO DATA,
WA_IT_FLDCAT TYPE LVC_S_FCAT.
Create fields .
DO P_FLDS TIMES.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = SY-INDEX.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 5.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
ENDDO.
Create dynamic internal table and assign to FS
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT
IMPORTING
EP_TABLE = NEW_TABLE.
ASSIGN NEW_TABLE->* TO <DYN_TABLE>.
Create dynamic work area and assign to FS
CREATE DATA NEW_LINE LIKE LINE OF <DYN_TABLE>.
ASSIGN NEW_LINE->* TO <DYN_WA>.
ENDFORM. "build_dyn_itab
*********************************************************************
Form build_report
*********************************************************************
FORM BUILD_REPORT.
DATA: FIELDNAME(20) TYPE C.
DATA: FIELDVALUE(5) TYPE C.
DATA: INDEX(3) TYPE C.
FIELD-SYMBOLS: <FS1>.
DO P_FLDS TIMES.
INDEX = SY-INDEX.
Set up fieldvalue
CONCATENATE 'FLD' INDEX INTO
FIELDVALUE.
CONDENSE FIELDVALUE NO-GAPS.
<b> assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.</b>
ENDDO.
Append to the dynamic internal table
APPEND <DYN_WA> TO <DYN_TABLE>.
ENDFORM. "build_report
************************************************************************
CALL_ALV
************************************************************************
FORM CALL_ALV.
DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.
DO P_FLDS TIMES.
CLEAR WA_CAT.
WA_CAT-FIELDNAME = SY-INDEX.
WA_CAT-SELTEXT_S = SY-INDEX.
WA_CAT-OUTPUTLEN = '5'.
APPEND WA_CAT TO ALV_FLDCAT.
ENDDO.
Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = ALV_FLDCAT
TABLES
T_OUTTAB = <DYN_TABLE>.
ENDFORM. "call_alv
Thanks,
Sankar M
‎2008 Mar 04 5:16 AM
How do we know the no of records we will be writing to a ALV ?
I want to display the entire data in the ALV.
Should i go for sy-dbcnt
and write as do a times
where a = sy-dbcnt
Thanks and Regards
Sakthi
‎2008 Mar 04 6:12 AM
Hi,
You can use the Function Module DB_GET_TABLE_FIELDS to get the field names of the table. or table for field names is DD03L.
after getting the table field names you can proceed to build the field catalogue.
Hope it helps you.
Kind Regards,
Ravi Sankar.Z
‎2008 Mar 04 5:16 AM
Hi,
For this sitution you may have to follow the OO ALV, there you can find out the Way for this.
Regards,
Kumash
‎2008 Mar 04 6:23 AM
‎2008 Mar 04 6:38 AM
Hi Sakthivel,
Check these blogs :
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically
This would help you .
Reward If useful.
Regards,
Chitra