‎2008 Nov 07 4:19 AM
Hi all,
Hi all,
I am writing code like this.
*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_bukrs LIKE bukrs,
p_belnr like belnr,
p_gjahr like gjahr.
*initialization event
INITIALIZATION.
p_table = 'BSEG'.
*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>
where bukrs = p_bukrs
and belnr = p_belnr
gjahr = gjahr.
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.
Here i am getting all the data from the BSEG table based on the condition.
But I want only date ,account and amount field,here i am using dynamic internal table,
I want data like below:
DATE account amount
2008/12 A 1000
2008/12 b 2000
after that in displaying(in alv) time I need like below
DATE account
2008/12 A B
1000 2000
Please tell me how to do that.
regards,
Rakesh.
‎2008 Nov 07 4:24 AM
Hello,
First fetch all the data in the dynamic internal table then loop the internal tabl with required condition then move all the data to final internal table
Example.
In your final internal table take only those records which need to be displayed in ALV
FIELD-SYMBOLS :
<y_i_table> TYPE STANDARD TABLE,
<y_wa_table> TYPE ANY,
LOOP AT <y_i_table> ASSIGNING <y_wa_table>.
MOVE-CORRESPONDING <y_wa_table> TO y_wa_vfscaid.
APPEND y_wa_vfscaid TO y_i_vfscaid.
CLEAR y_wa_vfscaid.
ENDLOOP.
‎2008 Nov 07 4:24 AM
Hello,
First fetch all the data in the dynamic internal table then loop the internal tabl with required condition then move all the data to final internal table
Example.
In your final internal table take only those records which need to be displayed in ALV
FIELD-SYMBOLS :
<y_i_table> TYPE STANDARD TABLE,
<y_wa_table> TYPE ANY,
LOOP AT <y_i_table> ASSIGNING <y_wa_table>.
MOVE-CORRESPONDING <y_wa_table> TO y_wa_vfscaid.
APPEND y_wa_vfscaid TO y_i_vfscaid.
CLEAR y_wa_vfscaid.
ENDLOOP.
‎2009 Jan 22 4:15 AM
Hi,
issue :
i have created a dynamic internal table(dyn_tab) and a dynamic work area (dyn_wa).
1. actually i have to calculate some data and then insert the same in to the dynamic table .
ex:
if suppose i have 10 fields in my dynamic table.
and my field names are suppose from 0 to 10 .(wil be created at run time)
iam not able to write " <dyn_wa>-0 = 'help'. " (it is showing an syntax error because the structure is created dynamically which does not have that field name befor the program is executed )
("I WANT TO APPEND A RECORD IN TO DYNAMIC INTERNAL TABLE ")
"PLEASE HELP ME "
please help me out regarding this issue i hope u can do this.
WATING.
Thanks in advance,
shivkanth