Skip to Content
author's profile photo Former Member
Former Member

Dynamic table declaration in FM

Hi Geeks,

I am calling a FM from a program where the FM should get the structure data and set that data into a single line with delimiters and send it out. The table structure can be anything. So how can I declare that table structure data (in tables tab in FM). Could somebody help me with this.

Thanks,

Kiran.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jan 18, 2008 at 02:35 PM

    Ok, so which approach did you try, what does the dump say, and you may want to post the code of the function module, and/or is interface definition.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 02:22 PM

    Hi Kiran, try this code.

    Try this piece of code:

    REPORT YDEMO .

    PARAMETERS: TBLNAME(50). "DEFAULT 'SPFLI'.

    DATA: TOTAL_ROWS TYPE P.

    SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS.

    WRITE: / TBLNAME, TOTAL_ROWS.

    cheers,

    Hema.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 18, 2008 at 02:25 PM

    In the function module interface, do not assign a TYPE for the table if you are using a TABLES parameter. If you are passing the table in the IMPORTING and EXPORTING parameters, then you will want to type it as STANDARD TABLE. This allows you to pass a table with any structure. Once inside the function module you will then need to read this table using field symbols.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 18, 2008 at 02:27 PM

    Just give the name of the internal table, don't give any type to this parameter.

    Then in the source you will have to use dynamic assignment to access records and fields.

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 18, 2008 at 02:32 PM

    So inside your function module then, you can read the importing table and then build the output table, maybe using comma as your delimiter. Here IM_TAB is the imcoming table. You can pass LT_DATA back out via an EXPORTING parameter or TABLES parameter

    
    FIELD-SYMBOLS: <fs_im_tab> TYPE ANY,
                   <fs_comp>   type any.
    
    DATA: lt_data TYPE TABLE OF string.
    DATA: ls_data TYPE string.
    
    
    LOOP AT im_tab ASSIGNING <fs_im_tab> .
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE <fs_im_tab> TO <fs_comp>.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        IF sy-index = 1.
          ls_data = <fs_comp>.
        ELSE.
          CONCATENATE ls_data <fs_comp> INTO ls_data SEPARATED BY ','.
        ENDIF.
      ENDDO.
      APPEND ls_data TO lt_data.
    ENDLOOP.
    
    
    

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

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.