2009 Apr 13 5:54 AM
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.
2009 Apr 13 6:10 AM
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.
2009 Apr 13 6:12 AM
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
2009 Apr 13 6:13 AM
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!
2009 Apr 13 6:16 AM
i have tried removing that clear statement but still the problem has not been resolved.
2009 Apr 13 6:20 AM
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
2009 Apr 13 6:27 AM
hi surinder
but the problem still persists. now the total logic is getting changed and the desired output is not displayed.
thanks.
2009 Apr 13 6:30 AM
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
2009 Apr 13 6:36 AM
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
2009 Apr 13 6:46 AM
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
2009 Apr 13 6:47 AM
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
2009 Apr 13 6:48 AM
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
2009 Apr 13 6:15 AM
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
2009 Apr 13 6:16 AM
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
2009 Apr 13 6:48 AM
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.
2009 Apr 13 8:07 AM
2009 Apr 13 8:11 AM
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.
2009 Apr 15 4:57 AM
if am declearing both the fields with same name the first value only getting added. the second value is the problem.please help.
2009 Apr 15 5:16 AM
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
2009 Apr 15 5:41 AM
2009 Apr 15 6:41 AM
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..
2009 Apr 15 6:53 AM
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
2009 Apr 15 7:13 AM
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.
2009 Apr 15 8:12 AM