Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Arithmatic(add, sub, mult) operations using radiobutton Selection

former_member682701
Discoverer
0 Likes
5,092

Hi,

I want to create simple arithmatic operation program, in that I want to use radiobutton for selection of type of arithmatic( addition or subtraction etc) and display output. This output is concerned about the selection of radioutton. please anyone give me idea about this.

1 ACCEPTED SOLUTION
Read only

philipdavy
Contributor
2,065

PARAMETERS: A TYPE I,

             B TYPE I.

DATA: C TYPE I.

PARAMETERS: R1 RADIOBUTTON GROUP RB,

             R2 RADIOBUTTON GROUP RB,

             R3 RADIOBUTTON GROUP RB,

             R4 RADIOBUTTON GROUP RB.

FORM CALCULATE.

IF R1 = 'X'.

   C = A + B.

ELSEIF R2 = 'X'.

   C = A - B.

ELSEIF R3 = 'X'.

   C = A * B.

ELSEIF R4 = 'X'.

C = A / B.

ENDIF.

WRITE: C.

ENDFORM.

START-OF-SELECTION.

PERFORM CALCULATE.

  • Also do not forget that we have a pretty function module which works as calculator for F4 help, FITRV_CALCULATOR

Regards,

Philip.

8 REPLIES 8
Read only

Former Member
0 Likes
2,065

Hello Khamkar,

                    For each PAI processing, check which of the four object (Add, Subtract, Multiply, Divide) is not intial. After that include the corresponding logic.

Eg:

    if add = 'X'.

    ......

  

    if sub = 'X'.
    .....

etc...

Hope it helps!!!

Regards,

Deepak Mohan

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,065

I prefer this Simple GUI Calculator using ABAP using pushbuttons for numbers and operators.


Regards,

Raymond

Read only

former_member202818
Active Contributor
0 Likes
2,065

Hi,

Group all radio buttons and assign a Function code, which will help you to trigger the code while choosing each radio button.

Read only

philipdavy
Contributor
2,066

PARAMETERS: A TYPE I,

             B TYPE I.

DATA: C TYPE I.

PARAMETERS: R1 RADIOBUTTON GROUP RB,

             R2 RADIOBUTTON GROUP RB,

             R3 RADIOBUTTON GROUP RB,

             R4 RADIOBUTTON GROUP RB.

FORM CALCULATE.

IF R1 = 'X'.

   C = A + B.

ELSEIF R2 = 'X'.

   C = A - B.

ELSEIF R3 = 'X'.

   C = A * B.

ELSEIF R4 = 'X'.

C = A / B.

ENDIF.

WRITE: C.

ENDFORM.

START-OF-SELECTION.

PERFORM CALCULATE.

  • Also do not forget that we have a pretty function module which works as calculator for F4 help, FITRV_CALCULATOR

Regards,

Philip.

Read only

0 Likes
2,065

Thanks Philip...

Read only

Former Member
0 Likes
2,065

Hi khamkar,

This code may be help you,

parameters: a(10) type i   ,

            b(10) type i   .

data: c type int4.

parameters : Plus radiobutton group rad1,

             Minus radiobutton group rad1 default 'X',

             Multi radiobutton group rad1,

             Other radiobutton group rad1.

if plus = 'X' or Other = 'X'.

c = a + b.

write:/ c.

  if sy-subrc <> 0.

* Implement suitable error handling here

  endif.

elseif

  Minus = 'X' or Other = 'X'.

  c = a - b.

write:/ c.

  if sy-subrc <> 0.

* Implement suitable error handling here

  endif.

elseif

  Multi = 'X' or Other = 'X'.

  c = a * b.

write:/ c.

  if sy-subrc <> 0.

* Implement suitable error handling here

  endif.

endif.

Thanks and Regards

Niraj Sinha

Read only

Former Member
0 Likes
2,065

Hi,

this is an example (sum and subtract) that you could extend

   DATA W_NUM TYPE I.

SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_NUM1 TYPE I OBLIGATORY,
            P_NUM2 TYPE I OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS : P_ADD RADIOBUTTON GROUP GR1, "sum
             P_SUB RADIOBUTTON GROUP GR1. "subtract
SELECTION-SCREEN END OF BLOCK BL1.


START-OF-SELECTION.
  CLEAR W_NUM.

  PERFORM CALCULATE USING P_NUM1 P_NUM2.

  WRITE W_NUM.
*&---------------------------------------------------------------------*
*&      Form  CALCULATE
*&---------------------------------------------------------------------*

FORM CALCULATE  USING  PR_NUM1
                       PR_NUM2.

  IF P_ADD EQ ABAP_ON.
    COMPUTE W_NUM = PR_NUM1 + PR_NUM2.
  ENDIF.

  IF P_SUB EQ ABAP_ON.
    COMPUTE W_NUM = PR_NUM1 - PR_NUM2.
  ENDIF.

*others operation

ENDFORM.                    " CALCULATE

Regards

Ivan

Read only

Former Member
0 Likes
2,065

There are too many examples available related to radio buttons. A little bit of research on your own will help you to learn as well