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 database query.

rohit_trivedi
Product and Topic Expert
Product and Topic Expert
0 Likes
906

Hi,

I've query like this:

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

FOR ALL ENTRIES IN lt_leglrgi

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg.

Now, instead of all entries in lt_leglrgi, i want to select specific entries only. lt_leglrgi has a field SCRVT. I want the above query to work on only those lt_leglrgi entries for which SCRVT is set.

Deleting entries from lt_leglrgi is not a option.

I want to avoid a extra loop.

Is there any way i can restructure this database query for my requirement?

Thanks,

Rohit.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
870

This seems to be the only option left:

IT_TEMP[] = LT_LEGLRGI[].

DELETE FROM IT_TEMP WHERE NOT SCRVT IS INITIAL.

and now,

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

FOR ALL ENTRIES IN <b>IT_TEMP</b>

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg.

Hope this helps.

Sudha

6 REPLIES 6
Read only

Former Member
0 Likes
870

Hi rohit,

1. only those lt_leglrgi entries for which SCRVT is set

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

FOR ALL ENTRIES IN lt_leglrgi

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg

<b>AND LT_LEGLRGI-SCRVT IS NOT INITIAL.</b>

regards,

amit m.

Read only

Former Member
0 Likes
870

Hi,

Fill the internal table lt_leglrgi with the required entries only and then use FOR ALL ENTRIES.

i.e. while filling the records into lt_leglrgi, aply the condition of SCRVT.

Regards,

Shashank

Read only

Former Member
0 Likes
870

Hai Rohit

Check the Following Code

sort lt_leglrgi by adrnr lgreg.

if not lt_leglrgi[] is initial.

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

FOR ALL ENTRIES IN lt_leglrgi

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg

AND LT_LEGLRGI-SCRVT IS NOT INITIAL.

endif.

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Likes
870

Hi Rohit,

Use this

If lt_leglrgi-SCRvt = 'X'.

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg.

and lt_leglrgi-scrvt is not initial

endif.

Read only

rohit_trivedi
Product and Topic Expert
Product and Topic Expert
0 Likes
870

Hi,

@Shanshank: The table lt_leglri has to be filled by all the entries.

@Sreenivasulu / amit : That is a syntax error. Please check again.

@mukesh : lt_leglrgi is a internal table, not a structure.

Regards,

Rohit.

Read only

Former Member
0 Likes
871

This seems to be the only option left:

IT_TEMP[] = LT_LEGLRGI[].

DELETE FROM IT_TEMP WHERE NOT SCRVT IS INITIAL.

and now,

SELECT * FROM /sapsll/adrcon INTO TABLE lt_adrcon_tmp

FOR ALL ENTRIES IN <b>IT_TEMP</b>

WHERE adrnr EQ lt_leglrgi-adrnr

AND lgreg EQ lt_leglrgi-lgreg.

Hope this helps.

Sudha