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: 

ALV not getting refreshed when call screen is executed second time

amber_garg
Active Participant
0 Kudos
5,064

I have 2 screens 9001 and 9002. In 9001 , I am displaying the fields of a database table in a Table Control. The user has to select some of those fields and click on a button 'Generate ALV'. After clicking , the control navigates to 9002 where I am displaying ALV with data in the selected fields(the other fields remain empty). (using custom container)

Now there is BACK button in 9002 where i have written LEAVE TO SCREEN 9001. After this if the user again make changes in column selection and click on 'Generate ALV' , then still the old alv data is displayed. (Mind you the structure of alv is same , only the selected fields should show data).

I am using REFRESH_ALV_DISPLAY also and when i tested this function independently , its working fine (although for interactive alv in the same screen).

I am making use of <fs> for dynamic internal table and i checked it using breakpoints , during the 2nd time , it contains the correctly updated data so i think the problem lies with alv

Kindly check this code

MODULE STATUS_9002 OUTPUT.
  SET PF-STATUS 'ZALV'.
*  SET TITLEBAR 'xxx'.

  CREATE OBJECT C_CONT
    EXPORTING
      CONTAINER_NAME               = 'CUST_CONT'
      .
  IF SY-SUBRC <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


 IF OBJ_ALV IS INITIAL.
  CREATE OBJECT OBJ_ALV
    EXPORTING
      I_PARENT           = C_CONT
      .

  CALL METHOD OBJ_ALV->SET_TABLE_FOR_FIRST_DISPLAY
     EXPORTING
       I_STRUCTURE_NAME              = INP_TABLE
     CHANGING
      IT_OUTTAB                      = <itab>
          .
 ELSE.
   CALL METHOD OBJ_ALV->REFRESH_TABLE_DISPLAY
           .
  ENDIF.
ENDMODULE.                 " STATUS_9002  OUTPUT 

Edited by: amber22 on Sep 16, 2011 6:45 PM

1 ACCEPTED SOLUTION

Kiran_Valluru
Active Contributor
0 Kudos
303

Hi amber,

when you press back before LEAVE TO SCREEN 9001,

try this,

clear obj_alv.

free: obj_alv.

hope this may help u,

Thanks & Regards,

Kiran

12 REPLIES 12

Kiran_Valluru
Active Contributor
0 Kudos
304

Hi amber,

when you press back before LEAVE TO SCREEN 9001,

try this,

clear obj_alv.

free: obj_alv.

hope this may help u,

Thanks & Regards,

Kiran

0 Kudos
303

I tried that but its not working

0 Kudos
303

Hi amber,

Try to use the destructor methods when leaving your screen:

call method: obj_alv->free, c_cont->free.

clear: obj_alv, c_cont.

call method cl_gui_cfw=>flush.

Also include the container object creation within your IF statement.

Hope it helps...

Kr

0 Kudos
303

@Manu D'Haeyer : I tried the steps you told. Now what happens , the 2nd time no alv is displayed at all (just an empty screen).I have tried debugging and the objects of alv and cont both are getting set to initial just before LEAVE SCREEN and then in PBO again these objects are created . So that part is happening as expected i guess.

Only thing is Those IF statement (IF obj_alv is initial ) now dont have any meaning because on leaving the screen we are setting the objects to initial so in PBO everytime the object will have to created.

Kindly help

0 Kudos
303

Amber,

Something like:


*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
  SET PF-STATUS 'ST9001'.
ENDMODULE.                 " STATUS_9001  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_9001 INPUT.
  CASE sy-ucomm.
    WHEN 'GEN'.
      SELECT * FROM spfli INTO TABLE gt_outtab.
      CALL SCREEN 9002.
    WHEN 'BACK'.
      LEAVE.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9001  INPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_9002  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_9002 OUTPUT.
  SET PF-STATUS 'ST9002'.

  IF obj_alv IS INITIAL.
    CREATE OBJECT c_cont
      EXPORTING
        container_name = 'CUST_CONT'.

    CREATE OBJECT obj_alv
      EXPORTING
        i_parent = c_cont.

    CALL METHOD obj_alv->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SPFLI'
      CHANGING
        it_outtab        = gt_outtab.
  ELSE.
    CALL METHOD obj_alv->refresh_table_display.
  ENDIF.

ENDMODULE.                 " STATUS_9002  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_9002 INPUT.
  CASE sy-ucomm.

    WHEN 'BACK'.
      CALL METHOD: obj_alv->free, c_cont->free.
      CLEAR: obj_alv, c_cont.
      CALL METHOD cl_gui_cfw=>flush.
      LEAVE TO SCREEN 9001.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_9002  INPUT

Altough it's not a really nice solution... Why using 2 screens for example? you could use two containers instead...

Also I would recommand playing with the new salv class for your grids.

Anyway don't hesitate to give feed-back.

Kr,

m.

0 Kudos
303

Actually I also wrote the in the similar way as u told. The only thing is I am generating the ALV using dynamic structure and fields (which the user is entering and selecting in the 1st screen).

In your code , refresh_alv_display method will normally not trigger anytime because everytime before leaving the 2nd screen we are clearing the contents of objects , right??? .This thing i checked in debugger also.

Now why I am using 2 screens is because in my 1st screen already so many components are there like table control buttons text fields spread across so its a bit crowded. Hence I want to display ALV in max possible space therefore i went for 2 screens

Anyway I will try and see if a solution is possible

THANKS for your help.

0 Kudos
303

Actually I quickly wrote that the similar way you did to try to understand where could be the problem. My code above is working... Indeed the refresh method is not usefull because new objects are beeing created each time you generate a new ALV. It can be usefull however if you would handle an editable ALV...

So you still have an issue?

Kr,

Manu

0 Kudos
303

Hey now its working . Actually i was writing clear before free. THANKS A LOT.

Can u just explain me what is the difference between the method free and command clear in this case.

And what is the exact use of the flush statement and in which case we should be using it.

THANKS A LOT ONCE AGAIN

0 Kudos
303

Basically, the FREE method will release the memory used by your object while CLEAR statement simply empty your variable, and so in this case, removes the reference to the object. If you remove the object reference before freeing its memory ressource, then the memory will still be occupied...

The flush command is used to synchronize the automation queue and restrict the network traffic between the frontend & backend.

In fact here, the flush command is quite useless since the automation queue is always synchronized after PBO process.

Some usefull links:

http://sap.ittoolbox.com/documents/the-flush-command-17946

http://help.sap.com/saphelp_nw04/helpdata/en/06/3fa1879f2811d2bd68080009b4534c/content.htm

http://help.sap.com/saphelp_wp/helpdata/en/9b/d080ba9fc111d2bd68080009b4534c/frameset.htm

Kr,

m.

0 Kudos
303

Thank you very much , I almost understood it.

Former Member
0 Kudos
303

@Manu:-

I am also have same issue i make one GUI status , the process of screen as follow

Screen 100 -


> this User Slection screen, Here user start to make input and one Push button 'Display" when user click this Display the Programme Goes to Screen--101

Screen 101------> this is the result screen here ALV grid Display shows the result,

Now user click the Back Button (Standard Tool Bar) , then he see the first screen means screen 100 (Input screen)

Now user changes the value and again click Display for result ,so the problem is User can not see the correct result after pressing back , ALV shows the old result below is my code where i exporting the filed catalog.


 PERFORM get_fieldcatalog.

  CALL METHOD alv_grid->set_table_for_first_display
    EXPORTING
      is_layout        = layout
      is_variant       = variant
      i_save           = 'U'
      i_structure_name = 'I_ALV2'

    CHANGING

      it_outtab        = i_alv2[]
      it_fieldcatalog  = fieldcat[].

Plz give me some suggestion how to solve this issue.

0 Kudos
303

Hi,

Check answer above...

your screen 100 is the screen 9001 in example while your screen 101 is the screen 9002. This is basically the same issue...

When the BACK function is triggered, clear your objects.

Kr,

Manu.