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 OUTPUT USING CHECKBOX

pbiswas
Explorer
0 Kudos
188

I am developing a ALV grid report and there should be a checkbox on the selection screen, when i check the checkbox and click on download button it should download  to text,  what should be the coding for checked  checkbox.



REPORT y_pb_retest.

TABLES : pernr.

NODES: peras, person.

INFOTYPES 0002, 0006, 0105.

TYPES : BEGIN OF ty_itab,

          chk TYPE checkbox,

           pernr TYPE p0002-pernr,

           vorna TYPE p0002-vorna,

           nachn TYPE p0002-nachn,

           stras TYPE p0006-stras,

           pstlz TYPE p0006-pstlz,

           ort01 TYPE p0006-ort01,

           telnr TYPE p0006-telnr,

           usrid_long TYPE p0105-usrid_long,

          END OF ty_itab.

DATA : itab TYPE TABLE OF ty_itab,

        wa TYPE ty_itab .

*DATA: chk(1) TYPE c.

DATA: i_fcat TYPE slis_t_fieldcat_alv,

       wa_fcat TYPE slis_fieldcat_alv.

DATA: gs_selfield TYPE slis_selfield .

START-OF-SELECTION.

GET peras.

   rp_provide_from_last p0002 space  pn-begda pn-endda.

   rp_provide_from_last p0006 '1' pn-begda pn-endda.

   rp_provide_from_last p0105 '0010' pn-begda pn-endda.

   wa-pernr = p0002-pernr.

   wa-vorna = p0002-vorna.

   wa-nachn = p0002-nachn.

   wa-stras = p0006-stras.

   wa-pstlz = p0006-pstlz.

   wa-ort01 = p0006-ort01.

   wa-telnr = p0006-telnr.

   wa-usrid_long = p0105-usrid_long.

   APPEND wa TO itab.

   CLEAR wa.

END-OF-SELECTION.

   PERFORM call_alv.

   PERFORM alv_grid.

*&---------------------------------------------------------------------*

*&      Form  call_alv

*&---------------------------------------------------------------------*

*       text

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

FORM call_alv.

   wa_fcat-fieldname   = 'CHK'.

   wa_fcat-seltext_m   = 'SELECT'.

   wa_fcat-checkbox = 'X'.

   wa_fcat-edit = 'X'.

   wa_fcat-col_pos     = 1.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'PERNR'.

   wa_fcat-seltext_m   = 'EMPLOYEE NUMBER'.

   wa_fcat-col_pos     = 2.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'VORNA'.

   wa_fcat-seltext_m   = 'FIRST NAME'.

   wa_fcat-col_pos     = 3.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'NACHN'.

   wa_fcat-seltext_m   = 'LAST NAME'.

   wa_fcat-col_pos     = 4.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'STRAS'.

   wa_fcat-seltext_m   = 'STREET NO.'.

   wa_fcat-col_pos     = 5.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'ORT01'.

   wa_fcat-seltext_m   = 'CITY'.

   wa_fcat-col_pos     = 6.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'PSTLZ'.

   wa_fcat-seltext_m   = 'POSTAL CODE'.

   wa_fcat-col_pos     = 7.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'TELNR'.

   wa_fcat-seltext_m   = 'TELEPHONE NUMBER'.

   wa_fcat-col_pos     = 8.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

   wa_fcat-fieldname   = 'USRID_LONG'.

   wa_fcat-seltext_m   = 'EMAIL'.

   wa_fcat-col_pos     = 9.

   APPEND wa_fcat TO i_fcat.

   CLEAR  wa_fcat.

ENDFORM.                    "call_alv

*&---------------------------------------------------------------------*

*&      Form  SET_PF_STATUS

*&---------------------------------------------------------------------*

*       text

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

*      -->RT_EXTAB   text

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

FORM set_pf_status USING rt_extab TYPE slis_t_extab.

   SET PF-STATUS 'YMENU'.

ENDFORM.                    "SET_PF_STATUS

*&---------------------------------------------------------------------*

*&      Form  alv_grid

*&---------------------------------------------------------------------*

*       text

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

FORM alv_grid.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

*     I_INTERFACE_CHECK                 = ' '

*     I_BYPASSING_BUFFER                = ' '

*     I_BUFFER_ACTIVE                   = ' '

      i_callback_program                = sy-repid

     i_callback_pf_status_set          = 'SET_PF_STATUS'

     I_CALLBACK_USER_COMMAND           = 'DATA_DOWNLOAD'

*     I_CALLBACK_TOP_OF_PAGE            = ' '

*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '

*     I_CALLBACK_HTML_END_OF_LIST       = ' '

*    I_STRUCTURE_NAME                  = 'I_FINAL'

*     I_BACKGROUND_ID                   = ' '

*     I_GRID_TITLE                      =

*     I_GRID_SETTINGS                   =

*     IS_LAYOUT                         =

      it_fieldcat                       = i_fcat

*     IT_EXCLUDING                      =

*     IT_SPECIAL_GROUPS                 =

*    IT_SORT                           = itab

*     IT_FILTER                         =

*     IS_SEL_HIDE                       =

*     I_DEFAULT                         = 'X'

*    I_SAVE                            = 'X '

*     IS_VARIANT                        =

*     IT_EVENTS                         =

*     IT_EVENT_EXIT                     =

*     IS_PRINT                          =

*     IS_REPREP_ID                      =

*     I_SCREEN_START_COLUMN             = 0

*     I_SCREEN_START_LINE               = 0

*     I_SCREEN_END_COLUMN               = 0

*     I_SCREEN_END_LINE                 = 0

*     I_HTML_HEIGHT_TOP                 = 0

*     I_HTML_HEIGHT_END                 = 0

*     IT_ALV_GRAPHICS                   =

*     IT_HYPERLINK                      =

*     IT_ADD_FIELDCAT                   =

*     IT_EXCEPT_QINFO                   =

*     IR_SALV_FULLSCREEN_ADAPTER        =

*   IMPORTING

*     E_EXIT_CAUSED_BY_CALLER           =

*     ES_EXIT_CAUSED_BY_USER            =

     TABLES

       t_outtab                          = itab

*   EXCEPTIONS

*     PROGRAM_ERROR                     = 1

*     OTHERS                            = 2

             .

   IF sy-subrc <> 0.

*  MESSAGE 'ENTER EMPLOYEE NUMBER' TYPE 'I'.

   ENDIF.

ENDFORM.                    "alv_grid

*&---------------------------------------------------------------------*

*&      Form  data_download

*&---------------------------------------------------------------------*

*       text

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

*      -->R_UCOMM      text

*      -->RS_SELFIELD  text

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

FORM data_download USING r_ucomm     LIKE sy-ucomm

                      rs_selfield TYPE slis_selfield.


   case r_ucomm.

     when 'DLOAD'.

       perform file_download.

   ENDCASE.

ENDFORM.                    "data_download

*&---------------------------------------------------------------------*

*&      Form  file_download

*&---------------------------------------------------------------------*

*       text

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

FORM file_download.

   CALL FUNCTION 'GUI_DOWNLOAD'

     EXPORTING

*   BIN_FILESIZE                    =

       filename                        = 'C:\test.TXT'

*   FILETYPE                        = 'ASC'

*   APPEND                          = ' '

*   WRITE_FIELD_SEPARATOR           = ' '

*   HEADER                          = '00'

*   TRUNC_TRAILING_BLANKS           = ' '

*   WRITE_LF                        = 'X'

*   COL_SELECT                      = ' '

*   COL_SELECT_MASK                 = ' '

*   DAT_MODE                        = ' '

*   CONFIRM_OVERWRITE               = ' '

*   NO_AUTH_CHECK                   = ' '

*   CODEPAGE                        = ' '

*   IGNORE_CERR                     = ABAP_TRUE

*   REPLACEMENT                     = '#'

*   WRITE_BOM                       = ' '

*   TRUNC_TRAILING_BLANKS_EOL       = 'X'

*   WK1_N_FORMAT                    = ' '

*   WK1_N_SIZE                      = ' '

*   WK1_T_FORMAT                    = ' '

*   WK1_T_SIZE                      = ' '

*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE

*   SHOW_TRANSFER_STATUS            = ABAP_TRUE

*   VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'

* IMPORTING

*   FILELENGTH                      =

     TABLES

       data_tab                        = itab

*   FIELDNAMES                      =

* EXCEPTIONS

*   FILE_WRITE_ERROR                = 1

*   NO_BATCH                        = 2

*   GUI_REFUSE_FILETRANSFER         = 3

*   INVALID_TYPE                    = 4

*   NO_AUTHORITY                    = 5

*   UNKNOWN_ERROR                   = 6

*   HEADER_NOT_ALLOWED              = 7

*   SEPARATOR_NOT_ALLOWED           = 8

*   FILESIZE_NOT_ALLOWED            = 9

*   HEADER_TOO_LONG                 = 10

*   DP_ERROR_CREATE                 = 11

*   DP_ERROR_SEND                   = 12

*   DP_ERROR_WRITE                  = 13

*   UNKNOWN_DP_ERROR                = 14

*   ACCESS_DENIED                   = 15

*   DP_OUT_OF_MEMORY                = 16

*   DISK_FULL                       = 17

*   DP_TIMEOUT                      = 18

*   FILE_NOT_FOUND                  = 19

*   DATAPROVIDER_EXCEPTION          = 20

*   CONTROL_FLUSH_ERROR             = 21

*   OTHERS                          = 22

             .

   IF sy-subrc <> 0.

* Implement suitable error handling here

   ENDIF.

ENDFORM.                    "data_download

4 REPLIES 4

Former Member
0 Kudos
117

Hi Pinku,

You needs to pass events for your requirement not I_CALLBACK_USERCOMMAND

Need to pass as below.

  CLEAR ls_event.
   ls_event-name = 'USER_COMMAND'.
   ls_event-form = 'USER_COMMAND'.
   APPEND ls_event TO lt_events.


Pass lt_events to ALV function module.




Regards

Mani

Former Member
0 Kudos
117

Hi Pinku,

FORM data_download USING r_ucomm     LIKE sy-ucomm

                      rs_selfield TYPE slis_selfield.


   case r_ucomm.

     when 'DLOAD'.

      

       READ itab INTO wa_itab INDEX  rs_selfield-tabindex.

       IF sy-subrc EQ 0 AND wa_itab-chk EQ 'X'.

        perform file_download USING wa_itab-pernr.

       ENDIF.

   ENDCASE.

ENDFORM.                    "data_download

regards,

Archer

0 Kudos
117

showing error we can't take itab(internal table) instead of table.

0 Kudos
117

You mean you need download all lines which is checked?

when 'DLOAD'.

     

       rs_selfield-refresh = ‘X’

       delete itab where chk = ''.

       perform file_download.


ENDCASE.