‎2008 Mar 13 5:14 AM
hi
I am new to abap..I have to fetch data from two related tables to an internal table..i need to fetch only the data corresponding to the entries in a selection screen.....i tried with joins ..but some problem....i think the coding is not correct...can anybody help me?
regards
ranjillla
‎2008 Mar 13 5:22 AM
***(Here the two tables are cosP AND BSEG .They are having common fields
Such as bukrs gjahr and lednr.
Lednr and rldnr are similar fields in respective tables Of this atleast one should be primary key for both tables.through where condition you can connect it to the entries in selections screen)
TABLES: COSP, BKPF.
TYPES: begin of i_plant,
GJAHR type COSP-GJAHR,
VERSN type COSP-VERSN,
GLVOR TYPE BKPF-GLVOR,
KUTY2 TYPE BKPF-KUTY2.
TYPES : end of i_plant.
.
data : itab type standard table of i_plant WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
SELECTION-SCREEN SKIP.
PARAMETERS: P_VERSN LIKE COSP-VERSN,
P_GJAHR LIKE COSP-GJAHR,
P_PERBL LIKE COSP-PERBL.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK B1.
SELECT AGJAHR AVERSN
BGLVOR BKUTY2
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM COSP AS A INNER JOIN BKPF AS B
ON
( ABUKRS EQ BBUKRS ) AND ( ALEDNR EQ BRLDNR ) AND
( AGJAHR EQ BGJAHR )
WHERE A~VERSN EQ P_VERSN
AND ( A~GJAHR EQ P_GJAHR ) AND
A~PERBL EQ P_PERBL.
LOOP AT ITAB.
WRITE:/ '|',
ITAB-GJAHR COLOR 4 INTENSIFIED OFF HOTSPOT,'|', "f year
20 itab-VERSN COLOR 4 INTENSIFIED OFF, 33 '|',
40 itab- GLVOR COLOR 4 INTENSIFIED OFF,'|',"DNO
60 itab- KUTY2 COLOR 4 INTENSIFIED OFF,'|'.
ENDLOOP.
‎2008 Mar 13 5:18 AM
Hi,
Can you paste the code you have written, and I will help you.
Regards,
Mayank
‎2008 Mar 13 5:19 AM
‎2008 Mar 13 5:20 AM
hi,
Inner joins using 3 tables
Try this :-
SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpo~stlnr = mast~stlnr
JOIN mara ON mara~matnr = mast~matnr
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr
AND mast~werks = 1000.
Here s_matnr is a select-options on the selection-screen.
Or this.
Code:
Select single Vbrk~Bukrs Vbrk~Kunrg Vbrk~Vbeln
Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
Vbak~Vbeln Vbak~Bstdk
Likp~Vbeln Likp~lfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on Tvzbt~Zterm = Vbrk~Zterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on Vbak~Vbeln = SalesLnk~Vbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on Likp~Vbeln = DeliveryLnk~Vbelv
where vbrk~vbeln = pu_Vbeln.
This code locates sales, delivery and payment terms info from a billing document number.
Hope this helps, Do reward.
‎2008 Mar 13 5:21 AM
Hi,
Refer to this sample code.
select aabc bdef
into table itab
from a join b
on aghi = bghi
where <conditon matching selection screen>.
Make sure that u use index(primary key) field in join condn. Else u will get performnace error. Avoid joining more than three tables.
Reward if helpful
Regards,
Ramya
‎2008 Mar 13 5:22 AM
Hi,
here iam sending some sample code.
try like this .
tables : ekko,ekpo.
select-options : s_ebeln for ekko-ebeln.
data : begin of it_itab occurs 0,
ebeln like ekko-ebeln,
netwr like ekko-ebeln,
posnr like ekpo-posnr,
matnr like ekpo-matnr,
end of it_itab.
select ekkoebeln ekkonetwr ekpoposnr ekpomatnr into it_itab from ekko inner join on ekpoebeln = ekkoebeln.
loop at it_itab.
write :
endloop.
regards,
swami.
‎2008 Mar 13 5:22 AM
hi just check this code:
SELECT a~pernr
a~subty
a~objps
a~endda
a~begda
a~seqnr
a~bukrs
a~werks
a~persg
a~persk
a~btrtl
a~abkrs
a~kostl
a~orgeh
a~plans
b~nachn
b~vorna
b~midnm
INTO CORRESPONDING FIELDS OF TABLE i_pa0001_pa0002
FROM pa0001 AS a INNER JOIN pa0002 AS b
ON apernr = bpernr
AND asubty = bsubty
AND aobjps = bobjps
WHERE a~pernr IN s_pernr
AND a~werks IN s_werks
AND a~orgeh IN s_orgeh
AND a~plans IN s_plans.
‎2008 Mar 13 5:22 AM
***(Here the two tables are cosP AND BSEG .They are having common fields
Such as bukrs gjahr and lednr.
Lednr and rldnr are similar fields in respective tables Of this atleast one should be primary key for both tables.through where condition you can connect it to the entries in selections screen)
TABLES: COSP, BKPF.
TYPES: begin of i_plant,
GJAHR type COSP-GJAHR,
VERSN type COSP-VERSN,
GLVOR TYPE BKPF-GLVOR,
KUTY2 TYPE BKPF-KUTY2.
TYPES : end of i_plant.
.
data : itab type standard table of i_plant WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
SELECTION-SCREEN SKIP.
PARAMETERS: P_VERSN LIKE COSP-VERSN,
P_GJAHR LIKE COSP-GJAHR,
P_PERBL LIKE COSP-PERBL.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK B1.
SELECT AGJAHR AVERSN
BGLVOR BKUTY2
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM COSP AS A INNER JOIN BKPF AS B
ON
( ABUKRS EQ BBUKRS ) AND ( ALEDNR EQ BRLDNR ) AND
( AGJAHR EQ BGJAHR )
WHERE A~VERSN EQ P_VERSN
AND ( A~GJAHR EQ P_GJAHR ) AND
A~PERBL EQ P_PERBL.
LOOP AT ITAB.
WRITE:/ '|',
ITAB-GJAHR COLOR 4 INTENSIFIED OFF HOTSPOT,'|', "f year
20 itab-VERSN COLOR 4 INTENSIFIED OFF, 33 '|',
40 itab- GLVOR COLOR 4 INTENSIFIED OFF,'|',"DNO
60 itab- KUTY2 COLOR 4 INTENSIFIED OFF,'|'.
ENDLOOP.
‎2008 Mar 13 5:23 AM
Hi,
You can use a select query using a join condition on the two database tables with a condition on the input parameters.
eg: SELECT a~project_id
a~spr_project_id
a~circle_id
b~circle_desc
b~p_circle_id
INTO CORRESPONDING FIELDS OF TABLE it_output
FROM ( zscp_project AS a
JOIN zscp_circle_m AS b
ON acircle_id = bcircle_id )
FOR ALL ENTRIES IN it_circle
WHERE a~spr_project_id <> space
AND a~rq_stat IN s_pstat.
In the above example zscp_project and zscp_circle_m are two database tables..
using a join condition and the parameter s_pstat is an input parameter.
This might be help you.
Pls reward if useful.
Thanks.