Scenario- Generally in MNC’s there will be a need to maintain multiple Software’s and access the data from one system to another.
In the below steps I tried to explain how to trigger stored procedure of SQL server and get the result data into SAP system.
Step-1 Need to maintain database connections between SAP and SQL server in t-code DBCO. Basis admin can help you on this.
Click on New Entries and add the connection credentials.
SQL Administrator can give the right details to connect to database from which data is extracted.
After maintaining the connections details it looks like –
SQL Server Screen Shot
Step-2 Deploy code below -
In this example stored procedure needs Input as Fiscal Year and Month, 7 columns of data is extracted into internal table and can be processed further.
parameters: p_year like bkpf-gjahr,
p_month like bkpf-monat.
data: c type cursor.
* structure for 7 columns
types: begin of ithead,
id1(24) type c,
id2(8) type c,
id3(40) type c,
id4(6) type c,
id5(6) type c,
id6(6) type c,
id7 type p decimals 2,
end of ithead.
data: wa type ithead,
it_table type table of ithead.
* opening the Database connection
EXEC SQL.
CONNECT TO 'ELIPSE'
ENDEXEC.
* Triggering the Stored Procedure
exec sql.
open c for
select * from $PROC$GetTrialBalTable
where ( :p_year , :p_month )
endexec.
* Separating data line by line
do.
EXEC SQL.
FETCH NEXT c INTO :wa
ENDEXEC.
if wa is not initial.
append wa to it_table.
else.
endif.
clear:wa.
if sy-subrc ne 0.
exit.
endif.
enddo.
* Closing SQL connection
EXEC SQL.
CLOSE c
ENDEXEC.
*Disconnecting Database connection
EXEC SQL.
DISCONNECT :'ELIPSE'
ENDEXEC.
* Writing records
loop at it_table into wa.
write: / wa-id1, wa-id2, wa-id3, wa-id4, wa-id5, wa-id6, wa-id7.
endloop.
Good Luck..!!