Application Development 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: 

How to capture values from ALV grid into program ?

Former Member
0 Kudos
1,673

HI,

How we could get values from ALV grid into same program from which we are displying ALV grid? I mean I want to capture values from first ALV grid & using these values I want to do some calculation & display second ALV grid.

anybody knows how to do it?

Regards,

Prafulla

10 REPLIES 10

Former Member
0 Kudos
267

Hi Prafulla,

You usually create an alv grid, call the method set_table_for_first_display to display an itab with corrsponding values. Depending on user response, ur handler methods do the required processing and possibly change the contents of ur itab. Then u can re-display in the same grid by using method refresh_table_display.

Hope this helps. Lemme know if u r looking for something else. Some methods u might find helpful:

GET_GRID_MODIFIED, GET_SELECTED_COLUMNS, SAVE_DATA

GET_MODIFIED_CELLS, GET_SELECTED_ROWS

GET_SELECTED_CELLS_BASE_RANGE etc

jayanthi_jayaraman
Active Contributor
0 Kudos
267

Hi,

If you are going to display a ALV Grid,you definetely need an internal table.So take that internal table and do the manipulations for the second output table and display it in second grid.

Suppose if you are using Reuse_Alv_Grid_Display, you will have to pass tables.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

....

TABLES

t_outtab = itab1.

This is the table [itab1]which makes you to see the ALV Output.

So take this table and do the manipulations and show the second ALV.

Loop at itab1 into wa1.

wa2-field2 = wa1-field1 * 10.

...

append wa2 to itab2.

endloop.

Then itab2 internal table will be your new internal table for second ALV display.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

....

TABLES

t_outtab = itab2.

If you are using OOPS concept , you have to use

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

is_variant = w_variant

i_save = c_a

is_layout = p_layout

it_special_groups = p_groups[]

it_toolbar_excluding = p_exclude[]

CHANGING

it_outtab = itab1[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

Here itab1[] will make to see the ALV output.

Use this internal table itab1[] for manipulation and build a second internal table itab2[] as I told before.

Hope this is useful.

If so,reward points.If not,get back.

Former Member
0 Kudos
267

former_member65049
Active Participant
0 Kudos
267

Hi Prafulla,

If I get you correctly, firstly you are displaying an ALV list and then you want to capture any displayed value(may be by double clicking) and display another ALV using this value.

You can do something like this.

1. Declare an Internal Table for User command event.

DATA: i_callback_user_command TYPE slis_formname.

2. Call your ALV list using the FM and passing the parameter i_callback_user_command.

i_callback_user_command = 'USER_COMMAND'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_user_command = i_callback_user_command

is_layout = ls_layout

it_fieldcat = i_fieldcat

it_events = i_events

TABLES

t_outtab = i_output

EXCEPTIONS

program_error = 1

OTHERS = 2.

3. Write the subroutine user command, which will be

called automatically when some action is taken on

displayed ALV.

Subroutine to trap the user action.

  • --> p_ucomm User comnand

  • --> ps_selfield Structure containing deatils of

selected entry

FORM user_command USING p_ucomm LIKE sy-ucomm

ps_selfield TYPE slis_selfield.

  • Checking the User action and taking action accordingly.

CASE p_ucomm.

WHEN '&IC1'. "Double click

PERFORM call_another_list

USING ps_selfield.

WHEN OTHERS.

ENDCASE.

ENDFORM. "user_command

4. Then in the subroutine "CALL_ANOTHER_LIST", you can

capture the value of the field that was clicked and

do whatever you want.

  • -->PS_SELFIELD Structure contaning information about

data selected.

FORM call_another_list USING ps_selfield TYPE

slis_selfield.

  • Call another list based on the field selected.

  • ps_selfield-sel_tab_field -> gives the value of the

field clicked.

CASE ps_selfield-sel_tab_field.

when 'selected field'.

perform do_necessary_action.

ps_selfield-refresh = 'X'.

ps_selfield-row_stable = 'X'.

ENDCASE.

Write the code necessary for your requirement in the

subroutine do_necessary_action.

Prafulla, you can try using this approach, it does not OOPS concept. In 4th step, You get the value of selected field in your structure "ps_selfield". You can also use other parameters of this structure and do the processing.

You can do something like in 4th step -

CASE ps_selfield-sel_tab_field.

when 'I_OUTPUT-FIELD1'.

perform do_necessary_action.

ps_selfield-refresh = 'X'.

ps_selfield-row_stable = 'X'.

ENDCASE.

Hope this helps you.

Rgds,

Rupam

Message was edited by: Rupam Agarwalla

0 Kudos
267

Thanx a lot for your replies....

Well let me once again explain my requirement.....

I am not taking OOPs approch here. On my first ALV grid there are number of rows & i want to read all rows at a time may be in table & depending on contains in this table I will do processing for next screen. I tried to see if my output table for first screen has updated values or not, so that I can use these values....but the values which user puts on First ALV grid doesnt get updated in output table for first ALV grid. so I cannot use output table of first grid fot processing of second grid.

does anybody knows any FM to get all values from ALV screen?

Regards,

Prafulla

Former Member
0 Kudos
267

Hello Prafulla,

When you change any data in the alv, you can catch the changed data in the DATA_CHANGED event or the data gets automatically updated in the internal table of first alv in the DATA_CHANGED_FINISHED event.

In the DATA_CHANGED event, you have to get the data using any of the following methods of CL_GUI_ALV_GRID

GET_GRID_MODIFIED, GET_SELECTED_COLUMNS, GET_MODIFIED_CELLS, GET_SELECTED_ROWS

If you handle the DATA_CHANGED_FINISHED event, since the internal table is automatically gets filled, using this data, you can display the second ALV after doing the required modifications for the second ALV.

Regards

Kalyan

0 Kudos
267

Hi,

Just try to append DATA_CHANGED as events and pass the same in Reuse_Alv_Grid_Display.I think you will get the modified output in the table.

Former Member
0 Kudos
267

Hi,

In the PAI of the screen

DATA: i_fieldrows TYPE lvc_t_row,

MODULE user_command_9001 INPUT.

<b>CALL METHOD o_alvgrid->get_selected_rows

IMPORTING

et_index_rows = i_fieldrows.</b>

<i><b>LOOP AT i_fieldrows INTO w_fieldrows.

READ TABLE i_output INTO w_output INDEX w_fieldrows-index.

ENDLOOP.</b></i>

Now u can do the calculation part by using the w_fieldrows-index read the output table.

v_val = w_output-field1 * w_output-field2.

Similarly u can do ur calc.

CASE sy-ucomm.

WHEN 'XX'.

.

.

.

ENDCASE.

<i>If u want all the data that are in the ALV output, it will be in the output table that u r using to pulate the ALV grid.</i>

Then y u need to select all the rows and then get all the values?

Hope this helps u.

Thanks & Regards,

Judith.

Dont forget to reward points for the helpful answers.

Message was edited by: Judith Jessie Selvi

Former Member
0 Kudos
267

Hi, my friend.

I understand you requirement.

You want to get the user inputted data from ALV, after the REUSE_ALV_GRID_DISPLAY return, right?

Then there is a field named INPUT in the SLIS_FIELDCAT_ALV, set it 'X', then all of the inputted data will reflect in the internal table after REUSE_ALV_GRID_DISPLAY return.

No need to use OO ALV for this requirement.

Hope it will be useful.

Thanks a lot

Former Member
0 Kudos
267

Hi, I find that my former reply isn't correct.

About how to capture the inputted data from ALV, you can do as following:

DATA:

LC_GLAY TYPE LVC_S_GLAY.

  • this is the critical point

LC_GLAY-EDT_CLL_CB = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_GRID_SETTINGS = LC_GLAY

IT_FIELDCAT = L_ALV_FILEDCAT

TABLES

T_OUTTAB = ITAB.

Sorry for the mistake in my former reply.