Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

To write a Generic Programming to accept any internal table

Former Member
0 Kudos
103

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

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos
66

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

5 REPLIES 5

Former Member
0 Kudos
66

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

Former Member
0 Kudos
66

Hi,

Try this..

PERFORM display TABLES ITAB.

FORM display TABLES LT_TAB.

LOOP AT LT_ITAB.

WRITE: / LT_ITAB.

ENDLOOP.

ENDFORM.

Thanks,

Naren

Former Member
0 Kudos
66

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

Former Member

uwe_schieferstein
Active Contributor
0 Kudos
67

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