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

ALV object in function module shows old data

Former Member
0 Likes
1,417

Hello,

I create a function module with import parameter matnr.

This function module calls a screen that displays an ALV with the whole info of matnr out of table mara.

I include this in a program where a material can be selected. This is then input for the function module. Everything looks good for the first material. However when the function module is called for a second material I still see the ALV with the data of the previous material.

When I debug the code I see that new data is selected and put on the alv (with method set_table_for_first_display) but still I see the old ALV (which I free by the way in the exit of my function module...). It drives me crazy, what's the problem?

<b>My function module:

</b>


FUNCTION ZJVB_TEST.
*"----------------------------------------------------------------------
*"*"Lokale interface:
*"  IMPORTING
*"     REFERENCE(I_MATNR) TYPE  MATNR
*"----------------------------------------------------------------------

g_matnr = i_matnr.
call SCREEN 1979.
ENDFUNCTION.

<b>TOP include:</b>


FUNCTION-POOL ZJVB_TEST.                    "MESSAGE-ID ..

data: ok_code type sy-ucomm,
      container type ref to cl_gui_custom_container,
      alv type ref to cl_gui_alv_grid,
      g_matnr type matnr.

*&---------------------------------------------------------------------*
*&      Module  STATUS_1979  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_1979 OUTPUT.
  SET PF-STATUS 'FMAIN'.
*  SET TITLEBAR 'xxx'.

  if container is INITIAL.
    CREATE OBJECT CONTAINER
      EXPORTING
        CONTAINER_NAME              = 'CONTAINER'    .


    CREATE OBJECT ALV
      EXPORTING
        I_PARENT          = container.

    data: itab type TABLE OF mara.

    select *
      from mara
      into TABLE itab
      where matnr = g_matnr.

    CALL METHOD ALV->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
         I_STRUCTURE_NAME              = 'MARA'
      CHANGING
        IT_OUTTAB                     = itab.
  endif.

ENDMODULE.                 " STATUS_1979  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1979  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1979 INPUT.

  case ok_code.
    when 'BACK'.
      free container.
      free alv.
      LEAVE to SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_1979  INPUT

<b>My program:</b>


*&---------------------------------------------------------------------*
*& Report  ZJEROEN_ALV_FM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZJEROEN_ALV_FM.

data: ok_code type sy-ucomm,
      l_matnr type matnr.

call SCREEN 1979.
*&---------------------------------------------------------------------*
*&      Module  STATUS_1979  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_1979 OUTPUT.
  SET PF-STATUS 'MAIN'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_1979  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1979  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1979 INPUT.

case ok_code.
  when 'BACK'.
    leave to screen 0.
  when 'CALL'.
      CALL FUNCTION 'ZJVB_TEST'
      EXPORTING
                i_matnr = l_matnr.
endcase.

ENDMODULE.                 " USER_COMMAND_1979  INPUT

Thx for helping,

jeroen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
878

Hi Jeroen,

Try using following methods, you put them at the end of MODULE STATUS_1979 OUTPUT

call method alv_grid->refresh_table_display.

call method cl_gui_cfw=>flush.

Best regards,

Dirk.

5 REPLIES 5
Read only

Former Member
0 Likes
879

Hi Jeroen,

Try using following methods, you put them at the end of MODULE STATUS_1979 OUTPUT

call method alv_grid->refresh_table_display.

call method cl_gui_cfw=>flush.

Best regards,

Dirk.

Read only

Former Member
0 Likes
878

Hi

<b>Refresh</b> your internal table <b>itab</b> before populating it with data from MARA table.

Regards,

Raj

Read only

Former Member
878

Hello,

I found out that the container lifetime was the problem... When you create a container to put the ALV in the lifetime is set to default. Normally you never change this, I didn't mention it before I had the problem. But you have to change the lifetime to <your_instance_name>->lifetime_dynpro for instance my_container->lifetime_dynpro.

Also check this helplink: http://help.sap.com/saphelp_nw04/helpdata/en/9b/d080b79fc111d2bd68080009b4534c/frameset.htm

Read only

0 Likes
878

I had the same problem and solved it with this. Thank you.

CREATE OBJECT g_container2 EXPORTING

      container_name = container2

      lifetime = cl_gui_container=>lifetime_dynpro.

Read only

0 Likes
878

I think when you call the function second time, the program would not go into "if container is INITIAL." condition in the PBO of screen 1979.

You can try to set a breakpoint to check this.

I think you can put the select statement before "call screen".