How to Download Data from Output Screen for Selected Checkbox in ABAP
1. Introduction
This guide explains how to download data from an ABAP output screen (classical report) where each row
includes a checkbox.
Users can select multiple rows using the checkboxes, and upon triggering a user command (like pressing a
'DOWNLOAD' button), the selected rows are collected and saved for further use.
2. Steps and Sample Code
1. Define an internal table to display data.
2. Add a checkbox (type C length 1) to each row using WRITE ... AS CHECKBOX.
3. Use SET PF-STATUS to activate a GUI status that includes a function code like 'DOWNLOAD'.
4. Use AT USER-COMMAND to handle the event when the user clicks 'DOWNLOAD'.
5. Loop over the lines of the list using DO ... TIMES.
6. Use READ LINE sy-index FIELD VALUE <checkbox> INTO <flag> to check if the checkbox is selected.
7. If selected, use READ TABLE to get the corresponding row from the internal table and APPEND it to
another internal table.
8. Use WRITE or EXPORT to handle the selected data.
3. Example Code Snippet
DATA: a TYPE c LENGTH 1, b TYPE c LENGTH 1.
DATA: it_vbak TYPE TABLE OF ty_vbak, wa_vbak TYPE ty_vbak.
DATA: it_selected TYPE TABLE OF ty_vbak, wa_selected TYPE ty_vbak.
LOOP AT it_vbak INTO wa_vbak.
WRITE: / a AS CHECKBOX, wa_vbak-vbeln, wa_vbak-erdat.
ENDLOOP.
SET PF-STATUS 'OPTIONS2'.
AT USER-COMMAND.
IF sy-ucomm = 'DOWNLOAD'.
DO LINES( it_vbak ) TIMES.
READ LINE sy-index FIELD VALUE a INTO b.
IF b = 'X'.
How to Download Data from Output Screen for Selected Checkbox in ABAP
READ TABLE it_vbak INTO wa_selected INDEX sy-index.
IF sy-subrc = 0.
APPEND wa_selected TO it_selected.
ENDIF.
ENDIF.
ENDDO.
LOOP AT it_selected INTO wa_selected.
WRITE: / 'Selected:', wa_selected-vbeln.
ENDLOOP.
ENDIF.
4. Notes
- This approach works for classical reports only (not ALV).
- Ensure the checkbox variable is displayed on screen and is aligned properly.
- GUI status 'OPTIONS2' should include a button with function code 'DOWNLOAD'.
- For exporting selected data to a file, additional logic can be added to write to the application server or
frontend using GUI_DOWNLOAD.