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

How do use SAP Select All functionality in checkbox

Former Member
0 Likes
2,892

Hi,

I have a screen which I show the user with each row having a checkbox on the left side of the screen. The user can click on 1 or more checkbox and select close order button on top of screen. If they wanted to do Select all to mark all checkbox, how would I do such a thing?

Thanks

Ram

8 REPLIES 8
Read only

Former Member
0 Likes
1,714

Report or module pool?

Rob

Read only

Former Member
0 Likes
1,714

HI,

Create a new button called Select all or you can use the standard button available in the tool bar.

When ever it is clicked, Loop the table and modify each record with table-check = 'X'.

and you have to call the method

DATA ls_ref1 TYPE REF TO cl_gui_alv_grid .

CALL METHOD ls_ref1->refresh_table_display .

after this you will be able to see all the check boxes as marked.

Regards,

Venkatesh

Read only

Former Member
0 Likes
1,714

Venkatesh,

How do I activate the standard Select All functionality button? If I use that button, would it automatically set the checkbox to 'X' and I just have to call the refresh table display?

thanks

Ram

Read only

0 Likes
1,714

You want the similar output of the program

BCALV_EDIT_05

Read only

Former Member
0 Likes
1,714

Vijay,

Thanks for the lead. But in my environment, we do not have a BCALV_EDIT_05. We have a 01 through 04 but do not have a 05. Do you mind posting the piece of code found there?

Thanks

Ram

Read only

0 Likes
1,714

It is long program. Which version are you in..any way here is the code. This is the standard code.

custm controll name BCALV_GRID_DEMO_0100_CONT1 on screen 100.

program bcalv_edit_05.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This example shows how to use checkboxes within an ALV Grid Control.
* You learn:
*  o how to define a column for editable checkboxes for an attribute
*    of your list (see also remark below)
*  o how to evaluate the checked checkboxes
*  o how to switch between editable and non-editable checkboxes
*
* Important Remark
* ~~~~~~~~~~~~~~~~
* The checkbox functionality has been replaced by selection buttons
* in front of each row (field SEL_MODE of the layout structure
* set to 'A' or 'D'; when using the editable ALV Grid Control,
* these selection buttons are always visible).
* Class methods like GET_SELECTED_ROWS work only for this new
* functionality and not for checkboxes.
* Thus checkboxes should not be used for line selection but for
* a column as an additional or for an already existing attribute
* (like field SMOKER in SBOOK).
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Try out the functions displayed in the application toolbar:
* o The first sets all checked lines to initial values.
*   (see form reset_selected_entries)
* o The seconds marks all checkboxes that are input enabled
* o The third unmarks all checkboxes that are input enabled
* o To try the forth, you have to select a line first using
*   the selection buttons on the left.
*   The function deactivates/activates a checkbox.
*
* Checkboxes may be locked/unlocked using a double click on the
* checkbox cell.
*
*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* This example focusses on two aspects of checkboxes in an
* editable ALV Grid Control:
* A How to integrate, set, reset and evaluate checkboxes
* B What you must do to lock particular checkboxes against input
*
* A) Integrate, set, reset and evaluate checkboxes
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* A1.Extend your output table by a checkbox field.
* A2.Add an entry for the checkbox in the fieldcatalog
* A3.Optionally, check checkboxes initially after selecting data.
* A4.Before you (a)set, (b)reset, (c)(de)activate or
*    (d)evaluate checkboxes, you must check the input cells.
*
* B) Lock particular checkboxes against input
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* B1.Extend your output table by a field to dis- or enable
*     cells for input.
* B2.After selecting data,
*     assign a style for each row of your checkbox column.
* B3.Use the layout structure to aquaint additional field to ALV.
* B4.Switch the style to dis- or enable a cell for input
*-----------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
class lcl_event_receiver definition deferred.  "for event handling

data: ok_code like sy-ucomm,
      save_ok like sy-ucomm,
      g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
      g_grid  type ref to cl_gui_alv_grid,
      g_custom_container type ref to cl_gui_custom_container,
      g_event_receiver type ref to lcl_event_receiver,
      gt_fieldcat type lvc_t_fcat,
      gs_layout type lvc_s_layo,
      g_max type i value 100.

*
*§A1.Extend your output table by a checkbox field.
*     If you do not want to lock sole checkboxes against input
*     you do not need field 'celltab'.

types: begin of gs_outtab.
types: checkbox type c.                "field for checkbox
* §B1.Extend your output table by a field to dis- or enable
*     cells for input.
types: celltab type lvc_t_styl.        "field to switch editability
        include structure sflight.
types: end of gs_outtab.

data: gt_outtab type gs_outtab occurs 0 with header line.

***********************************************************************
* LOCAL CLASSES
***********************************************************************
*
* This local class only handles event DOUBLE_CLICK.
* Wenn the user double clicks on a checkbox cell the status of
* this cell is switched from editable to not editable and vice versa.
*
class lcl_event_receiver definition.

public section.
methods: catch_doubleclick
         for event double_click of cl_gui_alv_grid
         importing
            e_column
            es_row_no
            sender.
endclass.

*-----

class lcl_event_receiver implementation.

method catch_doubleclick.
  data: ls_outtab type gs_outtab,
        ls_celltab type lvc_s_styl.
*--
* Function:
*  Switch between 'editable' and 'not editable' checkbox.
*--

* If the user clicked on another column there is
* nothing to do.
  if e_column-fieldname ne 'CHECKBOX'.
    exit.
  endif.

  read table gt_outtab into ls_outtab index es_row_no-row_id.

* The loop is only needed if there are other columns that
* use checkboxes. At this point the loop could be
* replaced by a READ of the first line of CELLTAB.
      loop at ls_outtab-celltab into ls_celltab.
        if ls_celltab-fieldname eq 'CHECKBOX'.
* §B4.Switch the style to dis- or enable a cell for input
         if ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
          ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
         else.
          ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
         endif.
         modify ls_outtab-celltab from ls_celltab.
        endif.
      endloop.
      modify gt_outtab from ls_outtab index es_row_no-row_id.

    call method sender->refresh_table_display.
endmethod.
endclass.
*
********************************************************************

*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
end-of-selection.
  call screen 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
module pbo output.
  set pf-status 'MAIN100'.
  set titlebar 'MAIN100'.
  if g_custom_container is initial.
    perform create_and_init_alv.
  endif.

endmodule.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
module pai input.
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    when 'EXIT'.
      perform exit_program.
    when 'SELECT'.
      perform select_all_entries changing gt_outtab[].
    when 'DESELECT'.
      perform deselect_all_entries changing gt_outtab[].
    when 'RESET'.
      perform reset_selected_entries changing gt_outtab[].
    when 'SWITCH'.
      perform switch_activation changing gt_outtab[].
  endcase.
endmodule.
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
form exit_program.
  leave program.
endform.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
form build_fieldcat changing pt_fieldcat type lvc_t_fcat.

  data ls_fcat type lvc_s_fcat.

  call function 'LVC_FIELDCATALOG_MERGE'
       exporting
            i_structure_name = 'SFLIGHT'
       changing
            ct_fieldcat      = pt_fieldcat.

*§A2.Add an entry for the checkbox in the fieldcatalog
  clear ls_fcat.
  ls_fcat-fieldname = 'CHECKBOX'.
* Essential: declare field as checkbox and
*            mark it as editable field:
  ls_fcat-checkbox = 'X'.
  ls_fcat-edit = 'X'.

* do not forget to provide texts for this extra field
  ls_fcat-coltext = text-f01.
  ls_fcat-tooltip = text-f02.
  ls_fcat-seltext = text-f03.

* optional: set column width
  ls_fcat-outputlen = 10.
*
  append ls_fcat to pt_fieldcat.

endform.
*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB  text
*      <--P_GT_FIELDCAT  text
*      <--P_GS_LAYOUT  text
*----------------------------------------------------------------------*
form create_and_init_alv.

  data: lt_exclude type ui_functions.

  create object g_custom_container
         exporting container_name = g_container.
  create object g_grid
         exporting i_parent = g_custom_container.

  perform build_fieldcat changing gt_fieldcat.

* Exclude all edit functions in this example since we do not need them:
  perform exclude_tb_functions changing lt_exclude.

  perform build_data.

*§ B3.Use the layout structure to aquaint additional field to ALV.

  gs_layout-stylefname = 'CELLTAB'.

  call method g_grid->set_table_for_first_display
       exporting is_layout             = gs_layout
                 it_toolbar_excluding  = lt_exclude
       changing  it_fieldcatalog       = gt_fieldcat
                 it_outtab             = gt_outtab[].

  create object g_event_receiver.
  set handler g_event_receiver->catch_doubleclick for g_grid.

* Set editable cells to ready for input initially
  call method g_grid->set_ready_for_input
   exporting
    i_ready_for_input = 1.


endform.                               "CREATE_AND_INIT_ALV

*&---------------------------------------------------------------------*
*&      Form  EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LT_EXCLUDE  text
*----------------------------------------------------------------------*
form exclude_tb_functions changing pt_exclude type ui_functions.

  data ls_exclude type ui_func.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
  append ls_exclude to pt_exclude.


endform.                               " EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*&      Form  build_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_data.

  data: lt_sflight type table of sflight,
        ls_sflight type sflight,
        ls_celltab type lvc_s_styl,
        lt_celltab type lvc_t_styl,
        l_index type i.

  select * from sflight into table lt_sflight up to g_max rows.
  if sy-subrc ne 0.
* generate own entries if db-table is empty so that this example
* still works
    perform generate_entries changing lt_sflight.
  endif.

*§A3.Optionally, check checkboxes initially after selecting data.
* (Omitted in this example)
  loop at lt_sflight into ls_sflight.
    move-corresponding ls_sflight to gt_outtab.
*   if gt_outtab-connid eq '400'.
*     gt_outtab-checkbox = 'X'.
*   endif.
    append gt_outtab.
  endloop.

* §B2.After selecting data,
*    assign a style for each row of your checkbox column.
*
* Initially, set all checkbox cells editable.
  ls_celltab-fieldname = 'CHECKBOX'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.

  loop at gt_outtab.
    l_index = sy-tabix.
    refresh lt_celltab.

    ls_celltab-fieldname = 'CHECKBOX'.
    ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
    insert ls_celltab into table lt_celltab.

    insert lines of lt_celltab into table gt_outtab-celltab.
    modify gt_outtab index l_index.
  endloop.

endform.                               " build_data
*&---------------------------------------------------------------------*
*&      Form  generate_entries
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LT_SLFIGHT  text
*----------------------------------------------------------------------*
form generate_entries changing pt_slfight type standard table.
*
* This form is only needed for the case that there is no
* data in database table SFLIGHT.
*
  data: ls_sflight type sflight,
        l_month(2) type c,
        l_day(2) type c,
        l_date(8) type c.


  ls_sflight-carrid = 'LH'.
  ls_sflight-connid = '0400'.
  ls_sflight-currency = 'DEM'.
  ls_sflight-planetype = '747-400'.
  ls_sflight-seatsmax = 660.

  do 110 times.
    ls_sflight-price = sy-index * 100.
    ls_sflight-seatsocc = 660 - sy-index * 6.
    ls_sflight-paymentsum = ls_sflight-seatsocc * ls_sflight-price.

    l_month = sy-index / 10 + 1.
    do 2 times.
      l_day = l_month + sy-index * 2.
      l_date+0(4) = '2000'.
      l_date+4(2) = l_month+0(2).
      l_date+6(2) = l_day+0(2).
      ls_sflight-fldate = l_date.
      append ls_sflight to pt_slfight.
    enddo.
  enddo.
endform.                               " generate_entries
*&---------------------------------------------------------------------*
*&      Form  select_all_entries
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB  text
*----------------------------------------------------------------------*
form select_all_entries changing pt_outtab type standard table.
  data: ls_outtab type gs_outtab.
  data: l_valid type c,
        l_locked type c.

*§A4ad. Before you (a)set, reset or (d)evaluate checkboxes,
*       you must check the input cells.
*
* If all entries are ok, ALV transferes new values to the output
* table which you then can modify.

  call method g_grid->check_changed_data
              importing
                 e_valid = l_valid.

  if l_valid eq 'X'.

    loop at pt_outtab into ls_outtab.
      perform check_lock using    ls_outtab
                         changing l_locked.
      if l_locked is initial
         and not ls_outtab-checkbox eq '-'.
        ls_outtab-checkbox = 'X'.
      endif.
      modify pt_outtab from ls_outtab.
    endloop.

    call method g_grid->refresh_table_display.

  endif.

endform.                               " select_all_entries
*&---------------------------------------------------------------------*
*&      Form  deselect_all_entries
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB[]  text
*----------------------------------------------------------------------*
form deselect_all_entries changing pt_outtab type standard table.
  data: ls_outtab type gs_outtab.
  data: l_valid type c,
        l_locked type c.


*§A4ad. Before you (a)set, reset or (d)evaluate checkboxes,
*       you must check the input cells.
*
* If all entries are ok, ALV transferes new values to the output
* table which you then can modify.

  call method g_grid->check_changed_data
              importing
                 e_valid = l_valid.

  if l_valid eq 'X'.

    loop at pt_outtab into ls_outtab.
      perform check_lock using    ls_outtab
                       changing l_locked.
      if l_locked is initial
         and not ls_outtab-checkbox eq '-'.
        ls_outtab-checkbox = ' '.
      endif.

      modify pt_outtab from ls_outtab.
    endloop.

    call method g_grid->refresh_table_display.

  endif.



endform.                               " deselect_all_entries
*&---------------------------------------------------------------------*
*&      Form  reset_selected_entries
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB[]  text
*----------------------------------------------------------------------*
form reset_selected_entries changing pt_outtab type standard table.
  data: ls_outtab type gs_outtab.
  data: l_valid type c.

*§A4b. Before you set, (b)reset or evaluate checkboxes,
*      you must check the input cells.
*
* If all entries are ok, ALV transferes new values to the output
* table which you then can modify.

  call method g_grid->check_changed_data
              importing
                 e_valid = l_valid.

  if l_valid eq 'X'.

    loop at pt_outtab into ls_outtab.
      if     not ls_outtab-checkbox is initial
         and not ls_outtab-checkbox eq '-'.
        clear ls_outtab.
        modify pt_outtab from ls_outtab.
      endif.
    endloop.

    call method g_grid->refresh_table_display.

  endif.

endform.                               " reset_selected_entries

*-----------------------------

form switch_activation changing pt_outtab type standard table.
  data: ls_outtab type gs_outtab.
  data: l_valid type c,
        lt_row_no type lvc_t_roid with header line.

*§A4c. Before you set, reset, (c)(de)activate


*      or evaluate checkboxes, you must check the input cells.
*
* If all entries are ok, ALV transferes new values to the output
* table which you then can modify.

  call method g_grid->check_changed_data
              importing
                 e_valid = l_valid.

  if l_valid eq 'X'.
    call method g_grid->get_selected_rows
      importing
         et_row_no     = lt_row_no[].

    loop at lt_row_no.
       read table pt_outtab into ls_outtab index lt_row_no-row_id.
       if ls_outtab-checkbox ne '-'.
         ls_outtab-checkbox = '-'.
       else.
         ls_outtab-checkbox = ' '.
       endif.
       modify pt_outtab from ls_outtab index lt_row_no-row_id.

    endloop.

    call method g_grid->refresh_table_display.

  endif.

endform.                               " switch_activation

*&---------------------------------------------------------------------*
*&      Form  check_lock
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LS_OUTTAB  text
*      <--P_L_LOCKED  text
*----------------------------------------------------------------------*
form check_lock using    ps_outtab type gs_outtab
                changing p_locked.
  data ls_celltab type lvc_s_styl.

  loop at ps_outtab-celltab into ls_celltab.
    if ls_celltab-fieldname = 'CHECKBOX'.
      if ls_celltab-style eq cl_gui_alv_grid=>mc_style_disabled.
        p_locked = 'X'.
      else.
        p_locked = space.
      endif.
    endif.
  endloop.

endform.                               " check_lock

Read only

Former Member
0 Likes
1,714

Hii!

Check this sample code


REPORT z_sdn.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables                                                      *
*"--------------------------------------------------------------------*
DATA:
  BEGIN OF fs_spfli,
    carrid   LIKE spfli-carrid,        " Airline Code
    connid   LIKE spfli-connid,        " Flight Connection Number
    airpfrom LIKE spfli-airpfrom,      " Departure airport
    airpto   LIKE spfli-airpto,        " Destination airport
    deptime  LIKE spfli-deptime,       " Departure time
    arrtime  LIKE spfli-arrtime,       " Arrival time
  END OF fs_spfli,

  BEGIN OF fs_sflight,
    carrid   LIKE sflight-carrid,       " Airline Code
    connid   LIKE sflight-connid,       " Flight Connection Number
    fldate   LIKE sflight-fldate,       " Flight date
    seatsmax LIKE sflight-seatsmax,     " Maximum seats in economy class
    seatsocc LIKE sflight-seatsocc,     " Occupied seats in economyclass
  END OF fs_sflight,
  w_checkbox TYPE c,                    " Variable for checkbox
  w_currentline TYPE i,                 " Variable to display current
                                        " line
  w_lines TYPE i,
  w_read TYPE c .

*"--------------------------------------------------------------------*
* Internal Table to hold flight schedule information                  *
*"--------------------------------------------------------------------*
DATA:
  t_spfli LIKE
    TABLE OF
          fs_spfli.

*"--------------------------------------------------------------------*
* Internal Table to hold flight information                           *
*"--------------------------------------------------------------------*
DATA:
  t_sflight LIKE
      TABLE OF
            fs_sflight,
  t_sflight1 LIKE t_sflight.

*"--------------------------------------------------------------------*
*    START-OF-SELECTION Event                                         *
*"--------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM get_data_spfli.

*"--------------------------------------------------------------------*
*    END-OF-SELECTION Event                                           *
*"--------------------------------------------------------------------*
END-OF-SELECTION.
  SET PF-STATUS 'MENU'.
  PERFORM display_data_spfli.

*"--------------------------------------------------------------------*
*    TOP-OF-PAGE Event                                                *
*"--------------------------------------------------------------------*
TOP-OF-PAGE.
  PERFORM header_table_spfli.

*"--------------------------------------------------------------------*
*    AT LINE-SELECTION EVENT                                          *
*"--------------------------------------------------------------------*
AT LINE-SELECTION.
  SET PF-STATUS space.
  IF sy-lsind EQ 1 AND sy-lilli GE 4.
    PERFORM get_data_sflight.
    PERFORM display_data_sflight.
    PERFORM flag_line.
  ENDIF.                               " IF sy-lsind EQ 1..

*"--------------------------------------------------------------------*
*    AT USER-COMMAND                                                  *
*"--------------------------------------------------------------------*
AT USER-COMMAND.
  IF sy-lsind EQ 1.
    SET PF-STATUS space.
    CASE sy-ucomm.
      WHEN 'DISPLAY'.
        PERFORM get_data_sflight1.
        PERFORM display_data_sflight.
      WHEN 'SELECTALL'.
        PERFORM select_all.
        PERFORM flag_line.
      WHEN 'DESELECTAL'.
        PERFORM deselect_all.
        PERFORM flag_line.
    ENDCASE.                           " CASE sy-ucomm
  ENDIF.                               " IF sy-lsind EQ 1

*"--------------------------------------------------------------------*
*    TOP-OF-PAGE DURING LINE-SELECTION                                *
*"--------------------------------------------------------------------*
TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM sec_list_heading.

*&---------------------------------------------------------------------*
*&      Form  get_data_spfli
*&---------------------------------------------------------------------*
*  This subroutine fetches the data from SPFLI
*----------------------------------------------------------------------*
* This subroutine does not have parameters to pass
*----------------------------------------------------------------------*
FORM get_data_spfli .

  SELECT carrid                        " Airline Code
         connid                        " Flight Connection Number
         airpfrom                      " Departure airport
         airpto                        " Destination airport
         deptime                       " Departure time
         arrtime                       " Arrival time
    FROM spfli
    INTO TABLE t_spfli.

ENDFORM.                               " GET_DATA_SPFLI

*&---------------------------------------------------------------------*
*&      Form  display_data_spfli
*&---------------------------------------------------------------------*
* This subroutine displays the data of SPFLI
*----------------------------------------------------------------------*
* This subroutine does not have parameters to pass
*----------------------------------------------------------------------*
FORM display_data_spfli .
  LOOP AT t_spfli INTO fs_spfli.
    WRITE: /02 w_checkbox AS CHECKBOX,
            05 w_read,
               fs_spfli-carrid UNDER text-001,
               fs_spfli-connid UNDER text-002,
               fs_spfli-airpfrom UNDER text-003,
               fs_spfli-airpto UNDER text-004,
               fs_spfli-deptime UNDER text-005,
               fs_spfli-arrtime UNDER text-006.
    HIDE:
      fs_spfli-carrid,
      fs_spfli-connid.
  ENDLOOP.                             " LOOP AT t_spfli..
ENDFORM.                               " DISPLAY_DATA_SPFLI

*&---------------------------------------------------------------------*
*&      Form  header_table_spfli
*&---------------------------------------------------------------------*
* This subroutine diplays the headings of table spfli
*----------------------------------------------------------------------*
* This subroutine does not have parameters to pass
*----------------------------------------------------------------------*
FORM header_table_spfli .

  WRITE: /10 text-001 COLOR 4,
          25 text-002 COLOR 4,
          40 text-003 COLOR 4,
          55 text-004 COLOR 4,
          70 text-005 COLOR 4,
          85 text-006 COLOR 4.

ENDFORM.                               " HEADER_TABLE

*&---------------------------------------------------------------------*
*&      Form  get_data_sflight
*&---------------------------------------------------------------------*
* This subroutine fetches the data from SFLIGHT
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM get_data_sflight .

  SELECT carrid                        " Airline Code
         connid                        " Flight Connection Number
         fldate                        " Flight date
         seatsmax                      " Maximum seats in economy class
         seatsocc                      " Occupied seats in economyclass
    FROM sflight
    INTO TABLE t_sflight
   WHERE carrid EQ fs_spfli-carrid
     AND connid EQ fs_spfli-connid.

ENDFORM.                               " GET_DATA_SFLIGHT

*&---------------------------------------------------------------------*
*&      Form  display_data_sflight
*&---------------------------------------------------------------------*
* This subroutine displays the SFLIGHT data
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM display_data_sflight .

  LOOP AT t_sflight INTO fs_sflight.
    WRITE: / fs_sflight-carrid UNDER text-001,
             fs_sflight-connid UNDER text-002,
             fs_sflight-fldate UNDER text-007,
             fs_sflight-seatsmax UNDER text-008 LEFT-JUSTIFIED,
             fs_sflight-seatsocc UNDER text-009 LEFT-JUSTIFIED.
  ENDLOOP.
  CLEAR: fs_sflight.
ENDFORM.                               " DISPLAY_DATA_sflight

*&---------------------------------------------------------------------*
*&      Form  sec_list_heading
*&---------------------------------------------------------------------*
*  This subroutine diplays the headings of table spfli
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM sec_list_heading .

  WRITE: /2 text-001 COLOR 4,
         15 text-002 COLOR 4,
         33 text-007 COLOR 4,
         45 text-008 COLOR 4,
         60 text-009 COLOR 4.

ENDFORM.                               " SEC_LIST_HEADING

*&---------------------------------------------------------------------*
*&      Form  get_data_sflight1
*&---------------------------------------------------------------------*
* This subroutine displays the data from SFLIGHT according to checkbox
* clicked.
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM get_data_sflight1 .

  DATA:
    lw_checkbox TYPE c.
  DESCRIBE TABLE t_spfli LINES w_lines.
  DO w_lines TIMES.
    w_currentline = 3 + sy-index.
    CLEAR:
      w_checkbox,
      fs_spfli.

    READ LINE w_currentline FIELD VALUE
      w_checkbox INTO lw_checkbox
      fs_spfli-carrid INTO fs_spfli-carrid
      fs_spfli-connid INTO fs_spfli-connid.
    IF sy-subrc EQ 0.
      IF lw_checkbox EQ 'X'.
        SELECT carrid                  " Airline Code
               connid                  " Flight Connection Number
               fldate                  " Flight Date
               seatsmax                " Max Seats
               seatsocc                " Occupied Seats
          FROM sflight
          INTO TABLE t_sflight1
         WHERE carrid EQ fs_spfli-carrid
           AND connid EQ fs_spfli-connid.
        IF sy-subrc EQ 0.
          APPEND LINES OF t_sflight1 TO t_sflight.
        ENDIF.                         " IF sy-subrc EQ 0.
      ENDIF.                           " IF lw_checkbox EQ 'X'
    ENDIF.                             " IF sy-subrc EQ 0.
  ENDDO.                               " DO w_lines TIMES

ENDFORM.                               " GET_DATA_SFLIGHT1

*&---------------------------------------------------------------------*
*&      Form  select_all
*&---------------------------------------------------------------------*
* This subroutine selects all the records of SPFLI
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM select_all .

  DESCRIBE TABLE t_spfli LINES w_lines.
  DO w_lines TIMES.
    w_currentline = sy-index + 3.
    READ LINE w_currentline FIELD VALUE
    w_checkbox INTO w_checkbox.
    IF sy-subrc = 0.
      MODIFY LINE w_currentline FIELD VALUE
      w_checkbox FROM 'X'.
    ENDIF.                             " IF sy-subrc = 0.
  ENDDO.                               " DO lw_line TIMES.

ENDFORM.                               " SELECT_ALL

*&---------------------------------------------------------------------*
*&      Form  deselect_all
*&---------------------------------------------------------------------*
* This subroutine deselects all the records of SPFLI
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM deselect_all .

  DESCRIBE TABLE t_spfli LINES w_lines.
  DO w_lines TIMES.
    w_currentline = sy-index + 3.
    READ LINE w_currentline FIELD VALUE
    w_checkbox INTO w_checkbox.
    IF sy-subrc = 0.
      MODIFY LINE w_currentline FIELD VALUE
      w_checkbox FROM ' '.
    ENDIF.                             " IF sy-subrc = 0.
  ENDDO.                               " DO lw_line TIMES.

ENDFORM.                               " DESELECT_ALL

*&---------------------------------------------------------------------*
*&      Form  flag_line
*&---------------------------------------------------------------------*
* This subroutine flags the line which has been read
*----------------------------------------------------------------------*
* This subroutine does not have interface parameters to pass
*----------------------------------------------------------------------*
FORM flag_line .

  DESCRIBE TABLE t_spfli LINES w_lines.
  DO w_lines TIMES.
    w_checkbox = 'X'.
    READ LINE sy-lilli FIELD VALUE
      w_read INTO w_read
      w_checkbox INTO w_checkbox.
    IF sy-subrc EQ 0.

      MODIFY CURRENT LINE
      FIELD FORMAT w_checkbox INPUT OFF
      FIELD VALUE w_read FROM '*'.

    ENDIF.                             " IF sy-subrc EQ 0
  ENDDO.                               " DO w_lines TIMES

ENDFORM.                               " FLAG_LINE

Regards

Abhijeety

Read only

Former Member
0 Likes
1,714

Hi,

In your at user-command ...

case sy-ucomm.

when 'SELECTALL'.

DESCRIBE TABLE <internal table > LINES w_lines.

DO w_lines TIMES.

w_currentline = sy-index + 3.

READ LINE w_currentline FIELD VALUE

w_checkbox INTO w_checkbox.

IF sy-subrc = 0.

MODIFY LINE w_currentline FIELD VALUE

w_checkbox FROM 'X'.

ENDIF. " IF sy-subrc = 0.

ENDDO.

endcase.

regards

padma