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

problem in selecting records

Former Member
0 Likes
1,217

Hi, everyone.

I have a problem in selecting records. In this case, I want to select records from database

LFA1,and the components of this table are LIFNR,ERDAT,LOEVM ,and so on.The type of LIFNR is char(10).There is a internal table:tab_cdhdr , the elements of tab_cdhdr are: objectid,udate and change_ind.The type of objectid is char(50).

And the select-rule is that: LIFNR = objectid. So I write like this:

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = tab_cdhdr-objectid+0(10).

But there is a warning: When using FOR ALL ENTRIES IN the specifyed length for "OBJECTID" is ignored in this condition.

Can you help me to solve this problem?

Thanks.

1 ACCEPTED SOLUTION
Read only

former_member404244
Active Contributor
0 Likes
1,164

Hi ,

try like this..

take a field of type lifnr in the table tab_cdhdr..

Now u do like this

LOOP AT TAB_CDHDR.

TAB_CDHDR-LIFNR = tab_cdhdr-objectid+0(10).

MODIFY TAB_CDHDR.

ENDLOOP.

Now write ur query..

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = lifnr.

reward if helpful

Regards,

Nagaraj

Hi, everyone.

I have a problem in selecting records. In this case, I want to select records from database

LFA1,and the components of this table are LIFNR,ERDAT,LOEVM ,and so on.The type of LIFNR is char(10).There is a internal table:tab_cdhdr , the elements of tab_cdhdr are: objectid,udate and change_ind.The type of objectid is char(50).

And the select-rule is that: LIFNR = objectid. So I write like this:

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = tab_cdhdr-objectid+0(10).

But there is a warning: When using FOR ALL ENTRIES IN the specifyed length for "OBJECTID" is ignored in this condition.

Can you help me to solve this problem?

Thanks.

9 REPLIES 9
Read only

varma_narayana
Active Contributor
0 Likes
1,164

Hi Feng..

Just give like this:

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = tab_cdhdr-objectid(10). "It will compare only first 10 characters

REWARD IF HELPFUL.

Read only

0 Likes
1,164

> Hi Feng..

>

> Just give like this:

>

> select lifnr

> erdat

> loevm

> form lfa1

> into tab_lfa1

> for all entries in tab_cdhdr

> where lfa1 = tab_cdhdr-objectid(10). "It will

> compare only first 10 characters

>

> REWARD IF HELPFUL.

Thank you very much, Varma@infyTree . I think your code is the same as mine. And I chaned tab_cdhdr-objectid+0(10) to tab_cdhdr-objectid(10) , the result wasn't changed.

And I want to only compare the first 10 characters.

Read only

Former Member
0 Likes
1,164

Do one thing - In our internal table <b>tab_cdhdr</b> add one more field-

LIFNR type LIFNR.

and while populating the Internal table - populate this lifnr with ur syntax <b>tab_cdhdr-objectid+0(10).</b>

and during the SELECT - FOR ALL ENTRIES use this lifnr field instead of objectid+0(10).

During FOR ALL ENTRIES SAP checks the data types - thats why u r having the problem. The above mentioned steps will solve ur problem.

Read only

former_member404244
Active Contributor
0 Likes
1,165

Hi ,

try like this..

take a field of type lifnr in the table tab_cdhdr..

Now u do like this

LOOP AT TAB_CDHDR.

TAB_CDHDR-LIFNR = tab_cdhdr-objectid+0(10).

MODIFY TAB_CDHDR.

ENDLOOP.

Now write ur query..

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = lifnr.

reward if helpful

Regards,

Nagaraj

Read only

0 Likes
1,164

Thanks very much, SKC and nagaraj kumar nishtala .

But I don't want to change tab_cdhdr.

Is there any other methods to solve this problem?

Read only

0 Likes
1,164

Hi Feng..

If you dont want to change the Internal table TAB_CDHDR, Then declare another internal table (TEMPTAB_CDHDR.) with the same structure but Objectid with only 10 chars.

IF TAB_CDHDR[] IS NOT INITIAL.

LOOP AT TAB_CDHDR.

MOVE-CORRESPONDING TAB_CDHDR TO TEMPTAB_CDHDR.

APPEND TEMPTAB_CDHDR.

ENDLOOP.

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

for all entries in tab_cdhdr

where lfa1 = TEMPtab_cdhdr-objectid.

ENDIF.

Sure ... this will work for u.....

REWARD IF HELPFUL.

Read only

Former Member
0 Likes
1,164

the create a local copy of the internal table tab_cdhdr. say tab_cdhdr_copy.

In this internal table you can have the additional field LIFNR type LIFNR.

do this -

tab_cdhdr_copy[] = tab_cdhdr[]

then after doing a loop on tab_cdhdr_copy populate the vendor number. you can then do the SELECT on LAF1 performing the FOR ALL ENTRIES on this temporary table tab_cdhdr_copy[].

I guess this is the only way out if you are not interested in modifying tab_cdhdr.

Read only

Former Member
0 Likes
1,164

Hi,

Try the below method.. it is the best one i feel.

ranges r_lifnr for lfa1-lifnr.

loop at tab_cdhdr.

r_lifnr-low = tab_cdhdr-objid(10)

r_lifnr-sign = 'I'.

r_lifnr-option = 'EQ'.

append r_lifnr.

clear r_lifnr.

endllop.

select lifnr

erdat

loevm

form lfa1

into tab_lfa1

where lfa1 IN r_lifnr.

Read only

0 Likes
1,164

Thanks very much, Sreejith Ramachandran .

But I can't understand your solution. Could you give me more examples about RANGES?

And I want to do like this:

LOOP AT TAB_CDHDR INTO WA_CDHDR.

SELECT LIFNR

ERDAT

LOEVM

FROM LFA1

APPENDING TABLE TAB_LFA1

WHERE LIFNR = WA_CDHDR-OBJECTID(10).

ENDLOOP.

Am I right?