Skip to Content
avatar image
Former Member

Recreating ABAP Calculator with F4

I built finally a calculator (yep, still new to ABAP but I'm trying). Now i want to recreate it with "F4"-Button.

The code without looks like this:

REPORT ZCALC.
PARAMETERS Zahl1 TYPE i.
PARAMETERS plus RADIOBUTTON GROUP grp1.
PARAMETERS minus RADIOBUTTON GROUP grp1.
PARAMETERS mal RADIOBUTTON GROUP grp1.
PARAMETERS durch RADIOBUTTON GROUP grp1.
PARAMETERS Zahl2 TYPE i.

IF plus = 'X'. add Zahl2 to Zahl1. 
WRITE : 'Das Ergebnis der Addition lautet: ' , Zahl1.
ENDIF.

IF minus = 'X'. SUBTRACT Zahl2 FROM Zahl1. WRITE : 'Das Ergebnis der Subtraktion lautet: ' , Zahl1.
ENDIF.

IF mal = 'X'. MULTIPLY Zahl2 by Zahl1. WRITE : 'Das Ergebnis der Multiplikation lautet: ' , Zahl1.
ENDIF.

IF durch = 'X'. IF zahl2 = 0. 
WRITE 'Division durch 0 nicht möglich. Bitte nochmal versuchen!'.
ELSE.
DIVIDE Zahl1 by Zahl2.
WRITE : 'Das Ergebnis der Division lautet: ' , Zahl1.
ENDIF. ENDIF.

All works like it should (I now, some things are double but I first want it to work).. Even Division with 0 is cleared.

Now I added the new Parameter:

PARAMETERS auswahl TYPE ZCALC_OPERATOREN.
I know I have to deactivate the Radiobuttons but I am not sure what comes next.
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jan 26 at 12:18 PM

    You could replace the radiobuttons by an input field with a dropdown list of values, fill values with FM RM_SET_VALUES in the PBO (AT SELECTION-SCREEN OUTPUT) attach a function code to this field. In the PAI (AT SELECTION-SCREEN) use a CASE auswahl WHEN '+', etc. ENDCASE syntax.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Not exactly what I want to do I think.

      I create a ned menu where I can enter +, -, *, / and next to that field is the seleciton Box where I could also choose one of those 4 (or that box openes with F4).
      This Function works with 'PARAMETERS auswahl TYPE ZCALC_OPERATOREN.' but I want to edit the Code.

      Or maybe you said it right but i am not familiar with your shortcuts (Sry if so :D )

  • Jan 26 at 02:35 PM

    I have a calculator in different versions in a subpackage of SABAPDEMOS, Check it out.

    Add comment
    10|10000 characters needed characters exceeded