‎2008 Feb 26 10:35 AM
Dear all,
I want to connect to a Database (MS SQL Server) that does not correspond
to the DB platform of the R/3 database through ABAP
How to achive this ?
We have SAP 4.7 , Basis 620 .
‎2008 Feb 28 8:46 AM
You should add the two tables in the FM header without type or likepart. They're declared in the caller and they haven't restrictions.
Here you have an example of how to call the FM (IN this example I neededboth tables to have 255 char per line but they may be greater if youneed so. That's why the tables should not have a type or like part inthe FM declaration.
I hope this clarify your doubts. If not, just let me know.
Ps: here is the example
data: begin of sqltable occurs 0,
linea(255),
end of sqltable.
data: begin of recordset occurs 0,
linea(255),
end of recordset.
define addsql.
if &1 <> ''.
sqltable-linea = &1. append sqltable.
endif.
end-of-definition.
zrepid = sy-repid.
zlevel = sy-uname.
concatenate ' empresa = "' p_empre '"' into g_cndempresa.
concatenate ' and periodo_pago = "' p_ppago '"' into g_cndppago.
refresh sqltable.
addsql:
'Select nro_leg, centro_costo, sum(importe_final * 1000 ) if ',
' from histcon_propor where ',
g_cndempresa ,
g_cndppago ,
' and cod_cpto between "0001" and "0599"',
' group by 1,2',
' Union ',
' Select distinct nro_leg, centro_costo, 0 if ',
' from histcon_propor where ',
g_cndempresa ,
g_cndppago ,
' and cod_cpto in ("0625", "3566")'.
the sql should look like:
*select nro_leg, centro_costo, sum(importe_final) if
from histcon_propor
where periodo_pago = "200407"
and empresa = "0001"
and cod_cpto between "0001" and "0599"
group by nro_leg, centro_costo
union
select distinct nro_leg, centro_costo, 0 if
from histcon_propor
where empresa = "0001"
and periodo_pago = "200407"
and cod_cpto in ("0625","3566")
call function 'ZEXECSQL'
exporting
dsn1 = dsn
zrepid1 = zrepid
zlevel1 = zlevel
tables
sqltable = sqltable
recordset = recordset.
loop at recordset.
clear wa_liquidado.
split recordset at ',' into wa_liquidado-nro_leg
wa_liquidado-centro_costo
wa_liquidado-importe_final.
perform some_work_with_wa_liquidado
endloop.
Here you have a copy of the FM: I've translated as many comments as ican.
notes: the FM receives three parameters and a table and returns the
recordset in another table.
the parameters are: DSN1 Data source name to be used (because we can
access more than one database)
zrepid1 (a variable that maintains the name of the caller report, DONOT
USE sy-repid, move it to another variable and use this new variable inthe
caller program,
because sy-repid is maintained by the system and when the systemissues
the fm call sy-repid changes it's name to the FM's name)
zlevel (just in case you want to issue several sql's from the samepc, you
can send 'vbs' in this field for example).
sqltable: an itab with the sql you want to run. The only thing youhave to
keep in mind is that every line - except the first one - should startwith
at column 2 at least.
FM code:
function zexecsql.
‎2008 Feb 28 8:46 AM
You should add the two tables in the FM header without type or likepart. They're declared in the caller and they haven't restrictions.
Here you have an example of how to call the FM (IN this example I neededboth tables to have 255 char per line but they may be greater if youneed so. That's why the tables should not have a type or like part inthe FM declaration.
I hope this clarify your doubts. If not, just let me know.
Ps: here is the example
data: begin of sqltable occurs 0,
linea(255),
end of sqltable.
data: begin of recordset occurs 0,
linea(255),
end of recordset.
define addsql.
if &1 <> ''.
sqltable-linea = &1. append sqltable.
endif.
end-of-definition.
zrepid = sy-repid.
zlevel = sy-uname.
concatenate ' empresa = "' p_empre '"' into g_cndempresa.
concatenate ' and periodo_pago = "' p_ppago '"' into g_cndppago.
refresh sqltable.
addsql:
'Select nro_leg, centro_costo, sum(importe_final * 1000 ) if ',
' from histcon_propor where ',
g_cndempresa ,
g_cndppago ,
' and cod_cpto between "0001" and "0599"',
' group by 1,2',
' Union ',
' Select distinct nro_leg, centro_costo, 0 if ',
' from histcon_propor where ',
g_cndempresa ,
g_cndppago ,
' and cod_cpto in ("0625", "3566")'.
the sql should look like:
*select nro_leg, centro_costo, sum(importe_final) if
from histcon_propor
where periodo_pago = "200407"
and empresa = "0001"
and cod_cpto between "0001" and "0599"
group by nro_leg, centro_costo
union
select distinct nro_leg, centro_costo, 0 if
from histcon_propor
where empresa = "0001"
and periodo_pago = "200407"
and cod_cpto in ("0625","3566")
call function 'ZEXECSQL'
exporting
dsn1 = dsn
zrepid1 = zrepid
zlevel1 = zlevel
tables
sqltable = sqltable
recordset = recordset.
loop at recordset.
clear wa_liquidado.
split recordset at ',' into wa_liquidado-nro_leg
wa_liquidado-centro_costo
wa_liquidado-importe_final.
perform some_work_with_wa_liquidado
endloop.
Here you have a copy of the FM: I've translated as many comments as ican.
notes: the FM receives three parameters and a table and returns the
recordset in another table.
the parameters are: DSN1 Data source name to be used (because we can
access more than one database)
zrepid1 (a variable that maintains the name of the caller report, DONOT
USE sy-repid, move it to another variable and use this new variable inthe
caller program,
because sy-repid is maintained by the system and when the systemissues
the fm call sy-repid changes it's name to the FM's name)
zlevel (just in case you want to issue several sql's from the samepc, you
can send 'vbs' in this field for example).
sqltable: an itab with the sql you want to run. The only thing youhave to
keep in mind is that every line - except the first one - should startwith
at column 2 at least.
FM code:
function zexecsql.
‎2008 Feb 28 9:13 AM
hi
good
Check whether the JDBC related services are up in Visual admin
MS Sql Server Drivers.Could you please give me details
msbase.jar
mssqlserver.jar
msutil.ja
The JDBC drivers should be:
com.microsoft.jdbc.sqlserver.SQLServerDriver
The connection :
jdbc:microsoft:sqlserver://STPROTO:XXXX;DatabaseName=Prototype
This will help you
thanks
mrutyun^