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: 

check box provlem in ALV ( Flag NOT set to 'X' )

Former Member
0 Kudos

Hi Friends,,

Hope all are doing fine!!!

I have written code for getting checkbox ,,,am able display checkbox for every record ,,,,but when i click the check box ,, the field flag is not set to 'X' at runtime ,,,

i mean whenever i select the required checkboxes the respective flag(s) for the records should be set to 'X'....but the flag is not set to 'X'....

for your information am pasting the code here ..kindly do the needful.

<< Unformatted code removed >>

Edited by: jack jill on Apr 1, 2009 8:46 PM

Edited by: Rob Burbank on Apr 1, 2009 2:59 PM

7 REPLIES 7

Former Member
0 Kudos

HI,

You need to have the check box field as one of the field in the internal table.chek this link.you get the idea.[Get MARK (box) for each record in ALV Grid (an alternative of ALV with checkbox) |https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/getMARK%2528box%2529foreachrecordinALVGrid%2528analternativeofALVwithcheckbox%2529]

0 Kudos

Hi Avinash,

I am able to display the checkbox in the alv,,,

but when select the checkbox in the alv output,,,,the flag is not set to 'X' in the internal table for which i have selected the checkboxes for the corresponding records

Thanks & regards

Jack

0 Kudos

Hi,

Check this code ..Put the break point in the USER_COMMAND perfrom and execute the program and select the any check box and double click on any of the cell and it navigates to the break point no check the i_data internal table ..you can find the X in the check box cloumn of internal table.

TYPE-POOLS: slis.

DATA: BEGIN OF i_data OCCURS 0,kunnr TYPE kunnr,
ws_row TYPE i,

ws_char(5) TYPE c,

chk,

END OF i_data.

DATA: report_id LIKE sy-repid.

DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.

DATA: i_layout TYPE slis_layout_alv.

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.

SELECT kunnr

INTO TABLE i_data

FROM kna1.

" WHERE qmnum <= '00030000010'.

LOOP AT i_data.

  i_data-ws_row = sy-tabix.

  i_data-ws_char = 'AAAAA'.

  MODIFY i_data.

ENDLOOP.

report_id = sy-repid.

PERFORM f1000_layout_init CHANGING i_layout.

PERFORM f2000_fieldcat_init CHANGING i_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program      = report_id
    i_callback_user_command = 'USER_COMMAND'
    i_grid_title            = ws_title
    is_layout               = i_layout
    it_fieldcat             = i_fieldcat
    i_save                  = 'A'
  TABLES
    t_outtab                = i_data
  EXCEPTIONS
    program_error           = 1
    OTHERS                  = 2.

IF sy-subrc <> 0.

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.
*&---------------------------------------------------------------------*

*& Form F1000_Layout_Init

*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.

  CLEAR i_layout.

  i_layout-colwidth_optimize = 'X'.

  i_layout-edit = 'X'.

ENDFORM. " F1000_Layout_Init
*&---------------------------------------------------------------------*

*& Form f2000_fieldcat_init

*&---------------------------------------------------------------------*
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.

  DATA: line_fieldcat TYPE slis_fieldcat_alv.

  CLEAR line_fieldcat.

  line_fieldcat-fieldname = 'CHK'.

  line_fieldcat-tabname = 'I_DATA'.

  line_fieldcat-seltext_l = 'Checkbox'.

  line_fieldcat-checkbox = 'X'. " Display this field as a checkbox

  line_fieldcat-edit = 'X'. " This option ensures that you can

  " edit the checkbox. Else it will

  " be protected.

  APPEND line_fieldcat TO i_fieldcat.

  CLEAR line_fieldcat.

  line_fieldcat-fieldname = 'WS_ROW'.

  line_fieldcat-tabname = 'I_DATA'.

  line_fieldcat-seltext_m = 'Row Number'.

  APPEND line_fieldcat TO i_fieldcat.

  CLEAR line_fieldcat.

  line_fieldcat-fieldname = 'WS_CHAR'.

  line_fieldcat-tabname = 'I_DATA'.

  line_fieldcat-seltext_l = 'Test Character Field'.

  line_fieldcat-datatype = 'CHAR'.

  line_fieldcat-outputlen = '15'. " You can specify the width of a

  APPEND line_fieldcat TO i_fieldcat. " column.

ENDFORM. " f2000_fieldcat_init
*&---------------------------------------------------------------------*
*&      Form  user_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm     LIKE sy-ucomm
                                      rs_selfield TYPE slis_selfield.
  BREAK-POINT.
  WRITE 😕 'TEST.'.                       " Put the break point here
ENDFORM.                    "user_command

I355602
Advisor
Advisor
0 Kudos

Hi,

Refer this demo code to add checkbox to each record in alv and then select some records.

Create a pf-status with three more buttons for select all, deselect all and execute.

Goto SE41, create a pf-status for your alv report program.

On the next screen, click menu EXTRAS --> click option ADJUST TEMPLATES and select radiobutton LIST VIEWER --> you will get all standard buttons of alv in the pf-status.

Delete the unwanted buttons and also you can add new buttons if reqd.

Activate pf-status --> and apply in alv program.

Now refer code


* final table from which the records need to be displayed
        BEGIN OF t_final,
          aufnr TYPE aufk-aufnr, " order number
          ktext TYPE aufk-ktext, " description
          qmnum TYPE qmel-qmnum, " notification number
          flag(1), " for selection of records
        END OF t_final.

* TYPE OF T_FINAL
* final internal table to select final records to be displayed
DATA : it_final TYPE STANDARD TABLE OF t_final,
* final work area to select final records to be displayed
       wa_final TYPE t_final.

* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
       wa_field TYPE slis_fieldcat_alv. "work area for field catalog

START-OF-SELECTION.

  "select query into internal table it_final

  wa_field-fieldname = 'FLAG'.   " name of field from internal table
  wa_field-tabname = 'IT_FINAL'. " internal table name
  wa_field-outputlen = 2.        " output length on screen
  wa_field-checkbox = c_check.   " print as checkbox
  wa_field-edit = c_check.       " make field open for input
  wa_field-seltext_l = ' '.      " header information
  APPEND wa_field TO it_field.   " append field catalog internal table
  CLEAR wa_field.                " clear field catalog work area

  "similarly append other fields into field catalog internal table it_field

END-OF-SELECTION.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = sy-repid       " report id
     i_callback_pf_status_set          = 'PF'           " for PF-STATUS
     i_callback_user_command           = 'USER_COMMAND' " for User-Command
     it_fieldcat                       = it_field       " field catalog
    TABLES
      t_outtab                          = it_final      " internal table
   EXCEPTIONS
     program_error                     = 1
     OTHERS                            = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


*&---------------------------------------------------------------------*
*&      Form  pf
*&---------------------------------------------------------------------*
*       SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
*       ON WHICH THE ALV GRID IS DISPLAYED
*----------------------------------------------------------------------*
*       -->RT_EXTAB
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZPM_WO_STATUS'.
ENDFORM.                    "pf

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
*       AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
*      -->LV_OKCODE   used to capture the function code
*                     of the user-defined push-buttons
*      -->L_SELFIELD   text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.

* assign the function code to variable v_okcode
  lv_okcode = sy-ucomm.

* handle the code execution based on the function code encountered
  CASE lv_okcode.

* when the function code is EXECUTE then process the selected records
    WHEN 'EXECUTE'.

* to reflect the data changed into internal table
      DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new

      IF ref_grid IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            e_grid = ref_grid.
      ENDIF.

      IF NOT ref_grid IS INITIAL.
        CALL METHOD ref_grid->check_changed_data.
      ENDIF.

"at this point your internal table has flag X for fields selected in alv output

* refresh the ALV Grid output from internal table
      l_selfield-refresh = 'X'.
"changes reflected to alv

"so can include your own code as per your requirement for selected records

    WHEN 'SEL_ALL'. "<--select all records
* to select all the records displayed in ALV Grid
      LOOP AT it_final INTO wa_final.
        wa_final-flag = 'X'.
        MODIFY it_final FROM wa_final.
      ENDLOOP.
* refresh the ALV Grid output from internal table
      l_selfield-refresh = 'X'.

    WHEN 'DESEL_ALL'. "<--deselect all records
* to deselect all the records displayed in ALV Grid
      LOOP AT it_final INTO wa_final.
        wa_final-flag = ' '.
        MODIFY it_final FROM wa_final.
      ENDLOOP.
* refresh the ALV Grid output from internal table
      l_selfield-refresh = 'X'.

  ENDCASE.

ENDFORM.                    "USER_COMMAND

Hope this helps you.

Regards,

Tarun

I355602
Advisor
Advisor
0 Kudos

Hi,

I posted the above thread with all formatting tips.

But cant make out why it was not working.

No formatting tools are having any effect to data display.

I know it will be difficult to understand the code, but still you can try.

Let me know in case of any problem.

Regards,

Tarun

Former Member
0 Kudos

Hi,

You can get the changes by calling the method check_changed_data in the class CL_GUI_ALV_GRID.

Example: if o_alv is the object ref to CL_GUI_ALV_GRID.

then

CALL METHOD o_alv->check_changed_data.

Regards,

Karthick

Former Member
0 Kudos

Thanks