How to create a faster function?
Dear all,
I am trying to create function which can replace certain words with hyperlink in sql. When I call the function as query in sql, its
takes a very long time to execute the query, more than 2-3min. I assumed this is because, the tag_libary table
has around 300,000 records and iterating through large number of records, would consume a lot of processing time.
CREATE FUNCTION dbo.ReplaceTags(@body VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SELECT @body = REPLACE(@body,name,'<a href="pagename.aspx?tag='+name+'">'+name+'</a>')
FROM Tag_Library
RETURN @body
END
Sample Datasets:
article table (id, title, body) { Story1, At the same time there is a list consisting of: DUCHS, EUROC, GLSPE and WODST. Only two of the tags
have covered with the prices in the last three months - GROSV at 99.11 on 8 October and JUBIL at 0s on 11 September. }
tag_library table (id, name, uploadDate)
( 1,DRYDN33 2,DUCHS 3,DRYDN33 4,DRYDN15 5,EUROC 6,DRYDN15 7,GROSV )
I am slightly struggling, in how I can optimize this function, would partitioning the 'tag_library' name records (i.e. look through distinct names only), help in making it, faster.
I attached a sample dataset for further reference.
Any help would be very much appreciated.
Many thanks.
Try a recursive query directly without using the function:
Create table article (id int, title varchar(100), body varchar(4000))
insert into article values(1, 'Story1', 'At the same time there is a list consisting of: DUCHS, EUROC, GLSPE and WODST. Only two of the tags have covered with the prices in the last three months - GROSV at 99.11 on 8 October and JUBIL at 0s on 11 September.')
Create table tag_library (id int, name varchar(10), uploadDate date)
insert into tag_library (id ,name) values( 1,'DRYDN33'), (2,'DUCHS'), (3,'DRYDN33'), (4,'DRYDN15'), (5,'EUROC'), (6,'DRYDN15'), (7,'GROSV')
;with mycte (i, title, body ) as (
select 1 as i, title, body from article
union all
Select m.i+1 as i, m.title, cast(replace(m.body,tl.name,'<a href="pagename.aspx?tag='+tl.name+'">'+tl.name+'</a>') as varchar(4000)) body
from mycte m inner join tag_library tl ON tl.id= m.i )
Select distinct title, body from mycte m
WHERE i = (SELECT MAX(i) FROM mycte c
WHERE m.title = c.title)
drop table article, tag_library
Similar Messages
-
How to create a callback function module
Hi all,
I am working in a requirement where we need to call a function module at a 'after change' event. So how to create a callback function module and register it with the crmvevent ?_
I created a sample function module and try to create entries in table crmv_event_cust, but i got an error message saying that the function module name I provided is not in table CRMC_FUNC_ASSIGN. When I try to create entry there, I got a message that function module is not in CRMC_OBJ_FUNC and that table is a standard table with no maintanance options !!
looks like i am going in wrong way ... can any one please help ??Looking at my system all you need to do is create the entry for the callback function in maint view: CRMV_FUNC_ASSIGN.
Your entry should be as simple as Z-function name Object Function - <same as others in the segment you are assigning>
IE for the partner it would be CRM_PARTNER as object function, for general order processing CRM_ORDER
Take care,
Stephen -
How to create a custom function module with the records in SAP R/3?
Hi All,
How to create a custom function module with the records in SAP R/3? Using RFC Adapter I have to fetch the custom function module records.
Regards
SaraHi
goto se37...here u need to create a function group... then u need to create a function module. inside assign import/export parameters. assign tables/exceptions. activate the same. now write ur code within the function module
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
Look at the below SAP HELP links, These links will show you the way to create a Function Module
http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm -
How to create a procedure function with a return value of ref cursor?
Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
Thanks a lot.http://osi.oracle.com/~tkyte/ResultSets/index.html
-
How to create a Payroll function
Hi all,
I have just begun HR programming. can anyone tell me how to create a payroll function step by step? I have read a few threads on payroll in SDN but i had trouble understanding what they were talking about.
any help will be appreciated.
regards,
HamzaHi
HR deals with the INFOTYPES which are similar to Tables in General ABAP.
There are different ways of fetching data from these infotypes.
There are different areas in HR LIKE Personal Admn, Orgn Management, Benefits, Time amangement, Event Management, Payroll etc
Infotypes for these areas are different from one another area.
storing of records data in each type of area is different
LDBS like PNP are used in HR programing.
Instead of Select.. we use some ROUTINES and PROVIDE..ENDPROVIDE.. etc
and in the case of Pay roll we use Clusters and we Import and Export them for data fetching.
On the whole Normal ABAP is different from HR abap.
For Personal Admn the Infotypes start with PA0000 to PA1999
Time Related Infotypes start with PA2000 to PA2999.
Orgn related Infotypes start with HRP1000 to HRP1999.
All custom developed infotypes stsrat with PA9000 onwards.
In payroll processing we use Clusters like PCL1,2,3 and 4.
Instead of Select query we use PROVIDE and ENDPROVIDE..
You have to assign a Logical Database in the attributes PNP.
Go through the SAp doc for HR programming and start doing.
http://www.sapdevelopment.co.uk/hr/hrhome.htm
See:
http://help.sap.com/saphelp_46c/helpdata/en/4f/d5268a575e11d189270000e8322f96/content.htm
http://www.sapfans.com/forums/viewtopic.php?p=498530&sid=d7ec5866e3fb26880da129de45ce79de
http://www.sapcookbook.com/preview_hr_questions.htm
http://www.atomhr.com/library_full.htm
http://www.sapdevelopment.co.uk/hr/hrhome.htm
http://www.planetsap.com/hr_abap_main_page.htm
http://expertanswercenter.techtarget.com/eac/knowledgebaseAnswer/0,295199,sid63_gci983590,00.html
Reward points if useful
Regards
Anji -
How to create a grouping function
How to create a grouping function ?? For example, can I create a function:myavg and I can use it like :
select col_a, col_b, myavg(col_c)
from table_a
group by col_a, col_b
Thanks in advance !!
nullI don't think that you can create a grouping function in Oracle, but you can create a function and use it in Select statments.
null -
How to create user defined functions in xi.
how to create user defined functions in xi.
can anyone give info with screen shots.Hi,
Please follow the steps mentioned in below link
http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/frameset.htm
also refer below links to know more about UDF
udf
Thanks
Swarup
Edited by: Swarup Sawant on Mar 3, 2008 3:59 PM -
How to create EXCEPTION in function module
hi experts,
how to create exeptions in function module i want step by step.
regards,
chaituhi,
Raising Exceptions
There are two ABAP statements for raising exceptions. They can only be used in function modules:
RAISE except.
und
MESSAGE.....RAISING except.
The effect of these statements depends on whether the calling program handles the exception or not. The calling program handles an exception If the name of the except exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement.
If the calling program does not handle the exception
· The RAISEstatement terminates the program and switches to debugging mode.
· The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type.
If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4.
Source Code of READ_SPFLI_INTO_TABLE
The entire source code of READ_SPFLI_INTO_TABLE looks like this:
FUNCTION read_spfli_into_table.
""Local Interface:
*" IMPORTING
*" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '
*" EXPORTING
*" VALUE(ITAB) TYPE SPFLI_TAB
*" EXCEPTIONS
*" NOT_FOUND
SELECT * FROM spfli INTO TABLE itab WHERE carrid = id.
IF sy-subrc NE 0.
MESSAGE e007(at) RAISING not_found.
ENDIF.
ENDFUNCTION.
The function module reads all of the data from the database table SPFLI where the key field CARRID is equal to the import parameter ID and places the entries that it finds into the internal table spfli_tab. If it cannot find any entries, the exception NOT_FOUND is triggered with MESSAGE ... RAISING. Otherwise, the table is passed to the caller as an exporting parameter.
Calling READ_SPFLI_INTO_TABLE
The following program calls the function module READ_SPFLI_INTO_TABLE:
REPORT demo_mod_tech_fb_read_spfli.
PARAMETERS carrier TYPE s_carr_id.
DATA: jtab TYPE spfli_tab,
wa LIKE LINE OF jtab.
CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
EXPORTING
id = carrier
IMPORTING
itab = jtab
EXCEPTIONS
not_found = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
WHEN 2.
MESSAGE e702(at).
ENDCASE.
LOOP AT jtab INTO wa.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDLOOP.
The actual parameters carrier and jtab have the same data types as their corresponding interface parameters in the function module. The exception NOT_FOUND is handled in the program. It displays the same message that the function module would have displayed had it handled the error.
Hope this is helps,Do reward. -
How to create a new function module?
I was doing the tutorial to create a SAP data widget and the tutorial was using BAPI_FLIGHT_GETLIST to display the data. However, in my system, theres no data in the table SFLIGHT2 and i couldnt populate any data in it.
So i am trying to create my own function module. Can anyone tell me how should i go about doing it?Hi Low Soon ,
please check the below links for creating a new function module.
SAP Help :
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/frameset.htm
Step by Sterp approach to create a Functional Module:
http://www.****************/Tutorials/ABAP/FunctionModule/page1.htm
Thanks
Jaideep Srinivasan -
How to create the INBOUND Function Module for INBOUND IDOCs
Hi Friends,
Can any Suggest me How to proceed to Create an INBOUND Function Module for Processing the INBOUND IDOCS
which are recieved from XI Server ?
I am working in SAP-ISU
Here i will recieve the INBOUND IDOCs for the Meter Reading Orders.
We have a Standard INBOUND FUNCTION MODULE
IDOC_INPUT_ISU_MR_UPLOAD
which Uploads the Meter Reading Results.
I copied the Same function Module into ZIDOC_INPUT_
and working on it.
Can any one suggest me, whether i am going in correct way or not.
In IDOC_INPUT_ISU_MR_UPLOAD Inbound fun module,
BAPI_MTRREADDOC_UPLOAD is used to Update or Insert the Meter Reading Results,
My requirment is to Insert and Update the Meter Reading Orders which are Inbounded from XI.
Can I Use the Same BAPI
BAPI_MTRREADDOC_UPLOAD
to Update the below fields,
EABL-SERNR
EABL-ZWNUMMER
EABLG-ABLESGR
EABL-V_ZWSTAND
EABL-N_ZWSTAND
EABL-ABLHINW
EABL-ZSKIPC
EABL-ADAT
EABL-ATIMTATS
EABL-ADATTATS
EABL-ATIM
EABL-ZMESSAGE
EABL-ABLESER(Meter reader number)
Kindly Suggest me,
Thanks in Advance,
GaneshHello Ganesh
I think you are going completely astray with you z-function module for IDoc processing.
If you look at TABLES parameter METERREADINGRESULTS (type BAPIEABLU ) of BAPI_MTRREADDOC_UPLOAD you will find many of the requested fields already:
EABL-SERNR => BAPIEABLU-SERIALNO
EABL-ZWNUMMER =>REGISTER
EABLG-ABLESGR
EABL-V_ZWSTAND
EABL-N_ZWSTAND
EABL-ABLHINW
EABL-ZSKIPC
EABL-ADAT
EABL-ATIMTATS => ACTUALMRTIME
EABL-ADATTATS => ACTUALMRDATE
EABL-ATIM
EABL-ZMESSAGE
EABL-ABLESER(Meter reader number)
Field EABL-ZMESSAGE appears to be custom field (at least I cannot find it on ECC 6.0). If this field was added using include CI_EABL then you probably can get these values into the BAPI using the EXTENSIONIN parameter.
Check routine CHECK_UPLOADRECORDS in the BAPI which allows two extension structures:
- BAPI_TE_EABL
- BAPI_TE_EOSB
Not surprisingly BAPI_TE_EABL contains the include CI_EABL.
Regards
Uwe -
How to create a Z Function Module
Hi,
I am trying to create a Z function module in BI 7.0 that i can use in Transformations.
SE37> Name of FM.Create..>
It is prompting me to enter Function Group.
What is Function Group and How can i create a new function group (Detail Steps please)
and steps involved in creating a Function Module in BI 7.0
Thanks in AdvanceHi,
Function Group is just like a folder under which we can store n no. of function modules for organizational purpose. If u want any global declarations we will declare at function Group Level.
It is mandatory to save a function module under one function group. Select Goto menu item, select Function Group, then select, create function group in SE37. Just give the technical name and description and save.
Hope this helps u..
Regards
Ramakrishna Kamurthy -
How to create Ticket Booking Functionality in SharePoint 2013 App?
We have created a Ticket Booking site in Asp.Net.
In that in Ticket Booking page user can book the ticket and the booked seats will be stored in the database. If there are any booked seats it will be disabled for the user and from other user can book tickets.
Took reference from this site:
http://techbrij.com/online-ticket-booking-system-asp-net-sql-server
Now I want to do same functionality using SharePoint 2013 App Part with SharePoint Hosted App.
I don't know how to start
Anybody having Idea.
Thanks in Advance.Hi,
According to your post, my understanding is that you want to create a Ticket Booking solution as SharePoint Hosted App.
To build the similar solution in SharePoint, I would suggest you take a look at the links below about how to create ShrePoint Hosted App for a quick start:
Create Host App:
How to: Create a basic SharePoint-hosted app
Create App Part:
How to: Create app parts to install with your app for SharePoint
Then for the data storage, here is a documentation will provide more information:
App data storage:
Data storage options in apps for SharePoint
For the responsive UI, HTML plus JavaScript would be OK.
Feel free to reply if there are still any questions.
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
How to create a Z Function module for the standard FM VIEW_KURGV?
Hi all,
There is a requirement to the change the functionality of the standard FM VIEW_KURGV. This FM is being used in a Z report. Hence, I have a copied this FM to a Z FM ZVIEW_KURGV after having created the Z Function Group ZV05E. However, there are a number of standard routines which are present in the standard FM VIEW_KURGV which need to be also created in the Z FM ZVIEW_KURGV. Please advise how to proceed.
Thanks and regards,
AnishurInstead of copyg the std fm to z, do the following,
1. Go to se37 open FM VIEW_KURGV in display mode.
2. Click on the spiral icon on the top.
3. Then in menu go edit->enhancment options -> show implicit enhancement
4. """""""""""""""""""""" kind of lines will appear in the cde, just rt click on the line at the place u want to insert the code and select
enhancement implementation create.
5. Give apropriate name for thi , it will inset a n place to write your code.
This is an std sap methodology and is supported in upgradde also. -
How to create SSWA plsql function in Oracle Apps of HTML call .html
Hello Team,
I am working on Oracle Apps 11i (11.5.10.2)
I want to know , what is the process to create a , "SSWA plsql function" in Oracle Apps of type "HTML" and html call tab.
How to create that Function and how to attach the PL/SQL code to these functions.
How it works.
Please help me to understand this concept from basics.
Kind RegardsHi;
Please review:
how to setup a forms function in R12 to launch an URL?
http://www.trutek.com/serendipity/index.php?/archives/15-An-Example-of-How-to-Create-Custom-Functions,-Menus,-and-Responsibilities.html
Regard
Helios -
How to Create a Procedure/Function to Return more than one value
How I can write a function/Procedure to which one value is passed and it will return nine values. How I can use these values
Syed,
I would use PL_SQL table versus a VARRAY for this purpose as you will have an advantage of joining PL_SQL table if you want to in your SQL statements in the procedure.
1. At the SQL prompt, create a type using,
create or replace type myTable as table of VARCHAR2(100);
2. Pass the table to your procedure as IN OUT parameter,
Create or replace procedure
myProc(pvar1 IN Number, passingArray IN OUT myTable) AS
Begin
--Fill the array with your logic
for i in 1..9
loop
passingArray.extend;
passingArray(passingArray.count) := 'what ever';
end loop;
End;
3. From your Main prog, you call Myproc
--declare a variable for type first
passingArray myTable := myTable();
begin
myProc(10, passingArray());
--At this point, You would be able to Join the PL_SQL table
--which gives you the power of using SQL with PL_SQL tables
end; -- end of main program
4. All done!I have not shown how to use PL_SQL tables in SELECT statements, as that is not the subject here.
At the end of the story, I would say, if you know the number of arguments that you are going to pass to a procedure, Simply use "that many" IN OUT parameters to finish your task(9 in your case). Although the proc call looks large with this, it is much simpler. The above approach is VERY helpful if YOU DO NOT KNOW THE NUMBER OF ARGUMENTS that you are sending AND receiving From a procedure.
Thx,
SriDHAR
Maybe you are looking for
-
New WIFI card will NOT connect correctly.
Hi, I just purchased a Gigafast WF748-CUI wireless card for my iMac G3 running Mac OS X Tiger (10.4.10) and I followed the instructions exactly and did everything right but it will NOT connect. It keeps generating these weird IP addresses beginning w
-
I use Yahoo mail in both IE8 and Firefox 8 (now 9). Many times the imbedded pictures in email are not shown except as an attachment which must be downloaded and opened by an ancillary program (don't know which one IE8 uses). IE8 will open the file an
-
A lot of time to multiply two arrays
Hello! I want to multiply two arrays. The size of the two arrays is 1568x1568. I use to do it a AxB.vi block....but it spends a huge time, almost 17 seconds, when a operation like this have to be done it less than in a second. I 've attached an examp
-
I just downloaded Acrobat reader Dc for windows and cannot print two sided.
-
Toolbar on Secondary Viewer?
I'm using Aperture with my MacBook Pro and a second display. I have designated the external monitor as the secondary viewer and have Aperture secondary viewer control set to Alternate. This works great for viewing the selected image large but croppin