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

Accepting Dynamic Values

Hai! Experts!

i want to get a data from table based on the users choice (for this i have a created a parameter on selection screen) and i want to display the table contents on the list....how to do it?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2008 at 04:41 AM

    hi,

    Select the data from the Db table inot an internal table and Assign the Internal table to ALV list Function Module.

    Use Query.

    Select * from <DBtable>

    into table <itab>

    where <field > EQ <p_val>.

    This Query will store Data in the Internal table.

    Regards

    Sumit Agarwal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2008 at 04:54 AM

    Hi,

    For fetching data from Dynamic database table and disply it into list you can use field -symbol concept.

    Refer the link for the ceoncept-

    http://www.sap-img.com/ab030.htm

    Regards,

    Sujit

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2008 at 05:14 AM

    refer to the link for sample code on dynamic table selection:

    http://www.sap-img.com/abap/how-can-we-give-dynamic-table-name-in-select-statement.htm

    With luck,

    Pritam.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 02, 2008 at 05:25 AM

    1.First Get the components from the table(fields)

    2.Create the fieldcatalog

    3.Create the Dynamic Table using the CL_ALV_TABLE_CREATE

    4. Now use the select

    5. Display the data

    Check the sample code.

    REPORT  ytest_dynamic.
    
    TYPE-POOLS : abap.
    DATA : table_des TYPE REF TO cl_abap_structdescr.
    DATA : ifields TYPE abap_compdescr_tab,
              wa_field LIKE LINE OF ifields.
    DATA: it_fieldcat TYPE lvc_t_fcat,
              wa_fieldcat TYPE lvc_s_fcat.
    DATA: i_tab TYPE REF TO data.
    
    FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
    
    PARAMETERS: p_table(30) TYPE c DEFAULT 'SFLIGHT'.
    
    
    "Table definiton using the table name
    table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
    "Now Read all the fields to a table.
    ifields = table_des->components.
    
    
    LOOP AT ifields INTO wa_field.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = wa_field-name .
      wa_fieldcat-datatype = wa_field-type_kind.
      wa_fieldcat-inttype = wa_field-type_kind.
      wa_fieldcat-intlen = wa_field-length.
      wa_fieldcat-decimals = wa_field-decimals.
      wa_fieldcat-coltext = wa_field-name.
      wa_fieldcat-outputlen = wa_field-length.
    
      APPEND  wa_fieldcat TO it_fieldcat.
    ENDLOOP.
    
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog           = it_fieldcat
      IMPORTING
        ep_table                  = i_tab
    *    e_style_fname             =
      EXCEPTIONS
        generate_subpool_dir_full = 1
        OTHERS                    = 2
            .
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    
    ASSIGN i_tab->* TO <fs>.
    
    *-fill the data
    APPEND INITIAL LINE TO <fs>.
    
    SELECT  *
    INTO TABLE <fs>
    FROM (p_table)
    UP TO 20 ROWS.
    
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        i_callback_program = sy-repid
        it_fieldcat_lvc    = it_fieldcat
      TABLES
        t_outtab           = <fs>
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    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.