Application Development 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: 

calculator logic

Former Member
0 Kudos
195

hi experts

i am facing problem in module pool prgramming for calculator logic. my coding is like this

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

endif.

clear output.

if loc1 is not initial.

move output to loc2.

w_output1 = output.

loc2 = w_output1.

endif.

clear output.

WHEN 'EQUAL'.

s_output = loc1 + loc2.

output = s_output.

while in debugging i found that loc1 contains value but loc2 does not. if i am adding the result is coming as loc1loc1 ie eventhough the coding is loc1loc2 the value of loc1 is added and displayed at the output. and i am also finding that loc2 also contains the value of loc1.

please help me in resolving this problem.

23 REPLIES 23

former_member438956
Active Participant
0 Kudos
149

make sure that u clear all the variables before calling the PAI module so that the variable contains the latest value entered.

Regards,

Anil N.

dev_parbutteea
Active Contributor
0 Kudos
149

Hi,

There should have been another variable for loc2 instead of output unless u want same value for loc1 and loc2

clear output.

if loc1 is not initial.

move output to loc2. "

w_output1 = output.

loc2 = w_output1.

endif.

Edited by: Dev Parbutteea on Apr 13, 2009 7:15 AM

Former Member
0 Kudos
149

Hi sriramlal,

WHEN 'ADD'.
if loc1 is initial.
move output to loc1.
w_output = output.
loc1 = w_output.
endif.
clear output.        " Remove this line
if loc1 is not initial.
move output to loc2.
w_output1 = output.
loc2 = w_output1.
endif.
clear output.
WHEN 'EQUAL'.
s_output = loc1 + loc2.
output = s_output.

why are u clearing the output, as u are moving that to loc2

hope it works

Thanks!

0 Kudos
149

i have tried removing that clear statement but still the problem has not been resolved.

0 Kudos
149

Hi Prasanth and Ravi,

If he just removes that clear statement then in the same loop it will put the same value in both loc1 and loc2 because in the first instance say loc1 is initial it will do the processing and when it will get out of that if statement and then loc1 will not be initial and put the smae value in loc2 as well.

Cheers,

Surinder

0 Kudos
149

hi surinder

but the problem still persists. now the total logic is getting changed and the desired output is not displayed.

thanks.

0 Kudos
149

Hi,

Try putting the clear statement in the if clause.

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

clear output.

endif.

if loc1 is not initial.

move output to loc2.

w_output1 = output.

loc2 = w_output1.

clear output.

endif.

WHEN 'EQUAL'.

s_output = loc1 + loc2.

output = s_output.

Cheers,

Surinder

0 Kudos
149

in debugging i found that loc2 does not contains any value. if i am removing the clear statement then the value of loc1 is going into loc2 and gives me wrong output.

thanks.

Edited by: sriramlal on Apr 13, 2009 7:39 AM

0 Kudos
149

Hi,

If i understand you insert first value and click add (OK_CODE = 'ADD') then the second and you click equal (OK_CODE = 'EQUAL').

Is it right right?

The problem is that when you click equal you don't perform any assignment because the block ADD is not executed in the PAI.

WHEN 'ADD'.
if loc1 is initial.
move output to loc1.
w_output = output.
loc1 = w_output.
endif.
clear output.
WHEN 'EQUAL'.
if loc1 is not initial.                  "start moving
move output to loc2.
w_output1 = output.
loc2 = w_output1.
endif.
clear output.                  "end moving
s_output = loc1 + loc2.
output = s_output.

Regards,

Ivan

0 Kudos
149

Hi,

If you want just add to work.

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

clear output.

endif.

WHEN 'EQUAL'.

if loc1 is not initial.

move output to loc2.

w_output1 = output.

loc2 = w_output1.

clear output.

endif.

s_output = loc1 + loc2.

output = s_output.

Cheers,

Surinder

0 Kudos
149

Hi,

try code

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc2 = w_output.

else.

move output to loc2.

w_output1 = output.

loc1 = w_output1.

endif.

clear output.

thanks

ravi

Former Member
0 Kudos
149

Hi,

WHEN 'ADD'.
if loc1 is initial.
move output to loc1.
w_output = output.
loc1 = w_output.
endif.
clear output.                    " Remove this statement & donot clear the value of output
if loc1 is not initial.
move output to loc2.
w_output1 = output.
loc2 = w_output1.
endif.

this will work

thanks

ravi

Former Member
0 Kudos
149

Hi,

Try this

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

else.

move output to loc2.

w_output1 = output.

loc2 = w_output1.

endif.

clear output.

Cheers,

Surinder

awin_prabhu
Active Contributor
0 Kudos
149

Just use only below code.

WHEN 'ADD'.

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

clear output.

endif.

WHEN 'EQUAL'.

s_output = loc1 + loc2.

output = s_output.

0 Kudos
149

but hten wat will be the value of loc2.

0 Kudos
149

Hi

Declare input and output fields with same name in both program and screen layout.

Values will be automatically get collected inside program in those variables.

0 Kudos
149

if am declearing both the fields with same name the first value only getting added. the second value is the problem.please help.

0 Kudos
149

Hi,

Dont declare both the fields with same name.

I said declare fields inside program with same names as given in Screen Painter.

In screen painter, double click on the first input field, in 'NAME' field give as loc1.

Double click on the second input field, in 'NAME' field give as loc2.

Double click on the output field, in 'NAME' field give as output.

In program,

In Top include declare fields as,

DATA: output, <--- Output field

loc1, <--- Input field1

loc2. <--- Input field2

Thanks

0 Kudos
149

can u please explain in detail??

thanks

0 Kudos
149

Hi,

Open SE80.

Enter 'Program' name.

Expand 'Screen', double click on screen number.

Open 'Layout'.

Drag & drop 3 Input/Output fields.

Double click on the first input field, and in 'NAME' field give 'loc1'.

Make sure the field has length 5. U can see length in 'Lg' field at the top. Set it to 5.

Double click on the second input field, in 'NAME' field give 'loc2'.

Make sure the field has length 5. U can see length in 'Lg' field at the top. Set it to 5.

Double click on the output field, in 'NAME' field give 'output'.

Make sure the field has length 10. U can see length in 'Lg' field at the top. Set it to 10.

Drag & drop a 'Push Button'.

Double click on the second 'Push Button', and in 'NAME' field give 'EQUAL', and in 'FctCode' field give 'EQUAL'.

Activate the screen.

Close 'Layout'.

Now double click on screen number.

Click 'Flow Logic' tab.

Uncomment the line in PAI -> MODULE USER_COMMAND_2000.

Double click on it.

Create the module.

Inside it use below code,

MODULE user_command_2000 INPUT.

DATA: ok_code TYPE sy-ucomm,

output(10),

loc1(5),

loc2(5),

s_output(10).

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'EQUAL'.

s_output = loc1 + loc2.

output = s_output.

ENDCASE.

ENDMODULE. " USER_COMMAND_2000 INPUT

Activate all.

Create a Transaction.

Run it.

Thanks..

0 Kudos
149

thanks for your detailed explanation.

actually my condition is not to give any input fields in screen painter.

genrally in calculator if i press 7 the output should display as 7. for me 7 is the input which is displaying 7 at the output. then wat is the need for declearing input fields seperately in screen painter.

thanks

0 Kudos
149

Hi Sri,

I think,

U use a flag 'f' in case 'ADD',

WHEN 'ONE'.

if f = 1.

f = 0.

loc2 = 1. <-- Getting value into loc2

else.

loc1 = 1. <-- Getting value into loc1

endif.

WHEN 'ADD'.

f = 1. <-- Add

if loc1 is initial.

move output to loc1.

w_output = output.

loc1 = w_output.

endif.

clear output.

if loc1 is not initial.

move output to loc2.

w_output1 = output.

loc2 = w_output1.

endif.

clear output.

WHEN 'EQUAL'.

s_output = loc1 + loc2.

output = s_output.

0 Kudos
149

but still i am not gettin value in loc2.

thanks