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

ABAP Code - Urgent

Former Member
0 Likes
1,942

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,912

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

18 REPLIES 18
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,912

There is no WHERE clause in this select statement.

 SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
INNER JOIN T001W ON T001K~BWKEY = T001W~BWKEY.

Regards,

Rich Heilman

Read only

TuncayKaraca
Active Contributor
0 Likes
1,912

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.

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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.

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

Hi

But why don't you write:

SELECT SINGLE BUKRS

INTO (l_bukrs)

FROM T001K WHERE BWKEY = i_t_data-WERKS.

Max

Read only

0 Likes
1,912

Hi Anurag,

l_bukrs is returning values. But, when i debugged the code, the second SELECT statement is not getting executed.

Thanks

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

Not getting executed or not retrieving data? The code you posted should run the second select regardless.

Rob

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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

Read only

0 Likes
1,912

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

Read only

Former Member
0 Likes
1,913

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

Read only

0 Likes
1,912

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.

Read only

ferry_lianto
Active Contributor
0 Likes
1,912

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