Skip to Content

How to create dynamic internal table output based on selection-screen data

Hi All,

I have 200 fields in ITAB, ....THOSE 200 FIELDS WILL BE DISPLAYED IN selctions-screen output....

user will select only 10 fields...

Now my requirement is to download only those 10 fields and that too the fields with data...Please advise..I am searching from 1 week and couldnt able to get the exact output what i am looking for ........Today I need to deliver this..Thanks in advanse

Regard

Sas

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 11, 2014 at 09:22 AM

    hii saslove,

    append user input in one internal table.

    compare that with your internal table and put a flag where its avaibale

    and then in fieldcat use this flag to display output.

    Regards

    Gaurav

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 11, 2014 at 10:08 AM

    Which ALV methods are you using ? If you use CL_SALV_TABLE then it could be done using the column object and the descriptor classes.

    wa_table in below example is the structure (WORK AREA) of your output table, lt_table is the output TABLE.

    DATA: l_rcl_struc TYPE REF TO cl_abap_structdescr.

    gr_table TYPE REF TO cl_salv_table,

    gr_columns_table TYPE REF TO cl_salv_columns_table,

    gr_column TYPE REF TO cl_salv_column.

    FIELD-SYMBOLS: TYPE abap_compdescr.

    TRY.

    CALL METHOD cl_salv_table=>factory

    IMPORTING

    r_salv_table = gr_table

    CHANGING

    t_table = lt_table.

    CATCH cx_salv_msg INTO lcx_salv_msg.

    ENDTRY.

    .

    gr_functions = gr_table->get_functions( ).

    gr_functions->set_all( 'X' ).

    l_rcl_struc ?=

    cl_abap_structdescr=>describe_by_data( wa_table ).

    gr_columns_table = gr_table->get_columns( ).

    LOOP AT l_rcl_struc->components ASSIGNING <components>.

    lv_name = <components>-name.

    read table lt_names with key name = lv_name

    show = 'X'

    if sy-subrc = 0.

    TRY.

    gr_column = gr_columns_table->get_column( columnname = lv_name ).

    gr_column->set_optimized( 'X' ).

    lv_text = lv_textm = lv_textl = lv_tip = lv_name.

    gr_column->set_short_text( lv_text ).

    gr_column->set_medium_text( lv_textm ).

    gr_column->set_long_text( lv_textl ).

    gr_column->set_tooltip( lv_tip ).

    CATCH cx_salv_not_found .

    ENDTRY.

    else.

    TRY.

    gr_column = gr_columns_table->get_column( columnname = lv_name ).

    gr_column->set_technical( 'X' ). "this will delete the field from the output display.

    CATCH cx_salv_not_found .

    ENDTRY.

    endif.

    ENDLOOP.

    gr_table->display( ).

    The table lt_names have to be filled according to what the user selected in selection screen. Offcourse the names used in this table need to be the same as the names used in the type definition of your output table. (in this example wa_table)

    Add a comment
    10|10000 characters needed characters exceeded

    • What is it you don't understand ? There is nothing to download, the code is in text format in my first post.

      If a user selects 2 fields in a popup then you need to code something like:

      if P_fld1 = 'X'.

      wa_names-name = 'FLD1_OLD'. "the name of the field to be shown in UPPERCASE

      wa_names-show = 'X'.

      append wa_names to lt_names.

      wa_names-name = 'FLD1_NEW'.

      wa_names-show = 'X'.

      apend wa_names to lt_names

      clear wa_names.

      endif.

      if p_fld2 = 'X'.

      wa_names-name = 'FLD2_OLD'.

      wa_names-show = 'X'.

      append wa_names to lt_names.

      wa_names-name = 'FLD2_NEW'.

      wa_names-show = 'X'.

      append wa_names to lt_names.

      clear wa_names.

      endif.

      and do this for all fields that the user has selected to be shown.

      Now you are downloading both files and compare them for changes. (Or compare only the fields that the user selected for changes whatever you programmed.)

      If during comparising the old and new value have not been changed for all records then check if the field (name) is in the internal table. (remember you need to do this twice for the old and new field name). This way you can delete a field to be shown if there have been no differences.

      Read lt_names into wa_Names with key name = 'FLD1_OLD'.

      if sy-subrc = 0.

      clear wa_Names-show.

      modify lt_names from wa_names index sy-tabix.

      endif.

      read lt_names into wa_names with key name = 'FLD1_NEW'.

      if sy-subrc = 0.

      clear wa_names-show.

      modify lt_names from wa_names index sy-tabix.

      endif.

      At the end you call the ALV code as mentioned in my first post and only the fields that the user has chosen and are in lt_names with show = 'X' will be shown.

      There is not much more I can tell you then this pseudo code. The rest you will really need to do yourself with trial and error. Just go ahead and try it..

      Good luck.

      Peter

  • author's profile photo Former Member
    Former Member
    Posted on Dec 11, 2014 at 10:30 AM

    For dynamic internal table you can follow this link which is very good to understand.

    Dynamic Internal Table iIlustrated with an example of creating the transpose of internal table

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 11, 2014 at 10:40 AM

    hiii saslove

    you can use flag for to select 5 inputed fields

    and then write if condition for initial data to append in ftab.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 16, 2014 at 02:58 PM

    Hi,

    Please find the logic to provide the output of your requirement.

    1. Create a three dynamic table with same structure, in your case 200 fields.

    2. While updating 2 table ITAB & JTAB, use the selected field to update the data.

    Use "ASSIGN COMPONENT selected field name of structure <field Symbol> To <VAL-FS>.

    here the selected field name would be user selected fields from the select-option.

    3. After that, do the comparison, and then if as you mentioned and append into the 3ed table of only value field require,

    so for that you can use the flag logic.

    4. And finally only display those fields in Output, which is selected by user and having the value (Use Flag Value with respect to selected Field ) and hide the rest of the fields.

    Regards.

    Praveer.

    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.