09-08-2014 7:53 AM
Hi all,
I am trying to read the all the values on user selection screen select options.
I have an internal table loaded with data.
So while looping this internal table, I need to check the table certain tank field (lgort) against the select options tank values entered by user.
It is fine when user uses the multiple values on the select options since I use the "READ" statement on the select options and get the matching values.
Example: when user uses the multiple value selection on a select-options to enter values A554 and A555
The select-options table will be:
sign option low high
I EQ A554
I EQ A555
LOOP AT gt_output_location INTO gw_output.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* append row to another table.
ENDIF.
ENDLOOP.
Problem:
Example: when user uses range on a select-options to enter values A554 and A555
sign option low high
I BT A554 A555
The read statement can only get matching value A554.
LOOP AT gt_output_location INTO gw_output.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* append row to another table.
ENDIF.
ENDLOOP.
Anyone have any idea on this?? Thanks!!
09-08-2014 8:11 AM
Hi,
Can you try this way -
LOOP AT gt_output_location INTO gw_output WHERE lgort IN s_lgort.
* append row to another table.
ENDLOOP.
Since WHERE condition is also allowed in LOOP like SELECT it should work.
Please check and let me know.
Regards,
Nipun Bhambri
09-08-2014 8:14 AM
You can't use a read with selection options. You must use
LOOP AT gt_output_location INTO gw_output WHERE lgort IN s_lgort.
To understand why, have a look at s_lgort in debug. See what it contains when you have many complex selections.
09-08-2014 8:26 AM
Hi Siong.
Hope it helps.
try this.
CHECK gw_output-lgort IN gw_lgort.
Regards,
Venkat.
09-08-2014 9:03 AM
Hi all, I need to consider each and every lines of the gt_output_location as there are other fields need to consider also. Basically I am checking each and every lines of this table to see which lines I need to append to another table.
That is why I did not use "LOOP AT gt_output_location INTO gw_output WHERE lgort IN s_lgort"
The full gt_output_location:
LOOP AT gt_output_location INTO gw_output.
* IF p_lgort = space AND p_umlgo = space.
IF gv_lines_lgort = 0 AND gv_lines_umlgo = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
* ELSEIF p_lgort = space AND p_umlgo <> space.
ELSEIF gv_lines_lgort = 0 AND gv_lines_umlgo > 0.
* IF gw_output-umlgo = p_umlgo.
READ TABLE s_umlgo INTO gw_umlgo WITH KEY low = gw_output-umlgo.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
* ELSEIF p_umlgo = space AND p_lgort <> space.
ELSEIF gv_lines_umlgo = 0 AND gv_lines_lgort > 0.
* IF gw_output-lgort = p_lgort.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
ELSE.
* IF gw_output-lgort = p_lgort AND gw_output-umlgo = p_umlgo.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
READ TABLE s_umlgo INTO gw_umlgo WITH KEY low = gw_output-umlgo.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR gw_lgort.
CLEAR gw_umlgo.
ENDLOOP.
09-08-2014 9:38 AM
HI Siong,
Check with IF Condition.
if gw_output-umlgo IN s_umlgo.
endif.
Regards,
Venkat.
09-08-2014 9:52 AM
Hi,
please replace
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
with
IF gw_output-lgort IN s_lgort.
and
READ TABLE s_umlgo INTO gw_umlgo WITH KEY low = gw_output-umlgo.
IF sy-subrc = 0.
with
IF gw_output-umlgo IN s_umlgo.
Check that both SELECT-OPTIONS are not empty.
Regards,
Klaus
09-08-2014 10:12 AM
09-08-2014 10:12 AM
Thanks Klaus!!!!
By the way, how do I close this post?? Layout seems to changed already.
09-08-2014 10:58 AM
Hi,
for you didn't mark this thread as a question, it is a discussion, which can't be marked as answered.
Please check the following thread:
Regards,
Klaus
09-08-2014 9:54 AM
Basically if you don't want to restrict user input on selection-screen, you must use a LOOP AT with the IN operator in the WHERE clause, or code for every option : values, range, wildcard, exclusion of records, etc.
Another solution, would be to restrict user input with FM SELECT_OPTIONS_RESTRICT.
Regards,
Raymond