0
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.

How Can make this happen:I want that on click of the button to show the table.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 radiobutton or smth else. Thanks in advance!

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Demotivated
  • 117
  • 3
  • 13

2 Answers2

2

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.
Meidi
  • 36
  • 5
  • how about when I want tocheck if the parameters are empty or not?I have two parameters and three radiobuttons.'code'IF vendor <> 0 and alv = 'X' and material <> 0 . MESSAGE TEXT-e04 TYPE 'E'. ENDIF. 'code' – Demotivated Jul 28 '17 at 12:18
  • For parameters, you use "IS (NOT) INITIAL" construct. Something like: `IF pa_param IS NOT INITIAL. *do something*. ENDIF.` – Meidi Jul 28 '17 at 13:05
  • Ok, I think I know what the deal is. You need to capitalise `WHEN 'PRESS'` entirely. My bad, forgot it was a thing. – Meidi Jul 28 '17 at 13:23
  • 1
    I mean, in the original code, I typed `WHEN 'press'`. It won't work because sy-ucomm automatically capitalises user commands. It should be `CASE sy-ucomm. WHEN 'PRESS'. IF vendor IS NOT INITIAL AND alv = 'X' AND material IS NOT INITIAL. MESSAGE TEXT-e04 TYPE 'E'. ENDIF. ENDCASE.` (Assuming you're using a button) – Meidi Jul 28 '17 at 13:26
  • no its a parameter thats why I am struggling.vendor and material are prams and alv is radiobutton sorry – Demotivated Jul 28 '17 at 13:28
  • In my case I'm using a button to check for every parameter. When I press it, the command 'PRESS' gets sent to sy-ucomm and then it starts to check for paramaters. I just debugged that little bit of code I typed above and it works fine, I get the message. – Meidi Jul 28 '17 at 13:33
1

The most common way to display internal tables like this is with an ALV, a simple example of how to build up an ALV can be found here: https://archive.sap.com/discussions/thread/873601

If you'd like it to do the WRITE: to screen under one circumstance, and display the ALV Grid in another, you should use Select Options and parameters.

Your code needs the addition of EVENTS, please take a look here on what they are and how to use them: http://www.erpworkbench.com/abap/abap-events.htm

Zack Cain
  • 35
  • 7