‎2009 Jul 07 7:11 AM
Hi all,
I want to develop a alv report where the column will be variable and created in runtime as per data.Is it possible in SAP ALV grid display?If possible tell me how I develop such type of report.
For example
MATERIAL BATCH QTY
M1 B1 Q1
M1 B2 Q2
M1 B3 Q3
M2 B4 Q1
This is normal display. I want the following
MATERIAL BATCH1 BATCH2 BATCH3 BATCH4
M1 Q1 Q2 Q3 --
M2 --- -- -- Q4
Please advise and provide your valuable suggestion.
Thanks & Regards
Nirmal
‎2009 Jul 07 7:15 AM
Yes this is possible, and this question has be asked for many times
Perfiorm some search at sdn with keywords like [dynamic internal table ALV|https://forums.sdn.sap.com/search.jspa?threadID=&q=dynamicinternaltable+ALV&objID=c42&dateRange=all&numResults=30&rankBy=10001]
Basically
- create a dynamic field catalog
- create internal table
- fill internal table
- display with ALV
Just one result : [Creating a dynamic internal table based on data |https://wiki.sdn.sap.com/wiki/display/Snippets/Creatingadynamicinternaltablebasedon+data] in [Code Gallery|https://wiki.sdn.sap.com/wiki/display/Snippets]
Regards,
Raymond
‎2009 Jul 09 5:15 AM
Hi Raymond,
As per your suggestion I am developing dynamic ALV report.But I am facing a problem at the time of Method Calling.I am not getting component_table and component_name Methods in cl_abap_structdescr class.We are using SAP R/3 4.7 and my question is is this methods are not supported by SAP 4.7.If it is not supported then please suggest me what to do.
Thanks & Regards
Nirmal
‎2009 Jul 07 7:15 AM
‎2009 Jul 07 7:26 AM
Hi Nirmal, It is possible using dynamic internal table concept. Here is one sample program which is very useful. Check at this link :<b>[ Dynamic internal table with dynamic fields|http://an-abaper.blogspot.com/2009/06/dynamic-internal-table-with-dynamic.html]</b> Thanks Venkat.O
‎2009 Jul 09 7:06 AM
Hi Frn
The Below code will Create the dyanmic internal table ....what you need to do is only pass this internal table and field catalog to Function module "Reuse_alv_display" .
REPORT zhrrt_retention.
TYPE-POOLS : abap.
TABLES: pa0001 , pa0003 .
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,<dyn_wa>,<dyn_field>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data .
DATA : xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-s11 .
SELECT-OPTIONS:s_pernr FOR pa0003-pernr .
SELECT-OPTIONS:s_orgeh FOR pa0001-orgeh .
SELECT-OPTIONS:s_date FOR sy-datum .
SELECTION-SCREEN END OF BLOCK b1.
DATA: BEGIN OF it_itab OCCURS 0 ,
depid LIKE pa0001-orgeh ,
pernr LIKE pa0003-pernr,
subty LIKE pa9260-subty,
date LIKE sy-datum,
END OF it_itab .
DATA: BEGIN OF it_date OCCURS 0,
date TYPE sy-datum ,
len TYPE i,
ty TYPE c,
END OF it_date .
SELECT a~orgeh
b~pernr
b~subty
b~begda
FROM pa0001 AS a INNER JOIN pa9260 AS b
ON apernr = bpernr
INTO TABLE it_itab
WHERE a~orgeh IN s_orgeh AND
a~pernr IN s_pernr AND
b~begda IN s_date.
WHILE s_date-low <= s_date-high.
it_date-date = s_date-low .
it_date-len = 8 .
it_date-ty = 'c'.
APPEND it_date.
s_date-low = s_date-low + 1.
ENDWHILE.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM proc_data .
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
xfc-fieldname = 'pernr' . " XDETAILS-NAME .
xfc-datatype = 'c'. "XDETAILS-TYPE_KIND.
xfc-inttype = 'c'. "XDETAILS-TYPE_KIND.
xfc-intlen = 8 . "XDETAILS-LENGTH.
APPEND xfc TO ifc.
xfc-fieldname = 'empname' . " XDETAILS-NAME .
xfc-datatype = 'c'. "XDETAILS-TYPE_KIND.
xfc-inttype = 'c'. "XDETAILS-TYPE_KIND.
xfc-intlen = 30 . "XDETAILS-LENGTH.
APPEND xfc TO ifc.
LOOP AT it_date .
CLEAR xfc.
xfc-fieldname = it_date-date . " XDETAILS-NAME .
xfc-datatype = it_date-ty. "XDETAILS-TYPE_KIND.
xfc-inttype = it_date-ty. "XDETAILS-TYPE_KIND.
xfc-intlen = it_date-len . "XDETAILS-LENGTH.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
FORM create_dynamic_itab.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. "create_dynamic_itab
FORM proc_data .
DATA: l_tabix TYPE sy-tabix .
SORT it_itab BY depid .
LOOP AT it_itab .
READ TABLE it_date WITH KEY date = it_itab-date .
l_tabix = sy-tabix.
IF sy-subrc = 0 .
ASSIGN COMPONENT l_tabix OF STRUCTURE dy_table TO <dyn_field>.
ENDIF.
ENDLOOP.
ENDFORM. " PROC_DATA
Thanks and regards
Priyank
‎2010 Mar 24 5:21 AM