‎2006 Nov 06 4:23 PM
Hi All,
This code is not working properly. Say, after first pass through the loop, l_bukrs has value '100', the second pass throught he loop is again taking '100' without going to the next value of l_bukrs.
LOOP AT I_T_DATA....
clear: l_salesorg, l_dischan, l_matnr, l_bukrs.
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY.
SELECT SINGLE TARGET1 TARGET2
INTO (l_salesorg, l_dischan)
from ZABC
where VALID_FROM le sy-datum
and SOUR2_FROM ge l_bukrs
and SOUR2_TO le l_bukrs.
case sy-subrc.
when 0.
WHEN 4.
endcase.
ENDLOOP. "I_T_DATA.
Thanks
‎2006 Nov 06 4:34 PM
Replace:
where VALID_FROM le sy-datum
and SOUR2_FROM ge l_bukrs
and SOUR2_TO le l_bukrs.
with
where VALID_FROM le sy-datum
and SOUR2_TO eq l_bukrs.
They're logically the same, but the new one will have better performance.
Rob
‎2006 Nov 06 4:27 PM
‎2006 Nov 06 4:30 PM
Sachin,
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001K~BWKEY = T001W~BWKEY.In this code, you don't have a WHERE clause, and even you made INNER JOIN. The question is what is your purpose of INNER JOIN since you don't select any fields from T001W.
And because you didn't use WHERE, the SQL statement always selects the first record from T001W table.
Think about your logic.
‎2006 Nov 06 4:34 PM
Hi,
Thanks guys. The purpose of the 'INNER JOIN' is to retrieve the company codes assigned to a plant.
Based on the retrieved 'BUKRS' value, we have to look up a Z-table and get values for 'Sales Org' and 'Distribution Channel'.
Thanks
‎2006 Nov 06 4:40 PM
U would need to modify your SELECT statement so that you filter it using a WHERE clause otherwise it would always return the same value.
If you have valuation area in your internal table I_T_DATA.
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY
WHere t001K~bwkey = i_t_data-bwkey.
OR if you have the plant
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY
where t001w-werks = i_t_data-werks.
Regards
Anurag
‎2006 Nov 06 5:05 PM
Hi Guys,
I am not getting any result with this modified code too:
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY
WHERE T001W~WERKS = i_t_data-WERKS.
SELECT SINGLE TARGET1 TARGET2
INTO (l_salesorg, l_dischan)
from ZABC
where VALID_FROM le sy-datum
and SOUR3_FROM ge i_t_data-prctr
and SOUR3_TO le i_t_data-prctr
and SOUR2_FROM ge l_bukrs
and SOUR2_TO le l_bukrs
and SOUR1_FROM = 'C100'
and SOUR1_TO = 'C100'.
Please help.
‎2006 Nov 06 5:10 PM
U mean l_bukrs is blank or has some value ??
Please check the data in table T001W and T001K...do the records match as per you inner join ???
Regards
Anurag
‎2006 Nov 06 5:11 PM
Hi
But why don't you write:
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K WHERE BWKEY = i_t_data-WERKS.
Max
‎2006 Nov 06 5:18 PM
Hi Anurag,
l_bukrs is returning values. But, when i debugged the code, the second SELECT statement is not getting executed.
Thanks
‎2006 Nov 06 5:23 PM
Hi Sachin,
YOu are looping at Internal Table and in second Select statemnt, always, the value of L_bukrs will be same as it is not in loop.
Try to check that value.
Shylesh
‎2006 Nov 06 5:24 PM
Not getting executed or not retrieving data? The code you posted should run the second select regardless.
Rob
‎2006 Nov 06 5:25 PM
Hi Guys,
This is how it is:
LOOP AT I_T_DATA....
clear: l_salesorg, l_dischan, l_matnr, l_bukrs.
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY
WHERE T001W~WERKS = i_t_data-WERKS.
SELECT SINGLE TARGET1 TARGET2
INTO (l_salesorg, l_dischan)
from ZABC
where VALID_FROM le sy-datum
and SOUR3_FROM ge i_t_data-prctr
and SOUR3_TO le i_t_data-prctr
and SOUR2_FROM ge l_bukrs
and SOUR2_TO le l_bukrs
and SOUR1_FROM = 'C100'
and SOUR1_TO = 'C100'.
case sy-subrc.
when 0.
WHEN 4.
endcase.
ENDLOOP. "I_T_DATA.
The first SELECT return values for BUKRS. The second SELECT does not return any values. i.e. l_salesorg and l_dischan are still not getting populated.
Thanks
Message was edited by: Sachin Guptha
‎2006 Nov 06 5:26 PM
One question are the fields SOURCE_FROM and SOURCE_TO fields character and why are you comparing it with GE and LE ???
Can you please cut-paste the data from ZABC table as for a particular case...?
I feel it is now purely a data issue !!
Regards
Anurag
‎2006 Nov 06 5:30 PM
Anurag,
SOUR3_FROM is 'Profit Center'
SOUR3_TO is 'Profit Center'
SOUR2_FROM is company code
SOUR2_TO is company code
SOUR1_FROM is controlling area
SOUR1_TO is controlling area
Thanks
‎2006 Nov 06 5:33 PM
Do all your from and to field have data or it can be blank ??
I am bit confused as why are you comparing it with GE and LE rather than EQ ?
Regards
Anurag
‎2006 Nov 06 5:38 PM
Anurag,
The GE and LE comparions are due to the COPA derivative rules defined in the operating concern.
The Z-table has entries for 'Profit Center', 'Company Code', 'Controlling area'.
We do have null data for some of the values.
Thanks
‎2006 Nov 06 4:34 PM
Replace:
where VALID_FROM le sy-datum
and SOUR2_FROM ge l_bukrs
and SOUR2_TO le l_bukrs.
with
where VALID_FROM le sy-datum
and SOUR2_TO eq l_bukrs.
They're logically the same, but the new one will have better performance.
Rob
‎2006 Nov 06 4:38 PM
Hi Guys,
I changed the first 'SELECT' statement to:
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001KBWKEY = T001WBWKEY
WHERE BUKRS is not null.
Even now, 'l_salesorg' and 'l_dischan' are not retrieving any values.
Thanks.
‎2006 Nov 06 5:35 PM
Hi Sachin,
Perhaps there is no data matching your condition.
Please try manually via SE16 to browse table ZABC with entering the same conditions as your coding. Use selection options button (F2) to enter GE or LE condition for a field selection.
Regards,
Ferry Lianto