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

error handling in a select statement

Former Member
0 Likes
3,823

Hello.

I am working on a report andwe have two fields on the selection screen:

Vendor Number:

Sortl:

on the selection screen user will enter the list of vendors and then I need to update the field SORTL with what user enters on the field SORTL on the selection screen. for this I have written the following code:

SELECT lifnr FROM lfa1
                   INTO TABLE it_lfa1
                   WHERE lifnr IN s_lifnr AND
                         bukrs = '001'.

the above code is updating the table it_lfa1with the valid vendor numbers, but I need to put a logic that if a user enters an invalid vendor number then it should produce an error log for all the invalid vendor number and for thsi I modify the above code as:

SELECT lifnr FROM lfa1
                   INTO TABLE it_lfa1
                   WHERE lifnr IN s_lifnr AND
                         bukrs = '001'.

if sy-subrc <> 0.
move s_lifnr to it_invalid-lifnr.
endif.

but when I use the above code it just look for the first vendor and then just don't continue with the other vendors entered by the user. can you please tell what am i doing wrong here?

Thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,474

Hi,

SELECT lifnr

FROM lfa1

INTO TABLE it_lfa1

WHERE lifnr IN s_lifnr

AND burks eq '100'.

...

LOOP AT s_lifnr ASSIGNING <lfs_lifnr>.

READ TABLE it_lfa1 ASSIGNING <lfs_lfa1>

WHERE lifnr = <lfs_lifnr>-low

TRANSPORTING NO FIELDS

BINARY SEARCH.

IF sy-subrc NE 0.

lw_invalid_lifnr-lifnr = <lfs_lifnr>-lifnr.

APPEND lw_invalid_lifnr to it_invalid_lifnr.

ENDIF.

ENDLOOP.

This is what i think can help you solve your problem. (Sorry if i misunderstood)

Hope it helps.

Regards,

Thyaga.

Edited by: Thyaga on Nov 3, 2011 9:10 AM

12 REPLIES 12
Read only

Former Member
0 Likes
2,474

Hi,

your code seems to be incomplete. What do you mean

if sy-subrc  0.

Read only

0 Likes
2,474

I am sorry I meant:

IF sy-subrc ne 0.

Read only

0 Likes
2,474

This code won't work because it absolutely incorrect. I think you've meant that "it_invalid" is a table. If yes, you don't have any appends or inserts to fill this table.

Read only

Former Member
0 Likes
2,474

hi rahul ,

i think you r missing the loop statement .


loop at s_lifnr .
SELECT lifnr FROM lfa1
                   INTO TABLE it_lfa1
                   WHERE lifnr IN s_lifnr AND
                         bukrs = '001'.
 
if sy-subrc = 0.
move s_lifnr to it_invalid-lifnr.
endif.
endloop 

regards

ranjan

Read only

Former Member
0 Likes
2,474

loop at s_lifnr .
SELECT lifnr FROM lfa1
                   INTO TABLE it_lfa1
                   WHERE lifnr IN s_lifnr AND
                         bukrs = '001'.
 
if sy-subrc <>  0.
 it_invalid-lifnr  =  s_lifnr  .

append  it_invalid  .
endloop .
endif.

regards

ranjan

Read only

0 Likes
2,474

And what to do if the SELECT-OPTIONS contain ranges or exclusions or patterns or...?

Rob

Read only

0 Likes
2,474

I agree Rob... any suggestion please?

Read only

0 Likes
2,474

It's a mug's game. Explain the problems to the person who gave you the requirements and see if they will change them to something more reasonable.

Rob

Read only

0 Likes
2,474

Hi goel,

... or, as I love it simple.

AT SELECTION-SCREEN ON s_lifnr.
  LOOP AT s_lifnr WHERE SIGN NE 'I' OR OPTION NE 'EQ'.
    MESSAGE TYPE 'E' 'Enter distinct numers only!'.
  ENDLOOP.
  
START-OF-SELECTION.

LOOP AT s_lifnr .
  SELECT COUNT ( * )  FROM lfa1
    WHERE lifnr = s_lifnr-low 
      AND bukrs = '001'.
  CHECK sy-subrc &lt;&gt; 0.
  it_invalid-lifnr = s_lifnr-low  .
  APPEND it_invalid.
ENDLOOP

Regards

Clemens

Edited by: Clemens Li on Nov 1, 2011 10:36 PM

Read only

Former Member
0 Likes
2,474

Hi,

Well, If the user always enter a list as selection (no range, exclusion, ...), I can understand the need.. otherwise this is indeed a bit strange... In case they only need to use single element list in SO, you could restrict all other SO features with the FM SELECT_OPTIONS_RESTRICT and then loop on values and select each single vendor...

E.g under your INITIALIZATION event:


* Only option 'EQ' and sign 'I' are allowed
  lt_opt_list-name        = 'ONLY_EQ'.
  lt_opt_list-options-eq  = 'X'.
  APPEND lt_opt_list TO ls_restriction-opt_list_tab.

  lt_ass-kind             = 'S'.        "select-option
  lt_ass-name             = 'S_LIFNR'.  "name of select-option
  lt_ass-sg_main          = 'I'.        "only inclusive
  lt_ass-sg_addy          = space.
  lt_ass-op_main          = 'ONLY_EQ'.
  lt_ass-op_addy          = space.
  APPEND lt_ass TO ls_restriction-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
      restriction            = ls_restriction
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9.

Then just loop on SO table, select single and check subrc...

Kr,

Manu.

Read only

Former Member
0 Likes
2,475

Hi,

SELECT lifnr

FROM lfa1

INTO TABLE it_lfa1

WHERE lifnr IN s_lifnr

AND burks eq '100'.

...

LOOP AT s_lifnr ASSIGNING <lfs_lifnr>.

READ TABLE it_lfa1 ASSIGNING <lfs_lfa1>

WHERE lifnr = <lfs_lifnr>-low

TRANSPORTING NO FIELDS

BINARY SEARCH.

IF sy-subrc NE 0.

lw_invalid_lifnr-lifnr = <lfs_lifnr>-lifnr.

APPEND lw_invalid_lifnr to it_invalid_lifnr.

ENDIF.

ENDLOOP.

This is what i think can help you solve your problem. (Sorry if i misunderstood)

Hope it helps.

Regards,

Thyaga.

Edited by: Thyaga on Nov 3, 2011 9:10 AM

Read only

Former Member
0 Likes
2,474

Hi Goel,

s_lifnr in your code is a type RANGE variable, and it can not be moved to a variable with data type LIFNR (if i am not wrong).

please consider this code sample:

select-options: s_lifnr for lfa1-lifnr no interval.

data: wa_lifnr type range of lifnr.

SELECT lifnr

FROM lfa1

INTO TABLE it_lfa1

WHERE lifnr IN s_lifnr AND

bukrs = '001'.

loop at s_lifnr into wa_lifnr.

read table it_lfa1 with key

lifnr = wa_lifnr-low.

if sy-subrc ne 0.

move wa_lifnr-low to it_invalid-lifnr.

append it_invalid.

endif.

endloop.

By the way, why should you need to collect the invalid vendor instead of the valid ?

Regards,

Oki