buttonabapdynpro

How to WRITE on screen after pressing selection screen custom button


I want to show the table built with WRITE on click of the button "PRESS".

Currently, nothing happens after clicking the button.

Please the code to be as simple as possible and as easy to understand as possible. If you can't make it with a button, make it with a radio button or something else.

Thanks in advance!

TABLES: mara, marc.
"marc is N
"mara is 1 
SELECTION-SCREEN PUSHBUTTON 15(10) text-001 USER-COMMAND press.
DATA: lt_mara TYPE TABLE OF mara WITH HEADER LINE,
      ls_mara TYPE mara.
DATA: lt_marc TYPE TABLE OF marc WITH HEADER LINE,
      ls_marc TYPE marc,
      Sum  type P length 8 DECIMALS 2.
PARAMETERS: p_mtart TYPE mara-mtart.
SELECT-OPTIONS: so_werks FOR marc-werks.
SELECT * FROM mara INTO TABLE lt_mara
  WHERE mtart = p_mtart.
IF sy-subrc = 0.
  SELECT * FROM marc INTO TABLE lt_marc
  FOR ALL ENTRIES IN lt_mara
  WHERE  matnr = lt_mara-matnr
  AND werks IN so_werks.
  LOOP AT lt_marc INTO ls_marc.
    READ TABLE lt_mara INTO ls_mara
   WITH KEY matnr = ls_marc-matnr.
    sum = ls_mara-brgew + ls_mara-ntgew .
  WRITE:/ ls_mara-mtart, ls_marc-matnr , ls_marc-werks , ls_mara-brgew, ls_mara-ntgew,sum.
  ENDLOOP.
ELSE.
  MESSAGE TEXT-e02 TYPE 'E' .
ENDIF.

Solution

  • If you want to keep it simple, you can use "sy-ucomm" which stores your last triggered action. With your button, it'd look like this:

    AT SELECTION-SCREEN.
      CASE sy-ucomm.
        WHEN 'PRESS'.
          *code for displaying your table via ALV or WRITE goes here*
      ENDCASE.