Application Development and Automation 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: 
Read only

Where to write a code of changing screen fields?

hagit
Active Participant
0 Likes
2,794

Hello experts,

In selection screen there is:

1. A parameter

2. A radio group with 2 buttons

The parameter can be updated by a user, and also by pressing the radio button.

The question is in which event the code of updating the parameter should be written.

As mentioned in another question (' At SELECTION-SCREEN on RADIOBUTTON GROUP event') https://answers.sap.com/questions/13156222/at-selection-screen-on-radiobutton-group-event.html

ABAP fields are overwritten by their corresponding screen fields. Except for special cases. (input is disabled OR when the field was initially blank, and no data is input in it by a user).

This leads to a conclusion that it is better to update ABAP fields (which influence screen fields) after all screen fields were copied to ABAP fields. (in order not to overwrite the update). As far as I know:

  • AT SELECTION-SCREEN on <field> event copies the screen field to its ABAP field
  • The events AT SELECTION-SCREEN and AT SELECTION-SCREEN OUTPUT are fired after all AT SELECTION-SCREEN <field> were fired.

The question is where is it better to write the code which updates an ABAP field? In AT SELECTION-SCREEN or AT SELECTION-SCREEN OUTPUT?

In the following code- Is it better to put the code in line 15 or in line 18?

REPORT ztry8.
PARAMETER p_add_1 RADIOBUTTON GROUP grp1  USER-COMMAND grp1_pressed DEFAULT 'X'.
PARAMETER p_add_2 RADIOBUTTON GROUP grp1 .
PARAMETER p_txt TYPE i.

AT SELECTION-SCREEN OUTPUT.
  PERFORM add. "line 15

AT SELECTION-SCREEN.
  PERFORM add. "line 18

FORM add.
  IF p_add_1 = abap_true.
    p_txt = p_txt + 1 . "line
  ELSE.
    p_txt = p_txt + 2 .
  ENDIF.
ENDFORM. "add

Thank you

1 ACCEPTED SOLUTION
Read only

patil477pavan
Explorer
2,621

Hi ,

It is better to put at EVENT -

ATSELECTION-SCREEN as this is used for validations and performing some actions as mentioned in subroutine ( FORM add ) [when user enters the values in the fields of the selection screen and clicks on execution button, this event gets triggered. This event is basically for checking the value entered by the user for the field of the selection screen i.e data validity checking]

whereas EVENT-

ATSELECTION-SCREENOUTPUT is used for doing screen level changes on certain actions like dynamic screen modifications - it executes just like PBO Event of Module Pool Programing.

Ans : ATSELECTION-SCREEN

Regards,

Pavan

Hello experts,

In selection screen there is:

1. A parameter

2. A radio group with 2 buttons

The parameter can be updated by a user, and also by pressing the radio button.

The question is in which event the code of updating the parameter should be written.

As mentioned in another question (' At SELECTION-SCREEN on RADIOBUTTON GROUP event') https://answers.sap.com/questions/13156222/at-selection-screen-on-radiobutton-group-event.html

ABAP fields are overwritten by their corresponding screen fields. Except for special cases. (input is disabled OR when the field was initially blank, and no data is input in it by a user).

This leads to a conclusion that it is better to update ABAP fields (which influence screen fields) after all screen fields were copied to ABAP fields. (in order not to overwrite the update). As far as I know:

  • AT SELECTION-SCREEN on <field> event copies the screen field to its ABAP field
  • The events AT SELECTION-SCREEN and AT SELECTION-SCREEN OUTPUT are fired after all AT SELECTION-SCREEN <field> were fired.

The question is where is it better to write the code which updates an ABAP field? In AT SELECTION-SCREEN or AT SELECTION-SCREEN OUTPUT?

In the following code- Is it better to put the code in line 15 or in line 18?

REPORT ztry8.
PARAMETER p_add_1 RADIOBUTTON GROUP grp1  USER-COMMAND grp1_pressed DEFAULT 'X'.
PARAMETER p_add_2 RADIOBUTTON GROUP grp1 .
PARAMETER p_txt TYPE i.

AT SELECTION-SCREEN OUTPUT.
  PERFORM add. "line 15

AT SELECTION-SCREEN.
  PERFORM add. "line 18

FORM add.
  IF p_add_1 = abap_true.
    p_txt = p_txt + 1 . "line
  ELSE.
    p_txt = p_txt + 2 .
  ENDIF.
ENDFORM. "add

Thank you

8 REPLIES 8
Read only

FredericGirod
Active Contributor
2,621

The event AT SELECTION-SCREEN itself is raised as the last event in selection screen processing if all the input values were passed to the program. All user input can be checked in this event block. Sending a warning or an error message in the event block makes all the screen fields ready for input once again.



OUTPUT

This event is raised by the dynpro event PBO of a selection screen. In the event block, the selection screen can be prepared using assignments to the data objects of parameters and selection criteria and using dynamic screen modifications.

Read only

patil477pavan
Explorer
2,622

Hi ,

It is better to put at EVENT -

ATSELECTION-SCREEN as this is used for validations and performing some actions as mentioned in subroutine ( FORM add ) [when user enters the values in the fields of the selection screen and clicks on execution button, this event gets triggered. This event is basically for checking the value entered by the user for the field of the selection screen i.e data validity checking]

whereas EVENT-

ATSELECTION-SCREENOUTPUT is used for doing screen level changes on certain actions like dynamic screen modifications - it executes just like PBO Event of Module Pool Programing.

Ans : ATSELECTION-SCREEN

Regards,

Pavan

Read only

hagit
Active Participant
2,621

patil477pavan , Thank for your answer

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,621

For sure, choose one or the other, don't mix modification at both PBO and PAI, that would be a mess.

I guess it's better to do it in the PAI because, if there's no error, further processing like call screen, update database, etc., may need to have the updated value (that would happen too late if you update it in the PBO).

Note that if an error message is sent (in the PAI obviously) you don't go through the PBO.

Read only

hagit
Active Participant
0 Likes
2,621

sandra.rossi , Just to be sure I understood you.

You wrote: Note that if an error message is sent (in the PAI obviously) you don't go through the PBO.

Do you mean that if the message has the type 'E' (like line 20 in the following code), than the process is stopped and PBO is not raised. But if the message has the type 'I' (like line 21 in the following code),than PBO is raised?

REPORT ztry8.
PARAMETER p_add_1 RADIOBUTTON GROUP grp1  USER-COMMAND grp1_pressed DEFAULT 'X'.
PARAMETER p_add_2 RADIOBUTTON GROUP grp1 .
PARAMETER p_txt TYPE i.

AT SELECTION-SCREEN OUTPUT.
  PERFORM add. "line 15
  MESSAGE 'pbo 2' TYPE 'I'.

AT SELECTION-SCREEN.
  PERFORM add. "line 18
*  MESSAGE 'pai' TYPE 'E'.   "LINE 20
  MESSAGE 'pai' TYPE 'I'. "LINE 21

FORM add.
  IF p_add_1 = abap_true.
    p_txt = p_txt + 1 . "line
  ELSE.
    p_txt = p_txt + 2 .
  ENDIF.
ENDFORM. "add
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,621

That should take you 2 seconds to test, no need to spend 2 minutes to write the question 😉

Read only

hagit
Active Participant
0 Likes
2,621

sandra.rossi I tested it before asking. And I noticed that the above is true. I just wanted to insure that this is what you meant

Read only

hagit
Active Participant
0 Likes
2,621

Frederic Girod thanks for your answer