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

Select statement where have 2 same field type.

Former Member
0 Likes
985

hi abaper,

how to do the select statement where there are 2 same variables which have exactly same name , same data type but different table source. as below where both table TJ30T and TJ02T have variables name TXT04 with same data typer J_TXT04.

table TJ30T

MANDT MANDT

STSMA J_STSMA

ESTAT J_ESTAT

SPRAS SPRAS

TXT04 J_TXT04

TXT30 J_TXT30

LTEXT J_LANGTEXT

table TJ02T

ISTAT J_ISTAT

SPRAS SPRAS

TXT04 J_TXT04

TXT30 J_TXT30

both i have to select using select statement and choose the TJ30Ttxt04 and TJ02Ttxt04. but the problems i faced, since both using txt04, one of it i have to rename with different name, ustxt04. when i did the select statement, the data for TJ30T~txt04 failed to find the ustxt04. here the select statement. thanks you


**********data types declaration*********
types: begin of stobj,
  pspnr type proj-pspnr,
  stspr type proj-stspr,
  objnr type proj-objnr,
  pspid type proj-pspid,
  psphi type prps-psphi,
  posid type prps-posid,
  aufnr type aufk-aufnr,
  pspel type aufk-pspel, 
  inact type jest-inact,
  stat type jest-stat,
  udate type jcds-udate,
  usnam type jcds-usnam, 
  utime type jcds-utime, 
  estat type tj30t-estat,
  TXT04 type TJ02T-txt04,
  USTXT04 type TJ30T-txt04,
end of stobj.

*******Internal and work area declaration*******
 data: itobj type table of stobj,
       waobj like line of itobj.

** select statement code*********
select
    a~pspnr a~stspr a~objnr a~pspid
    b~psphi b~posid
    c~aufnr c~pspel
    d~inact d~stat
    e~udate e~usnam e~utime "e~stat
   F~TXT04
    g~estat
    G~TXT04
    from proj as a
    inner join prps as b on a~pspnr = b~psphi
    inner join aufk as c on b~pspnr = c~pspel
    inner join jest as d on c~objnr = d~objnr
    inner join jcds as e on d~objnr = e~objnr
                         and d~stat = e~stat
    inner join tj02t as f on e~stat = f~istat
    inner join tj30t as g on a~stspr = g~stsma
    for all entries in itparm
    where  a~pspid = itparm-pspid "or e~stat = itparm-psy )
    or  b~posid = itparm-posid "or e~stat = itparm-wsy )
    or  c~aufnr = itparm-aufnr "or e~stat = itparm-nsy  )
    and ( d~inact <> 'X' or e~inact <> 'X')
    and f~spras = 'E' and g~spras = 'E'.

1 ACCEPTED SOLUTION
Read only

guilherme_frisoni
Contributor
0 Likes
841

Hi,

have you tried to use an alias to each field?


SELECT F~TXT04 as txt1
    G~TXT04 as txt2
...

But if you use INTO CORRESPONDIG FIELDS OF.. may fail to find correst field.

So you should declare your structure in the same order as your select statement.

Regards,

Frisoni

5 REPLIES 5
Read only

Former Member
0 Likes
841

Hi,

Since you are using a~tablename, I think there would be no issues if there are fields having the same names.

Hope this helps.

Benedict

Read only

guilherme_frisoni
Contributor
0 Likes
842

Hi,

have you tried to use an alias to each field?


SELECT F~TXT04 as txt1
    G~TXT04 as txt2
...

But if you use INTO CORRESPONDIG FIELDS OF.. may fail to find correst field.

So you should declare your structure in the same order as your select statement.

Regards,

Frisoni

Read only

0 Likes
841

Thanks Frisoni,

I used INTO CORRESPONDIG FIELDS OF.. i declare the internal table as i declare in the select statement.

Thanks you very much!

Read only

Former Member
0 Likes
841

correctio0n on the select statement

    • select statement code*********

select

apspnr astspr aobjnr apspid

bpsphi bposid

caufnr cpspel

dinact dstat

eudate eusnam eutime "estat

F~TXT04

g~estat

G~TXT04

into corresponding fields of table itobj

from proj as a

inner join prps as b on apspnr = bpsphi

inner join aufk as c on bpspnr = cpspel

inner join jest as d on cobjnr = dobjnr

inner join jcds as e on dobjnr = eobjnr

and dstat = estat

inner join tj02t as f on estat = fistat

inner join tj30t as g on astspr = gstsma

for all entries in itparm

where apspid = itparm-pspid "or estat = itparm-psy )

or bposid = itparm-posid "or estat = itparm-wsy )

or caufnr = itparm-aufnr "or estat = itparm-nsy )

and ( dinact 'X' or einact 'X')

and fspras = 'E' and gspras = 'E'.

Read only

daixiong_jiang3
Active Participant
0 Likes
841

SOLUTION 1.:

select
    a~pspnr a~stspr a~objnr a~pspid
    b~psphi b~posid
    c~aufnr c~pspel
    d~inact d~stat
    e~udate e~usnam e~utime  g~estat
    F~TXT04 G~TXT04
INTO TABLE  itobj.

SOLUTION 2

select

a~pspnr a~stspr a~objnr a~pspid
    b~psphi b~posid
    c~aufnr c~pspel
    d~inact d~stat
    e~udate e~usnam e~utime "e~stat
   F~TXT04
    g~estat
    G~TXT04 as USTXT04
into corresponding fields of ....