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

adding a button to standard bar

Former Member
0 Likes
461

hi,

it is like i want to add sort filter sum button in my report after the output displayed.

can anybody plz help me its a bit urgent.

thanks

Anupama

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
442

Hi ,

Below code is a program for sorting using a button on toolbar.

TABLES :
       spfli.

************************************************************************
** Declaring Selection Screens                                         *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK b1.
                  

SELECT-OPTIONS s_range  FOR spfli-carrid NO-EXTENSION.
SELECT-OPTIONS s_range1 FOR spfli-connid NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK b1.


***********************************************************************
*   Structure Declaration to Hold the FLIGHT  Data                    *
***********************************************************************

DATA:

     BEGIN OF fs_spfli,
       carrid    LIKE spfli-carrid,
       connid    LIKE spfli-connid,
       cityfrom  LIKE spfli-cityfrom,
       cityto    LIKE spfli-cityto,
       airpfrom  LIKE spfli-airpfrom,
       airpto    LIKE spfli-airpto,
       countryfr LIKE spfli-countryfr,
       countryto LIKE spfli-countryto,
      END OF fs_spfli.

***********************************************************************
*   Internal Table And Work Area Declarations  For SPFLI TABLE         *
***********************************************************************

DATA :
  t_spfli LIKE
 STANDARD TABLE
       OF fs_spfli.



***********************************************************************
*                  START-OF-SELECTION                                 *
***********************************************************************
START-OF-SELECTION.


  PERFORM get_spfli_data.
  PERFORM display_data.

***********************************************************************
*                  AT USER-COMMANDE                                   *
***********************************************************************
AT USER-COMMAND.

Perform user_command.


*&---------------------------------------------------------------------*
*&      Form  get_spfli_data
*&---------------------------------------------------------------------*
*       Getting t_spfli Data from SPFLI Table
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*
FORM get_spfli_data .

  SELECT
        carrid
        connid
        cityfrom
        cityto
        airpfrom
        airpto
        countryfr
        countryto
   INTO TABLE  t_spfli
   FROM spfli
  WHERE carrid IN s_range
    AND connid IN s_range1.

  IF sy-subrc NE 0.
    MESSAGE 'Entries Not Found' TYPE 'E'.
  ENDIF.

ENDFORM.                    " get_spfli_data

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       Subroutine to  display SPFLI Contents                          *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*


FORM display_data .

  LOOP AT t_spfli INTO fs_spfli.

    SET PF-STATUS 'PUSHBUTTON'.

    WRITE : / fs_spfli-carrid,
            8 fs_spfli-connid,
            15 fs_spfli-cityfrom,
            30 fs_spfli-cityto,
            45 fs_spfli-airpfrom,
            56 fs_spfli-airpto,
            65 fs_spfli-countryfr,
            75 fs_spfli-countryto.
  ENDLOOP.
ENDFORM.                    " display_data


*&--------------------------------------------------------------------*
*&      Form  sortspflidata                                           *
*&--------------------------------------------------------------------*
*       subroutine to Sort list on Cursor position.                   *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*


FORM sortspflidata .

  DATA : lw_cursor(20) TYPE c ,
         lw_cursor1(20) TYPE c .


  GET CURSOR FIELD lw_cursor.

  IF sy-subrc NE 0.
    MESSAGE 'Error' TYPE 'E'.
  ELSE.

    MOVE lw_cursor+9 TO lw_cursor.
    SORT t_spfli BY (lw_cursor).

    LOOP AT t_spfli INTO fs_spfli.
      WRITE : / fs_spfli-carrid,
                8 fs_spfli-connid,
                15 fs_spfli-cityfrom,
                30 fs_spfli-cityto,
                45 fs_spfli-airpfrom,
                56 fs_spfli-airpto,
                65 fs_spfli-countryfr,
                75 fs_spfli-countryto.

    ENDLOOP.
  ENDIF.
ENDFORM.                    " sortspflidata

*&---------------------------------------------------------------------*
*&      Form  SORT_data_by_window
*&---------------------------------------------------------------------*
*  Subroutine to Sort by selecting a Field from window                 *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM sort_data_by_window .

  SET PF-STATUS 'WIN'.

  WINDOW STARTING AT 1  15
         ENDING   AT 79 23.
  DATA:
    box TYPE c,
    box1 TYPE c,
    box2 TYPE c,
    box3 TYPE c,
    box4 TYPE c,
    box5 TYPE c,
    box6 TYPE c,
    box7 TYPE c.

  WRITE:  box AS CHECKBOX .
  WRITE: 'carrid',
        / box1 AS CHECKBOX .
  WRITE: 'connid',
        / box2 AS CHECKBOX .
  WRITE: 'cityfrom',
        / box3 AS CHECKBOX.
  WRITE: 'cityto',
        / box4 AS CHECKBOX.
  WRITE: 'airpfrom',
        / box5 AS CHECKBOX.
  WRITE: 'airpto',
         / box6 AS CHECKBOX.
  WRITE: 'countryfr',
        / box7 AS CHECKBOX.
  WRITE: 'countryto'.
ENDFORM.                    " SORT_data_by_window

*&---------------------------------------------------------------------*
*&      Form  ascending
*&---------------------------------------------------------------------*
*   Subroutine for sorting data in window IN ASCENDING
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM ascending .

  DATA:

       w_lisel TYPE sy-lisel,
       w_word(15) TYPE c.

  DO 9 TIMES.
    READ LINE sy-index FIELD VALUE sy-lisel INTO w_lisel.
    IF w_lisel+0(1) = 'X'.
      w_word = sy-lisel+1(15).
      SORT t_spfli ASCENDING BY (w_word).
      PERFORM display.
    ENDIF.
  ENDDO.
ENDFORM.                    " enddo

*&---------------------------------------------------------------------*
*&      Form  DESCENDING
*&---------------------------------------------------------------------*
* subroutine for sorting data by selected column in decending.         *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM descending .
  DATA:

        lw_lisel TYPE sy-lisel,
        lw_word(15) TYPE c.

  DO 9 TIMES.
    READ LINE sy-index FIELD VALUE sy-lisel INTO lw_lisel.

    IF lw_lisel+0(1) = 'X'.
      lw_word = sy-lisel+1(15).
      SORT t_spfli DESCENDING BY (lw_word).
      PERFORM display.
    ENDIF.
  ENDDO.
ENDFORM.                    " DESCENDING
*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
*   subroutine for sorting data by selected column
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM display .


  LOOP AT t_spfli INTO fs_spfli.
    WRITE : / fs_spfli-carrid,
              8 fs_spfli-connid,
              15 fs_spfli-cityfrom,
              30 fs_spfli-cityto,
              45 fs_spfli-airpfrom,
              56 fs_spfli-airpto,
              72 fs_spfli-countryfr,
              79 fs_spfli-countryto.

  ENDLOOP.
ENDFORM.                    " display
*&---------------------------------------------------------------------*
*&      Form  user_command                                             *
*&---------------------------------------------------------------------*
*      Subroutine  to perform User Command                             *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*
form user_command .
  CASE sy-ucomm.

      WHEN'SORT'.
      PERFORM sortspflidata.
    WHEN 'SORTWIN'.
      PERFORM sort_data_by_window.
    WHEN 'ASCENDING'.
      PERFORM ascending.
    WHEN 'DESCENDING'.
      PERFORM descending.
    WHEN 'CANCEL'.
      LEAVE screen.
  ENDCASE.
endform.                    " user_command

You have to set PF status which I have mentioned in report and activate it.

ie. Pf status : 'PUSHBUTTON' & 'WIN'.

for PF status ' Pushbutton' , take two buttons on application toolbar,

one for 'sort data' & 'Sort Data By'.

Sort data by will open new window.

for that window also set pf status ie , 'WIN '.

in that take three butttons ...for sorting list.. assending or decending and one for exit.

Thanks & regards,

reward points if helpful,

Brijesh

Edited by: Briesh Patel on Apr 15, 2008 10:12 PM

3 REPLIES 3
Read only

Former Member
0 Likes
443

Hi ,

Below code is a program for sorting using a button on toolbar.

TABLES :
       spfli.

************************************************************************
** Declaring Selection Screens                                         *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK b1.
                  

SELECT-OPTIONS s_range  FOR spfli-carrid NO-EXTENSION.
SELECT-OPTIONS s_range1 FOR spfli-connid NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK b1.


***********************************************************************
*   Structure Declaration to Hold the FLIGHT  Data                    *
***********************************************************************

DATA:

     BEGIN OF fs_spfli,
       carrid    LIKE spfli-carrid,
       connid    LIKE spfli-connid,
       cityfrom  LIKE spfli-cityfrom,
       cityto    LIKE spfli-cityto,
       airpfrom  LIKE spfli-airpfrom,
       airpto    LIKE spfli-airpto,
       countryfr LIKE spfli-countryfr,
       countryto LIKE spfli-countryto,
      END OF fs_spfli.

***********************************************************************
*   Internal Table And Work Area Declarations  For SPFLI TABLE         *
***********************************************************************

DATA :
  t_spfli LIKE
 STANDARD TABLE
       OF fs_spfli.



***********************************************************************
*                  START-OF-SELECTION                                 *
***********************************************************************
START-OF-SELECTION.


  PERFORM get_spfli_data.
  PERFORM display_data.

***********************************************************************
*                  AT USER-COMMANDE                                   *
***********************************************************************
AT USER-COMMAND.

Perform user_command.


*&---------------------------------------------------------------------*
*&      Form  get_spfli_data
*&---------------------------------------------------------------------*
*       Getting t_spfli Data from SPFLI Table
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*
FORM get_spfli_data .

  SELECT
        carrid
        connid
        cityfrom
        cityto
        airpfrom
        airpto
        countryfr
        countryto
   INTO TABLE  t_spfli
   FROM spfli
  WHERE carrid IN s_range
    AND connid IN s_range1.

  IF sy-subrc NE 0.
    MESSAGE 'Entries Not Found' TYPE 'E'.
  ENDIF.

ENDFORM.                    " get_spfli_data

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       Subroutine to  display SPFLI Contents                          *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*


FORM display_data .

  LOOP AT t_spfli INTO fs_spfli.

    SET PF-STATUS 'PUSHBUTTON'.

    WRITE : / fs_spfli-carrid,
            8 fs_spfli-connid,
            15 fs_spfli-cityfrom,
            30 fs_spfli-cityto,
            45 fs_spfli-airpfrom,
            56 fs_spfli-airpto,
            65 fs_spfli-countryfr,
            75 fs_spfli-countryto.
  ENDLOOP.
ENDFORM.                    " display_data


*&--------------------------------------------------------------------*
*&      Form  sortspflidata                                           *
*&--------------------------------------------------------------------*
*       subroutine to Sort list on Cursor position.                   *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed                      *
*---------------------------------------------------------------------*


FORM sortspflidata .

  DATA : lw_cursor(20) TYPE c ,
         lw_cursor1(20) TYPE c .


  GET CURSOR FIELD lw_cursor.

  IF sy-subrc NE 0.
    MESSAGE 'Error' TYPE 'E'.
  ELSE.

    MOVE lw_cursor+9 TO lw_cursor.
    SORT t_spfli BY (lw_cursor).

    LOOP AT t_spfli INTO fs_spfli.
      WRITE : / fs_spfli-carrid,
                8 fs_spfli-connid,
                15 fs_spfli-cityfrom,
                30 fs_spfli-cityto,
                45 fs_spfli-airpfrom,
                56 fs_spfli-airpto,
                65 fs_spfli-countryfr,
                75 fs_spfli-countryto.

    ENDLOOP.
  ENDIF.
ENDFORM.                    " sortspflidata

*&---------------------------------------------------------------------*
*&      Form  SORT_data_by_window
*&---------------------------------------------------------------------*
*  Subroutine to Sort by selecting a Field from window                 *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM sort_data_by_window .

  SET PF-STATUS 'WIN'.

  WINDOW STARTING AT 1  15
         ENDING   AT 79 23.
  DATA:
    box TYPE c,
    box1 TYPE c,
    box2 TYPE c,
    box3 TYPE c,
    box4 TYPE c,
    box5 TYPE c,
    box6 TYPE c,
    box7 TYPE c.

  WRITE:  box AS CHECKBOX .
  WRITE: 'carrid',
        / box1 AS CHECKBOX .
  WRITE: 'connid',
        / box2 AS CHECKBOX .
  WRITE: 'cityfrom',
        / box3 AS CHECKBOX.
  WRITE: 'cityto',
        / box4 AS CHECKBOX.
  WRITE: 'airpfrom',
        / box5 AS CHECKBOX.
  WRITE: 'airpto',
         / box6 AS CHECKBOX.
  WRITE: 'countryfr',
        / box7 AS CHECKBOX.
  WRITE: 'countryto'.
ENDFORM.                    " SORT_data_by_window

*&---------------------------------------------------------------------*
*&      Form  ascending
*&---------------------------------------------------------------------*
*   Subroutine for sorting data in window IN ASCENDING
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM ascending .

  DATA:

       w_lisel TYPE sy-lisel,
       w_word(15) TYPE c.

  DO 9 TIMES.
    READ LINE sy-index FIELD VALUE sy-lisel INTO w_lisel.
    IF w_lisel+0(1) = 'X'.
      w_word = sy-lisel+1(15).
      SORT t_spfli ASCENDING BY (w_word).
      PERFORM display.
    ENDIF.
  ENDDO.
ENDFORM.                    " enddo

*&---------------------------------------------------------------------*
*&      Form  DESCENDING
*&---------------------------------------------------------------------*
* subroutine for sorting data by selected column in decending.         *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM descending .
  DATA:

        lw_lisel TYPE sy-lisel,
        lw_word(15) TYPE c.

  DO 9 TIMES.
    READ LINE sy-index FIELD VALUE sy-lisel INTO lw_lisel.

    IF lw_lisel+0(1) = 'X'.
      lw_word = sy-lisel+1(15).
      SORT t_spfli DESCENDING BY (lw_word).
      PERFORM display.
    ENDIF.
  ENDDO.
ENDFORM.                    " DESCENDING
*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
*   subroutine for sorting data by selected column
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*

FORM display .


  LOOP AT t_spfli INTO fs_spfli.
    WRITE : / fs_spfli-carrid,
              8 fs_spfli-connid,
              15 fs_spfli-cityfrom,
              30 fs_spfli-cityto,
              45 fs_spfli-airpfrom,
              56 fs_spfli-airpto,
              72 fs_spfli-countryfr,
              79 fs_spfli-countryto.

  ENDLOOP.
ENDFORM.                    " display
*&---------------------------------------------------------------------*
*&      Form  user_command                                             *
*&---------------------------------------------------------------------*
*      Subroutine  to perform User Command                             *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed                       *
*----------------------------------------------------------------------*
form user_command .
  CASE sy-ucomm.

      WHEN'SORT'.
      PERFORM sortspflidata.
    WHEN 'SORTWIN'.
      PERFORM sort_data_by_window.
    WHEN 'ASCENDING'.
      PERFORM ascending.
    WHEN 'DESCENDING'.
      PERFORM descending.
    WHEN 'CANCEL'.
      LEAVE screen.
  ENDCASE.
endform.                    " user_command

You have to set PF status which I have mentioned in report and activate it.

ie. Pf status : 'PUSHBUTTON' & 'WIN'.

for PF status ' Pushbutton' , take two buttons on application toolbar,

one for 'sort data' & 'Sort Data By'.

Sort data by will open new window.

for that window also set pf status ie , 'WIN '.

in that take three butttons ...for sorting list.. assending or decending and one for exit.

Thanks & regards,

reward points if helpful,

Brijesh

Edited by: Briesh Patel on Apr 15, 2008 10:12 PM

Read only

former_member5472
Active Contributor
0 Likes
442

Hi,

if you want to use oops concept then the coding will be simple and not so lengthy.

if you want i can send you the sample codes

pratyush

Read only

Former Member
0 Likes
442

HI,

Write this code in event initializaation.

----


INITIALIZATION.

----


  • Get the Display filter button on the screen.

sscrfields-functxt_01 = 'FILTER'.

when you press this button.

the above sy-ucomm wil trigger

then you can write the code

as you want filter the entries....

Suman