Skip to Content
avatar image
Former Member

Push buttons in module pool are not working correctly

Hi all,

i have made a simple module pool program on water puzzle . i have 8, 5 and 3 liter container and i need to fill at least one with 4 liter of water to solve the problem. so i made 6 different push buttons for moving water quantity from one to other container.

the coding is as follows:

case ok_code.

when 'mo85'.      " for moving water from 8L container to 5L

     perform first_routine.

when 'mo83'.      " for moving water from 8L container to 3L       "

     perform second_routine.

when 'mo58'.      " for moving water from 5L container to 8L

     perform third_routine.

when 'mo53'.      " for moving water from 5L container to 3L

     perform fourth_routine.

when 'mo38'.      " for moving water from 3L container to 8L

     perform fifth_routine.

when 'mo35'.      " for moving water from 3L container to 5L

     perform sixth_routine.

and the screen looks as follows:

so when i press the any button from the six listed for the first time it works but when i press any other button from the six it does not work.

for example i moved water from 8l to 5l so i pressed button "move to 5l" as shown in image . it worked but when i tried other button say "move to 3l" it did not work. where as the clear and result buttons are working fine.

what to do?

YWATER.PNG (30.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

9 Answers

  • Best Answer
    Sep 09, 2015 at 05:16 PM

    Hi Niketa,

    View the code, hope it helpful to avoid nested conditions.

    DATA : GLASS8(12) TYPE C  VALUE '8',

             GLASS5(12) TYPE C VALUE '1',

             GLASS3(12) TYPE C,

             lv_num     TYPE i,

             lv_result  TYPE i.

    CONSTANTS: c_val(01) value '5'.

    IF glass8 IS NOT INITIAL.

    CLEAR: lv_num.

    DO.

    CLEAR  lv_result.

    IF glass5 EQ c_val.

    lv_num = c_val.

    EXIT.

    ELSE.

    ADD 1 to lv_num.

    lv_result = glass5 + lv_num.

    CHECK lv_result EQ c_val.

    EXIT.

    ENDIF.

    ENDDO.

    glass5 = glass5 + lv_num.

    glass8 = glass8 - lv_num.

    ENDIF.

    Regards,

    Venkat.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 09, 2015 at 08:57 AM

    Hi Niketa,

    This is because in your case statement fetch codes are written in small letters, make it capital.

    Example : when 'mo85' , make it when 'MO85'.

    Hope this helps.

    Regards,

    Shadab.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Shadab Maldar

      hi shadab,

      did that all same and as u said all the fetch codes are capital.

      to solve i removed the routines and the required steps i added them into case itself.

      what i mean is

      case ok_code.

      when 'MO85'.

           if condition.    "first if

                if condition.   "second if

                     "required task.

                elseif

                     "required task.

                endif.

      endif.

      but now when the button is pressed and it goes to correct if then its not implementing the inner loop.

      i.e. it going to first if rather than going to second if it exits the statement.

      Push buttons in module pool are not working correctly

  • avatar image
    Former Member
    Sep 09, 2015 at 06:42 PM

    Hi niketa,

    I worked on your game and tried to make the coding as per your game rule.

    Have a look at the code and reply whether it is correct or not.

    thanks.

    REPORT  ZR_WATER_PUZZLE.

    DATA OK_CODE TYPE SY-UCOMM.

    DATA: 8L type i VALUE 8,
           5L type i ,
           3L type i.


    CALL SCREEN 100.
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'ZSTATUS'.
    *  SET TITLEBAR 'xxx'.

    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE USER_COMMAND_0100 INPUT.
    CASE OK_CODE.
       WHEN 'RETURN' OR 'BACK' OR 'CANCEL'.
         LEAVE PROGRAM.
       WHEN 'M8_5'.
         PERFORM M8_5.  "Moving from 8 TO 5
       WHEN 'M8_3'.
         PERFORM M8_3. "Moving from 8 TO 3
       WHEN 'M5_8'.
         PERFORM M5_8. "Moving from 5 TO 8
       WHEN 'M5_3'.
         PERFORM M5_3. "Moving from 5 TO 3
       WHEN 'M3_8'.
         PERFORM M3_8. "Moving from 3 TO 8
       WHEN 'M3_5'.
         PERFORM M3_5. "Moving from 3 TO 5
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Form  M8_5
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M8_5 .
       DATA N TYPE I.
       N = 8L.
       WHILE N > 0.
         IF N = 0 OR 5L = 5.
           EXIT.
         ENDIF.

         5L = 5L + 1.
         8L = 8L - 1.
         N = N - 1.

       ENDWHILE.

    ENDFORM.                    " M8_5
    *&---------------------------------------------------------------------*
    *&      Form  M8_3
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M8_3 .
    DATA N TYPE I.
       N = 8L.
       WHILE N > 0.
         IF N = 0 OR 3L = 3.
           EXIT.
         ENDIF.

         3L = 3L + 1.
         8L = 8L - 1.
         N = N - 1.

       ENDWHILE.

    ENDFORM.                    " M8_3
    *&---------------------------------------------------------------------*
    *&      Form  M5_8
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M5_8 .
    DATA N TYPE I.
       N = 5L.
       WHILE N > 0.
         IF N = 0 OR 8L = 8.
           EXIT.
         ENDIF.

         8L = 8L + 1.
         5L = 5L - 1.
         N = N - 1.

       ENDWHILE.

    ENDFORM.                    " M5_8
    *&---------------------------------------------------------------------*
    *&      Form  M5_3
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M5_3 .

    DATA N TYPE I.
       N = 5L.
       WHILE N > 0.
         IF N = 0 OR 3L = 3.
           EXIT.
         ENDIF.

         3L = 3L + 1.
         5L = 5L - 1.
         N = N - 1.

       ENDWHILE.

    ENDFORM.                    " M5_3
    *&---------------------------------------------------------------------*
    *&      Form  M3_8
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M3_8 .
    DATA N TYPE I.
       N = 3L.
       WHILE N > 0.
         IF N = 0 OR 8L = 8.
           EXIT.
         ENDIF.

         8L = 8L + 1.
         3L = 3L - 1.
         N = N - 1.

       ENDWHILE.


    ENDFORM.                    " M3_8
    *&---------------------------------------------------------------------*
    *&      Form  M3_5
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM M3_5 .
    DATA N TYPE I.
       N = 3L.
       WHILE N > 0.
         IF N = 0 OR 5L = 5.
           EXIT.
         ENDIF.

         5L = 5L + 1.
         3L = 3L - 1.
         N = N - 1.

       ENDWHILE.


    ENDFORM.                    " M3_5

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi abdul,

      yeah it worked and thanks again for helping but as i made it in module pool , i did not used statement "call screen 0100". and also this code helped me alot .

      thanx again.

  • avatar image
    Former Member
    Sep 09, 2015 at 08:46 AM

    Hi Niketa,

    check your coding about handling the buttons. Probably something is missing at the end of the routine of every button like the step of going back to the main screen, restore values etc..

    Check with debugging why program responds when you press the firs time why not the second time, and compare. There must be a difference btw the two cases.

    Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi llie,

      thanks for the help. as u suggested i did the debugging and what i understood from it was that the second time when i press the button it goes to the routine but did not implement the steps specified and instantly comes out of it.

  • avatar image
    Former Member
    Sep 09, 2015 at 09:15 AM

    hi,niketa,

                ok code is clearing,so check ok code in debugging.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 09, 2015 at 09:30 AM

    hi,

      as per input given,logic is not a problem only ok code is problem,so first check screen push button fctcode and module user_command input check for ok_code,both should be same.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi vinodh,

      did what u said and still everything seems ok . i m pasting the code please have a look.

      DATA : GLASS8(12) TYPE C,

              GLASS5(12) TYPE C,

              GLASS3(12) TYPE C,

              SUM(12) TYPE C.

      DATA: OK_CODE TYPE SY-UCOMM,

             FLAG TYPE C.

      *&---------------------------------------------------------------------*

      *&      Module  STATUS_0500  OUTPUT

      *&---------------------------------------------------------------------*

      *       text

      *----------------------------------------------------------------------*

      MODULE STATUS_0500 OUTPUT.

         SET PF-STATUS 'STATUS'.

         IF FLAG IS INITIAL.

           GLASS8 = '8'.

           GLASS5 = '0'.

           GLASS3 = '0'.

         ENDIF.

         SET TITLEBAR 'TITLE'.

      ENDMODULE.                 " STATUS_0500  OUTPUT

      *&---------------------------------------------------------------------*

      *&      Module  USER_COMMAND_0500  INPUT

      *&---------------------------------------------------------------------*

      *       text

      *----------------------------------------------------------------------*

      MODULE USER_COMMAND_0500 INPUT.

         FLAG = 'X'.

      CASE OK_CODE.

         WHEN 'BACK' OR 'CANCEL'.

             LEAVE TO SCREEN 0.

         WHEN 'EXIT'.

             LEAVE PROGRAM.

         WHEN 'MO85'.

        IF glass8 eq '8'.

             IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 5.

                 glass8 = glass8 - 5.

             ENDIF.

        ELSEIF glass8 eq '7'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 5.

                 glass8 = glass8 - 5.

            ENDIF.

        ELSEIF glass8 eq '6'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 5.

                 glass8 = glass8 - 5.

            ENDIF.

        ELSEIF glass8 eq '5'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 5.

                 glass8 = glass8 - 5.

            ENDIF.

        ELSEIF glass8 eq '4'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 4.

                 glass8 = glass8 - 4.

            ENDIF.

        ELSEIF glass8 eq '3'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 3.

                 glass8 = glass8 - 3.

            ENDIF.

        elseif glass8 eq '2'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 2.

                 glass8 = glass8 - 2.

            ENDIF.

        ELSEIF glass8 eq'1'.

            IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 1.

                 glass8 = glass8 - 1.

            ENDIF.

        ENDIF.

         WHEN 'MO83'.

        if glass8 eq '8'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '7'.

              IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '6'.

              IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '5'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '4'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '3'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass8 = glass8 - 3.

           ENDIF.

        ELSEIF glass8 eq '2'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 2.

                 glass8 = glass8 - 2.

           ENDIF.

        ELSEIF glass8 eq '1'.

            IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 1.

                 glass8 = glass8 - 1.

           ENDIF.

        ENDIF.

         WHEN 'MO58'.

        IF glass5 eq '5'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

                ELSEIF glass8 eq '7'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '6'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '5'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '4'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

                ELSEIF glass8 eq '3'.

                  glass8 = glass8 + 5.

                  glass5 = glass5 - 5.

                ELSEIF glass8 eq '2'.

                  glass8 = glass8 + 5.

                  glass5 = glass5 - 5.

                ELSEIF glass8 eq '1'.

                  glass8 = glass8 + 5.

                  glass5 = glass5 - 5.

                ELSEIF glass8 eq '0'.

                  glass8 = glass8 + 5.

                  glass5 = glass5 - 5.

             ENDIF.

        ELSEIF glass5 eq '4'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

                ELSEIF glass8 eq '7'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '6'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '5'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '4'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

                ELSEIF glass8 eq '3'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

                ELSEIF glass8 eq '2'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

                ELSEIF glass8 eq '1'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

                ELSEIF glass8 eq '0'.

                  glass8 = glass8 + 4.

                  glass5 = glass5 - 4.

             ENDIF.

        ELSEIF glass5 eq '4'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

                ELSEIF glass8 eq '7'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '6'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '5'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '4'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '3'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '2'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '1'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

                ELSEIF glass8 eq '0'.

                  glass8 = glass8 + 3.

                  glass5 = glass5 - 3.

             ENDIF.

        ELSEIF glass5 eq '4'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

                ELSEIF glass8 eq '7'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '6'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '5'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '4'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '3'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '2'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '1'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

                ELSEIF glass8 eq '0'.

                  glass8 = glass8 + 2.

                  glass5 = glass5 - 2.

             ENDIF.

        ELSEIF glass5 eq '4'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

                ELSEIF glass8 eq '7'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '6'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '5'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '4'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '3'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '2'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '1'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

                ELSEIF glass8 eq '0'.

                  glass8 = glass8 + 1.

                  glass5 = glass5 - 1.

             ENDIF.

        ENDIF.

         WHEN 'MO53'.

        IF glass5 eq '5'.

             IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass5 = glass5 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass5 = glass5 - 3.

             ENDIF.

        ELSEIF glass5 eq '4'.

             IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass5 = glass5 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass5 = glass5 - 3.

             ENDIF.

        ELSEIF glass5 eq '3'.

             IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass5 = glass5 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 3.

                 glass5 = glass5 - 3.

             ENDIF.

        ELSEIF glass5 eq '2'.

             IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 2.

                 glass5 = glass5 - 2.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 2.

                 glass5 = glass5 - 2.

             ENDIF.

        ELSEIF glass5 eq '1'.

             IF glass3 eq '3'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass3 eq '2'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '1'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

               ELSEIF glass3 eq '0'.

                 glass3 = glass3 + 1.

                 glass5 = glass5 - 1.

             ENDIF.

        ENDIF.

         WHEN 'MO35'.

        IF glass3 eq '3'.

             IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 3.

                 glass3 = glass3 - 3.

             ENDIF.

        ELSEIF glass3 eq '2'.

             IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 2.

                 glass3 = glass3 - 2.

             ENDIF.

        ELSEIF glass3 eq '1'.

             IF glass5 eq '5'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass5 eq '4'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '3'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '2'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '1'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass5 eq '0'.

                 glass5 = glass5 + 1.

                 glass3 = glass3 - 1.

             ENDIF.

        ENDIF.

         WHEN 'MO38'.

        IF glass3 eq '3'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass8 eq '7'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '6'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '5'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass8 eq '4'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass8 eq '3'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass8 eq '2'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass8 eq '1'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

               ELSEIF glass8 eq '0'.

                 glass8 = glass8 + 3.

                 glass3 = glass3 - 3.

             ENDIF.

        ELSEIF glass3 eq '2'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass8 eq '7'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '6'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '5'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '4'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '3'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '2'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '1'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

               ELSEIF glass8 eq '0'.

                 glass8 = glass8 + 2.

                 glass3 = glass3 - 2.

             ENDIF.

        ELSEIF glass3 eq '1'.

             IF glass8 eq '8'.

                 MESSAGE 'GLASS CAPACITY IS FULL. YOU CANNOT ADD MORE WATER' TYPE 'I'.

               ELSEIF glass8 eq '7'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '6'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '5'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '4'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '3'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '2'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '1'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

               ELSEIF glass8 eq '0'.

                 glass8 = glass8 + 1.

                 glass3 = glass3 - 1.

             ENDIF.

        ENDIF.

         WHEN 'RESULT'.

             SUM = GLASS8 + GLASS3 + GLASS5.

             IF GLASS8 EQ '4' AND SUM EQ '8'.

               MESSAGE 'CONGRATULATIONS! YOU HAVE SOLVED THE PUZZLE.' TYPE 'I'.

             ELSEIF GLASS5 EQ '4' AND SUM EQ '8'.

               MESSAGE 'CONGRATULATIONS! YOU HAVE SOLVED THE PUZZLE.' TYPE 'I'.

             ELSE.

               MESSAGE 'SORRY! THIS IS NOT THE SOLUTION OF THE PUZZLE. KINDLY READ THE QUESTION AGAIN AND TRY AGAIN.' TYPE 'I'.

            ENDIF.

         WHEN 'CLEAR'.

             glass5 = '0'.

             glass3 = '0'.

             glass8 = '8'.

      ENDCASE.

      ENDMODULE.                 " USER_COMMAND_0500  INPUT

  • avatar image
    Former Member
    Sep 09, 2015 at 10:07 AM

    HI,

    Instead of using ok code just try sy-ucomm for case statement directly.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi,

      did that .

      Its taking the right fctcode and going to the right case as well. but the problem is that nested ifs are not implemented even when the condition is true.

      what should i do?

  • avatar image
    Former Member
    Sep 09, 2015 at 10:22 AM

    hi,

    declare glass 5,glass 8,glass 3 type as I(integer).

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 05, 2015 at 03:42 PM

    Hi Niketa,

    Make OK Code as Capital in between ' '.

    and use CEAR ok_code as below for all cases.

    CASE ok_code.

    WHEN 'M3_5'

    CLEAR ok_code.

    ,,

    ,,

    ,,,

    ENDCASE.

    Regards,

    Sivanadh

    Add comment
    10|10000 characters needed characters exceeded