GET CURSOR → to capture the position of the cursor in a list/report.
HIDE → to store values “hidden” behind a line for later retrieval.
USER COMMAND (AT USER-COMMAND) → to react to user actions (e.g., double-clicks, buttons, PF keys).
1. GET CURSOR
This is used to know where the user placed the cursor or clicked in a list.
GET CURSOR FIELD gv_field VALUE gv_value.
gv_field
→ variable to hold the field name under the cursor.gv_value
→ variable to hold the value of that field.
Example:
GET CURSOR FIELD lv_field VALUE lv_value.
WRITE: / ‘Cursor on:’, lv_field, ‘Value:’, lv_value.
2. HIDE
The HIDE
statement stores the value of a variable in the system’s hide area, linked to the current line.
Later, when the user double-clicks on that line, the hidden values are retrieved automatically.
Example:
LOOP AT it_mara INTO wa_mara.
WRITE: / wa_mara-matnr, wa_mara-maktx.
HIDE: wa_mara-matnr, wa_mara-maktx.
ENDLOOP.
When the user double-clicks on a line, the hidden fields for that line become available again.
3. USER COMMAND (AT USER-COMMAND)
This event block reacts to user actions (function keys, buttons, or double-clicks).
Example:
AT USER-COMMAND.
CASE sy-ucomm.
WHEN ‘DETAIL’. “Custom function code
WRITE: / ‘Details for material:’, wa_mara-matnr.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.
Full Example:
REPORT zsample_report.
TABLES: mara.
DATA: wa_mara TYPE mara.
START-OF-SELECTION.
SELECT * FROM mara UP TO 10 ROWS.
WRITE: / mara-matnr, mara-mtart, mara-mbrsh.
HIDE: mara-matnr.
ENDSELECT.
AT LINE-SELECTION. “Triggered by double-click
WRITE: / ‘You selected material:’, mara-matnr.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN ‘DETAIL’.
GET CURSOR FIELD DATA(lv_field) VALUE DATA(lv_value).
WRITE: / ‘Field:’, lv_field, ‘Value:’, lv_value.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.