2007 May 12 1:27 AM
Hi Gurus,
<b>By Generic Programming</b>
May I know how to write a form WRITE_TABLE which accepts any internal table and also to write the contents of the internal table to the ABAP list, line
by line and field by field?
Thanks,
Raja
2007 May 14 10:43 AM
Hello Raja
The most generic form of an itab I can think of is a <b>data object</b> referencing the internal table. Perhaps the following sample coding may be useful:
DATA:
ldo_data TYPE REF TO data.
" Fill you itab with data (any type)
" Get the data reference of your itab
GET REFERENCE OF <itab> INTO ldo_data.
" Pass the itab as data reference to your FORM routine
PERFORM write_table USING ldo_data.
FORM write_table using udo_data TYPE REF TO data.
* define local data
field-symbols:
<lt_itab> TYPE table,
<ls_line> TYPE any,
<ld_fld> TYPE any.
" De-reference your data object
ASSIGN udo_data->* to <lt_itab>.
CHECK ( <lt_itab> IS ASSIGNED ).
LOOP AT <lt_itab> ASSIGNING <ls_line>.
DO.
ASSIGN COMPONENT syst-index OF STRUCTURE <ls_line> TO <ld_fld>.
IF ( syst-subrc ne 0 ).
EXIT.
ENDIF.
" Do your write statement
ENDDO.
ENDLOOP.
ENDFORM.
Regards
Uwe
2007 May 12 3:39 AM
http://help.sap.com//saphelp_470/helpdata/EN/d1/803279454211d189710000e8322d00/content.htm
Anyway, I would recommend to use USING or CHANGING by passing the 'body' of the table like this :
*_ User selection
PERFORM user_selection USING s_bname[]
CHANGING wt_bname[].
FORM user_selection USING ps_bname LIKE s_bname[]
CHANGING pt_bname LIKE wt_bname[].
...
ENDFORM. " user_selection
2007 May 12 4:44 AM
Hi,
Try this..
PERFORM display TABLES ITAB.
FORM display TABLES LT_TAB.
LOOP AT LT_ITAB.
WRITE: / LT_ITAB.
ENDLOOP.
ENDFORM.
Thanks,
Naren
2007 May 12 8:10 PM
Hi,
if you have input variable lt_itab type any table then you can do something like this:
field-symbols: <row> type any, <field> type any.
loop at lt_itab assigning <row>.
do.
assign component sy-index of structure <row> to <field>.
if sy-subrc ne 0.
* no more components left in row
exit. "exit do
endif.
if sy-index eq 1.
write / <field>.
else.
write <field>.
endif.
enddo.
endloop.
Hope this helps,
Björn
2007 May 14 9:15 AM
2007 May 14 10:43 AM
Hello Raja
The most generic form of an itab I can think of is a <b>data object</b> referencing the internal table. Perhaps the following sample coding may be useful:
DATA:
ldo_data TYPE REF TO data.
" Fill you itab with data (any type)
" Get the data reference of your itab
GET REFERENCE OF <itab> INTO ldo_data.
" Pass the itab as data reference to your FORM routine
PERFORM write_table USING ldo_data.
FORM write_table using udo_data TYPE REF TO data.
* define local data
field-symbols:
<lt_itab> TYPE table,
<ls_line> TYPE any,
<ld_fld> TYPE any.
" De-reference your data object
ASSIGN udo_data->* to <lt_itab>.
CHECK ( <lt_itab> IS ASSIGNED ).
LOOP AT <lt_itab> ASSIGNING <ls_line>.
DO.
ASSIGN COMPONENT syst-index OF STRUCTURE <ls_line> TO <ld_fld>.
IF ( syst-subrc ne 0 ).
EXIT.
ENDIF.
" Do your write statement
ENDDO.
ENDLOOP.
ENDFORM.
Regards
Uwe