Skip to Content
avatar image
Former Member

How to add next button in to ALV program?

Hiii i am beginner in SAP. And i have created ALV program for displaying the details of but000 table with 10 rows. now its working but i want to add a [next] button when i clicked it then next 10 records should be display over the screen as output?

i have used this Program code:-

TYPE-POOLS: slis. " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_but000 TYPE TABLE OF but000.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
SELECT * FROM BUT000 INTO TABLE it_but000 up to 10 rows.

*Build field catalog
wa_fieldcat-fieldname = 'TYPE'. " Fieldname in the data table
wa_fieldcat-seltext_m = 'BU_TYPE'. " Column description in the output
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'PARTNER'.
wa_fieldcat-seltext_m = 'BU_PARTNER.'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'BU_GROUP'.
wa_fieldcat-seltext_m = 'BU_GROUP'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'NAME_FIRST'.
wa_fieldcat-seltext_m = 'BU_NAMEP_F'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'NAME_LAST'.
wa_fieldcat-seltext_m = 'BU_NAMEP_L'.
APPEND wa_fieldcat TO it_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_but000
EXCEPTIONS
program_error = 1

OTHERS = 2.

And i have followed this link also for next button. But didn't get

https://blogs.sap.com/2014/06/26/how-to-activate-next-page-last-page-buttons-in-alv-reports/

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Apr 18 at 11:08 AM

    HI.

    There is simple examplet how to add your own GUI status to your ALV and handle user commands.

      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid "name of the current program
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND'
          it_fieldcat              = it_fieldcat
        TABLES
          t_outtab                 = it_but000
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
    * Implement suitable error handling here
      ENDIF.
    
    FORM set_pf_status
      USING ut_extab TYPE slis_t_extab.
      SET PF-STATUS 'XYZ' "XYZ - name of GUI Status(create/copy GUI status to your program!)
        EXCLUDING ut_extab.
    ENDFORM.
    
    FORM user_command
      USING uv_ucomm    LIKE sy-ucomm
            us_selfield TYPE slis_selfield.
      CASE uv_ucomm.
        WHEN '&NEXT'. "function code
          TODO. "write code for select next 10 records into it_but000
          us_selfield-refresh = abap_true.
      ENDCASE.
    ENDFORM.

    JG

    Add comment
    10|10000 characters needed characters exceeded