Dynamic returntype in CFC function?

Is there a way to dynamically set a function returntype in a CFC?
For example; if I have a function that contains a 700 line query, and need it to work with two different objects, each of which requires a different format..
.. instead of having two 700+ line functions, one to return a query and the other to return a struct, is there a way to tell the function which format to return the data in?  Can it be passed using CFARGUMENT?
Thanks,
^_^

Is there a way to dynamically set a function returntype in a CFC?
It looks like your requirement here has changed anyhow, but to answer the question you actually asked: no, this is not possible.  The returntype is needed at compile time, whereas any dynamic determination is done at runtime, after the code is already compiled.
For example; if I have a function that contains a 700 line query,
Really? Ye gods.  How?
and need it to work with two different objects, each of which requires a different format..
As Dan said: have two functions.  One which returns the query, one which calls that function, messes with it, and returns a struct.
Someone suggested using returntype="any", and whilst that's possible, having one function which could possibly return two different types of data is... um... "less than ideal".  As a rule, a function should do one thing, so having code that either does x or does y is doing two things.
Adam

Similar Messages

  • Dynamic table in RFC function

    Dear all
    I like to create a dynamic table in a RFC function and pass this table to the calling programm. Is this possible?
    Herbert

    Hi,
    check the Below FM to create Dynamic table in RFC function ..
    RFC_READ_TABLE              --   External access to R/3 tables via RFC
    RFC_GET_TABLE_ENTRIES     --     Read table entries
    Prabhu

  • Using Tree Elements as parameters to a CFC function using AJAX

    I would like to use a <CFTREEITEM> tag element ("value") as a parameter to a CFC function.  I regret that I am fairly new to AJAX and I do not have te exertise to accomplish this.  Does anyone have a method?  Page 671 of the Coldfusion 8 Developers Guide indicates that it is not posiible to do this "directly", but I am hoping to find a way through possibly less direct means.

    Hi kanishka wickrama 
    Here is an example of passing parameters from SAP to a Stored Procedure:
    In the stored procedure you need your variable with the word output as follows:
    @FromDate varchar(12) OUTPUT,
    @ToDate varchar(12) OUTPUT
    Then in your query in SAP pass them as follows (in this example the dates are pulled from OPCH, but you can also use OFPR as it contains all the start and end dates for each financial period)::
    DECLARE @FromDate DATETIME
    DECLARE @ToDate DATETIME
    SELECT @FromDate = T0.DocDate FROM dbo.OPCH T0 WHERE T0.DocDate = '[%0]'
    SELECT @ToDate = T1.DocDate FROM dbo.OPCH T1 WHERE T1.DocDate = '[%1]'
    EXEC MY_STORED_PROCEDURE @FromDate, @ToDate
    Hope this helps
    Kind regards
    Peter Juby

  • CFC - function not found.

    Can anyone see why this is not working? I am pulling my hair
    out. I have setup autosuggest to bind to a CFC before without a
    problem, but getting VERY wierd results with this one. Can anyone
    see what is wrong here?? I can't !!
    Many thanks in advance for any suggestions.
    CFINPUT....
    <cfinput type="text" name="fMunicipality"
    id="fMunicipality" class="LrgTextField" maxlength="50"
    autosuggest="cfc:lu_municipality.getMunicipality{(cfautosuggestvalue)}">
    THE CFC
    <cfcomponent>
    <cffunction name="getMunicipality" access="remote"
    returntype="array" output="false">
    <cfargument name="suggestvalue" required="true">
    <cfset var myarray = ArrayNew(1)>
    <cfquery name="getMunicipality"
    datasource="datasource">
    SELECT suburb FROM lu_geo_data
    WHERE suburb LIKE <cfqueryparam value="#suggestvalue
    & '%'#" cfsqltype="cf_sql_varchar">
    </cfquery>
    <cfloop query="getMunicipality">
    <cfset arrayAppend(myarray, suburb)>
    </cfloop>
    <cfreturn myarray>
    </cffunction>
    </cfcomponent>
    THE ERROR COMING BACK
    The specified remote function getMunicipality{ was not found
    on the CFC lu_municipality.

    you got your { and ( in the wrong order - it should be
    cfc:cfcpath.functionname({bind control}) - in the bind
    attribute of your
    cfinput... thus it is looking for function getMunicipality{
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • Not possible to output CFTREEITEM in a CFC function?

    Hi there,
    I am parsing a sorted list of strings (in the form of a/b/c/,
    a/b/c, /a/c/d etc.) and trying to make a treeview out of it.
    I have the CFFORM and CFTREE tag in the top function and the
    code that generate CFTREEITEM in a subfunction, but I got the
    following error:
    Context validation error for tag cftreeitem.
    The tag must be nested inside a cftree tag.
    It seems that ColdFusion doesn't recognize that calling code
    is already nested inside a CFTREE tag in the top function. I
    extract the code generating CFTREEITEMs to a sub function because
    it is called multiple times from different context, it would be a
    lot of hassle and quite stupid to "inline" it.
    If what I am trying is, for whatever reason, not possible,
    would it be possible then to have the sub function generate the
    code into a string and somehow dynamically evaluate that?
    Any hints or tips will be greatly appreciated!
    Billy

    Hi there,
    I am parsing a sorted list of strings (in the form of a/b/c/,
    a/b/c, /a/c/d etc.) and trying to make a treeview out of it.
    I have the CFFORM and CFTREE tag in the top function and the
    code that generate CFTREEITEM in a subfunction, but I got the
    following error:
    Context validation error for tag cftreeitem.
    The tag must be nested inside a cftree tag.
    It seems that ColdFusion doesn't recognize that calling code
    is already nested inside a CFTREE tag in the top function. I
    extract the code generating CFTREEITEMs to a sub function because
    it is called multiple times from different context, it would be a
    lot of hassle and quite stupid to "inline" it.
    If what I am trying is, for whatever reason, not possible,
    would it be possible then to have the sub function generate the
    code into a string and somehow dynamically evaluate that?
    Any hints or tips will be greatly appreciated!
    Billy

  • Dynamic return from a function based on an argument

    I have a function that I am using to output a nested list of
    child/parent relationships
    the function works wonderfully except that i want to be able
    to change the way the list is displayed depending on an argument
    being passed
    i want the list to be displayed twice on the same page, one
    with output in a table, and one with output in a drop down box
    i thought the easiest way would be to create an argument that
    can be used in IF statements
    look at my code below
    quote:
    <!--- establish default values --->
    <cfparam name="output" default="">
    <cfparam name="catNameOutput" default="">
    <cfparam name="indent" default="">
    <cffunction name="GenerateCategories" access="public"
    returntype="string">
    <!--- this holds the outermost parent value being passed
    to the function --->
    <cfargument name="GenCatParent" type="uuid"
    required="yes" default=0 >
    <!--- this holds the nested level we are on --->
    <cfargument name="level" type="numeric" required="yes"
    default=0 >
    <!--- this holds the output_type we need for display
    purposes --->
    <cfargument name="output_type" type="numeric"
    required="yes" default=0 >
    <!--- grab the children of the received category --->
    <cfquery name="rsCategoryChildren"
    datasource="webdsn">
    SELECT * FROM dbo.BlogCategories
    WHERE catParent = '#GenCatParent#'
    ORDER BY catName ASC
    </cfquery>
    <cfloop query="rsCategoryChildren">
    <!--- keep track of the indentation needed depending on
    which level we are at --->
    <cfloop from="0" to="#arguments.level#" index="i">
    <cfset indent = indent & "  ">
    </cfloop>
    <!--- if the nest is being used in the dropdown on the
    category manage page, we need to use option tags --->
    <cfif arguments.output_type EQ 1>
    <cfset catNameOutput = "<option value='" & catPK
    & "'>" & indent & Trim(catName) &
    "</option>">
    </cfif>
    <!--- if the nest is being used in the table on the
    category manage page, we need to use table row tags --->
    <cfif arguments.output_type EQ 2>
    <cfset catNameOutput = "<tr>
    <td>edit</td> <td>delete</td> <td>"
    & indent & Trim(catName) & "</td>
    </tr>">
    </cfif>
    <cfset output = output & catNameOutput>
    <!--- reset the indentation --->
    <cfset indent = "">
    <!--- check for children of this child --->
    <cfquery name="checkForKids" datasource="webdsn">
    SELECT * FROM dbo.BlogCategories
    WHERE catParent = '#rsCategoryChildren.catPK#'
    ORDER BY catName ASC
    </cfquery>
    <!--- if there are any, call this function recursively
    --->
    <cfif checkForKids.recordcount GT 0>
    <cfset GenerateCategories(genCatParent=catPK, level =
    level +1, output_type = arguments.output_type)>
    </cfif>
    </cfloop>
    <cfreturn output>
    </cffunction>
    <cfquery name="rsCategoryParents" datasource="webdsn">
    SELECT * FROM dbo.BlogCategories
    WHERE catParent IS NULL
    ORDER BY catName ASC
    </cfquery>
    and here is how i am calling the function for each situation
    (the table and the dropdown):
    quote:
    <table width="100%" class="managementtable">
    <tr bgcolor="#F6F6F6">
    <td> </td>
    <td> </td>
    <td>Category Name</td>
    </tr>
    <cfloop query="rsCategoryParents">
    <cfoutput><tr> <td>edit</td>
    <td>delete</td> <td>#Trim(catName)#</td>
    </tr></cfoutput>
    <cfset recursivecats =
    GenerateCategories(genCatParent=catPK,level=0,output_type=2)>
    <cfoutput>#recursivecats#</cfoutput>
    </cfloop>
    </table>
    <!---------------------------------------------------------------------------->
    <select name="select">
    <option>None</option>
    <cfoutput query="rsCategoryParents">
    <option value="#catPK#">#Trim(catName)#</option>
    <cfset recursivecats =
    GenerateCategories(genCatParent=catPK,level=0,output_type=1)>
    #recursivecats#
    </cfoutput>
    </select>
    calling the function for the table and the dropdown on the
    same page does not work
    if the function is first called with the argument for table,
    it tries to also output the table formatted code when the function
    is called again (even if it is called again with the argument for
    dropdown)
    is there another way i can have the same function output two
    different sets of data based on an argument? what am i doing wrong
    thanks for your time

    sjlsam2,
    Yeah, I think the main problem you had was a scoping one. For
    the second function call, the output variable already contained all
    of the output code from the first function call. In fact, I
    wouldn't be surprised to find that the output string for the second
    function call contained the output of the first plus the output of
    the second, and that it didn't render correctly on screen. A
    View Source would have determined that.
    Anyhow, I suggest that you VAR your output variable as
    cf_dev2 suggests, and delete the three CFParam lines at the top.
    Further, your recursive call would therefore need to return it's
    result to the output variable, thus completing the recursive loop.
    See below:
    <!--- this holds the output_type we need for display
    purposes --->
    <cfargument name="output_type" type="numeric"
    required="yes" default=0 >
    <CFSet Var Output = "">
    <CFSet Var catNameOutput = "">
    <CFSet Var indent= RepeatString("  ",
    Arguments.Level)>
    <!--- grab the children of the received category --->
    <cfquery name="rsCategoryChildren" datasource="webdsn">
    SELECT * FROM dbo.BlogCategories
    and
    <!--- if there are any, call this function recursively
    --->
    <cfif checkForKids.recordcount GT 0>
    <cfset
    Output = Output & GenerateCategories(genCatParent=catPK,
    level = level +1, output_type = arguments.output_type)>
    </cfif>
    </cfloop>
    This is what I suggest with your code. HTH :)
    Swift

  • Set label of an item dynamically through pl/sql function

    Hi ,
    How Can I get the label of an item dynamically through a pl/sql function.
    I have a table that stores the label name for these items.
    I want to set the label for the item based on the value in my table ?
    Is it possible ?
    any ideas ?
    Thanks in advance,
    Dippy
    Edited by: Dippy on Feb 23, 2010 11:02 AM
    Edited by: Dippy on Feb 23, 2010 11:02 AM

    If I understand you correctly, you are using a standard report region, but want to dynamically name the column headers? The only way I've been able to get this to work is to create hidden items for each column header, calculate the value you want for each item, then reference the item in the column header using &item_X. for the column header name.
    The problem is that at this point, APEX doesn't allow for dynamic column naming unless you want to do everything yourself using a PL/SQL process that builds the report table manually. I've done that for certain complex reporting tools.
    I understand it's tedious to create all the column header items; I have one report that has over 72 items used in this way. It was a pain, but it got the job done.

  • Dynamic Internal Table in Function Module

    Hi,
    I am developing a function module which is similar to GUI_DOWNLOAD. So , In My function module I would like to pass the internal table dynamically.I saw the paramter DATA_TAB in the function module GUI_DOWNLOAD. But there is no type associated with that. Could anyone help Me out for achieving thsi fucntionality.
    Regards
    Elini.P

    Hi Elini,
    When the tables parameter of the function module has got no line type specified, it will acquire the same type as the parameter that is passed to it during the call. In other words, the table is of generic type. you can pass any table to that parameter.
    However, in case your function module is Remote Enabled, you will not be able to define the tables parameter as generic. IOt must be given some line type.
    Regards,
    Anand Mandalika.

  • Defining Dynamic structure in Remote Function module(RFC)

    Team,
    I got a requirement, where I need to create a dynamic structure and dynamic table in the exporting tab of Function module(RFC).
    Say, I have sales request(4 fields) and sales quotation(5 fields).
    Depending on the importing parameter, If it sales request I need to export 4 fields as a structure and if in the importing parameter it is sales quotation then I need to pass 5 fields as a structure.
    Any help please??
    Thanks,
    Sai

    Hi Manu,
    Those are dummy functions.
    Check out
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/047ab790-0201-0010-a9b1-e612f8b71dcd
    (page 14)
    regards,
    Edgar

  • Passing multiple dynamic params to JS function

    Hi,
    I have a problem that I have been grappling with for some time now.
    My JSP shows the user a list of textboxes dynamically, depending on a value from the DB. So, if the field value is 10, the user will see 10 textbixes and they will sequentially be assigned names as - text1, text2.....
    The problem arises when I try to pass the values of these textboxes to a JS function. Now, my function does not know how many params to expect, so I am trying to send it as a single string separated by : (colon).
    My method call looks like this -
    <input type="button" value="Click Here" style="width:140px;"
                   onClick="myJSFunction(
    <c:forEach var="item" items='${sessionScope.textFields}' varStatus="status">
              document.form.text<c:out value='${status.count}'/>.value+':'
                        </c:forEach>
                        );">          
    Pls. note that I am putting the colon at the end of every call in the forEach loop.
    I get a syntax error if I run this code for more than 1 textbox. The compiler expects a closing bracket ) at the end of the last line, which I have already provided.
    Is there any other way to do this or is there anything obviously wrong with my code?
    Thanks in advance.

    There are several ways around it.
    javascript can have any number of parameters passed to a function.
    You don't even have to declare them.
    You can reference them as arguments[0], arguments[1], arguments[2]...
    Another suggestion: pass up the "basename" and a count of how many fields there are and use the "eval" function
    var base = "document.myform.text";
    for (var i = 0; i<numFields; i++){
      var value = eval(base + i + ".value");
    }or something like that (sorry don't have time to check it right now)

  • How to pass dynamic logical expression to function module

    Hi,
    I'm using FM META_READ_TABLE as below:
    As mentioned above im using META_READ_TABLE FM to get company codes from CSKS table of ECC. Below is the code im using:
       DATA:i_opt type STANDARD TABLE OF RFC_DB_OPT, i_fld type STANDARD TABLE OF RFC_DB_FLD,
           i_res type STANDARD TABLE OF TAB512.
    Constants:   c_expr(72) TYPE c VALUE 'KOSTL EQ COST_CTR', c_fld(5) TYPE c VALUE 'BUKRS'.
      w_opt-text = c_expr.
    w_fld-FIELDNAME = c_fld.
    append: w_opt to i_opt,
            w_fld to i_fld.
    data i_control type STANDARD TABLE OF BBP_CONTROL_RECORD.
    **&&--Get Co code from ECC (CSKS table)
    CALL FUNCTION 'META_READ_TABLE'
      EXPORTING
        QUERY_TABLE          = c_table
    *   DELIMITER            = ' '
    *   NO_DATA              = ' '
    *   ROWSKIPS             = '0'
    *   ROWCOUNT             = '0'
        LOGICAL_SYSTEM       = v1_logsys
      TABLES
        OPTIONS              = i_opt
        FIELDS               = i_fld
        DATA                 = i_res
        CONTROL_RECORD       = i_control.
    however it is giving me 'Communication Error' while executing this piece of code. I guess the problem here is with passing query to i_opt table. obviously the way im doing this is wrong and it has to be dynamic. Could anybody please give me idea how to execute fm with dynamic query i.e., 'KOSTL EQ COST_CTR' where COST_CTR is cost center and an importing parameter to this.please advise.
    Rgds

    The "communication error" would seem more likely to be a problem with an RFC call - does 'META_READ_TABLE" call another function in the remote system?
    We don't have that function module here (is it SRM?) but you should be able to construct your dynamic "where" something like this (p_kostl is the variable in this example):
      data:
        l_where     type text72.
      concatenate
        'KOSTL EQ_'
        p_kostl      "variable
        into l_where.
      translate l_where using '_ '.  "replace underscore with space
    Jonathan

  • Dynamic Call --- User Exit/Function Module

    Hi All,
    We have a User Exit/Function Module which is called dynamically. This is configured and we are missing its configuration path. Could any of you guys let me know more details where this configuration could reside ?
    Thanks much
    Raghu

    Hi,
    When this function module CALL FUNCTION LT_TRWPR-FUNCTION is called, it automatically goes into a Z_XXXXXXXXX function module.
    This function module is called in all transactions where financial postings could happen, however to be precise i would say at the time of Vendor invoice postings.
    Eg: Tcodes MIRO, FB60.
    Thanks
    Raghu Kolla

  • Cfc/function error?

    high, sorry, this is going to be a long code, this is a
    function in my db access component. the stored procedure is running
    fine, the e-mail sending are also running fine, but the function
    itself is not. Here is the error message
    The start tag must have a matching end tag. An explicit end
    tag can be provided by adding </cffunction>. If the body of
    the tag is empty you can use the shortcut <cffunction .../>.
    The error occurred in
    /Applications/CF/wwwroot/SabryCorp/in/07/CFC/toDb.cfc: line 796
    794 : </cffunction>
    795 : <!--- The new function to replace the add function
    --->
    796 : <cffunction name="todb" access="public">
    797 : <!--- the structure that holds the information
    --->
    798 : <cfargument name="fields" type="struct"
    required="yes">
    which should normally indicate that I have some sort of
    overlapping tags, i checked could not find any
    Any Ideas? or is this a bug in cfm?

    Yes, there are two functions above it, but both are running
    without any problems.
    I found a work around, as strange as it can be, but when i
    moved the last two arguments a couple of line earlier everything
    seems to work fine. I think there might be a bug of some sort, but
    I could not figure it out!
    thanks

  • Weird things happen when using .cfc function arguments

    Hey Guys,
    I have a function as the following attached code, I can
    invoke this function and it works well. but when I change the
    number
    32144809 to
    <cfqueryparam value="#arguments.jpRunNum#"
    cfsqltype="cf_sql_integer"> and invoke it by
    <cfset qGetJPDependency =
    CreateObject("component","cfdocs.imd.criticalPath.components.CriticalPath").test(run_num) >,it
    firstly takes a long time waiting without any response, then it
    shows a message "Request timed out waiting to execute", I don't how
    to explain this, is there anyone know the reason caused this
    issue????
    Thanks!

    Have you checked the logs to see what (if anything) else is
    being reported
    back about this?
    Can you check what's going on on the Oracle - am guessing
    it's Oracle from
    the "CONNECT BY PRIOR" - box @ the time? I presume you can
    set it to log
    all SQL or JDBC activity?
    Are you certain (absolutely ~) that arguments.jpRunNum
    contains 32144809,
    for the purposes of the test that's failing?
    What if you factor the query out into a CF template and run
    these tests:
    1) as is in your example
    2) change 32144809 to use a <cfqueryparam>, but still
    hard code the value
    to 32144809.
    3) set a variable to 32144809, and use the variable as the
    value of the
    parameter.
    From what you're describing, it seems like your query is
    getting in a loop,
    which with this sort of thing can be down to giving the
    CONNECT BY PRIOR a
    bung value.
    Adam

  • Dynamic text select all function

    Hi there
    I want to make a dynamic text box that when i click on it to
    focus it, it will select all the contents of the text box rather
    than having the user click and drag to select the contents. Is
    there some actionscript to get make the textbox select all when
    focused?
    Many thanks
    Trev

    yes, you can use the textfield properties for this.

Maybe you are looking for

  • Trying to create a service that starts at boot

    People, I'm trying to create a service that will start at boot (in single-user mode, actually). I am up and running but I do NOT want to run the service now. I only want to run the service when the machine reboots. I've been rummaging around all day

  • Server 2012 Essentials Active Directory users

    I am in the process of setting up a small business with 40 users and 12 workstations, most of the users will be working in a client site on they workstation and some will have access to anywhere access. I'm aware of essentials limited to 25 users, my

  • 3 problems in one .. sort of.

    this problem just came up today. i went to plug in my 1gen nano to update it with new songs, only after a split second the "do not disconnect" screen disappeared and it obviously did not update. i disconnected the ipod and reconnected it, only this t

  • Create data models using interactive reporting

    Hey guys, I was wondering how you create data models using interactive reporting. An simple example would be great? I would really appreciate if I could get an answer. Also, I wanted to understand a real world situation that you guys might have faced

  • No facetime in my iphone!!

    I have purchased my new white 16GB iPhone4 but I could not find facetime any where. I ave tried phone in the setting menu but the switch never appear there. Please help.