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

Fetching value from Table

Former Member
0 Likes
1,407

In my table (not internal table), I have the records

VBELN SHIPNO ATPDOC SELLER

1100000197 0000000471 0000000476 IFX::LEVEL1

1100000197 0000000472 0000000476 IFX::LEVEL1

1100000197 0000000473 0000000476 IFX::LEVEL1

1100000197 0000000474 0000000476 IFX::LEVEL1

1100000197 0000000475 0000000476 OTHER_1000::LEVEL3

I want to fetch the SELLER Value “OTHER_1000::LEVEL3” . Also I want to use the VBELN and SHIPNO as the fields in WHERE clause. Means, the last seller value from the set. How can I write the query?

15 REPLIES 15
Read only

Former Member
0 Likes
1,388

Hi,

Fetch the record based on SHIPNO, because that is the only field value which is not varying.

Regards,

Satish

Read only

0 Likes
1,388

Wrong response. Its a blind reply

Read only

Former Member
0 Likes
1,388

Hi Santo,

> Select seller

> from table

> where seller ne 'OTHER_1000::LEVEL3'.

Plzz reward if it is useful,

Mahi.

Read only

0 Likes
1,388

Wrong response. Its a blind reply

Read only

Former Member
0 Likes
1,388

select vbeln shipno atpdoc seller from dbtab into table itab.

if sy-subrc = 0.

sort itab by vbeln shipno descending.

read table itab index 1.

if sy-subrc = 0.

*-- itab-seller = OTHER_1000::LEVEL3

endif.

endif.

first u have to know the criteria for considering a record as last record....!!!! then sort itab accordingly to fetch it.....!!!

Read only

0 Likes
1,388

I think u tried to understand what is my problem unlike others responded blindly w/o reading query. Thx

Read only

0 Likes
1,388

Hi Santo,

I think it is not possible to get the last record from the database table. So first pass the values into internal table.

and write like this

DESCRIBE TABLE IT_TAB LINES COUNT.

COUNT = COUNT - 1.

**Then u know the last record.then write read statement

READ TABLE IT_TAB INTO WA_TAB INDEX COUNT.

Hope it may helpful,

regards,

ravi shankar reddy

Read only

Former Member
0 Likes
1,388

Hi Santo,

Use describe statment.

data: lv_line type i.

Describe table itab lines lv_line.

read table itab into wa_itab index lv_line.

cheers,

Hema.

Read only

0 Likes
1,388

I have already mentioned its not an internal table

Read only

Former Member
0 Likes
1,388

select vbeln

max ( shipno )

<other fields>

where vbeln = <condition>.

Read only

Former Member
0 Likes
1,388

if it works assign points and close the thread...

Read only

RoySayak
Active Participant
0 Likes
1,388

Hi Santo,

It may be helpful to u...

SELECT SELLER FROM <TABLE NAME> WHERE

VBELN = '1100000197' AND SHIPNO = '0000000475'.

************************************************************reward points if it works****************************

THANKS,

SAYAK

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,388

Try something like :

> SELECT seller FROM <ztable> UP TO 1 ROWS

> WHERE vbeln IN <range> AND shipno IN <range>

> ORDER BY VBELN ascending SHIPNO descending.

But if there is no adequate index, it would be better to read all records, sort them and get the last.

Regards

Read only

0 Likes
1,388

You can also use subquery, something like

> SELECT seller

> FROM ztable

> INTO wa

> WHERE vbeln = value AND shipno = ( SELECT MAX( shipno ) FROM ztable WHERE vebln = value ).

Regards

Read only

Former Member
0 Likes
1,388

Tx