‎2007 Jan 15 1:46 AM
Hi,
I am beginning in ABAP/4 development.
In creating a calculator dialog, how can i do the following:
1. Upon pressing a button (for example, to output 1,) how do i add another number to 1 without removing 1 (for example, to make 1 turn into 12)?
2. How do i distinguish between operators (+, _ and etc) and how do i make them work in a dialog?
Any help will be greatly appreciated. Source code examples are welcome.
Thank you,
John
‎2007 Jan 15 1:55 AM
Hi,
Create push buttons for the + , - , / , * , = in your dialog program.
Create an input field with the data type that can accept decimal places..
When the enter 12 then press the push button "+" button store the value 12 in a variable v1..Then clear the input field..
Then when the user enters another number..lets say "13"..
Then if the user presses the "=" button...Then sum the values from the variable v1 with the input field..
Hope this helps..
Check this sample code..
MODULE USER_COMMAND.
CASE SY-UCOMM.
WHEN 'ADDITION'.
ASSUMING THE INPUT FIELD NAME IS P_INPUT.
V_V1 = P_INPUT.
V_OPERATION = '+'.
CLEAR: P_INPUT.
WHEN 'EQUALTO'.
CASE V_OPERATION.
ADDITION
WHEN '+'.
SUM UP THE VALUES.
P_INPUT = P_INPUT + V_V1.
ENDCASE.
MULTIPLICATION
WHEN '*'.
MULTIPLY UP THE VALUES.
P_INPUT = P_INPUT * V_V1.
ENDCASE.
ENDCASE.
ENDMODULE.
Thanks,
Naren
‎2007 Jan 15 2:38 AM
Hi John,
Let me explain what needs to be done for this problem.
First of all you told that you need to append the number. for this there is a small code which you should write . Here is the code.
data: val type string. " val holds the actual text number.
data: test type c. " test holds which number the user clicks
concatenate val test into val. " concatenate the value of the total with the click no.Please add this code and you will definately get the output as what you want.
‎2007 Jan 15 4:48 AM
This is what my program source code looks like right now (what am i doing wrong)?
PROGRAM zdcal .
DATA: ok_code(4) TYPE c,
result TYPE P,
result_temp type string,
RESULT_BUT(20) TYPE C.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE status_0100 OUTPUT.
SET PF-STATUS 'CALCULATOR'.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
RESULT_TEMP = RESULT.
MODULE user_command_0100 INPUT.
CASE ok_code.
break-point.
WHEN 'B1'.
result = 1.
WHEN 'B2'.
result = 2.
WHEN 'B3'.
result = 3.
WHEN 'B4'.
result = 4.
WHEN 'B5'.
result = 5.
WHEN 'B6'.
result = 6.
WHEN 'B7'.
result = 7.
WHEN 'B8'.
result = 8.
WHEN 'B9'.
result = 9.
WHEN 'B0'.
result = 0.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'BCL'.
CLEAR result.
WHEN OTHERS.
ENDCASE.
RESULT_BUT = RESULT.
IF RESULT <> SPACE.
CONCATENATE RESULT_TEMP RESULT_BUT INTO RESULT_TEMP.
ENDIF.
RESULT_TEMP = RESULT.
ENDMODULE. " USER_COMMAND_0100 INPUT
‎2015 Apr 05 8:35 AM