2013 Dec 14 10:18 PM
Hello Everyone,
I am new to module pool programming. I want to know how to create quiz. here,i have to create couple of questions using screen painter. then the user should choose the correct answer and the result has to be displayed.i have been thinking different ways to do it. but could not get the correct one. any suggestion please.
2013 Dec 16 7:18 AM
Hello Maya
First You require Ztable fields
1.for mandt
2. For index int
3.for Question
4.for opt 1
5.for opt2
6.for opt3
7.for opt4
8.for right answer
Set Screen 100
wa-name1
wa-opt1
wa-opt2
wa-opt3
wa-opt4
same setting
Alloptions
is Set For Option & NAme
all options modif id must be same
DATA: lcl_random TYPE REF TO cl_abap_random_int,
v_min TYPE i,
v_max TYPE i,
v_random TYPE i.
CHECK sy-subrc = 0.
MOVE: v_from TO v_min,
v_to TO v_max.
* Get the Random Number generator class instance
module status_0100 output.
if wa-name1 is initial.
TRY.
lcl_random = cl_abap_random_int=>create( min = 1
max = v_max ).
CATCH cx_abap_random.
ENDTRY.
DO.
* Get the Random Number:
v_random = lcl_random->get_next( ).
Select Single * from Ztable where
index = v_random.
Set your Varient name in here
wa-name1 = ztable-myQuestion.
wa-opt1 = ztable-opt1.
wa-opt2 = ztable-opt2.
wa-opt3 = ztable-opt3.
wa-opt4 = ztable-opt4.
endif.
endmodule.
modif id
module user_command_0100 input.
case sy-ucomm.
when 'PROC'.
check answer is true or false .& code for next Question.
endcase.
endmodule.
2013 Dec 15 12:45 AM
If I were teaching, I would do it differently:
Questions, possible answers, correct answers in an ITab (or set of itabs). Loop at itab. Call modeless dialog 1 feeding it question and possible answers. Modeless dialog has radio buttons for choosing among the possible answers and a done button (or submit) for the student to submit a final answer. On retiurn, correct/incorrect calculations are done. Then the second modeless dialog gets the given answer and the correct answer. At the end a report can give the grade.
I know that's not exactly what you asked for, but is it viable?
Neal
2013 Dec 15 4:48 AM
Thank you neal. that's quite what i asked. but i have problem with the coding. can you please elaborate.
2013 Dec 15 5:22 AM
Hi Maya,
I remember having done this project long time before, though it was using Javascripts and Servlets.
1. First step would be to create database for the questions.
The fields could be like -
1. Question
2. Option a
3. Option b
4. Option c
5. Option d
6. Correct answer (a,b,c,d)
2. Create the screen in the screen painter with a text field for question, four radio buttons and four text fields for the options. Other buttons can also be added like going to the previous question and going to the next question, Get results, Quit, go to first question, go to last question etc.
3. In the PBO, use a function to randomly select a distinct question from database. Update it to an internal table. The internal table would ideally have all the fields in the database table in addition to answer given by candidiate and a flag to denote right or wrong. Populate the screen painter with the questions and the options.
4. In the PAI, update the internal table with the answer submitted by candidate. For this you need to give a function code for the radio button and handle that function code. Everytime a question is answered, update the internal table with the answer and the flag as correct or wrong.
Also handle other events like going to previous question, first question, get results etc in the PAI. Going to previous questions or first question can be handled by retrieving the data from internal table. And going to next question by taking the next distinct question from database (of course, only till the maximum number of questions have been asked) if current question is the last record in the internal table, or picking the next question from the internal table depending on the current displayed question.
On the button click for getting results, calculate the number of correct answers.
5. If you want to store the history of results, update the results in another database table with the results, giving the candidate name, date, time, score etc. For this you may have to give an addition screen in the beginning to input the candidate details.
Hope that would help you build the program. All the best. !.
2013 Dec 15 5:45 AM
Thank you susmitha. I did the same as you have described. But,the answers are not fetched from the internal table. is there any sample program for this scenario ?
2013 Dec 15 5:58 AM
I dont have any. Can you share your code so that we can check why the answers are not fetched ?
2013 Dec 15 7:24 AM
2013 Dec 15 2:08 PM
Start with just constants / hardcoded. Say 4 questions. 16 possible answers. 4 correct answers.
So your first screen is driven by an FM and also fully contained there. Nice for testing. The FM has parameters Question, PAns1, PAns2, PAns3, PAns4. It returns GAns.
Can you get that far?
Neal
2013 Dec 16 7:18 AM
Hello Maya
First You require Ztable fields
1.for mandt
2. For index int
3.for Question
4.for opt 1
5.for opt2
6.for opt3
7.for opt4
8.for right answer
Set Screen 100
wa-name1
wa-opt1
wa-opt2
wa-opt3
wa-opt4
same setting
Alloptions
is Set For Option & NAme
all options modif id must be same
DATA: lcl_random TYPE REF TO cl_abap_random_int,
v_min TYPE i,
v_max TYPE i,
v_random TYPE i.
CHECK sy-subrc = 0.
MOVE: v_from TO v_min,
v_to TO v_max.
* Get the Random Number generator class instance
module status_0100 output.
if wa-name1 is initial.
TRY.
lcl_random = cl_abap_random_int=>create( min = 1
max = v_max ).
CATCH cx_abap_random.
ENDTRY.
DO.
* Get the Random Number:
v_random = lcl_random->get_next( ).
Select Single * from Ztable where
index = v_random.
Set your Varient name in here
wa-name1 = ztable-myQuestion.
wa-opt1 = ztable-opt1.
wa-opt2 = ztable-opt2.
wa-opt3 = ztable-opt3.
wa-opt4 = ztable-opt4.
endif.
endmodule.
modif id
module user_command_0100 input.
case sy-ucomm.
when 'PROC'.
check answer is true or false .& code for next Question.
endcase.
endmodule.
2013 Dec 17 5:17 AM
thank you all . Thank you mohit.I got the output.I did exactly what you mention above and it was very helpful.
2013 Dec 17 5:18 AM