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

Dynamic variable in class / problem with refreshing ALV

kroslaniec
Explorer
0 Likes
2,536

Hi,

In my class I have 3 methods which I am using:

  • Prepare data method where we are selecting dynamically 1 name of the table from selection screen into string. I have global attribute TABLE_REF which is Type Ref DATA. Next steps are the only way I could think of how to get a reference to the global variable:
      CREATE DATA TABLE_REF TYPE TABLE OF   (GS_PARAMS-GV_SELECTED_TAB).
      CREATE DATA GS_PARAMS-LS_TABLE TYPE TABLE OF   (GS_PARAMS-GV_SELECTED_TAB).
      FIELD-SYMBOLS <FS_TABLE>             TYPE STANDARD TABLE.
      ASSIGN        GS_PARAMS-LS_TABLE->*   TO              <FS_TABLE>.
      ASSIGN TABLE_REF->* TO <FS_TABLE>.

Then I am selecting the data into <fs_table>, and I can refer to them in other methods by using TABLE_REF global attribute.

  • Create ALV method, it's a standard instance of cl_salv table, it's initialized by this code (go_alv is also a class attribute):
FIELD-SYMBOLS: <FS_TABLE> TYPE STANDARD TABLE.
      ASSIGN TABLE_REF->* TO <FS_TABLE>.

      TRY.
          CALL METHOD CL_SALV_TABLE=>FACTORY
            IMPORTING
              R_SALV_TABLE = GO_ALV
            CHANGING
              T_TABLE      = <FS_TABLE>.
        CATCH CX_SALV_MSG.
      ENDTRY.
  • On user command, where we have custom buttons to enter JSON (last column) of choosen row and then we can make some changes.

My problem is that whatever I am trying to do, I cannot refresh my ALV (it's r_table parameter is the same after many attempts of refreshing). I thought that I could create a new instance of go_alv and it's working, but when I am clicking the back button the old version is displayed (with old data). Any ideas what we could do there different?

8 REPLIES 8
Read only

Sandra_Rossi
Active Contributor
2,312

In your code, this line is useless and can be removed safely:

ASSIGN        GS_PARAMS-LS_TABLE->*   TO              <FS_TABLE>.

You can refresh the screen with:

GO_ALV->REFRESH( ).
Read only

kroslaniec
Explorer
0 Likes
2,312

sandra.rossi I deleted two additional lines, and the beginning of my code looks like this now:

CREATE DATA TABLE_REF TYPE TABLE OF   (GS_PARAMS-GV_SELECTED_TAB).
      FIELD-SYMBOLS <FS_TABLE>             TYPE STANDARD TABLE.
      ASSIGN TABLE_REF->* TO <FS_TABLE>.

Second thing - I will show some more code from display ALV method to clarify what's wrong:

      FIELD-SYMBOLS: <FS_TABLE> TYPE STANDARD TABLE.
      ASSIGN TABLE_REF->* TO <FS_TABLE>.

      if 1 = 2.
        go_alv->REFRESH( ).
      endif.

      TRY.
          CALL METHOD CL_SALV_TABLE=>FACTORY
            IMPORTING
              R_SALV_TABLE = GO_ALV
            CHANGING
              T_TABLE      = <fs_table>.
        CATCH CX_SALV_MSG.
      ENDTRY.

Then I am trying to call those lines after the user_command:

    GO_ALV->REFRESH( REFRESH_MODE = IF_SALV_C_REFRESH=>FULL ).
    CL_GUI_CFW=>FLUSH( ).
    GO_ALV->REFRESH( ).

Return is the same - old ALV is displayed. Like I said, TABLE_REF and GO_ALV are global attributes for my class, before calling refresh function I am checking the TABLE_REF and it's updated with the new information.

Problem may be solved with different parameter passed into T_TABLE, but I have no idea how to do that.

Read only

FredericGirod
Active Contributor
2,312

I am little bit lost. Your <fs_table> is not global, you declare it just before the factory.

Did you try to declare it in the public section ?

Read only

kroslaniec
Explorer
0 Likes
2,312

<fs_table> is declared locally in both methods - I couldnt figure out how to declare field symbol globally in a class.

Read only

Sandra_Rossi
Active Contributor
2,312

No need to flush after REFRESH, it's doing the flush itself.

Read only

Sandra_Rossi
Active Contributor
2,312

Are you recreating the internal table? SALV keeps reference of the original table only.

Read only

kroslaniec
Explorer
0 Likes
2,312

I am calling prepare data method after the handle user command method, so in my global attribute TABLE_REF is updated with the new data. The problem is that I don't know how to pass it back to the GO_ALV without creating a new instance

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,312

Execute CREATE DATA TABLE_REF ... and ASSIGN TABLE_REF->* TO <FS_TABLE> the first time, and the next times only execute ASSIGN TABLE_REF->* TO <FS_TABLE>.