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

db tables

Former Member
0 Likes
523

hi experts

we have an ztable(zvcustomer),in that ztable there are 2 fileds customer id and transaction time",one customer may have multiple "transaction time",based on customer id i have to pick the maximum or minimum "transaction time". plse help me how to fetch the data.

3 REPLIES 3
Read only

former_member189059
Active Contributor
0 Likes
497
select distinct cusid from zvcustomer into corresponding fields of table itab.

loop at itab.
  select max(ttime) from zvcustomer into itab-maxtime where cusid = itab-cusid.
  select min(ttime) from zvcustomer into itab-mintime where cusid = itab-cusid.
  modify itab.
endloop.

then write the data

i am just guessing your field names

ttime -> the database field for your transaction time

cusid -> the database field for your customer id

declare the internal table itab with

1. customer id like zvcustomer-cusid

2. maxtime like zvcustomer-time

3. mintime like zvcustomer-time

Message was edited by:

Kris Donald

Read only

Former Member
0 Likes
497

Get the data first - for a particular user-

SELECT *

from ZTABLE

into i_tran

where userid = p_user.

now do a sort DESCENDING if you want to have the max.

SORT i_TRAN by TRAN_TIME DESCENDING .

READ TABLE I_TRAN INDEX 1. "Fetching the Max value of Tran time.

or

SORT i_TRAN by TRAN_TIME ASCENDING .

READ TABLE I_TRAN INDEX 1. "Fetching the Min value of Tran time.

Hope it helps.

SKC

Read only

Former Member
0 Likes
497

hi serma......

here is the coding:


 data:
      begin of wa,
       id TYPE <dbtab-fieldname>,
      maxtime TYPE <dbtab-fieldname>,
      mintime TYPE <dbtab-fieldname>,
     END OF wa,

     it like STANDARD TABLE OF wa.

select max( ttime ) min( ttime ) FROM <dbtab> INTO TABLE it where
  cid = '<customer id>'.