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

slelection screen field validations

Former Member
0 Likes
1,158

hi experts,

how to validate a single field in the selection screen, i,e.. if a value in the selection is wrong and all the other values in the selection screen are correct then the curson should should blink at the 'wrong values entered field'. so how to validate it?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,122

Hi,

Below is the simple code which show how to validate selection screen elements...

DATA:
  w_matnr TYPE mara-matnr,
  w_werks TYPE marc-werks.

PARAMETERS:
  p_matnr LIKE mara-matnr,             " Material Number
  p_werks LIKE marc-werks.             " Plant

AT SELECTION-SCREEN .

  IF p_matnr IS NOT INITIAL.
    SELECT SINGLE matnr
      INTO w_matnr
      FROM mara
    WHERE matnr EQ p_matnr.

    CHECK sy-subrc NE 0.
    SET CURSOR FIELD 'P_MATNR'.
    MESSAGE 'Material Not Valid' TYPE 'E'.       " Invalid Material
  ENDIF.


  IF p_werks IS NOT INITIAL.
    SELECT SINGLE werks
      INTO w_werks
      FROM marc
    WHERE werks EQ p_werks.

    CHECK sy-subrc NE 0.
    SET CURSOR FIELD 'P_WERKS'.
    MESSAGE 'Plant Not Valid' TYPE 'E'.       " Invalid Plant
  ENDIF.

Best Regards,

Brijesh

9 REPLIES 9
Read only

Former Member
0 Likes
1,123

Hi,

Below is the simple code which show how to validate selection screen elements...

DATA:
  w_matnr TYPE mara-matnr,
  w_werks TYPE marc-werks.

PARAMETERS:
  p_matnr LIKE mara-matnr,             " Material Number
  p_werks LIKE marc-werks.             " Plant

AT SELECTION-SCREEN .

  IF p_matnr IS NOT INITIAL.
    SELECT SINGLE matnr
      INTO w_matnr
      FROM mara
    WHERE matnr EQ p_matnr.

    CHECK sy-subrc NE 0.
    SET CURSOR FIELD 'P_MATNR'.
    MESSAGE 'Material Not Valid' TYPE 'E'.       " Invalid Material
  ENDIF.


  IF p_werks IS NOT INITIAL.
    SELECT SINGLE werks
      INTO w_werks
      FROM marc
    WHERE werks EQ p_werks.

    CHECK sy-subrc NE 0.
    SET CURSOR FIELD 'P_WERKS'.
    MESSAGE 'Plant Not Valid' TYPE 'E'.       " Invalid Plant
  ENDIF.

Best Regards,

Brijesh

Read only

0 Likes
1,122

thanks brijexh, its working.........

regards,

venkat

Read only

0 Likes
1,122

Hi Venkat,

If ur query is answered, please close the thread .

Best regards,

Brijesh

Read only

Former Member
0 Likes
1,122

Hi Venkat,

Define the fields below the event

At Selection-Screen on block.

Regards,

Suresh.S

Read only

0 Likes
1,122

Hi,

you can validate single field validaions by using this syntax.

at selection-screen on <fieldname parameter/select-option>.

select single * from <dbtable> where condition.

if sy-dubrc ne 0.

error message.

endif.

Read only

former_member673464
Active Contributor
0 Likes
1,122

hi,

For your requirement you can use the selection-screen event at selection-screen on field.

AT SELECTION-SCREEN ON <field>

is triggered when the contents of each individual input field are passed from the selection screen to the ABAP program. The input field <field> can be checked in the corresponding event block. If an error message occurs within this event block, the corresponding field is made ready for input again on the selection screen.

Regards,

Veeresh

Read only

Former Member
0 Likes
1,122

Hiii!

Do the validation of that particular field in the event

AT SELECTION-SCREEN ON <field>.

By this event, only this field will be active, in case you put wrong value in it

Regards

Abhijeet Kulshreshtha

Read only

Former Member
0 Likes
1,122

Hi,

If you want to validate particular single field the validate in

AT SELECTION-SCREEN ON FIELD <field-name>.

AT SELECTION-SCREEN ON FIELD p_matnr.

if p_matnr is initial.

message e012<message-class-name> .

endif.

So, when you execute this event is triggered and checks the condition . if the P_MATNR fields is empty then it show ERROR message and cursor will be shown in that field. Until you correct that error it will not allow you to go further.

Regards,

Rajitha.

Read only

Former Member
0 Likes
1,122

Hello,

To validate a particular screen-field,use the event .

AT SELECTION-SCREEN ON FIELD <field-name>.

Example:-

AT SELECTION-SCREEN ON FIELD p_flight.
if p_flight is initial.
message  'field is empty ' type 'I'.
endif

.

IF you execute your program, it checks field p_flight . If p_flight field is empty then gives the message and cursor is placed on p_flight .