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 select statement

Former Member
0 Likes
1,147

hi experts,

my select query is like this..

SELECT pernr reinr receiptno exp_type loc_amount rec_date
  FROM ptrv_srec INTO table it_ptrv_srec
  FOR ALL ENTRIES IN it_ptrv_head
  WHERE pernr EQ it_ptrv_head-pernr
  AND   reinr EQ it_ptrv_head-reinr.

  SORT it_ptrv_srec BY exp_type loc_amount.

here when i deburg am getting 4 line items like

pernr         reinr          exp_type        loc_amount
30007       10003        zs01              1300
30007       10003        zs17              100
30007       10003        zs26              600
30007       10003        zs31              1500

but here i want to read the line item where exp_type is zs26 and loc_amount 600.

how to do it..

regards

sunita.

1 ACCEPTED SOLUTION
Read only

faisalatsap
Active Contributor
0 Likes
1,094

Hi,

Test the following Sample Statement hope will help you to solve you problem,

data: it_ptrv_srec like STANDARD TABLE OF ptrv_srec WITH HEADER LINE,
      it_ptrv_head like STANDARD TABLE OF ptrv_srec WITH HEADER LINE.

SELECT pernr reinr receiptno seqno exp_type loc_amount rec_date
  FROM ptrv_srec INTO CORRESPONDING FIELDS OF TABLE it_ptrv_srec
  FOR ALL ENTRIES IN it_ptrv_head
  WHERE pernr EQ it_ptrv_head-pernr
    AND reinr EQ it_ptrv_head-reinr
    and exp_type eq 'ZS26'
    and loc_amount eq 600.

SORT it_ptrv_srec BY exp_type loc_amount.

Kind Regards,

Faisal

9 REPLIES 9
Read only

former_member156446
Active Contributor
0 Likes
1,094

did u try pressing an F1 on read statement?

Read only

Former Member
0 Likes
1,094

Hi,

SELECT pernr reinr receiptno exp_type loc_amount rec_date

FROM ptrv_srec INTO table it_ptrv_srec

FOR ALL ENTRIES IN it_ptrv_head

WHERE pernr EQ it_ptrv_head-pernr

AND reinr EQ it_ptrv_head-reinr.

AND exp_type EQ 'zs26' " If category 'zs26' only reqd

AND loc_amount eq '600' " If category '600' only reqd

SORT it_ptrv_srec BY exp_type loc_amount.

Edited by: GP on Feb 10, 2009 8:33 AM

Read only

Former Member
0 Likes
1,094

Sunita,

If I understood your question correctly,

1.You can use a normal read table like the following.

read table it_ptrv_head with key exp_type = zs26

loc_amt = 600.

if sy-subrc eq 0.

<Do your custome code>.

endif.

2. Else you can use one more where condition at the time of selection query itself

WHERE pernr EQ it_ptrv_head-pernr

AND reinr EQ it_ptrv_head-reinr

and exp_type = 'ZS26'

and loc_amt = 600.

Let me understand your requirement fully.

-Shankar

Read only

Former Member
0 Likes
1,094

Hi,

Your Where clause should be more specific...

Either Use Exp_type in your where clause or Put data into an internal table and use Read Table..

This will resolve the issue.

Regards,

Gurpreet.

Read only

0 Likes
1,094

Hi,

Some friends have doubt about ur requirement. Hence they suggested some methods.

Still, It's better to filter from database selecton itself. rather filtering after moving to internal table

thanks & regards,

GP

Read only

Former Member
0 Likes
1,094

Hi ,

You can write the READ statement as follows ---

Read table it_ptrv_srec into field_string   with key exp_type = zs26  loc_amount = 600

Regards

Pinaki

Read only

faisalatsap
Active Contributor
0 Likes
1,095

Hi,

Test the following Sample Statement hope will help you to solve you problem,

data: it_ptrv_srec like STANDARD TABLE OF ptrv_srec WITH HEADER LINE,
      it_ptrv_head like STANDARD TABLE OF ptrv_srec WITH HEADER LINE.

SELECT pernr reinr receiptno seqno exp_type loc_amount rec_date
  FROM ptrv_srec INTO CORRESPONDING FIELDS OF TABLE it_ptrv_srec
  FOR ALL ENTRIES IN it_ptrv_head
  WHERE pernr EQ it_ptrv_head-pernr
    AND reinr EQ it_ptrv_head-reinr
    and exp_type eq 'ZS26'
    and loc_amount eq 600.

SORT it_ptrv_srec BY exp_type loc_amount.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,094

Hi

Either you can specify your select query like

SELECT pernr reinr receiptno exp_type loc_amount rec_date
  FROM ptrv_srec INTO table it_ptrv_srec
  FOR ALL ENTRIES IN it_ptrv_head
  WHERE pernr EQ it_ptrv_head-pernr
  AND   reinr EQ it_ptrv_head-reinr
AND exp_type EQ zs26 
AND loc_amount EQ  600.

OR

You can first fetch the data to table it_ptrv_srec and

then loop through the internal table like

LOOP AT IT_PTRV_SREC INTO WA.
IF   WA-exp_type     = zs26 
and WA-loc_amount = 600.
WRITE:/ WA-pernr  ,
             WA-reinr ,
            WA-exp_type,
            WA-loc_amount
ENDIF.
ENDLOOP.

In this case you will get only this row .

30007       10003        zs26              600

Try this .

This will solve your problem.

Regards

Hareesh.

Read only

Former Member
0 Likes
1,094

Hi ,

You can add the two extar conditions as below.

SELECT pernr reinr receiptno exp_type loc_amount rec_date

FROM ptrv_srec INTO table it_ptrv_srec

FOR ALL ENTRIES IN it_ptrv_head

WHERE pernr EQ it_ptrv_head-pernr

AND reinr EQ it_ptrv_head-reinr.

AND exp_type EQ 'zs26' " If category 'zs26' only reqd

AND loc_amount eq '600' " If category '600' only reqd

SORT it_ptrv_srec BY exp_type loc_amount.

Regards

Rajendra