To create a deep structure for dynamic internal table.
Hello
My ALV has fields which are defined dynamically during execution.
so, i did it in the following way,
Declared Field symbolds, DREF and fieldcatalog as,
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
<fs_dyntable>.
DATA: dref_dyntab TYPE REF TO data,
dref_dynwa TYPE REF TO data.
DATA: ts_fieldcatalog TYPE lvc_t_fcat.
DATA: wa_fieldcatalog TYPE lvc_s_fcat.
Updated Fieldcatalog dynamically as,
*function module to read segment structure
CALL FUNCTION 'SEGMENT_READ'
EXPORTING
segmenttyp = v_segment_name
TABLES
segmentstructure = ts_seg_structure
EXCEPTIONS
no_authority = 1
segment_not_existing = 2
OTHERS = 3.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN '1'.
MESSAGE e024.
STOP.
WHEN '2'.
MESSAGE e025 WITH v_segment_name.
STOP.
WHEN OTHERS.
MESSAGE e023.
ENDCASE.
ENDIF.
*FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
LOOP AT ts_seg_structure INTO wa_seg_structure.
ADD 1 TO v_counter.
wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
wa_fieldcatalog-col_pos = v_counter.
wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
APPEND wa_fieldcatalog TO ts_fieldcatalog.
CLEAR wa_fieldcatalog.
ENDLOOP.
and generated dynamic internal table using fieldcatalog as,
*--Method to get the structure of table using fieldcatalog.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ts_fieldcatalog
IMPORTING
*--Variable of type REF TO DATA.
ep_table = dref_dyntab.
IF sy-subrc <> 0.
MESSAGE e023.
ENDIF.
*--Dynamic internal tables required when show segments selected
IF p_selseg IS NOT INITIAL.
ASSIGN dref_dyntab->* TO <t_dyntable>.
*--Create dynamic work area and assign to FS
CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
ASSIGN dref_dynwa->* TO <fs_dyntable>.
And then i populated this <t_dyntable> which is being passed as data-table to method
CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
As you might be aware, we need a field
TS_STYLEROW TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
in the output internal table <t_dyntable> to meet our requirement.
My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
I tried in the following way by adding one such field to fieldcatalog :
*Field for Styling
ADD 1 TO v_counter.
wa_fieldcatalog-fieldname = 'TS_STYLEROW'.
wa_fieldcatalog-tabname = 'TS_STYLE'.
wa_fieldcatalog-col_pos = v_counter.
wa_fieldcatalog-no_out = 'X'.
wa_fieldcatalog-inttype = 'h'. " I even mentioned this
APPEND wa_fieldcatalog TO ts_fieldcatalog.
CLEAR wa_fieldcatalog.
But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
Guyz and respected,
Please advice me with the solution or ur ideas....
Note : The overall requirement is create a deep structure for dynamically generated internal table.
Your help is highly appreciated and unforgettable..!!!!!!!
hi,
Dynamic append
Dynamic internal table
Dynamic internal table
dynamic columns in ALV
Variant for dynamic selection
thanks
Similar Messages
-
Create a deep structure for dynamic internal table
Hi All,
I am creating a dynamic table using method cl_alv_table_create=>create_dynamic_table.
The normal structure gets created. but now I want to creat a Deep structure for having information of colors also for each column. So I want to add a COLTAB type LVC_T_SCOL for colors information .
How should I create this using above method?
Rgds,
MadhuriI created a zcelltab structure as below. But while creating dynamic internal table, I received the error with
'Type "ZCELLTAB" is unknown 68 ZCELLTAB-CELLTAB
Here is the code.
DATA: BEGIN OF ZCELLTAB,
CELLTAB LIKE LVC_S_STYL,
END OF ZCELLTAB.
FIELD-SYMBOLS <T_CELLTAB> TYPE LVC_T_STYL.
DATA : LT_CELLTAB TYPE LVC_T_STYL.
DATA: WA_CELLTAB TYPE LINE OF LVC_T_STYL.
DATA: GT_FCAT1 TYPE LVC_T_FCAT,
GW_FCAT1 TYPE LVC_S_FCAT,
GT_FCAT2 TYPE LVC_T_FCAT,
GW_FCAT2 TYPE LVC_S_FCAT.
After filling the FCAT1, I added the field in FCAT2 like below
GT_FCAT2[ ] = GT_FCAT1[ ].
G_TABIX = G_TABIX + 1.
GW_FCAT2-INTTYPE = 'C'.
MOVE G_TABIX TO GW_FCAT2-COL_POS.
GW_FCAT2-OUTPUTLEN = '10'.
GW_FCAT2-FIELDNAME = 'T_CELLTAB'.
GW_FCAT2-TABNAME = 'ZCELLTAB'.
GW_FCAT2-REF_FIELD = 'CELLTAB'.
GW_FCAT2-REF_TABLE = 'ZCELLTAB'.
APPEND GW_FCAT2 TO GT_FCAT2
CLEAR GW_FCAT2.
While calling the below method, the error with
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = GT_FCAT2
IMPORTING
EP_TABLE = GT_REQ.
ASSIGN GT_REQ->* TO <F_TAB>.
CREATE DATA GWA_REQ LIKE LINE OF <F_TAB>.
ASSIGN GWA_REQ->* TO <F_WA>.
LOOP AT ITAB.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <F_WA> TO <F_VAL>
<F_VAL> = ITAB-MATNR.
IF ITAB-MATNR IS INITIAL.
ASSIGN COMPONENT 'T_CELLTAB' OF STRUCTURE <F_WA> TO <T_CELLTAB>
CLEAR WA_CELLTAB.
WA_CELLTAB-FIELDNAME = 'MATNR'.
WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT WA_CELLTAB INTO TABLE <T_CELLTAB>.
ENDIF.
APPEND <F_WA> TO <F_TAB>
ENDLOOP.
CALL METHOD GR_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_CONSISTENCY_CHECK = G_CONSISTENCY_CHECK
IT_TOOLBAR_EXCLUDING = G_EXCLUDE
I_SAVE = G_SAVE
I_DEFAULT = 'X'
IS_LAYOUT = G_LAYOUT
CHANGING
IT_OUTTAB = <F_TAB>
IT_FIELDCATALOG = F_CAT1.
Please let me know where I was wrong.
Should I remove the T_CELLTAB as the field name is not mentioned in the structure 'ZCELLTAB'.
Thanks,
Kumar.
Edited by: venn e on May 7, 2010 4:10 PM -
How to get the NameTab Structure(X031L) for Dynamic internal table?
when we pass standard table to the FM 'DD_GET_NAMETAB' we will get the
nametab structure(x031l), like this i want to get the same structure for
dynamic internal table . how can I achieve this
please help me...Hi,
try this method
REPORT zmaschl_create_data_dynamic .
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'SYST' CHANGING ct_fieldcat = it_fcat[]. LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial. MOVE-CORRESPONDING is_fcat TO is_fieldcat. is_fieldcat-fieldname = is_fcat-fieldname. is_fieldcat-ref_field = is_fcat-fieldname. is_fieldcat-ref_table = is_fcat-ref_tabname. APPEND is_fieldcat TO it_fieldcat. ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING it_fieldcatalog = it_fieldcat IMPORTING ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.CREATE DATA new_line LIKE LINE OF <l_table>.ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP. -
Create object/structure like dynamic internal table
Hi,
We have created dynamic internal table with some fields.
for the above how to create structure or internal table like dynamic internal table structure .
Scenario: internal table itab1 ( with header line) have 5 fields.
Based on some of the conditions in layout of the report.
we have to create dynamic internal table.
field-symbols: <FS> type standard table.
we are able to create dynamic internal table with 3 fields
with assignment <fs> = itab1[]
the columns are not appearing but data appearing in next column.
how to solve this one
Thanks
RameshHi Ramesh,
I hope this code works...
report yup_alv_datbase .
*-Display Database table contents in ALV Grid Format
>********************************************************************
This report displays data from SAP tables, views (like SE16) *
FM : REUSE_ALV_GRID_DISPLAY *
tables:
dd02l, " SAP tables
dd03l. " Table Fields
type-pools: slis. " ALV Global Types
selection-screen :
begin of line, comment 1(35) v_1 for field p_table. "#EC NEEDED
parameters p_table like dd03l-tabname obligatory memory id dtb.
selection-screen end of line.
selection-screen :
begin of line, comment 1(35) v_2 for field p_max. "#EC NEEDED
parameters p_max(2) type n default '20' obligatory.
selection-screen end of line.
at selection-screen.
select single * from dd02l where tabname = p_table
and as4local = 'A'
and as4vers = '0000'.
if sy-subrc ne 0.
Table & is not active in the Dictionary
message e402(mo) with p_table.
elseif dd02l-tabclass = 'INTTAB'.
& is a structure, not a table
message e403(mo) with p_table.
endif.
initialization.
v_1 = 'Table'.
v_2 = 'Maximum of records'.
start-of-selection.
perform f_display_data.
Form F_DISPLAY_DATA
form f_display_data.
Macro definition
define m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
append ls_sort to lt_sort.
end-of-definition.
data:
l_long type i,
lp_struct type ref to data,
lp_table type ref to data, " Pointer to dynamic table
of_sdescr type ref to cl_abap_structdescr,
ls_lvc_cat type lvc_s_fcat,
lt_lvc_cat type lvc_t_fcat, " Field catalog
ls_fieldcat type slis_fieldcat_alv,
lt_fieldcat type slis_t_fieldcat_alv, " Field catalog
ls_layout type slis_layout_alv,
lt_sort type slis_t_sortinfo_alv, " Sort table
ls_sort type slis_sortinfo_alv.
field-symbols :
<fieldcat> type slis_fieldcat_alv,
<lt_data> type table, " Data to display
<fs> type any,
<components> type abap_compdescr.
Dynamic creation of a structure
create data lp_struct type (p_table).
assign lp_struct->* to <fs>.
Fields Structure
of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
loop at of_sdescr->components assigning <components>.
Field MANDT not displayed
if sy-tabix = 1 and <components>-name = 'MANDT'.
continue. " Next loop
endif.
Build Fieldcatalog
ls_lvc_cat-fieldname = <components>-name.
ls_lvc_cat-ref_table = p_table.
append ls_lvc_cat to lt_lvc_cat.
Build Fieldcatalog
ls_fieldcat-fieldname = <components>-name.
ls_fieldcat-ref_tabname = p_table.
append ls_fieldcat to lt_fieldcat.
endloop.
Create internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = lt_lvc_cat
importing ep_table = lp_table.
assign lp_table->* to <lt_data>.
Read data
select * from (p_table) up to p_max rows
into corresponding fields of table <lt_data>
order by primary key.
if <lt_data>[] is initial.
No table entries found for specified key
message i429(mo).
exit.
endif.
Read key field to Build Sort Table
select * from dd03l where tabname = p_table
and fieldname <> '.INCLUDE'
and as4vers = '0000'
and as4local = 'A'
order by position.
read table lt_fieldcat assigning <fieldcat>
with key fieldname = dd03l-fieldname.
check sy-subrc eq 0.
add dd03l-leng to l_long.
if dd03l-keyflag = 'X'.
Build Sort Table
m_sort dd03l-fieldname.
<fieldcat>-key = 'X'.
elseif l_long > 150.
<fieldcat>-tech = 'X'.
endif.
endselect.
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
tables
t_outtab = <lt_data>.
endform. " F_DISPLAY_DATA
END OF PROGRAM Z_ALV_DYNAMIC_DATA *********************
Regards,
Sampath -
At end of field, for dynamic internal table entries ?
Dear All,
I've data in my dynamic internal table.
But, to understand in a better way I created a test program with static entries.
Case 1 -->
DATA: BEGIN OF itab OCCURS 0,
year TYPE char4,
name TYPE char10,
END OF itab.
DATA: BEGIN OF itab2 OCCURS 0 ,
year TYPE char4,
name TYPE char10,
count TYPE i,
END OF itab2.
DATA: gv_count TYPE i,
gv_flag TYPE char1.
itab-name = 'AAAA'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAB'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAC'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAD'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBB'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBA'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBC'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBD'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCC'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCA'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCB'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCD'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCE'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCf'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDD'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDA'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDB'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDC'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDE'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
SORT itab BY year.
LOOP AT itab.
* Counter
gv_count = gv_count + 1.
AT END OF year.
itab2-count = gv_count.
MOVE-CORRESPONDING itab TO itab2.
APPEND itab2.
CLEAR gv_count.
WRITE:/ itab2-name,
itab2-year,
itab2-count.
CLEAR itab2.
CLEAR gv_flag.
ENDAT.
ENDLOOP.
Now for the above program the Output is :
Name Year Count
********** 2005 5
********** 2006 6
********** 2007 4
********** 2008 4
" Forget about the asterisk values as it's an example !
The above output is correct, But in my real case the table structure is not like the above .
The order of the field are in reverse.
i.e. The internal table is like this :
Case 2 -->
DATA: BEGIN OF itab OCCURS 0,
name TYPE char10,
year TYPE char4,
END OF itab.
DATA: BEGIN OF itab2 OCCURS 0 ,
name TYPE char10,
year TYPE char4,
count TYPE i,
END OF itab2.
In this case if I'm using at end of year the output is coming wrong.
Even on change of is also not working.
Request you guys to help me out so that I can achieve the same output as of case 1 with the table declaration as of CASE 2.
Regards,
Deepu.kHello Rich Heilman,
Again you came for my rescue ............
My code for this scenario is like this :
DATA: BEGIN OF itab OCCURS 0,
name TYPE char10,
year TYPE char4,
END OF itab.
DATA: BEGIN OF itab2 OCCURS 0 ,
name TYPE char10,
year TYPE char4,
count TYPE i,
END OF itab2.
DATA: gv_count TYPE i,
gv_flag TYPE char1.
itab-name = 'AAAA'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAB'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAC'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'AAAD'.
itab-year = '2008'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBB'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBA'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBC'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'BBBD'.
itab-year = '2007'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCC'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCA'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCB'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCD'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCE'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'CCCf'.
itab-year = '2006'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDD'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDA'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDB'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDC'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
itab-name = 'DDDE'.
itab-year = '2005'.
APPEND itab.
CLEAR itab.
SORT itab BY year.
LOOP AT itab.
* Counter
gv_count = gv_count + 1.
IF sy-tabix GT 1.
ON CHANGE OF itab-year.
itab2-count = gv_count.
MOVE-CORRESPONDING itab TO itab2.
APPEND itab2.
CLEAR gv_count.
WRITE:/ itab2-name,
itab2-year,
itab2-count.
CLEAR itab2.
CLEAR gv_flag.
ENDON.
ENDIF.
ENDLOOP.
The Output is :
DDDC 2005 2
CCCf 2006 4
BBBD 2007 6
AAAD 2008 4
The above output is wrong.
Can u correct me where I'm doing wrong ?
Regards,
Deepu.K -
Problem with grid display in ALV for dynamic internal tables
Hi,
I am using dynamic internal tables in my program. To display it in grid format after populating it, I have used the following class and method. Here Im getting sy-subrc = 0 but, the grid is not getting displayed. Can some one pls help me with this.,
DATA: W_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: w_tabname TYPE w_tabname.
CREATE OBJECT W_GRID
EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME = W_TABNAME
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = <FS_1>
IT_FIELDCATALOG = LT_FIELDCATALOG2
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
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, <FS_1> is the field symbol of table type and it holds all my data. and LT_FIELDCATALOG2 is the structure of my fieldcatalog
Thanks and Regards,
AvinashHi Avinash,
Either use parameter
I_STRUCTURE_NAME = W_TABNAME
or
IT_FIELDCATALOG = LT_FIELDCATALOG2
Both are not required.
At the end of ur program simply use a write statement like below. Your program will work.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write /. <----
Thanks,
Edited by: Sap Fan on Oct 6, 2009 7:17 AM -
Building Field-Catalog for dynamic internal tables
Hi All,
I created a dynamic internal table(<fs_final>,<fs_final_line>) and populated data into it.Now I want to provide field catalog to these dynamic internal table.
Can anyone suggest me the how to create a field catalog for existing dynamic internal table.Thanks in advance.
Regards,
Chakradhar.
Moderator message - Please use proper subject line in future.
Message was edited by: Suhas SahaUse this code to get all components of internal table.
Then build fieldcatlog.
DATA: tab_return type abap_compdescr_tab,
components like line of tab_return.
perform get_int_table_fields using <fs_it> changing tab_return.
loop at tab_return into components.
wa_fldcat-fieldname = components-name. "Field Name
wa_fldcat-scrtext_m = components-name. "Column Heading
wa_fldcat-inttype = components-type_kind. "Data Type
wa_fldcat-intlen = components-length. "Data Lenght
wa_fldcat-decimals = components-decimals. "Data Decimal Places
append wa_fldcat to it_fldcat.
endloop.
form get_int_table_fields using t_data type any table
changing t_return type abap_compdescr_tab.
data:
oref_table type ref to cl_abap_tabledescr,
oref_struc type ref to cl_abap_structdescr,
oref_error type ref to cx_root,
text type string.
*Get the description of data object type
try.
oref_table ?=
cl_abap_tabledescr=>describe_by_data( t_data ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.
*Get the line type
try.
oref_struc ?= oref_table->get_table_line_type( ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.
append lines of oref_struc->components to t_return.
endform.
Regards
Sreekanth -
Usage of 'Select for all entries' for dynamic internal tables..
Hi all,
I have a situation where I need to use select for all entries for a dynamic internal table.
select * from /BIC/AZHSD_O1500 into i_table for all entries in <b>Dynamic_table</b> where doc_number = <dynamic_table????????>
here iam not knowing how to match the <dynamic_table????????> doc_number ?
the dynamic_table contains the doc_number as one field.
here dynaimc_table is the internal table which is dynamic.
I have tried various options but couldnot find the solution.
Please resolve.
Sidhartha.data : i_dyn_where type char72 occurs 0.
field-symbols : <fs> type table.
assign itab[] to <fs>.
i_dyn_where = 'docno = <fs>-docno'.
append i_dyn_where.
select *
from vbak
into table t_vbak
for all entries in <fs>
where (I_dyn_where). "Populate this where condition dynamically too
Hope this will solve ur prob. -
Dynamic Alv for Dynamic Internal Table
Hi All,
I am new for abap dynpro.
How can i create a dynamic alv table in abap dynpro withoud ddic structure??
My requirement is as follows:
I have a table having some field e.g MATNR WERKS NETWR.
I want to pivot data werks and to display in webdynpro alv.
Thnx:
N. N. TiwariYou can use the RTTI to build up a dynamic structure in memory:
Something like this - where both the data and its structure and meta data all come from an external source (which happens to be MDM in this case):
****ALV
data:
rootnode_info type ref to if_wd_context_node_info,
dyn_node type ref to if_wd_context_node,
dyn_node_info type ref to if_wd_context_node_info,
tabname_node type ref to if_wd_context_node,
current_tablename type string,
tablename type string,
struct_type type ref to cl_abap_structdescr,
table_type type ref to cl_abap_tabledescr,
comp_tab type cl_abap_structdescr=>component_table,
comp like line of comp_tab,
my_table type ref to data,
my_row type ref to data.
field-symbols: <table> type table,
<row> type data,
<f> type any,
<wa_string> type string,
<wa_date_time> type mdm_cdt_date_time,
<wa_integer> type mdm_gdt_integervalue.
rootnode_info = wd_context->get_node_info( ).
* create subnode_info
try.
rootnode_info->remove_child_node( 'MDM_DATA' ).
catch cx_wd_context.
endtry.
field-symbols <wa_detail> like line of field_details.
field-symbols <wa_result> like line of result_set.
field-symbols <wa_pair> type mdm_name_value_pair.
read table result_set assigning <wa_result> index 1.
loop at field_details assigning <wa_detail>.
* build a structure description from the list of single fields
if strlen( <wa_detail>-field_code ) > 30.
comp-name = <wa_detail>-field_code+0(30).
else.
comp-name = <wa_detail>-field_code.
endif.
if <wa_result> is assigned.
read table <wa_result>-name_value_pairs assigning <wa_pair>
with key code = <wa_detail>-field_code.
if sy-subrc = 0.
case <wa_pair>-type.
when `MDM_CDT_DATE_TIME`.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'TZNTSTMPL' ).
when `MDM_GDT_INTEGERVALUE`.
if <wa_detail>-field_lookup_table is not initial.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
else.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'INT4' ).
endif.
when others.
comp-type ?= cl_abap_datadescr=>describe_by_name( <wa_pair>-type ).
endcase.
else.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
endif.
else.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
endif.
append comp to comp_tab.
endloop.
struct_type = cl_abap_structdescr=>create( comp_tab ).
dyn_node_info = rootnode_info->add_new_child_node(
name = 'MDM_DATA'
is_mandatory = abap_false
is_mandatory_selection = abap_false
static_element_rtti = struct_type
is_multiple = abap_true
is_static = abap_false ).
* get instance of new node
dyn_node = wd_context->get_child_node( name = 'MDM_DATA' ).
****Process Table Data
data content_string type string.
data l_tabix type sytabix.
table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).
create data my_table type handle table_type.
assign my_table->* to <table>.
loop at result_set assigning <wa_result>.
create data my_row type handle struct_type.
assign my_row->* to <row>.
loop at field_details assigning <wa_detail>.
l_tabix = sy-tabix.
read table <wa_result>-name_value_pairs assigning <wa_pair>
with key code = <wa_detail>-field_code.
* loop at <wa_result>-name_value_pairs assigning <wa_pair>.
if sy-subrc = 0 and <wa_pair>-value is not initial.
assign component l_tabix of structure <row> to <f>.
* READ TABLE field_details ASSIGNING <wa_detail> INDEX sy-tabix.
case <wa_pair>-type.
when 'STRING'.
assign <wa_pair>-value->* to <wa_string>.
if <wa_string> is assigned.
* DATA: int TYPE i VALUE 258.
* DATA: buffer TYPE xstring,
* text_buffer TYPE string,
* conv TYPE REF TO cl_abap_conv_out_ce.
* conv = cl_abap_conv_out_ce=>create(
* encoding = 'UTF-8'
* endian = 'L' ).
* CALL METHOD conv->write( data = <wa_string> ).
* buffer = conv->get_buffer( ).
* DATA: convin TYPE REF TO cl_abap_conv_in_ce.
* CALL METHOD cl_abap_conv_in_ce=>create
* EXPORTING
* input = buffer
* RECEIVING
* conv = convin.
* CALL METHOD convin->read
* IMPORTING
* data = text_buffer.
* MOVE text_buffer TO <f>.
move <wa_string> to <f>.
endif.
when 'MDM_CDT_DATE_TIME'.
assign <wa_pair>-value->* to <wa_date_time>.
if <wa_date_time> is assigned.
move <wa_date_time>-content to <f>.
endif.
when 'MDM_GDT_INTEGERVALUE'.
assign <wa_pair>-value->* to <wa_integer>.
if <wa_integer> is assigned.
if <wa_detail>-field_lookup_table is not initial.
content_string = wd_assist->perform_value_lookup(
i_lookup_table = <wa_detail>-field_lookup_table
i_lookup_key = <wa_integer> ).
move content_string to <f>.
else.
move <wa_integer> to <f>.
endif.
endif.
endcase.
endif.
endloop.
append <row> to <table>.
endloop.
dyn_node->bind_table( <table> ).
* Connect to the component Usage of the ALV
data: l_ref_cmp_usage type ref to if_wd_component_usage.
l_ref_cmp_usage = wd_this->wd_cpuse_alv( ).
if l_ref_cmp_usage->has_active_component( ) is initial.
l_ref_cmp_usage->create_component( ).
endif.
* Through the interface controller of the ALV Component set the DATA node dynamically
data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
l_ref_interfacecontroller->set_data(
r_node_data = dyn_node ).
data alv_model type ref to cl_salv_wd_config_table.
alv_model = l_ref_interfacecontroller->get_model( ).
data columns type salv_wd_t_column_ref.
field-symbols <wa_column> like line of columns.
columns = alv_model->if_salv_wd_column_settings~get_columns( ).
data column_id type string.
data header type ref to cl_salv_wd_column_header.
data l_text type string.
loop at field_details assigning <wa_detail>.
* build a structure description from the list of single fields
if strlen( <wa_detail>-field_code ) > 30.
column_id = <wa_detail>-field_code+0(30).
else.
column_id = <wa_detail>-field_code.
endif.
translate column_id to upper case.
read table columns assigning <wa_column> with table key id = column_id.
if sy-subrc = 0.
header = <wa_column>-r_column->get_header( ).
header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).
* if <wa_detail>-field_lookup_table is initial.
header->set_text( <wa_detail>-field_name1 ).
* else.
* l_text = wd_assist->read_table_desc_for_lookup( <wa_detail>-field_lookup_table ).
* header->set_text( l_text ).
* endif.
endif.
endloop.
catch cx_root into o_except.
data: l_current_controller type ref to if_wd_controller,
l_message_manager type ref to if_wd_message_manager.
l_current_controller ?= wd_this->wd_get_api( ).
l_message_manager = l_current_controller->get_message_manager( ).
l_message_manager->report_exception(
message_object = o_except ).
endtry. -
Creating the spool request for the internal table data
Hi..
I am little confused with the function module used for creating the spool request.
well...I am practicing the ALV report and sending the that report to the spool.
I ve used the FM SLVC_TABLE_PS_TO_SPOOL.
this is the way i defined the internal table.
Data:
begin of imat occurs 0,
matnr like marav-matnr,
maktx like marav-maktx,
matkl like marav-matkl,
ntgew like marav-ntgew,
gewei like marav-gewei,
end of imat.
data i_lines type sy-tfill
and i declared..
describe table imat lines i_lines.
then i given the value for i_file_length as i_lines in the export paramet of the FM SLVC_TABLE_PS_TO_SPOOL.
CALL FUNCTION 'SLVC_TABLE_PS_TO_SPOOL'
EXPORTING
i_file_length = i_lines
IMPORTING
E_SPOOLID = spoolid
tables
it_textdata = imat
when i executed it shows the list and wen going back it shows the runtime error as
CALL_FUNCTION_CONFLICT_LENG - Type conflict when calling a function module (field length).
please provide me some solutions.
thanks in advance.
etienne.Hi satyajit,
Thanks for your response....but the fields in my internal table "IMAT" is not compatible with the structure LVC_S_1022 as it has it componenrt - LINE.
so how can i define my internal table IMAT as type lvc_s_1022 as you suggested.
thanks in advance.
etienne. -
Field Texts for Dynamic Internal Tables
Hi All,
I want to know whether there is any way to get the field Headings (Not the field names)
Below is my CODE
For ex :
CLASS lvl_met DEFINITION.
PUBLIC SECTION.
METHODS : l_met IMPORTING m_itab TYPE STANDARD TABLE.
ENDCLASS.
CLASS lvl_met IMPLEMENTATION.
METHOD l_met.
data : l_t_fields TYPE abap_compdescr_tab." WITH HEADER LINE.
field-symbols:
<p_data> type any,
<p_field> type any,
<p_component> type abap_compdescr.
CREATE DATA MY_WA LIKE LINE OF m_itab.
ASSIGN MY_WA->* TO <P_DATA>.
DESC_STRUC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <P_DATA> ).
*I want the field Headings(Field Text) - In this case i want some thing like Material Number and Plant
I can read this texts if i know atleast the data element
At this point i see <p_data> in degbug mode under absolute type column i see \TYPE=WERKS_D aganst werks field
I don't know how to capture the \TYPE=WERKS_D this thing so atleast i can read field Text based on Data Element
Is there any other way to find out the field text
ENDCLASS.
TABLES : marc.
DATA : l_met TYPE REF TO lcl_met.
types : BEGIN OF t_itab,
matnr like marc-matnr,
werks like marc-werks,
end of t_itab.
data : itab type table of t_itab.
START-OF-SELECTION.
IF l_met IS INITIAL.
CREATE OBJECT l_met.
ENDIF.
select matnr werks from marc into TABLE itab up to 10 rows.
l_met->get_headertext( EXPORTING m_itab = itab ).
Thanks
DavidHi Naimesh,
I tried exactly what you said
lt_comp = desc_struc->get_components( ). "Get the fields of the structure
loop at lt_comp into ls_comp.
lo_elem_desc ?= cl_abap_elemdescr=>describe_by_name( ls_comp-name ).
lf_dfies = lo_elem_desc->get_ddic_field( ).
WRITE: / lf_dfies-scrtext_s,
/ lf_dfies-scrtext_m,
/ lf_dfies-scrtext_l.
WRITE:/ ls_comp-name. " Write the column names
endloop.
It Works fine for Matnr because field name and data element are same but when it comes to werks it gives me a dump because the date element is different werks_d
I just tried hard coding werks_d and it works fine
lo_elem_desc ?= cl_abap_elemdescr=>describe_by_name( 'WERKS_D' ).
lf_dfies = lo_elem_desc->get_ddic_field( ).
WRITE: / lf_dfies-scrtext_s,
/ lf_dfies-scrtext_m,
/ lf_dfies-scrtext_l.
Let me know how
Thanks
David
Edited by: DAVID KITSO on Nov 23, 2009 10:09 PM -
How to LOOP AT dynamic internal tables.
I have an internal table name declared in field I_DYN_TAB with me and I want to loop at this I_DYN_TAB.
( 4 example:
DATA: I_DYN_TAB(10) VALUE 'I_TAB'.
where I_TAB is my internal table with data in it.)
I already tried couple of things.
A. READ TABLE (I_DYN_TAB) WITH KEY I_DYN_TAB-FIELD1
but, it is not allowing me to read it dynamically this way.
B. LOOP AT (I_DYN_TAB). Again this is also not working.
Another option I tried is to create a field symbol for the internal table, which again is not useful or may be I am doing it wrong.
So if anybody can help me in solving this problem, it would be great.
Waiting for reply.
Regards
ArpitU can use
ASSIGN COMPONENT...
Eg:
FIELD-SYMBOLS: <dyn_field>,
<dyn_field1>,
<dyn_field2>,
<dyn_field3> TYPE ANY .
* Test when UOM, 'KMEIN' is '%'
* <b>ASSIGN COMPONENT 'KMEIN' OF STRUCTURE p_line1 TO <dyn_field1>.</b>
* ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field2>.
* ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field>.
* Test when Curr, 'KONWA' is '%'
ASSIGN COMPONENT 'KONWA' OF STRUCTURE p_line1 TO <dyn_field1>.
ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field2>.
ASSIGN COMPONENT 'KBETR' OF STRUCTURE p_line1 TO <dyn_field>.
IF <dyn_field1> = '%'.
<dyn_field> = <dyn_field2> / 10.
ENDIF.
if <dyn_field2> LE -1.
<dyn_field> = <dyn_field> * -1.
endif.
INSERT p_line1 INTO TABLE p_output1.
Hope this helps. -
To populate data in a dynamic internal table
Hi,
I have an internal table <FS_1> which I have created dynamically. Now i need to populate the columns (7th column onwards) in the internal table with my data in GT_REQMT which is an internal table.
Data: L_IDX type I.
L_IDX = 6.
Loop at <FS_1> assigning <FS_2>.
If sy-tabix = 1.
Loop at GT_REQMT.
Add 1 to L_IDX.
*****I need to populate GT_REQMT-DATA to column 7 then 8 etc depending on the number of loops.
Modify <FS_1> from <FS_2>.
Endloop.
Else.
**do other things here**
Endif.
Endloop.
I have search through the forums and weblogs but the solutions are catered to populating the internal tables from SAP database using SQL statements.
I couldn't find anything on populating own data in dynamic table by looping it. Please help. THANKS!!
Cheers,
ChelseaHi!
I have used classes for dynamic internal table, SO i here give you my sample code for your help.
DATA : new_table TYPE REF TO data,
new_line TYPE REF TO data.
FIELD-SYMBOLS : <TAB1> type standard table,
<l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
count = count + 1.
clear wa_fieldcat.
wa_fieldcat-col_pos = count.
wa_fieldcat-fieldname = 'CONDITION'.
wa_fieldcat-coltext = 'Condition Value'.
wa_fieldcat-ref_field = 'KWERT'.
wa_fieldcat-ref_table = 'KONV'.
wa_fieldcat-outputlen = 13.
append wa_fieldcat to it_fieldcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
ASSIGN COMPONENT KWERT OF STRUCTURE <l_line> TO <l_field>.
<l_field> = t_kschlkonv-vtext.
NOw u append internal table
IF its helps you then dont forget to rewards points.
Regards From
Priyank -
Dynamic internal table and dynamic field catalog
hi
i need to decide the number of fields of the internal table at runtime
and then need to pass value to this internal table.
then i need to create the field catalog for this internal table (so here
field catalog is also dynamic) to display in alv.
how to achieve this dynamic internal table creation and dyanmic field catalog generationHi Ajay,
U can use the below code to create a dynamic internal table.
*adding the field names only once for the dynamic table .
MOVE 'PRCTR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RCNTR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RACCT' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RYEAR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'YTDBAL' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'OBAL' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
*get structure descriptor -> GR_STRUCTDESCR
gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
create work area of structure GR_STRUCTDESCR -> GR_WA
CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
ASSIGN gr_wa->* TO <gw_wa>.
determine key components -> GT_KEYS
MOVE lv_value1 TO gw_key-name.
INSERT gw_key INTO TABLE gt_keys.
create descriptor for internal table -> GR_TABLEDESCR
gr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = gr_structdescr
p_table_kind = cl_abap_tabledescr=>tablekind_hashed
p_unique = abap_true
p_key = gt_keys
p_key_kind = cl_abap_tabledescr=>keydefkind_user ).
create internal table -> GR_ITAB
CREATE DATA gr_itab TYPE HANDLE gr_tabledescr.
ASSIGN gr_itab->* TO <gt_itab>.
CREATE DATA gr_itab LIKE STANDARD TABLE OF <gw_wa>.
ASSIGN gr_itab->* TO <gt_sttab>.
Now u r internal table named <gt_sttab> has been created with fields like RCNTR, PRCTR,RACCT, RYEAR etc whatever the field u need u can go ahead and create dynamically.
then by using the table <gt_sttab> u can create u r field catalog.
Regards,
Rose. -
Distinct values from dynamic internal tabls
Hi All,
I have a dynamic internal tables like <dy_table> , i want to get distinct values from this internal tables,
how to do that, structure of dynamic internal tables is dynamic acc. to user conditions.
regards,
AnujHi Anuj
Just try this,
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = tb_fields_for_it
IMPORTING
ep_table = gp_dyn_table.
ASSIGN gp_dyn_table->* TO <gt_table>.
ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.
LOOP AT tb_output.
*To assign value for serial number.
ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.
<ls_field> = tb_output-sno.
UNASSIGN <ls_field>.
*To assign value for Sales Organization.
ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.
<ls_field> = tb_output-vkorg.
UNASSIGN <ls_field>.
*To assign Rate for its respective Condition type.
LOOP AT tb_konp WHERE knumh = tb_output-knumh.
READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.
IF sy-subrc EQ 0.
lv_count = tb_fieldcat1-col_pos.
ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.
IF tb_konp-konwa EQ '%'.
tb_konp-kbetr = tb_konp-kbetr / co_10.
<ls_field> = tb_konp-kbetr.
ELSE.
<ls_field> = tb_konp-kbetr.
ENDIF.
ENDIF.
ENDLOOP.
lv_count = lv_count + 1.
APPEND <fs_table> TO <gt_table>.
CLEAR <fs_table>.
ENDLOOP.
Hope this proves helpful to you.
Maybe you are looking for
-
Java Web Start and Policy File
Hi, I've a problem for Java Web Start (JWS) in working with Policy File. I like to apply a policy file for a JWS application to fine tune the secuirty setting instead of granting permission in JWS. For an applet environment, I can apply policy file l
-
Apple will sell no whine before its time
<<<< WHINE UPDATE >>>> I believe the latest firmware update (1.0.1) has changed the quality of the whine. It hasn't gotten rid of it, it has just made it sound...different... (in my opinion). Of course, I'm willing to admit this could be my imaginati
-
How do I get 10.4.8 AUDIO VOLUME back?!
My daughters' iMac G3 is like a freakin' megaphone now after updating it to 10.4.9. Why did Apple have to mess with audio volume levels? It was FINE the way it was. Now, in 10.4.9, the lowest volume setting is around the 50%-65% mark it was in 10.4.8
-
GPO Disappeared from "Controlled" after checking in
I've been using AGPM for some time but haven't seen this before. I made a single change to my IE policy and checked it back in. At that point it threw an error (which I didn't screenshot thinking it would be in the event viewer). After the error, the
-
hi all, i have cursor like cursor b_details_E is select company,orgport,disport,agent,shipper from b_details where type = 'Export' and status = 'SEA'; begin for i in