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 grid display

Former Member
0 Kudos

Hello all,

Date is the main selection criteria in my selection screen

Once the user gets the ALV grid display output screen, he should be able to forward or backward the date

so accordingly the display changes

So req is, i should create two pushbuttons in that ALV grid display output screen where user can forward or backward the date directly, no need to go back to the selection screen once again

How can i handle this......

sample code plz..

11 REPLIES 11

Former Member
0 Kudos

Instead of creating push buttons , u can make the date fields as editable fields and create F4 help for the date fields so that you can select the dates

0 Kudos

ON the top of output display screen, user want that pushbutton so he dont want to go back to selection screen.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hi Johnn, you can accomplish this by using the CL_GUI_ALV_GRID class and embeding the ALV Grid in a screen container. Then add your buttons to the application toolbar by creating your gui status, then when the user clicks one of the buttons, get the new data and "Refresh" the ALV grid using the REFRESH method.

Regards,

Rich Heilman

0 Kudos

hello Rich,

can u please give me some sample code ........

0 Kudos

Hi Johnn, here is a sample program. Which should give you some idea. THere is a parameter on the selection screen which is for the number of rows to display. Default should be 10. You will need to create a screen 100, and put the custom container on this screen and name it as "ALV_CONTAINER". Also put two push buttons for "Reverse" and "Forward" make sure to assign the corresponding FCODEs for these buttons. Run the program, now enter 10 for the parameter and execute, an ALV grid will be display with 10 rows, click the "Forward" button and you will see that it just added 10 more rows and refreshed the ALV, now click the Reverse button, it now took away those 10 rows. This program should help you in your requirement.



report zrich_0001.

tables: mara.

data: begin of i_alv occurs 0,
      rows type i,
      valu type i,
      end of i_alv.

data: alv_container  type ref to cl_gui_custom_container.
data: alv_grid       type ref to cl_gui_alv_grid.
data: layout    type lvc_s_layo.
data: fieldcat  type lvc_t_fcat.
data: ok_code type sy-ucomm.
data: save_ok type sy-ucomm.

selection-screen begin of block b1 with frame title text-001 .
parameters: p_rows type i.
selection-screen end of block b1.

start-of-selection.

  perform set_data.
  call screen 100.

************************************************************************
*      Module  status_0100  OUTPUT
************************************************************************
module status_0100 output.
  set pf-status '0100'.
  set titlebar '0100'.

check alv_container is initial.

* Create Controls
  create object alv_container
         exporting
               container_name    = 'ALV_CONTAINER'.

  create object alv_grid
         exporting
               i_parent          =  alv_container.

*  ALV Specific. Data selection.
*  Populate Field Catalog
  perform get_fieldcatalog.

  call method alv_grid->set_table_for_first_display
      exporting
           is_layout              = layout
      changing
           it_outtab       = i_alv[]
           it_fieldcatalog = fieldcat[].

endmodule.

************************************************************************
*      Module  USER_COMMAND_0100  INPUT
************************************************************************
module user_command_0100 input.

  save_ok = ok_code.

  case ok_code.
    when 'BACK' or 'CANC'.
      clear ok_code.
      if not alv_container is initial.
        call method alv_container->free.
        clear: alv_container.
        free : alv_container.
      endif.
      if sy-subrc = 0.
        set screen 0.
        leave screen.
      else.
        leave program.
      endif.
    when 'EXIT'.
      clear ok_code.
      if not alv_container is initial.
        call method alv_container->free.
        clear: alv_container.
        free : alv_container.
      endif.
      leave program.
<b>    when 'REVE'.
      clear ok_code.
      p_rows = p_rows - 10.
      perform set_data.
      call method alv_grid->refresh_table_display.

    when 'FORW'.
      clear ok_code.
      p_rows = p_rows + 10.
      perform set_data.
      call method alv_grid->refresh_table_display.</b>

  endcase.

endmodule.

************************************************************************
* FORM GET_DATA
************************************************************************
form set_data.

  clear i_alv.  refresh i_alv.

  if p_rows < 10.
    p_rows = 10.
  endif.

  do p_rows times.
    i_alv-rows = sy-index.
    i_alv-valu = sy-index * 100.
    append i_alv.
  enddo.

endform.

************************************************************************
*      Form  Get_Fieldcatalog - Set Up Columns/Headers
************************************************************************
form get_fieldcatalog.

  data: ls_fcat type lvc_s_fcat.
  refresh fieldcat.

  clear ls_fcat.
  ls_fcat-reptext    = 'Row Number'.
  ls_fcat-coltext    = 'Row Number'.
  ls_fcat-fieldname  = 'ROWS'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '5'.
  append ls_fcat to fieldcat.

  clear ls_fcat.
  ls_fcat-reptext    = 'Value'.
  ls_fcat-coltext    = 'Value'.
  ls_fcat-fieldname  = 'VALU'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '5'.
  append ls_fcat to fieldcat.


endform.

Regards,

Rich Heilman

0 Kudos

Hello Rich,

This sample code is really helpful, i need to execute & check.

What should be created in the screen 100 apart from the

Pushbutton.

Please reply me

0 Kudos

Hello all,

i can create the pushbutton in the application toolbar.

i can forward & reverse the date.

but how i can change the display according to the date.

plz help me.

0 Kudos

Hi Johnn, you will need to get your data again from the db and put into your internal table that is tied to the ALV grid. You need to get the data based on the new date.

Please be sure to award points for helpful answers and mark your post as solved when solved completely. Thanks and welcome to SDN!

Regards,

Rich Heilman

0 Kudos

can i use the submit syntax like this to get the new data

  • SUBMIT /RB04/yl4_ns_LODWH_CRESS

  • WITH STRUKT = MEM_STRUKT

  • WITH DBNAME = DB_NAME

  • WITH ANZ_REC = ANZ_REC

  • WITH TAB_NEU = TAB_NEU

  • WITH DATNAME = P_DATNA1

because the internal table i am passing to alv grid has no date field

0 Kudos

?

You are filling this internal table with data at some point in your program. I assume that you are filling it based on some date. When you click on the "forward" button you now want to fill the internal table with data for the new date calculated when you push the button right? So do the same select statement which filled the ALV grid internal table eariler, only with this new date.

Or am I missing something.

Regards,

Rich Heilman

Former Member
0 Kudos

HI,

You need to REFRESH In the ALV,

In ALV, to refresh the table you have to call the method "refresh_table_display".

It has the syntax very similar to creating the table.

It has two parameters. In the first one, you can mention if you want to refresh only the data (the icons are not refreshed)

or

if you want to refresh only the icons around the grid (the data is not refreshed - this option is mostly not used in day to day applications).

the synatx is :-

call method grid (name of grid )->refresh_table_display

exporting

IS_STABLE = <STRUCT OF TYPE LVC_S_STBL> (THIS IS FOR DATA REFRESHING)

I_SOFT_REFRESH = <VARIABLE OF CHAR 01> (THIS IS FOR ICON REFRESHING).

See the below link for Autorefresh Example program:

http://www.sap-basis-abap.com/abap/auto-refresh-alv-list.htm

similarly you can write the program,

Look at the Thread also:

Regards

Sudheer