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: 

Is there any significant difference?

Former Member
0 Kudos
99

these are my programs that demonstrate radio button. there are 2 versions and they have the same output and they are all working fine. I am just wondering why on version 1 (I got this pattern from a tutorial) I have to create sy-ucomm many times. On version 2, it looks more simple. I just want to know if version 1 has advantage/disadvantage over version 2 and vice versa. newbie here. <b>Thanks for the help. </b>

====================================

Code version 1

====================================

data: rb1(1), rb2(1), rb3(1), field1(10).
data: ok_code type sy-ucomm,
      save_ok type sy-ucomm.

initialization.
save_ok = ok_code.
clear ok_code.

start-of-selection.
  set screen 0100.

module pai input.
  case save_ok.
      when 'RADIO'.
          if RB1 = 'X'.
              field1 = 'option 1'.
          elseif RB2 = 'X'.
              field1 = 'option 2'.
          else.
              field1 = 'option 3'.
          endif.
  endcase.

  case sy-ucomm.
    when 'BTNEXIT'.
      leave program.
  endcase.
endmodule.

====================================

Code version 2

====================================

data: rb1(1), rb2(1), rb3(1), field1(10).

start-of-selection.
  set screen 0100.

module pai input.
  case sy-ucomm.
    when 'BTNEXIT'.
      leave program.
    when 'RADIO'.
          if RB1 = 'X'.
              field1 = 'option 1'.
          elseif RB2 = 'X'.
              field1 = 'option 2'.
          else.
              field1 = 'option 3'.
          endif.
  endcase.
endmodule.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
60

Hi Dawson,

In effect there is no difference between the two code samples:

In the first code,

we are storing the SY_UCOMM value to a varible and then using tthis variable to track the user actions (it is a recommended way in SAP, so that we can track the value of SY_UCOMM using this variable even in the PBO.)

But in the code sample, both are used, which is a little strange...

<b>underlying FACT...If there are N people coding for one requirement, the code can be of N different ways..........</b>

Hope this helps,

Sajan Joseph.

3 REPLIES 3

ferry_lianto
Active Contributor
0 Kudos
60

Hi,

Both options are fine and nothing wrong.

But I prefer the second option which is simple and easy to read/follow thru the logic.

Regards,

Ferry Lianto

Former Member
0 Kudos
61

Hi Dawson,

In effect there is no difference between the two code samples:

In the first code,

we are storing the SY_UCOMM value to a varible and then using tthis variable to track the user actions (it is a recommended way in SAP, so that we can track the value of SY_UCOMM using this variable even in the PBO.)

But in the code sample, both are used, which is a little strange...

<b>underlying FACT...If there are N people coding for one requirement, the code can be of N different ways..........</b>

Hope this helps,

Sajan Joseph.

Former Member
0 Kudos
60

Hello Mr. Dawson,

The code u have written is will work fine in both versions but I will prefer the first one because both the check are satisfied with a sigle CASE.. ENDCASE statement.

So U can ahead with the second version.

Regards,

Vasanth