10-06-2008 11:07 AM
Hi frn's ,
i have a requirment of creating dynamic alv column ...depending upon the slection criteria . how it is possible.
Thanks and Regards.
Priyank Dixit
10-06-2008 11:16 AM
Hi Priyank,
check the program in the below link. I think you will get an idea
http://www.sap-img.com/ab030.htm
Cheers,
Kothand
10-06-2008 11:16 AM
Hi Priyank,
check the program in the below link. I think you will get an idea
http://www.sap-img.com/ab030.htm
Cheers,
Kothand
10-06-2008 11:24 AM
Hi,
The normal way is we will be declaring an internal table of type slis_fieldcat_alv and we will be creating a work area for the above said internal table . let the internal table name be it_fcat and work area be wa_fcat. see the below code is the not man way
wa_fcat-tabname = 'IT_FCAT' -
nothing but the internal table name.
wa_fcat-fieldname = Filed name.
wa_fcat-reptext_ddic = Description of the field'.
APPEND wa_fcat TO it_fcat.
As per your requirment, u can find out the table field that is to be added as column in ALV. get that fileds in an internal table that u need to show in alv.
Second point is : any way u know the interal table name that u are using in the program to store the data. So u can hard code it.
Then write a loop which contain the fields for example.
let the internal table name be it_fields and work area be wa_field.
loop at it_field into wa_field.
clear : wa_fcat.
wa_fcat-tabname = 'IT_FCAT'.
wa_fcat-fieldname = wa_field-field.
wa_fcat-reptext_ddic = Description of the field'.
APPEND wa_fcat TO it_fcat.
endloop.
by this way u can built a dynamic fcat as per your requirment.
there is on SAP table that stores the field name description ... from that you can query the description.. i forgot the table.. please search in SDN.. you can get it from there.
feel free in case of any doubt.
Regards
Maneesh Chandran
10-06-2008 11:26 AM
Hi ,
i need a dynamic internal table .
THanks and Regards
Priyank dixit
10-06-2008 11:43 AM
10-06-2008 11:53 AM
Hi Priyank,
You can use the demo program for your reference.
*&---------------------------------------------------------------------*
*& Report ZCC_DYNAMIC_INTERNAL_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ZCC_DYNAMIC_INTERNAL_TABLE.
type-pools : ABAP.
field-symbols: <DYN_TABLE> type standard table,
<DYN_WA>,
<DYN_FIELD>.
data: DY_TABLE type ref to DATA,
DY_LINE type ref to DATA,
XFC type LVC_S_FCAT,
IFC type LVC_T_FCAT.
selection-screen begin of block B1 with frame.
parameters: P_TABLE(30) type C default 'T001'.
selection-screen end of block B1.
start-of-selection.
perform GET_STRUCTURE.
perform CREATE_DYNAMIC_ITAB.
**********CREATES A DYANAMIC INTERNAL TABLE**********
PERFORM GET_DATA.
perform WRITE_OUT.
*&---------------------------------------------------------------------*
*& Form get_structure
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form GET_STRUCTURE.
data : IDETAILS type ABAP_COMPDESCR_TAB,
XDETAILS type ABAP_COMPDESCR.
data : REF_TABLE_DES type ref to CL_ABAP_STRUCTDESCR.
* Get the structure of the table.
REF_TABLE_DES ?=
CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( P_TABLE ).
IDETAILS = REF_TABLE_DES->COMPONENTS.
loop at IDETAILS into XDETAILS.
clear XFC.
XFC-FIELDNAME = XDETAILS-NAME .
XFC-DATATYPE = XDETAILS-TYPE_KIND.
XFC-INTTYPE = XDETAILS-TYPE_KIND.
XFC-INTLEN = XDETAILS-LENGTH.
XFC-DECIMALS = XDETAILS-DECIMALS.
append XFC to IFC.
endloop.
endform. "get_structure
*&---------------------------------------------------------------------*
*& Form create_dynamic_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
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 get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form GET_DATA.
* Select Data from table.
select * into table <DYN_TABLE>
from (P_TABLE).
endform. "get_data
*&---------------------------------------------------------------------*
*& Form WRITE_OUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_OUT .
*write OUT DATA FROM TABLE.
loop at <DYN_TABLE> into <DYN_WA>.
do.
assign component SY-INDEX
of structure <DYN_WA> to <DYN_FIELD>.
if SY-SUBRC = 0.
exit.
endif.
if SY-INDEX = 1.
write:/ <DYN_FIELD>.
else.
write: <DYN_FIELD>.
endif.
enddo.
endloop.
ENDFORM. " WRITE_OUT