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

at selection screen

Former Member
0 Likes
8,253

Hi every one,

AT SELECTION-SCREEN on s_lifnr .

     if not s_lifnr is INITIAL.

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

     ENDIF.

\mine is not validating......wrong ans also executing


36 REPLIES 36
Read only

Former Member
0 Likes
8,182

Try putting,

AT SELECTION-SCREEN on s_lifnr .

perform validate_vendor.


form validate_vendor.

     if not s_lifnr is INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

   EXPORTING

     input         = s_lifnr

IMPORTING

   OUTPUT        =s_lifnr

           .

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

     ENDIF.

endform.

BR,

Ankit.

Read only

0 Likes
8,182

Hi,

Following code is working fine for me throws error,

data : lv_lifnr type lifnr.

   select-options : s_lifnr for lv_lifnr.

   at selection-screen on s_lifnr .

      if not s_lifnr is initial.

      select single lifnr

         into lv_lifnr

        from lfa1

        where lifnr in s_lifnr.

      if sy-subrc <> 0.

        message 'INVALID ACCOUNT NUMBER' type 'E'.

      endif.

      endif.

Regards,

Ravi Shankar L

Read only

0 Likes
8,182

HI ANKIT,

it is validating the 1st vale in the selection screen not the other range of values.

Read only

Former Member
0 Likes
8,182

Hi Meenakshi.

1. At Selection screen on we use for single fields in general like for S_LIFNR-LOW / S_LIFNR-HIGH.

2. If you need to validate the entire select opt try like this.

SELECTION-SCREEN BEGIN OF BLOCK BL0.

  SELECT-OPTIONS SEL1 FOR SY-TVAR1.

SELECTION-SCREEN END   OF BLOCK BL0.

At selection-screen on block b0.

IF s-lifnr[] is not initial.

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

Endif.

OR if you want single fields

The write.

At selection-screen on S_LIFNR-HIGH.

IF s_lifnr-high is not initial.

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR eq S_LIFNR-high.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

Endif.

Similarly for low

Hope it helps

BR

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

     I executed the piece of code that you have written and it worked fine for me. The reason that select query fails maybe because the variable v_lifnr is of different type compared to the field lifnr in lfa1 table. Do check the variable declaration and see if data type is same as the table field value you are fetching.

Hope this helps,

~Athreya

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
8,182

Hi,

Do you want to provide error message if none of the LIFNR is available? If so, the below should be fine. Because it checks the range what you had provided. If you want to check each and every LIFNR in the range, you need to have loop between s_lifnr-low and s_lifnr-high.

AT SELECTION-SCREEN on s_lifnr .

     if s_lifnr[] is not INITIAL.

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

     ENDIF.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
8,182

Check documentation (F1) AT SELECTION-SCREEN ON selcrit will only be triggered for a line of selection, to get whole selection internal table use ON END OF selcritif user use the dialog box for select-options, so you may be require to put your check in a simple AT SELECTION-SCREEN..

Sample to check :

TABLES: lfa1.

SELECT-OPTIONS s_lifnr FOR lfa1-lifnr.

AT SELECTION-SCREEN ON END OF s_lifnr .
   IF NOT s_lifnr[] IS INITIAL.
     SELECT COUNT(*)
     FROM lfa1
     WHERE lifnr IN s_lifnr.
     IF sy-subrc <> 0.
       MESSAGE 'AT END OF selcrit' TYPE 'S'.
     ENDIF.
   ENDIF.

AT SELECTION-SCREEN ON s_lifnr .
   IF NOT s_lifnr IS INITIAL.
     SELECT COUNT(*)
     FROM lfa1
     WHERE lifnr IN s_lifnr.
     IF sy-subrc <> 0.
       MESSAGE 'AT selcrit' TYPE 'S'.
     ENDIF.
   ENDIF.

AT SELECTION-SCREEN.
   IF NOT s_lifnr IS INITIAL.
     SELECT COUNT(*)
     FROM lfa1
     WHERE lifnr IN s_lifnr.
     IF sy-subrc <> 0.
       MESSAGE 'AT nothing' TYPE 'S'.
     ENDIF.
   ENDIF.

Regards,

Raymond

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

The code which you had done to validate the vendor is perfect. Please check it properly.

Thanks & Regards.

Pavan.N

Read only

0 Likes
8,182

Hi Pavan,

The code is validating ok but wat means wen i give range of values say 45 to 50 where 47 is not available instead to it s taking in to account. I need help in this area.

Regards,

Meenakshi.

Read only

0 Likes
8,182

Hi Meenakshi,

For select options, it checks for the range not for individual account numbers.

Select option is the table with header line with the following structure .

So if you give a range the option would be BT.

if you give a single value, or multiple values (using this button ), the option would be EQ. Each account number will be appended to the table.

For Between option, you need to manually check for all the values.

data : msg type string, c_lifnr(10) type c.

at selection-screen on s_lifnr.

   if not s_lifnr is INITIAL.

    case s_lifnr-option.

   

     when 'BT'.

            lv_lifnr1 = s_lifnr-low.

           do.

           if lv_lifnr1 GT s_lifnr-high.

                 exit.

           endif.

              select single lifnr into v_lifnr from lfa1 where lifnr = lv_lifnr1.
             if sy-subrc ne 0.

                  c_lifnr = lv_lifnr1.

                  concatenate 'Invalid Account No' c_ lifnr into msg.
                  MESSAGE msg type 'E'.
              endif.

              lv_lifnr1 = lv_lifnr1 + 1.  

           enddo.

      

    when 'EQ'.

               loop at s_lifnr.

                     select single lifnr into v_lifnr from lfa1 where lifnr = s_lifnr-low.
                     if sy-subrc ne 0.

                         c_lifnr = s_lifnr-low.

                        concatenate 'Invalid Account No' c_lifnr into msg.
                       MESSAGE msg type 'E'.
                     endif.

               endloop.

      endcase.

Or another option is just allow one account number at a time.

parameters : p_lifnr like lfa1-lifnr.

at selection-screen on p_lifnr.

      

select single lifnr into v_lifnr from lfa1 where lifnr = p_lifnr.
                     if sy-subrc ne 0.

                       MESSAGE  'Invalid Account No' type 'E'.
                     endif.

           


Read only

0 Likes
8,182

Hi,

I tried ur code. The problem iam facing is ....

say for eg from 42 to 50 the range of value iam giving.....here 44 and 50 values are not there(invalid). But how the output is is showing means 42 is invalid, 43 is invalid........

Read only

0 Likes
8,182

Hi meenakshi,

Did you try the code which i gave you below in this discussion?

Link  (Direct Link)

Regards,

Madhumahesh,

Read only

Former Member
0 Likes
8,182

Your code seems to be fine.

Another option is, Instead of selection screen on s_lifnr.

Just give

At Selection-screen.

AT SELECTION-SCREEN.
   if not s_lifnr is INITIAL.
     select single lifnr into v_lifnr from lfa1 where lifnr in s_lifnr.
     if sy-subrc ne 0.
       MESSAGE 'Invalid Account No' type 'E'.
     endif.
   endif.

The event block sequence should be correct.

Selection Screen Declarations

at selection screen output

at selection screen

at selection screen on <field>

start of selection.
This graphic is explained in the accompanying text

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb2d67358411d1829f0000e829fbfe/content.htm

Read only

Former Member
0 Likes
8,182

Hi Meena,

    As per my knowledge,

    You are define select option in your selection screen it is nothing but an one internal table then how can you use single select statement. And also if user does not enter any value in the select option it will get the all vendor details.

If suppose your vendor selection is parameter then it will work fine.

For your understanding go through the following code,

TYPES: BEGIN OF ll,
        lv_lifnr type lifnr,
        END OF ll.

DATA: lv_lifnr type lifnr,

       lt_lifnr TYPE TABLE OF ll.

SELECT-OPTIONS s_lifnr for lv_lifnr.

AT SELECTION-SCREEN on s_lifnr .

perform validate_vendor.

form validate_vendor.
if not s_lifnr is INITIAL.
"IF SUPPOSE USER SELECT THE VENDOR NUMBER FROM SH IT IS NOT REQUIRED
*CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*
*   EXPORTING
*
*     input         = s_lifnr
*
*IMPORTING
*
*   OUTPUT        = s_lifnr

SELECT  lifnr INTO TABLE lt_lifnr FROM LFA1 WHERE LIFNR IN S_LIFNR.

IF SY-SUBRC <> 0.
MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.
ENDIF.
ELSE.
MESSAGE 'PLEASE ENTER VENDOR NUMBER' TYPE 'E'.
ENDIF.
endform.


Warm Regards,

John.

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

I suppose I got your point.... and there is some confusion...

A Select Option is a RANGE so if I put "A" To "Z".

Though the Table contains only B,C, D & E it will return all 4 as they fall in range.

So your select will not validate B , C , D or E individually.

If you want that you have to use the No interval that will force the user to enter single values and you can validate each of them

BR

Read only

0 Likes
8,182

hi Mohanmed,

But in input the range of values to be entered mand......

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

I suppose I got your point.... and there is some confusion...

A Select Option is a RANGE so if I put "A" To "Z".

Though the Table contains only B,C, D & E it will return all 4 as they fall in range.

So your select will not validate B , C , D or E individually.

If you want that you have to use the No interval that will force the user to enter single values and you can validate each of them

BR

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
8,182

Hi,

You can either restrict the intervals by no intervals or you can check as below which will help you to check if atleast one provided in the interval is valid. If you want to check everything in the interval, then you need to take everything in another internal table by looping s_lifnr from low and high.

select-options : s_lifnr for lv_lifnr.
   at selection-screen on s_lifnr .
      if s_lifnr[] is not initial.
      select single lifnr into lv_lifnr
        from lfa1 where lifnr in s_lifnr.
        if sy-subrc ne 0.
          message ...
        endif.
endif.

Read only

0 Likes
8,182

how is that possible? by using the condition loop

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

check the coding given by Susmitha. It is the correct way to validate present inside the range.

Let me know if any clarifications needed.

Thanks

Pavan.N

Read only

Former Member
0 Likes
8,182

Hi Meenakshi,

check the coding given by Susmitha. It is the correct way to validate present inside the range.

Let me know if any clarifications needed.

Thanks

Pavan.N

Read only

Former Member
0 Likes
8,182

Where are the moderators.....

Please close this thread....

Too much discussion on a FRESHER TOPIC.

Please READ SAP HELP

Read only

0 Likes
8,182

Use "Report Abuse" button if you want moderators to notice the discussion.

Read only

matt
Active Contributor
0 Likes
8,182

Noticed. I also noticed the answer marked as "correct" was wrong. So I've marked the whole discussion as pointless.

Read only

Former Member
0 Likes
8,182

Hi Meenakshi

Pls try the below code

AT SELECTION-SCREEN on s_lifnr-low .

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR-LOW.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

     ENDIF.

AT SELECTION-SCREEN on s_lifnr-high .

     SELECT SINGLE lifnr

        INTO v_lifnr

       FROM LFA1

       WHERE LIFNR IN S_LIFNR-HIGH.

     IF SY-SUBRC <> 0.

       MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

     ENDIF.

     ENDIF.

Regards

Suganya

Read only

Former Member
0 Likes
8,182

Hi Every ,

Got the ans......this is my code

FORM VALIDATE_VENDOR .

     IF s_lifnr-low is NOT INITIAL.

       LOOP AT s_lifnr.

         SELECT SINGLE lifnr

           from lfa1

           into  v_lifnr

           where lifnr = s_lifnr-low.

         IF sy-subrc <> 0.

           MESSAGE 'Invalid vendor number' TYPE 'E'.

         ENDIF.

         CLEAR v_lifnr.

         IF s_lifnr-high is NOT INITIAL.

           SELECT SINGLE lifnr

             from lfa1

             INTO v_lifnr

             where lifnr = s_lifnr-high.

           IF sy-subrc <> 0.

             MESSAGE 'Vendor number 2 is not valid' TYPE 'E'.

           ENDIF.

         ENDIF.

       ENDLOOP.

     ENDIF.

   ENDFORM.                    " VAL

useful for future refrence.

Thank You.

Read only

0 Likes
8,182

That is not going to work for all cases dear.

When you give the range as you had mentioned before from 45 to 50, it is just going to check for 45 and 50 and 47 will still not be validated.

Please check my code again. Use the entire thing if you want complete validation.

Read only

0 Likes
8,182

Hi,

I want to clarify my doubt,

1. How it will work fine. If suppose user enter multiple range of value then, what will happen?

ok if suppose you are using no extension then it will fine.

2. If suppose user enter both s_lifnr-low and s_lifnr-high mean time what will happen?

Warm Regards,

John.

Read only

0 Likes
8,182

Hi meenakshi,

This would be the better solution for your requirement.

data: v_lifnr type lifnr.

select-options: s_lifnr for lfa1-lifnr.


at selection-screen on s_lifnr.
   select lifnr into s_lifnr-low from lfa1 where lifnr in s_lifnr.
     s_lifnr-sign   = 'I'.
     s_lifnr-option = 'EQ'.
     append s_lifnr.
     clear s_lifnr.
   endselect.

   sort s_lifnr by low.
   delete adjacent duplicates from s_lifnr comparing low.

   """Here you can use your logic.


   loop at s_lifnr.
     select single lifnr
            from lfa1
            into  v_lifnr
            where lifnr = s_lifnr-low.

     if sy-subrc <> 0.
       message 'Invalid vendor number' type 'E'.
     endif.

     clear v_lifnr.
   endloop.

Regards,

Madhumahesh.

Read only

0 Likes
8,182

Hi Madhu,

The select single inside the loop statement makes the performance issue. First i used ur code i submitted also but my tl suggested me not to use select single inside the loop.

Read only

0 Likes
8,182

Hi meenakshi,

Check the below code once.

""in selection-screen enter vendors from 1-3 and check it. But i want to know, actually what is your requirement?

tables: lfa1.

data: v_lifnr type lifnr.

types: begin of ty_lifnr,
        lifnr type lifnr,
        end of ty_lifnr.

data: it_tab type table of ty_lifnr,
       wa_tab type ty_lifnr.


select-options: s_lifnr for lfa1-lifnr.


at selection-screen on s_lifnr.

*  select lifnr from lfa1 into table it_lifnr where lifnr in s_lifnr.

wa_tab-lifnr = 1.
append wa_tab to it_tab.
clear wa_tab.

wa_tab-lifnr = 3.
append wa_tab to it_tab.
clear wa_tab.

   loop at it_tab into wa_tab.
     if wa_tab-lifnr in s_lifnr.
     else.
       message 'Invalid vendor number' type 'E'.
     endif.
     clear: wa_tab.
   endloop.

Regards,

Madhumahesh.

Read only

matt
Active Contributor
0 Likes
8,182

Unmarked as correct, because it is wrong.

Read only

Former Member
0 Likes
8,182

HI meenakshi ,,

EPORT  ZLIFNR.

tables:lfa1.

select-options s_lifnr for lfa1-lifnr.

Data: v_lifnr type lifnr.

AT SELECTION-SCREEN on s_lifnr .

      if not s_lifnr is INITIAL.

*     loop at S_LIFNR.

      SELECT lifnr

         INTO v_lifnr

        FROM LFA1

        WHERE LIFNR IN S_LIFNR.

        endselect.

*       endloop.

      IF SY-SUBRC <> 0.

        MESSAGE 'INVALID ACCOUNT NUMBER' TYPE 'E'.

      ENDIF.

     ENDIF.

Read only

Former Member
0 Likes
8,182

Hi Meena,

   Please remove the Answered tick mark,

  Go through the following code, i hope this will meet your requirement,

TYPES: BEGIN OF ty_lifnr,
       lifnr TYPE lifnr,
        END OF ty_lifnr.

DATA : lv_lifnr TYPE lifnr,
        it_lifnr TYPE TABLE OF ty_lifnr,
        wa_lifnr TYPE ty_lifnr,
        str TYPE string.

SELECT-OPTIONS : s_lifnr FOR lv_lifnr.

AT SELECTION-SCREEN ON s_lifnr .

     SELECT  lifnr INTO TABLE it_lifnr FROM lfa1 WHERE lifnr IN s_lifnr.

     IF s_lifnr-low IS NOT INITIAL.
       READ TABLE it_lifnr INTO wa_lifnr WITH KEY lifnr = s_lifnr-low.
       IF sy-subrc <> 0.
         CONCATENATE 'Your enter vendor number' s_lifnr-low ' is wrong' INTO str.
         MESSAGE str TYPE 'E'.
       ENDIF.
     ENDIF.

     IF s_lifnr-high IS NOT INITIAL.
       READ TABLE it_lifnr INTO wa_lifnr WITH KEY lifnr = s_lifnr-high.
       IF sy-subrc <> 0.
         CONCATENATE 'Your enter vendor number' s_lifnr-high 'is wrong' INTO str.
         MESSAGE str TYPE 'E'.
       ENDIF.
     ENDIF.

Warm Regards,

John.

Read only

0 Likes
8,182

Hi John,

But this code not working for single value ranges. that is from 40 to 50 ....iam giving in the range as 41, 42, 44, 45, 49....but here 44 is not available.....but also executing

Read only

0 Likes
8,182

Hi Meena,

See in my system it is working fine. Kindly check your coding,

And also go through my previous post.

In my table have the 1 and 2 vendor id but my system can not have vendor id 3.

See also it is working for multiple selection range,

Warm Regards,

John.