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: 

method to fill teh internal table .

Former Member
0 Kudos

Hi Experts ,

How can i develop method of class for following purpose .

method importing parameter as name of the table ( dynamic :- caller can provide name of any table )

and exporting parameter as the internal table fill with the data from table whos name was entered by the user .

Thanks ,

Rushikesh

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Like this


CLASS lcl_filler DEFINITION.
  PUBLIC SECTION.
    METHODS: get_table IMPORTING tab_name TYPE string
                       RETURNING value(r_table) TYPE REF TO data.  "we return reference to table
ENDCLASS.                    "lcl_filler DEFINITION

CLASS lcl_filler IMPLEMENTATION.
  METHOD get_table.
    FIELD-SYMBOLS <tab> TYPE STANDARD TABLE.

    CREATE DATA r_table TYPE TABLE OF (tab_name).
    ASSIGN r_table->* TO <tab>.

    SELECT * FROM (tab_name) INTO TABLE <tab> UP TO 10 ROWS.
  ENDMETHOD.                    "get_table
ENDCLASS.                    "lcl_filler IMPLEMENTATION

START-OF-SELECTION.
  DATA: r_filler TYPE REF TO lcl_filler,
        r_table TYPE REF TO data.
  FIELD-SYMBOLS <tab> TYPE STANDARD TABLE.

  CREATE OBJECT r_filler.
  r_table = r_filler->get_table( 'SFLIGHT' ).
  ASSIGN r_table->* TO <tab>.  "here content of first table

  r_table = r_filler->get_table( 'SPFLI' ).
  ASSIGN r_table->* TO <tab>. "here content of another one

Regards

Marcin

2 REPLIES 2

MarcinPciak
Active Contributor
0 Kudos

Like this


CLASS lcl_filler DEFINITION.
  PUBLIC SECTION.
    METHODS: get_table IMPORTING tab_name TYPE string
                       RETURNING value(r_table) TYPE REF TO data.  "we return reference to table
ENDCLASS.                    "lcl_filler DEFINITION

CLASS lcl_filler IMPLEMENTATION.
  METHOD get_table.
    FIELD-SYMBOLS <tab> TYPE STANDARD TABLE.

    CREATE DATA r_table TYPE TABLE OF (tab_name).
    ASSIGN r_table->* TO <tab>.

    SELECT * FROM (tab_name) INTO TABLE <tab> UP TO 10 ROWS.
  ENDMETHOD.                    "get_table
ENDCLASS.                    "lcl_filler IMPLEMENTATION

START-OF-SELECTION.
  DATA: r_filler TYPE REF TO lcl_filler,
        r_table TYPE REF TO data.
  FIELD-SYMBOLS <tab> TYPE STANDARD TABLE.

  CREATE OBJECT r_filler.
  r_table = r_filler->get_table( 'SFLIGHT' ).
  ASSIGN r_table->* TO <tab>.  "here content of first table

  r_table = r_filler->get_table( 'SPFLI' ).
  ASSIGN r_table->* TO <tab>. "here content of another one

Regards

Marcin

0 Kudos

Thanks for your reply ,

this is very helpful for beginners like me .

THANKS ,

RUSHIKESH .