Skip to Content

Fetch data from Table

Hi all,

I am using function module through Call fucntion.

There i am getting <b>Table Name</b> as import Parameter.

Now i need to fetch data from that table (Which name we got througfh function module).

Is there any point to know how can we fetch data from runtime table .

i need some sample code for this.

Thanks inn advance,

Regards,

Bhaskar

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Dec 03, 2007 at 04:12 AM

    Hello,

    I'm not sure if I got your question correctly

    From what I understood, you need to fetch data from a table whose name is determined at runtime

    If that is your requirement, then use the following code

    DATA : LV_FIELD_DESC TYPE STRING.
    DATA : LV_DATA1 TYPE STRING.
    DATA : LV_DETAIL(128).
    DATA : COMMA TYPE C VALUE ','.
    DATA : LV_TNAME LIKE DD02L-TABNAME.
    DATA : LV_DBTAB1 LIKE DD02L-TABNAME.
    DATA : DREF TYPE REF TO DATA.
    
    FIELD-SYMBOLS: <ITAB> TYPE ANY TABLE, " used to store dynamic tables
                   <WA>    TYPE ANY,      " used to store record data
                    <WA1> TYPE ANY .      " used to store field data
    
    LV_DBTAB1 = 'MARA'. " <-- put your table name here
    
    * we do not know the sized of the table that must be generated beforehand
    * hence we use field symbols to dynamically generate the internal table
      CREATE DATA DREF TYPE STANDARD TABLE OF (LV_DBTAB1)
                                WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN DREF->* TO <ITAB> .
    
    * selects all data
      SELECT * FROM (LV_DBTAB1) INTO TABLE <ITAB> .
      LOOP AT <ITAB> ASSIGNING <WA>.
    
        DO.
          ASSIGN COMPONENT SY-INDEX
                 OF STRUCTURE <WA> TO <WA1>.
          IF SY-SUBRC <> 0.
            EXIT.
          ENDIF.
          IF SY-SUBRC = 1.
            WRITE :/ .
          ENDIF.
          MOVE <WA1> TO LV_DETAIL.
          CONCATENATE LV_DATA1 LV_DETAIL COMMA INTO LV_DATA1.
        ENDDO.
    
    *   display
        NEW-LINE.
        WRITE LV_DATA1.
    
    *   file output if required
    *   TRANSFER LV_DATA1 TO LV_OUTFILE.
    
    *   clears the variable for reuse
        CLEAR LV_DATA1.
    
      ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Bhaskar,

      The Function Module 'DDIF_NAMETAB_GET' returns the fields of the database table name you pass to it

      It may have been used in '/SAPAPO/TS_PA_COPY_TABLE_GET'

      If it returns a table parameter with the field names, then you will not need to use it here, but instead loop at that returned table

      Else, you will have to use it separately in this program

      You can check what it returns by testing the FM in SE37

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.