Dynamic sql with dynamic bulk collection variable

Hi,
I am facing the issue while bulk collecting dynamic sql query data into dynamic variable.
Eg:
query1:= << dynamic select query>>
Execute immediate query1 bulk collect into Dynamic_varibale;
here dynamic_varible is pl/sql table type with 1 column.
How do i declare "dynamic_variable" here????
please suggest...

create type t_id is table of number
SQL> create type t_id is table of number
  2  /
Type created.
SQL> declare
  2
  3   v_tid t_id;
  4   v_results sys_refcursor;
  5
  6   v_employee_id number;
  7   v_name varchar2(100);
  8
  9   v_sql varchar2(1000);
10
11
12  begin
13   v_tid := t_id(7902,7934);
14
15  --
16
17
18   v_sql := 'select empno, ename from scott.emp ' ||CHR(10)
19           || 'where empno in (select column_value from table(cast(:v_tid as
t_id)))';
20
21   dbms_output.put_line(v_sql);
22   dbms_output.put_line('----------');
23
24   open v_results for v_sql using v_tid;
25
26
27   IF v_results IS NOT NULL
28     THEN
29        LOOP
30           FETCH v_results
31            INTO v_employee_id, v_name;
32
33           EXIT WHEN (v_results%NOTFOUND);
34           dbms_output.put_line(v_name);
35        END LOOP;
36
37        IF v_results%ISOPEN
38        THEN
39           CLOSE v_results;
40        END IF;
41    END IF;
42
43  end;
44  /
select empno, ename from scott.emp
where empno in (select column_value from
table(cast(:v_tid as t_id)))
FORD
MILLER

Similar Messages

  • How can I fill a table of objects from cursor with select * bulk collect???

    Hi All, I have a TYPE as OBJECT
    create or replace type dept2_o as object (
    deptno NUMBER(2),
    dname VARCHAR2(14),
    loc VARCHAR2(13));
    I can fill a table of objects from cursor with out select * bulk collect...., row by row
    declare
    TYPE dept2_t IS TABLE of dept2_o;
    dept_o_tab dept2_t:=dept2_t();
    i integer;
    begin
    i:=0;
    dept_o_tab.extend(20);
    for rec in (select * from dept) loop
    i:=i+1;
    dept_o_tab(i):=dept2_o(
    deptno => rec.deptno,
    dname => rec.dname,
    loc =>rec.loc
    end loop;
    for k IN 1..i loop
    dbms_output.put_line(dept_o_tab(k).deptno||' '||dept_o_tab(k).dname||' '||dept_o_tab(k).loc);
    end loop;
    end;
    RESULT
    10 ACCOUNTING NEW YORK
    20 RESEARCH DALLAS
    30 SALES CHICAGO
    40 OPERATIONS BOSTON
    But I can't fill a table of objects from cursor with select * bulk collect construction ...
    declare
    TYPE dept2_t IS TABLE of dept2_o;
    dept_o_tab dept2_t:=dept2_t();
    begin
    dept_o_tab.extend(20);
    select * bulk collect into dept_o_tab from dept;
    end;
    RESULT
    ORA-06550: line 6, column 39;
    PL/SQL: ORA-00947: not enough values ....
    How can I fill a table of objects from cursor with select * bulk collect???

    create or replace type dept_ot as object (
    deptno NUMBER(2),
    dname VARCHAR2(14),
    loc VARCHAR2(13));
    create table dept
    (deptno number
    ,dname varchar2(14)
    ,loc varchar2(13)
    insert into dept values (10, 'x', 'xx');
    insert into dept values (20, 'y', 'yy');
    insert into dept values (30, 'z', 'zz');
    select dept_ot (deptno, dname, loc)
      from dept
    create type dept_nt is table of dept_ot
    declare
       l_depts dept_nt;
    begin
       select dept_ot (deptno, dname, loc)
         bulk collect
         into l_depts
         from dept
       for i in l_depts.first .. l_depts.last
       loop
          dbms_output.put_line (l_depts(i).deptno);
          dbms_output.put_line (l_depts(i).dname);
          dbms_output.put_line (l_depts(i).loc);    
       end loop;
    end;
    /

  • How to create dynamic DataTable with dynamic header/column in JSF?

    Hello everyone,
    I am having problem of programmatically create multiple DataTables which have different number of column? In my JSF page, I should implement a navigation table and a data table. The navigation table displays the links of all tables in the database so that the data table will load the data when the user click any link in navigation table. I have gone through [BalusC's post|http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable] and I found that the section "populate dynamic datatable" does show me some hints. In his code,
    // Iterate over columns.
            for (int i = 0; i < dynamicList.get(0).size(); i++) {
                // Create <h:column>.
                HtmlColumn column = new HtmlColumn();
                dynamicDataTable.getChildren().add(column);
                // Create <h:outputText value="dynamicHeaders"> for <f:facet name="header"> of column.
    HtmlOutputText header = new HtmlOutputText();
    header.setValue(dynamicHeaders[i]);
    column.setHeader(header);
    // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
    HtmlOutputText output = new HtmlOutputText();
    output.setValueExpression("value",
    createValueExpression("#{dynamicItem[" + i + "]}", String.class));
    column.getChildren().add(output);
    public HtmlPanelGroup getDynamicDataTableGroup() {
    // This will be called once in the first RESTORE VIEW phase.
    if (dynamicDataTableGroup == null) {
    loadDynamicList(); // Preload dynamic list.
    populateDynamicDataTable(); // Populate editable datatable.
    return dynamicDataTableGroup;
    I suppose the Getter method is only called once when the JSF page is loaded for the first time. By calling this Getter, columns are dynamically added to the table. However in my particular case, the dynamic list is not known until the user choose to view a table. That means I can not call loadDynamicList() in the Getter method. Subsequently, I can not execute the for loop in method "populateDynamicDataTable()".
    So, how can I implement a real dynamic datatable with dynamic columns, or in other words, a dynamic table that can load data from different data tables (different number of columns) in the database at run-time?
    Many thanks for any help in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    flyeminent wrote:
    However in my particular case, the dynamic list is not known until the user choose to view a table. Then move the call from the getter to the bean's action method.

  • Dynamic SQL with cursor variables in pro*c

    Please, what I need to do in order to be able
    to do something like this:
    EXEC SQL DECLARE :c CURSOR FOR :s;
    In other words: I want to use variables
    in cursor names.
    Is it possible ? How ?
    Thank you.

    OK. Here is an example of a Dynamic SQL #4 program I wrote several years ago (It's still running in production). It is currently running on a Sun E10K with Oracle 8.1.5. This code is JUST the pro*c part of a program which uses IBM MQ Series. MQ passes this program a Select SQL statement (as well as other parameters) as an argument. The Pro*c code allocates the structures, parses, and fetches, and executes the statement. I realize that this will not be easy to read. There are SOME comments in the code. However, I realize that to read anyone elses code is a chore. When you add Dynamic #4 to the list, it becomes much more complicated. Anyway, you'll probably need to copy and paste the code to a text file. It will be easier to read.
    ==========================================
    Code
    ==========================================
    | Program: mqsql.pc |
    | Creator: Jim Wartnick |
    | Purpose: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
    | XXXXXXXXXXX |
    | Date: 01/03/1997 |
    | Modifications: |
    #include"mqsql.h"
    #define DEBUG
    #ifdef DEBUG
    FILE *fp=stdout;
    #endif
    int
    disconnect_db() {
    char msg[256], oraclmsg[256];
    char buf[MAX_STRING_LENGTH+4];
    int buf_len = 0, msg_len = 0;
    EXEC SQL
    COMMIT WORK RELEASE;
    #ifdef DEBUG
    fprintf(fp, " --> Disconnecting from database. RC: %d.\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    error("disconnect_db()", "disconnect", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    connect_db() {
    char msg[256], oraclmsg[256];
    char buf[MAX_STRING_LENGTH+4];
    int buf_len = 0, msg_len = 0;
    char user[4];
    strcpy(user, "/");
    EXEC SQL
    CONNECT :user;
    #ifdef DEBUG
    fprintf(fp, " --> Connecting to database. RC is %d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    sprintf(Results, "%9d", sqlca.sqlcode);
    error("connect_db()", "connect", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    allocate_sqlda() {
    | Initialize the SQLDA structure. |
    | We only need the select descriptor |
    | because we do not have any bind |
    | variables. |
    if ((Select_da = sqlald(
    MAX_COLUMN_COUNT,
    MAX_COLUMN_STRING_LENGTH,
    MAX_INDICATOR_VARS
    )) == (SQLDA *) 0) {
    #ifdef DEBUG
    fprintf(fp, " Memory allocation for Select Descriptor failed.\n");
    fflush(fp);
    #endif
    strcpy(Results, "000000001");
    error("allocate_sqlda()", "create SQLDA", 0, "Memory Error");
    return(FAILURE);
    #ifdef DEBUG
    fprintf(fp, " Memory allocation for Select Descriptor succeeded.\n");
    fflush(fp);
    #endif
    Select_da->N = MAX_COLUMN_COUNT;
    return(SUCCESS);
    int
    prepare_sql() {
    char msg[256], oraclmsg[256];
    int buf_len = 0, msg_len = 0;
    | Prepare the Sql statement. |
    EXEC SQL
    PREPARE sql_stmt
    FROM :Sql;
    #ifdef DEBUG
    fprintf(fp, " Prepared SQL: %s. RC: %d.\n", Sql, sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    sprintf(Results, "%9d", sqlca.sqlcode);
    error("prepare_sql()", "Parse", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    declare_cursor() {
    char msg[256], oraclmsg[256];
    int buf_len = 0, msg_len = 0;
    | Set up the cursor to loop through |
    EXEC SQL
    DECLARE sql_cursor
    CURSOR FOR sql_stmt;
    #ifdef DEBUG
    fprintf(fp, " Declared cursor. RC: %d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof( oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    sprintf(Results, "%9d", sqlca.sqlcode);
    error("declare_cursor()", "declare cursor", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    open_cursor() {
    char msg[256], oraclmsg[256];
    int buf_len = 0, msg_len = 0;
    | Open the cursor. |
    EXEC SQL
    OPEN sql_cursor;
    #ifdef DEBUG
    fprintf(fp, " Opened cursor. RC:%d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    sprintf(Results, "%9d", sqlca.sqlcode);
    error("open_cursor()", "open cursor", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    describe_select_list() {
    char msg[256], oraclmsg[256];
    int buf_len = 0, msg_len = 0;
    | Get description of columns |
    EXEC SQL
    DESCRIBE SELECT LIST FOR sql_stmt
    INTO Select_da;
    #ifdef DEBUG
    fprintf(fp, " Described columns. RC %d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    sprintf(Results, "%9d", sqlca.sqlcode);
    error("describe_select_list()", "describe select list", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    setup_sqlda() {
    char buf[MAX_STRING_LENGTH+4];
    int done = FALSE, nullok = 0, i = 0;
    #ifdef DEBUG
    fprintf(fp, " --> Setting up SQLDA.\n");
    fflush(fp);
    #endif
    if (allocate_sqlda() == FAILURE)
    return(FAILURE);
    if (prepare_sql() == FAILURE)
    return(FAILURE);
    if (declare_cursor() == FAILURE)
    return(FAILURE);
    if (open_cursor() == FAILURE)
    return(FAILURE);
    if (describe_select_list() == FAILURE)
    return(FAILURE);
    | Too many columns in select list. |
    if (Select_da->F < 0) {
    strcpy(Results, "000000001");
    error("setup_sqlda()", "check select list count", 0, "Too many values in select list");
    return(FAILURE);
    | Set the number of columns to the actual |
    | number of columns. |
    Select_da->N = Select_da->F;
    | We are going to convert all fields to a string. |
    for (i == 0; i < Select_da->F; i++) {
    sqlnul(&(Select_da->T), &(Select_da->T[i]), &nullok);
    Select_da->T[i] = EXT_STRING;
    Select_da->L[i] = MAX_STRING_LENGTH;
    | Allocate the result area to be as big as |
    | MAX_STRING_LENGTH. |
    if ((Select_da->V[i] = malloc(Select_da->L[i])) == NULL) {
    #ifdef DEBUG
    fprintf(fp, " Allocation of column values failed.\n");
    fflush(fp);
    #endif
    strcpy(Results, "000000001");
    error("setup_sqlda()", "allocate column values", 0, "Memory Error");
    return(FAILURE);
    if ((Select_da->I[i] = (short *) malloc(sizeof(short))) == NULL) {
    #ifdef DEBUG
    fprintf(fp, " Allocation of idicator values failed.\n");
    fflush(fp);
    #endif
    strcpy(Results, "000000001");
    error("setup_sqlda()", "allocate indicator values", 0, "Memory Error");
    return(FAILURE);
    #ifdef DEBUG
    fprintf(fp, " Allocation of memory for values succeeded.\n");
    fflush(fp);
    #endif
    return(SUCCESS);
    | add_eom adds the end of message |
    | delimiter (an aditional comma). |
    int
    add_eom() {
    char *result_ptr;
    if (strlen(Results) >= sizeof(Results) - 1) {
    strcpy(Results, "000000001");
    error("add_eom()", "Add eom failed. Size overflow", 0, "Memory Error");
    return(FAILURE);
    result_ptr = &Results[strlen(Results)-1];
    while (*result_ptr && (*result_ptr != ','))
    result_ptr--;
    if (*result_ptr) {
    result_ptr++;
    *(result_ptr++) = ',';
    *result_ptr = '\0';
    return(SUCCESS);
    int close_cursor() {
    char msg[256], oraclmsg[256];
    int buf_len = 0, msg_len = 0;
    | Close the cursor. |
    EXEC SQL
    CLOSE sql_cursor;
    #ifdef DEBUG
    fprintf(fp, " Closing cursor. RC: %d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    error("generate_sql()", "close cursor", sqlca.sqlcode, oraclmsg);
    return(FAILURE);
    return(SUCCESS);
    int
    fetch() {
    char msg[256], oraclmsg[256];
    char buf[MAX_STRING_LENGTH+4];
    int buf_len = 0, msg_len = 0;
    EXEC SQL
    FETCH sql_cursor
    USING DESCRIPTOR Select_da;
    #ifdef DEBUG
    fprintf(fp, " --> Fetching rows. RC %d\n", sqlca.sqlcode);
    fflush(fp);
    #endif
    if (sqlca.sqlcode != 0) {
    if (sqlca.sqlcode != NODATAFOUND) {
    buf_len = sizeof(oraclmsg)-1;
    sqlglm(oraclmsg, &buf_len, &msg_len);
    oraclmsg[msg_len] = '\0';
    error("fetch()", "Error fetching row.", sqlca.sqlcode, oraclmsg);
    return(sqlca.sqlcode);
    return(NODATAFOUND);
    return(SUCCESS);
    | Free up any memory structures. |
    void
    free_memory() {
    int i = 0;
    for (i = 0; i < Select_da->F; i++) {
    free(Select_da->V[i]);
    free(Select_da->I[i]);
    | generate_sql() uses the message we received from the queue |
    | (a SQL statement) to query the database. We have to use |
    | dynamic Sql Version 4 for this type of Sql. The number of |
    | columns we are selecting is unknown. This means we can't |
    | use the INTO clause. |
    int
    generate_sql() {
    char buf[MAX_STRING_LENGTH+4];
    int rc = SUCCESS, done = FALSE, nullok = 0, i = 0;
    #ifdef DEBUG
    if ((fp = fopen(SQLLOG, "a")) == NULL)
    fp = stderr;
    #endif
    | Connect to the database |
    if (connect_db() == FAILURE)
    return(FAILURE);
    if (setup_sqlda() == FAILURE)
    return(FAILURE);
    | Place the answer in a comma delimited buffer. |
    memset(Results, NULL, sizeof(Results));
    done = FALSE;
    while (!done) {
    rc = fetch();
    if (rc != SUCCESS) {
    if (Results[0] == '\0')
    sprintf(Results, "%9d,", rc);
    done = TRUE;
    else {
    | Put return code of success in first. |
    if (Results[0] == '\0')
    strcpy(Results, "000000000,");
    for (i = 0; i < Select_da->F; i++) {
    Select_da->V[i][Select_da->L[i]] = '\0';
    | Check to see if the value is null. |
    if (*Select_da->I[i] < 0)
    strcpy(buf, " ,");
    else
    sprintf(buf, "%s,", Select_da->V[i]);
    if (strlen(Results) + strlen(buf) > sizeof(Results)) {
    strcpy(Results, "000000001");
    error("generate_sql()", "String concat failed. Size overflow", 0, "Memory Error");
    return(FAILURE);
    strcat(Results, buf);
    #ifdef DEBUG
    fprintf(fp, " --> Results %s\n", Results);
    fflush(fp);
    #endif
    | Close the cursor. |
    close_cursor();
    | Disconnect from the database |
    disconnect_db();
    | Remove trailing comma. |
    if (add_eom() == FAILURE)
    return(FAILURE);
    #ifdef DEBUG
    fflush(fp);
    #endif
    free_memory();
    #ifdef DEBUG
    fclose(fp);
    #endif
    null

  • Want to create dynamic SQL with table join

    I want to create a dynamic SQL query so that the user can enter any two table names on the selection screen and two field names that he wants to join. After which i should be able to dynamically generate the SQL (native or open) and show the result as report. I have already read the forum threads and know how to create dynamic SQL for single table, what i m struggling with is how to do inner join. I know i can use nested select but that will make the query very slow because i want to extend it to more than 2 tables later.
    Will give points to useful answer for sure, thanks for reading.

    Hi,
    Following is a piece of code which I have used in my program.
    DATA: ws_flds(72)   TYPE c.
    DATA: ftab  LIKE TABLE OF ws_flds.
    ws_flds = 'rbukrs rprctr racct ryear '.
      APPEND ws_flds TO ftab.
       SELECT (ftab)
        INTO CORRESPONDING FIELDS OF TABLE it_grp_glpca
        FROM glpca FOR ALL ENTRIES IN i_cert_item
        WHERE kokrs = c_kokrs
            AND rldnr = '8A'
            AND rrcty IN ('0','2')
            AND rvers  = '000'
            AND rbukrs = i_cert_item-bukrs
            AND ryear  = p_ryear
            AND rprctr = i_cert_item-prctr
            AND racct  = i_cert_item-saknr
            AND ( poper BETWEEN '001' AND ws_poper )
            AND aufnr IN s_aufnr
            AND kostl IN s_kostl
            AND rfarea IN s_fkber
            AND rmvct IN s_rmvct
            AND sprctr IN s_sprctr
            AND ( racct BETWEEN c_low AND c_high ).
    You can now pass your table name as (p_table) or append fieldnames to the internal table (ftab). if it is join then you can append this table like abukrs asaknr..etc.
    Regards
    Subramanian

  • Dynamic itab with Dynamic Where clause

    Hi, Dear All,
    Can someone provide a code extract for Dynamic where clause, i had already done with dynamic itab for a given set of fields, and i need to add where clause dynamically for a given field for a given range of values.
    select (i_fields) into table <dyn_table>
                      from (p_table)
                     where (v_where).
    In the above except the where clause, everything is done. Please help me.
    with best regards
    Mahesh

    Hi,
    here is the code extract for your reference.Pl. correct me.
    with regards
    REPORT  Z_DYN_ITAB                              .
    TYPE-POOLS: SLIS.
    DATA:NAME(100) TYPE C.
    TYPES: BEGIN OF ITAB_TYPE,
            WORD(20),
          END   OF ITAB_TYPE.
    DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH HEADER LINE.
    DATA: vg_fields(255) TYPE c,
          i_fields LIKE TABLE OF vg_fields.
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
          is_fcat LIKE LINE OF it_fcat,
          ls_layout TYPE slis_layout_alv.
    DATA: it_fieldcat TYPE lvc_t_fcat,
          is_fieldcat LIKE LINE OF it_fieldcat.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data.
    data: dy_line type ref to data,
          xfc type lvc_s_fcat.
    DATA: v_where TYPE string, " Variable for storing where clause.
          v_dynamic(18) TYPE c, "variable to store select option datatype
          o_field TYPE REF TO cx_root," object to catch exception
          text TYPE string. "string variable to store exception text.
    CONSTANTS: c_var(15) TYPE c VALUE ' IN S_RANGE'.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001',
                p_name(100) type c,
                p_field(10) TYPE c. " Parameter to capture field name.
    SELECT-OPTIONS: s_range FOR v_dynamic. " Select-option for range.
    selection-screen end of block b1.
    start-of-selection.
    NAME = p_name.
    SPLIT NAME AT ',' INTO TABLE ITAB.
    LOOP AT ITAB.
    is_fcat-fieldname = itab-word.
    is_fcat-tabname = p_table.
    APPEND is_fcat to it_fcat.
    ENDLOOP.
    LOOP AT it_fcat INTO is_fcat.
      is_fieldcat-fieldname = is_fcat-fieldname.
      is_fieldcat-tabname = is_fcat-tabname.
      APPEND is_fieldcat TO it_fieldcat.
      CONCATENATE is_fieldcat-tabname is_fieldcat-fieldname INTO
            vg_fields SEPARATED BY '~'.
      APPEND vg_fields TO i_fields.
    ENDLOOP.
    perform create_dynamic_itab.
    perform get_data.
    Create dynamic internal table and assign to FS
    form create_dynamic_itab.
    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = it_fieldcat
    importing
    ep_table = dy_table.
    assign dy_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
    create data dy_line like line of <dyn_table>.
    assign dy_line->* to <dyn_wa>.
    endform.
    form get_data.
    Select Data from table.
    CONCATENATE p_field c_var INTO v_where.
    TRY.
    select (i_fields) into table <dyn_table>
                      from (p_table)
                     where (v_where).
    if sy-dbcnt = 0.
    write : text-t02.
    endif.
    *Write out data from table.
    Loop at <dyn_table> into <dyn_wa>.
    do.
    assign component sy-index of structure <dyn_wa> to <dyn_field>.
    if sy-subrc <> 0.
      exit.
    endif.
    if sy-index = 1.
      write:/ <dyn_field>.
    else.
      write: <dyn_field>.
    endif.
    enddo.
    endloop.
    Exception Catching.
    CATCH cx_root INTO o_field.
    text = o_field->get_text( ).
    Calling Function to give information message regarding Exception
    CALL FUNCTION 'POPUP_TO_INFORM'
    EXPORTING
    titel = text-t03
    txt1 = text
    txt2 = text-t04.
    TXT3 = ' '
    TXT4 = ' '
    LEAVE TO LIST-PROCESSING.
    ENDTRY.
    endform.

  • Dynamic table with dynamic drop-down list values

    Hi,
    I need to display a dynamic table with 2 columns on an interactive form.
    My Context is defined as below:
    Root
    StudentData     0..n
    StudentName
    StudentCourses     0..n
    Text
    Value
    The 1st column should display student name, 2nd column should display student courses. The courses will be different for each student. I populated the context properly. I checked it by printing them. My DDL is bound to "Student Courses".
    When there is one row -> The DDL is populated with the courses of student 1 (as there is only one).
    When there are more rows -> The DDLs for all the students are populated with all the courses of all the students.
    I want to see the data populated like:
    TEXTFIELD    DROP-DOWN LIST
    Student 1------Student1-Course1
    Student1-Course2
    Student1-Course3
    Student 2------Student2-Course1
    Student2-Course2
    Student2-Course3
    I tried to do this in plain web dynpro using SVS.. it is also working similarly.
    I have set the singleton property of nodes "StudentData" and "StudentCourses" to false.
    Could any one tell me where I am going wrong?
    Thanks
    Ram

    Ram,
    I'm not sure how much this will help, but I know I had the same problem as you when I tried to get a similar thing working, but I can't remember which of the many changes I made fixed the problem, so I'll just show you my code and perhaps you can see if anything is different than yours.
    Here's where I'm creating my dropdown - in my case EastNew_RegOut is the same as your StudentData, and RateTypeDropValues is the same as your StudentCourses (the comments in the code are not meant to sound bossy to you, this is actually an example piece of code that other developers in my company "steal", so I have to put very specific instructions in there!):
    int nodeSize = wdContext.nodeEastNew_RegOut().size();
    for (int i = 0; i < nodeSize; i++) {
         //create an element called "table", that's the element at i.  So, basically it's a row.  Maybe I should have
         //called it "row" instead of table.
         IPublicDeviceExchange.IEastNew_RegOutElement table = (IPublicDeviceExchange.IEastNew_RegOutElement)wdContext.nodeEastNew_RegOut().getElementAt(i);
         //this line of code just executes an rfc that finds out what rates need to be in the dropdown for this particular row
         executeRateTypeDropdown(rateCategory, table.getNum(), wdContext.currentEastNew_MeterOutElement().getReggrp());
         //clear out what's already in there before we re-populate it.
         table.nodeRateTypeDropValues().invalidate();
         //now, I'm looping through all the values in the *actual* rate type dropdown (the one that's an RFC, populated by the above "execute" method)
         for (int j = 0; j < wdContext.nodeEastRatetype_DropdownOut().size(); j++) {
              //for each element in the *actual* Rate type dropdown, I'm going to create an element in my node that I created
              //and set the values from the *actual* one as the values in my node.
                        IPublicDeviceExchange.IRateTypeDropValuesElement element = wdContext.createRateTypeDropValuesElement();
              IPublicDeviceExchange.IEastRatetype_DropdownOutElement rateTypeOut = (IPublicDeviceExchange.IEastRatetype_DropdownOutElement)wdContext.nodeEastRatetype_DropdownOut().getElementAt(j);
              element.setText(rateTypeOut.getText());
              element.setValue(rateTypeOut.getRatetype());
              //here's another key - notice how I don't say wdContext.nodeRateTypeDropValues() - it's the one that's
              //directly off that table I created earlier - the thing that's essentially a row in my newReg table.
              //So, what I'm doing here is adding that new element I created to the dropdown FOR THAT ROW!               
              //(btw, if you're trying to duplicate this, and this method does not exist for your "table" object, it's
              //probably because you didn't listen to me above and you didn't create your node with the singleton property
              //set to false.)
              table.nodeRateTypeDropValues().addElement(element);
    As for my layout... my table is bound to the EastNew_RegOut node, and the column with the dropdown is bound to RateTypeDropValues.Value  (that's probably obvious, but there you have it anyway)
    Finally, in my context, EastNew_RegOut is singleton = true (I was surprised about this, actually, I would have assumed it was false) with a selection of 0..1 and RateTypeDropValues has singleton set to false with a selection of 0..1
    I hope that helps to some degree!
    Jennifer

  • Dynamic accordion with dynamic datagrid

    I’m trying to create a dynamic accordion with embedded
    datagrids in each accordion area. I have the base working but have
    2 problems I can’t seem to figure out.
    Bases; the accordion uses a repeater and vbox with a custom
    component from a webservice result set to create the accordion. The
    custom component has another webservice that gets a value from the
    repeater to pass it to the custom component.
    My 2 problems:
    1. how do I prevent the custom component from running the
    webservice until the accordion item is clicked or the area is
    visible? Otherwise I end up will a bunch of queries hitting the DB
    and if there is several items for the accordion and many items from
    the datagrid its slower.
    2. how can I get the datagrid query to refresh when the
    accordion item is clicked? Because the data may change I am not
    able to see the updated data unless I reload the entire
    application.
    1 thing I did try. With the tab control you can use the
    show() event and the data will refresh just fine, but with the
    accordion, the show() event does not seem to fire. Its as if they
    are all visible.
    Any help here would be much appreciated, I’ve been
    racking my brain for days now and I sure it is something simple
    that I am missing. Thanks in advance.
    See the example code below.
    the application code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute"
    width="100%"
    height="100%"
    initialize="ws.getMethod1.send()"
    xmlns:output="com.comp.*">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    [Bindable]
    public var thisWsdl:String = '
    http://localhost/webservice/service.cfc?wsdl';
    ]]>
    </mx:Script>
    <mx:WebService id="ws"
    wsdl="{thisWsdl}"
    useProxy="false"
    showBusyCursor="true"
    fault="Alert.show(event.fault.faultString, 'Error');"
    concurrency="multiple" requestTimeout="30">
    <mx:operation name="getMethod1">
    <mx:request>
    <param1>{param1data}</param1>
    <param2>{param2data}</param2>
    <param3>{param3data}</param3>
    </mx:request>
    </mx:operation>
    </mx:WebService>
    <mx:Accordion width="100%" height="100%"
    fillColors="[#808080, #808080]">
    <mx:Repeater id="rp"
    dataProvider="{ws.getMethod1.lastResult}">
    <mx:VBox label="{String(rp.currentItem.catname)}"
    backgroundColor="#C0C0C0" width="100%" height="100%"
    paddingRight="10">
    <output:comp catid="{rp.currentItem.catid}"/>
    </mx:VBox>
    </mx:Repeater>
    </mx:Accordion>
    </mx:Application>
    the component code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="100%"
    height="100%"
    focusIn="ws.getMethod.send()"
    horizontalAlign="center"
    backgroundColor="#FFFFFF">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    [Bindable]
    public var thisWsdl:String = '
    http://localhost/webservice/service.cfc?wsdl';
    [Bindable]
    public var catid:int;
    ]]>
    </mx:Script>
    <mx:WebService id="ws"
    wsdl="{thisWsdl}"
    useProxy="false"
    showBusyCursor="true"
    fault="Alert.show(event.fault.faultString, 'Error');"
    concurrency="multiple" requestTimeout="30">
    <mx:operation name="getMethod2">
    <mx:request>
    <catid>{catid}</catid>
    </mx:request>
    </mx:operation>
    </mx:WebService>
    <mx:DataGrid id="itemGrid"
    dataProvider="{ws.getMethod2.lastResult}" width="700"
    height="250">
    <mx:columns>
    <mx:DataGridColumn width="100" dataField="itemid"
    headerText="Item Id"/>
    <mx:DataGridColumn wordWrap="true" dataField="itemname"
    headerText="Item Name"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:VBox>

    Perhaps you could use the change event of the accordion, or
    the show event of the child containers?
    Tracy

  • Dynamic sql in dynamic page

    I have problem of retrieving data from dynamic sql query.
    I have
    select 'select * from some_table' from dual
    and I have to execute in dynamic page or report inner statement.
    htp.p not help
    I will appreciate any help from anybody.

    Hi,
    You cannot have a dynamic table selection but if you want to use a select statement then you can use oracle tags in the html code like this
    <html>
    <title>
    new page
    </title>
    <body>
    <oracle>
    select * from scott.emp
    </oracle>
    </body>
    </html>
    Thanks,
    Sharmila

  • Dynamic SQL substituting dynamic table name with slct statement having date

    Hello,
    I just wanted some help with the following PL block. My problem is whenever I try to run this block it ask for invoking values for 2 substitute variables, though no substitute variables present in the code. Please find the code below:
    Declare
    cursor C_1 is
    select unique table_name from gsi_daily_count;
    table_names varchar2(240);
    Begin
    Open C_1;
    Loop
    Fetch C_1 into table_names;
    EXIT WHEN C_1%NOTFOUND;
    EXECUTE IMMEDIATE' select last_extract_date,
    to_char(min(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') mi,
    to_char(max(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') ma
    from' || table_names ||'
    group by last_extract_date
    order by last_extract_date desc';
    End Loop;
    Close C_1;
    COMMIT;
    End;
    Please help.
    Thanks in advance.

    You cannot specify your dates the way you have since they are being intepreted as bind variables:
    Try this:
    Declare
      cursor C_1 is
        select unique table_name
        from gsi_daily_count;
        table_names varchar2(240);
    Begin
      Open C_1;
      Loop
        Fetch C_1 into table_names;
        EXIT WHEN C_1%NOTFOUND;
        EXECUTE IMMEDIATE' select last_extract_date,
                                  to_char(
                                          min(
                                                greatest(
                                                          nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                         ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                             ),''DD-MON-YY HH24:MI:SS''
                                         ) mi
                                  to_char(
                                          max(
                                                greatest(
                                                          nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                         ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                             ),''DD-MON-YY HH24:MI:SS''
                                         ) ma
                          from ' || table_names ||'
                          group by last_extract_date
                          order by last_extract_date desc';
      End Loop;
      Close C_1;
      COMMIT;
    End;
    / There is not way for me to test this, so you may have to play around with all the quotes!

  • Filling dynamic table with dynamic structure en fields!

    Hello All,
    I have written the following code. Which is okay according the syntax check. But when I run the abap code it will give a syntax error. I want to insert data from database table into internal table. Because the tables that have to read are so many I decided to make a dynamic statement which can be used for all tables. Except it won't work as I wish.
    (LT_FIELDS) content is the dynamic fields which are defined earlier in the code and will change each loop.
    (TAB_X) content is the dynamic internal table which is defined earlier in the code and will change each loop.
    = structure of PA0002.
    (TAB_N) = T_PA0002.
    The code:
              SELECT (LT_FIELDS) FROM (TAB_X) INTO CORRESPONDING FIELDS OF .
              ENDSELECT.
    Can someone give me some advice how to solve this issue?
    During the run at the line "INSERT (TAB_N) FROM . " SAP creates an error like below.
                                                                                    K. tekst                                                                               
    Ein in einem SQL-Befehl genannter Tabellenname ist unbekannt.                                                                               
    Wat is er gebeurd?                                                                               
    Error in ABAP application program.                                                                               
    The current ABAP program "ZPF_R_MUTATIEOVERZICHT_MAIA" had to be terminated                 
         because one of the                                                                         
        statements could not be executed.                                                                               
    This is probably due to an error in the ABAP program.                                                                               
    Foutenanalyse                                                                               
    Es ist eine Ausnahme aufgetreten, die weiter unten näher erläutert wird.                    
        Die Ausnahme, der die Klasse 'CX_SY_DYNAMIC_OSQL_SEMANTICS' zugeordnet ist,                 
        wurde nicht abgefangen und führte deshalb zu einem Laufzeitfehler.                          
        Der Grund für die Ausnahme ist:                                                                               
    In einem SELECT-, UPDATE- oder DELETE-Befehl wurde ein ungültiger                           
        Tabellenname "T_PA0002" angegeben.                                                          
        Aus einem der folgenden Gründe tritt der Fehler erst zur Laufzeit auf:                      
        - der Tabellenname wurde dynamisch angegeben, oder                                          
        - die SELECT-Klausel, WHERE-Klausel, GROUP-BY-Klausel, HAVING-Klausel                       
          oder ORDER-BY-Klausel wurde dynamisch angegeben.

    I Just want to insert data into internal table T_PA0002 from database table PA0002.
    The internal table and database table can change during the runtime of the program. But Its always filling the internal table with data from database table.
    I made it this way because the data I need to extract from data base tables can change depending on the procedures in table T9VS2.
    So I can't know the structure or the table which has to be selected each procedure. Or I have to make a big program with a lot of if or Case statements in it. I want to avoid that! Dynamic table is much quicker to write and understand when it works.
    It wil reduce a lot of code!  I hope someone can give me a hint to solve the problem.

  • Dynamic Columns with dynamic header colspans

    Hi All,
    Our project requires creation of dynamic data table at runtime. Following are the requirements.
    1.The number of columns and column headers should be dynamic. Basically the column headers are the Month names.
    2.Some or All of the above displayed months can be further split into 3 columns based on further values selected by the user. The months to be split into 3 columns will be identified only at runtime based on some calculations. When this happens, that particular month header should span 3 columns and an additional header for the 3 split columns have to be displayed. Check the screen shot below.
    ----------------------------------------------------------------------------------|-------------|
    Year: 2008 | Year: 2009 |
    ----------------------------------------------------------------------------------|-------------|
    |Current Month | | |
    -------------------------------------|--------------|-----------------------------|-------------|
    Sep | Oct | Nov | Dec | Year Total| Jan |
    ------------------|------------------|--------------|-----------------|-----------|-------------|
    | | |2008 |2009 |Total| | |
    ------------------|------------------|--------------|-----|-----|-----|-----------|-------------|
    Old |New |Total|Old |New |Total | | | | | | |
    Value|Value | |Value|Value| | | | | | | |
    -----|------|-----|-----|-----|------|--------------|-----|-----|-----|-----------|-------------|
    xx | xx | xx | xx | xx | xx | xx | xx | xx | xx | xx | xx |
    -------------------------------------------------------------------------------------------------Points to be noted:
    1.The colspan for the Year header is dynamic based on the months displayed for the previous, current, next year.
    2.The &lsquo;Current Month&rsquo; header is dynamic based on the month selected in the drop-down.
    3.The colspan for the month is dynamic based on whether it is displaying single column or 3 columns
    4.The header for the 3-column split is dynamic based on which are the months to be displayed with 3-column split.
    5. Irrespective of the month selected, DEC is always split into 3 columns.
    Is this achievable in JSF? Please let me know if anyone has worked on a similar requirement.
    Thanks and Regards,
    Anitha.

    Hi charishma/Raymond,
    Thanks for your response.
    charishma,
    I checked the link you provided and the code in that page. For me it looks like the colspan and rowspan are set by the user. Can it be done dynamically? I am still not in the development phase. I am still evaluating the possibilities. So it would be great if you can tell me if my requirements will be met with rich faces.
    Raymond,
    I am still in the evalution phase of whether this requirement is possible or not?
    In short, my requirement is to display columns dynamically. Based on certain conditions, each of the column can be further split to 3 more columns with 3 sub-headers below the main header. There are 4-5 rows of headers available for which the colspan has to be calculated dynamically depending on the total number of columns.
    The columns should be editable. i.e., the columns contain textboxes where the user can enter data. Again, the editable columns and non-editable columns are determined at run-time based on certain calculations.
    Is this possible? If not, i need reasoning as to why it is not acheivable.
    If it is not at all posible then the client is ready to compromise on the editing part. That is, data entry can be in a pop-up whereas, the the datatable should just display the data dynamically so as to print it for a report.
    Please let me know the possibility of this requirement.
    Thanks and Regards,
    Anitha.

  • Haw to create dynamic PDF with dynamic flowing tables across pages?

    Hi!
    Sorry for my english, I use it very rarely
    I try creating PDF form with many tables (example document: https://docs.google.com/open?id=0BxTpZtaOkLBbcEJzdGJFcXVSWDJ0RlladUZJd1hMZw). But, when the table or any element hit the bottom of page, they just flow over it. Also in designer elements don't distribute across pages but just disappear on first page bottom. I want to dynamically distribute elements across pages. What I do incorrect?
    m

    Please share you form with me [email protected]
    I will try to solve the problem.
    Nith

  • Dynamic table with dynamic binding

    Hello,
    I'm really not sure if I can realize that kind of feature using a table :
    I've created a dynamic table that have a dynimac number of columns except two.
    I've setted the value of the table to a certain list to fill out the two static field I need now to fill the data for each row for the dynamic columns but that kind of datas are inside another list
    Is it possible to manually create Row for Table and set the columns values ?

    Hi,
    I could not use both solution because I've two list (two data model) from different source, when the jsf page is generated it generated the correct number of column and output text but when I try to retrieve the component output text for example the 1 row and the second output text I got a null pointer exception because the column only have 1 child and not the full elements that we can see at html rendering.
    There is no solution for getting the full list of components before the page is generated ? because findComponent recursivly called doesn't found what I want.

  • Using bind variables (in & out) with dynamic sql

    I got a table that holds pl/sql code snippets to do validations on a set of data. what the code basically does is receiving a ID and returning a number of errors found.
    To execute the code I use dynamic sql with two bind variables.
    When the codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;however when I get to some more complex validations that need to do calculations or execute multiple queries, I'm running into trouble.
    I've boiled the problem down into this:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare
             some_var number;
          begin
          select 1 into some_var from dual
          where :2 = 61;
          :1 := :2;
          end;
          USING OUT counter, IN my_id;
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;this code doesn't really make any sense, but it's just to show you what the problem is. When I execute this code, I get the error
    ORA-6537 OUT bind variable bound to an IN position
    The error doesn't seem to make sense, :2 is the only IN bind variable, and it's only used in a where clause.
    As soon as I remove that where clause , the code will work again (giving me 61-61, in case you liked to know).
    Any idea whats going wrong? Am I just using the bind variables in a way you're not supposed to use them?
    I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

    Correction. With execute immediate binding is by position, but binds do not need to be repeated. So my statement above is incorrect..
    You need to bind it once only - but bind by position. And the bind must match how the bind variable is used.
    If the bind variable never assigns a value in the code, bind as IN.
    If the bind variable assigns a value in the code, bind as OUT.
    If the bind variable assigns a value and is used a variable in any other statement in the code, bind as IN OUT.
    E.g.
    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
    10                  1 into n
    11          from dual
    12          where :var1 = 61;       --// var1 is used as IN
    13 
    14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
    15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
    16  end;
    17  '
    18          using
    19                  in out id, in out cnt;  --// must reflect usage above
    20 
    21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
    22  end;
    23  /
    Procedure created.
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for

  • Resetting a game?

    I am creating a game where the challange is to collect all the coins while avoiding obsticules and before the times runs out. What I am trying to do is when the game runs out of time or the player has died, The player simply presses the R key on thei

  • I cannot print any kind of document using the File Print command on the tool bar of any application, but I can print using the printer icon. OS X 6.8 with HP Photosmart printer. Any thoughts?

    When trying to print any kind of document on my wife's Mac Pro, the File>Print Command will not work. She just downloaded an update to Microsoft Office and the problem began after that, but it also applies to other non-Microsoft Applications. However

  • ALV GRID PF status.

    Hi,     I am using the function module REUSE_ALV_GRID_DISPLAY and I have created the pf status after keeping PF status in report when I download data into excel only header is getting downloaded into excel but line item data is missing in the excel P

  • Query Selection View

    I'm using the Query Selection View web item on one of my web templates.  The issue is related to the Create and Delete command buttons not being displayed even though the Create/Delete - Display Button property has been selected for this control.  Th

  • Profit Center error in F-02

    Hi, I am passing following entry for transferring invoice amount into retention using TCode F-02 Entry: Vendor A A/c...  Dr (Special GL R, posting key 24)    To Vendor A/c A (posting key 39). There i want to enter profit center manually. But SAP does