Application Development and Automation 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: 
Read only

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

Former Member
0 Likes
3,141

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

14 REPLIES 14
Read only

Former Member
0 Likes
2,025

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

Read only

0 Likes
2,025

ok

data::begin of itab ,

a, b , c,d.

end of itab.

now user selected only b ,d....

what do you mean by user input to Internal table how do do that?

Read only

0 Likes
2,025

user must be selection it through select option or parameter

you can get that data in internal table.

Read only

0 Likes
2,025

Hi,

Provide some details of your issue, because in selection screen means user provide the data either through parameters or select options only.

Thanks,

Sree

Read only

0 Likes
2,025

Thanks please look for Peter Jonker i illusrtated a bit but not fully as I am nervous timing is running up ;(

Read only

PeterJonker
Active Contributor
0 Likes
2,025

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)

Read only

0 Likes
2,025

I now realize that you want to select from the database as well based on the user input, well then my previous solution is not the right one.

You will need to construct a dynamic where statement and create a dynamic internal table which fields depends on what the user selected. That will be much more complicated.

The solution I provided to you in my previous message is based on the assumption that you will always select all fields from the database.

Anyway it could be an alternative if you don't manage with the dynamic where statements and tables. Offcourse this depends on how much data will be selected and if the amount of data (fields) has any influence on the performance of your program

Read only

0 Likes
2,025

Hy guys Thank you very much for quick response...

ok I will tell you what exactly I am looking for....

I have 2 FILES IN application server ..Both are output of same Report but Report execute date is different..

user want to see what is the difference between yesterday file AND today file...

that file contains 200 columns each...

User may select only 5 fields ....on selection-screen(Its Popup box what i have created, so user can select from there).

Now I have yesterday data in ITAB., today data in JTAB...

i WILL LOOP from both and compare and put the final data in FTAB...

Now I need to download this data in FTAB OF THOSE 5 FIELDS ...but if 5 fields only 3 fields having data i need to download only 3 fields....

Like below:

FTAB:

Empname_today empname_yes   Emaddress_today empadress_yes

ABC                      CBA                  #123                       $345

Emptelephone field also selected but no change so we dont display in output....

Regards

Sas

Read only

0 Likes
2,025

OK, a little bit more complicated but possible. You can still use the code I provided before. This will delete the fields that you do not want to show on the alv, BUT.......

You will need to construct the table lt_names in my example a little bit different.

The table should hold every display name selected by the user in the popup, but twice (one time with extension today and the other with extension yesterday).

Now you can define the table type as follows:

Types: begin of ty_names,

               name type string, "this holds the name of the display field (in UPPER CASE )

               show type flag,

            end of ty_names,

            tt_names type standard table of ty_names.

Data: lt_names type tt_names,

          wa_names type ty_names.

Fill this table with the names selected.and show = 'X'

Now when you do you comparising and find out there is no difference between todays and yesterdays field values,  you delete the X in your internal table for these fields. (remember there are two )

The code I provided before will now take care of the rest.

But you will need to define an output table with all the fields that are possible to display and since you were talking about 200 fields this will result in a structure of 400 fields. That might be too much.

I don't know if there is a limit on the length of the type and data structures declared inside ABAP as internal types and tables (work areas).

Read only

0 Likes
2,025

I am unable to download from what you are saying, it will be great if you can do with sample of 3 fields..please..

Time is alreayd up but luckily some prod bug came so deviated for time being...

Read only

0 Likes
2,025

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

Read only

Former Member
0 Likes
2,025

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

Read only

Former Member
0 Likes
2,025

hiii saslove

you can use flag for to select 5 inputed fields

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

Read only

ipravir
Active Contributor
0 Likes
2,025

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.