‎2011 Nov 01 2:51 PM
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.
‎2011 Nov 03 8:08 AM
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
‎2011 Nov 01 3:08 PM
Hi,
your code seems to be incomplete. What do you mean
if sy-subrc 0.
‎2011 Nov 01 3:18 PM
‎2011 Nov 01 3:35 PM
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.
‎2011 Nov 01 3:29 PM
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
‎2011 Nov 01 3:53 PM
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
‎2011 Nov 01 3:58 PM
And what to do if the SELECT-OPTIONS contain ranges or exclusions or patterns or...?
Rob
‎2011 Nov 01 4:03 PM
‎2011 Nov 01 4:12 PM
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
‎2011 Nov 01 9:36 PM
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 <> 0.
it_invalid-lifnr = s_lifnr-low .
APPEND it_invalid.
ENDLOOP
Regards
Clemens
Edited by: Clemens Li on Nov 1, 2011 10:36 PM
‎2011 Nov 01 6:33 PM
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.
‎2011 Nov 03 8:08 AM
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
‎2011 Nov 03 10:51 AM
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