01-18-2005 6:53 AM
Hello ALL,
I am typically faced with a situvation where in I need to write a dynamic JOIN SQL statement in ABAP.
For example :
REPORT ZTEST .
PARAMETERS: TBLNAME(50) DEFAULT 'SPFLI'.
DATA: TOTAL_ROWS TYPE P.
SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS.
WRITE: / TBLNAME, TOTAL_ROWS.
In the above example, here the fetch from Table is dynamic.
Where as if i have to conisder the following SQL statement which is a normal JOIN statement in ABAP,
select
mara~matnr
marc~werks
from mara
join marc on maramatnr = marcmatnr
into table it_join
where mara~mtart = 'FERT' and
marc~werks = '3000'.
How do i convert this into DYNAMIC JOIN STATEMENT</b> .
Looking forward to your responses.
Thank you
01-19-2005 8:45 AM
Hi,
This is from the ABAP keyword help in 6.40, not sure if it works in previous releases or not.
Example
Dynamic specification of the inner joins. The column specification after SELECT is also dynamic.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
DATA: column_syntax TYPE string,
dbtab_syntax TYPE string.
column_syntax = `ccarrname pconnid f~fldate`.
dbtab_syntax = `( ( scarr AS c `
& ` INNER JOIN spfli AS p ON pcarrid = ccarrid`
& ` AND p~cityfrom = p_cityfr`
& ` AND p~cityto = p_cityto )`
& ` INNER JOIN sflight AS f ON fcarrid = pcarrid `
& ` AND fconnid = pconnid )`.
SELECT (column_syntax)
FROM (dbtab_syntax)
INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Regards
Vilmos
01-20-2005 4:25 AM
Hello Nagy,
Thank you for your response and is very helful.
But, I did not understand the "ABAP keyword help in 6.40".
Besides I also tried to use the program that you gave me, but I get a syntax error. Is it because , I have R/3 release 4.6c?
How can I get this workaround in R/3 release 4.6c.
Thanks a lot,
Ranjan MR
01-20-2005 7:40 AM
Hi,
The keyword help is what comes up when you click the blue 'i' icon in SE38 and select the third option with a keyword.
It is very much possible that this functionality is not present in 4.6C. Then you have to dynamically generate a program or subroutine pool to do the same.
Regars
Vilmos
01-20-2005 9:44 AM
Hello Vilmos,
Thanks again.
Well, in my case I have already made a dynamic program and this select should be a call within the dynamic program ie dynamic within a dynamic.
How can I get ABAP keyword release 4.6?
Thanks and Regards
Ranjan MR
03-03-2008 10:55 AM