Passing a table as a parameter
Hi,
I want to pass a table name as a parameter to a procedure . A cursor in the procedure will be using the passed parameter , to fetch the values.
For eg.
Procedure A(X varchar2)
cursor c1 is
select *
from X;
right now i'm getting an error , X must be defined...is there any other way to do the same..?
Thanx in advance.
Preetha
You'll need to use dynamic SQL for this. Look up either the dbms_sql package or the 'execute immediate' call.
With execute immediate, you'd do something like
Procedure A(X varchar2)
IS
sqlStatement varchar2(4000);
BEGIN
sqlStatement := 'select * from " || x;
execute immediate sqlStatement;
END
Justin
Similar Messages
-
How to pass internal table values to parameter
hi,
how to pass internal table values to parameter in selection screen.if is it possible means please sent codeings.
thanks.
stalin.hi,
tables : mara.
data : begin of itab_mara occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
end of itab_mara.
selection-screen : begin of block blk1 with frame title text-001.
parameters : p_matnr like mara-matnr.
selection-screen : end of block blk1.
select matnr ernam from mara into corresponding fields of itab_mara
where matnr = p_matnr.
loop at itab_mara.
write :/ itab_mara-matnr,
itab_mara-ernam.
endloop.
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
Error in passing internal table as returning parameter
Hi
Im new to ABAP OO.
I declared a parameter ret_kna1 Returning Type KNA1.
Inside the method, I am retrieving data from table KNA1 into internal table and then I want return the interal table value.
But Im not able to assing the internal table for eg : code
method READ_CUSTOMER_LIST.
data: lt_kna1 type TABLE OF kna1,
wa_kna1 LIKE LINE OF lt_kna1.
data: lv_kunnr type kna1-kunnr,
lv_land1 type kna1-LAND1.
SELECT * FROM kna1
INTO TABLE lt_kna1
WHERE land1 eq lv_land1.
insert LINES OF lt_kna1 INTO TABLE ret_kna1.
endmethod.
when I try to activate the error says 'ret_kna1 is not an internal table "OCCURS n" specification is missing.
but I can not declare the internal table 'ret_kna1' once again in the code, as it already defined in the parameter as type KNA1.
please help me how to assign internal table values to the returing structur.Are you passing it as an EXPORT parameter?
use and define it in the TABLES section of your function module as so:
*" IMPORTING
*" VALUE(INCLUDE_X_LEVELS) TYPE CHAR1 OPTIONAL
*" TABLES
*" I_SELECTED_OU STRUCTURE HRROOTOB
*" I_SELECTED_EE STRUCTURE OBJEC
*" E_VIP_EPM_DISTR STRUCTURE ZHR_VIP_EPM_DISTR
*" E_RETURN STRUCTURE BAPIRET1
That way you can pass value in the table (if needed) and then pass the table with your values based on your own logic -
Pass internal tables in Export Parameters of Function Module
Hi
How to pass internal tables through export parametes of the calling function module. i
think i can pass it by reference ....
if so can anyone suggest how to do it?Hi,
You can Export values of an Internal table in two ways, by :
1) specifying in Tables tab
(Not recommended since it's an obsolete in ECC 6.0)
If used, will reduce the performance of the FM
Tables are always passed by reference
2) specifying in Exports tab.
The parameter should be a Table type (created in se11)
having a Line type that refers to the structure of the data.
Pass by Value is not used for Normal Function modules.
Used usually for RFC enabled FMs.
Cheers,
Remi -
Pass table name as parameter in prepared Statement
Can I pass table name as parameter in prepared Statement
for example
select * from ? where name =?
when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
Thanks
Haroon Idrees.haroonob wrote:
I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
Well, I would say (ugly as it is) String concatenation, or stored procedures. -
Problem passing a table parameter in rfc call using the function control
I try to pass a Table as parameter to a Function Module using the SAP.Functions library (part of SAP frontend controls) from a Visual Basic (VBA) program.
The function module has been verified to work when invoked from SAP FrontEnd Function Builder.
The SAP RFC Control is created with
Set sapFunctions=CreateObject("SAP.Functions")
Following code snippet shows how I attempt to set exports and add a table row before calling the function module:
sapFunctions.Connection = sapConnection
Set sapMaterialUpd = sapFunctions.Add("Z_SD_BAPI_SALES_DATA_UPD")
With sapMaterialUpd
<i>'set exports</i>
.Exports("PA_GLPUPDLEVEL") = "S"
.Exports("PA_VKORG") = "FI14"
<i>'append table row</i>
.Tables("IT_SALES_DATA_UPD").AppendRow
.Tables("IT_SALES_DATA_UPD")(1, "VKORG") = "FI14"
.Tables("IT_SALES_DATA_UPD")(1, "MATNR") = "W_3100"
.Tables("IT_SALES_DATA_UPD")(1, "DATBI") = "99991231"
.Tables("IT_SALES_DATA_UPD")(1, "DATAB") = "20041231"
.Tables("IT_SALES_DATA_UPD")(1, "KBETR") = "2222"
.Tables("IT_SALES_DATA_UPD")(1, "KONWA") = "EUR"
End With
<i>'call the function module</i>
If sapMaterialUpd.Call() = True Then
<i>'do something with the return tables here...</i>Else
Debug.Print sapMaterialUpd.Exception
End If
The Call() returns <b>FALSE</b> and the exception is <b>"SYSTEM_FAILURE"</b>. The connection also resets.
The local logfile that the control generates shows that an exception occurs at the point of the call:
<i>10.02.2005 17:54:20.766 Packing Parameters for Z_SD_BAPI_SALES_DATA_UPD
Packing Parameter PA_GLPUPDLEVEL.
Packing Parameter PA_VKORG.
Packing Table 0.
Packing Table 1.
10.02.2005 17:54:20.766 *** Calling RFC Function 'Z_SD_BAPI_SALES_DATA_UPD'
10.02.2005 17:54:20.986 RFC CALL status = RFC_SYS_EXCEPTION
10.02.2005 17:54:20.986 RFC Error: RFC_IO27
-Status:CODE=CM_DEALLOCATED_NORMAL STATUS=CM_NO_STATUS_RECEIVED DATA=CM_COMPLETE_DATA_RECEIVED ID=69415076
-Message:connection closed
-Internal Status:IO HANDLE=23 DRV=EXT LINE=1420 CODE=27 : GET ID=ffff LINE=861 CODE=7
10.02.2005 17:54:20.986 Function call finished.</i>
Seen next code snippet. If the Table object is not touched, the function call goes through without any problems:
sapFunctions.Connection = sapConnection
Set sapMaterialUpd = sapFunctions.Add("Z_SD_BAPI_SALES_DATA_UPD")
With sapMaterialUpd
'set exports
.Exports("PA_GLPUPDLEVEL") = "S"
.Exports("PA_VKORG") = "FI14"
'do <b>not</b> append a table row, for testing only ;-)</b>
End With
<i>'call the function module</i>
If sapMaterialUpd.Call() = True Then
<i> 'do something with the return tables here...</i>
Else
Debug.Print sapMaterialUpd.Exception
End If
This code works perfectly when calling the function. It returns TRUE and behaves normally. The function module returns descriptive response text in a table telling that the table was empty, according to the BAPI implementation.
So is there something special needed here <i>after</i> appending the table row and <i>before</i> making the Call to properly attach the table as a parameter for the function module?
Can this be a bug in the SAP RFC Control? The version of the wdtfuncs.ocx is 6206.6.45.54.
Any hints are welcome!hi All partner,
who solved this problem , I meet it too and
can't clear it.
SAPfunc := sapfunctions1.Add('z_get_sfcs_dn_mo');
SAPitab := sapfunc.tables.item ('I_DNMO');
SAPitab.appendrow; SAPitab.value(1,'MANDT') := '220';
SAPitab.Value(1,'VBELN') := '2150000001';
SAPitab.Value(1,'POSNR') := '50';
SAPitab.value(1,'MATNR') := '19-99999-00';
SAPitab.value(1,'AUFNR') := '921241512001';
SAPitab.value(1,'DEDAT') := '2005/09/09';
SAPitab.value(1,'LFIMG') := '100';
IF SAPfunc.call = true then
begin
end
else
begin
showmessage('call fail!!') ;
end;
end;
RFC source code as below
FUNCTION z_get_sfcs_dn_mo.
""Local interface:
*" TABLES
*" I_DNMO STRUCTURE ZDN_MO
data: wa type zdn_mo.
LOOP AT i_dnmo.
wa-mandt = i_dnmo-mandt.
wa-vbeln = i_dnmo-vbeln.
wa-posnr = i_dnmo-posnr.
wa-matnr = i_dnmo-matnr.
wa-aufnr = i_dnmo-aufnr.
wa-dedat = i_dnmo-dedat.
wa-lfimg = i_dnmo-lfimg.
modify zdn_mo from wa.
insert into zdn_mo values wa. --dump at here
commit work.
ENDLOOP.
T/C: ST22 error message say at
insert into zdn_mo values wa. ---dump at here
the sapfunc.call returns fail.
Message was edited by: jorry wang -
Can I pass a table function parameter like this?
This works. Notice I am passing the required table function parameter using the declared variable.
DECLARE @Date DATE = '2014-02-21'
SELECT
h.*, i.SomeColumn
FROM SomeTable h
LEFT OUTER JOIN SomeTableFunction(@Date) I ON i.ID = h.ID
WHERE h.SomeDate = @Date
But I guess you can't do this?... because I'm getting an error saying h.SomeDate cannot be bound. Notice in this one, I am attempting to pass in the table function parameter from the SomeTable it is joined to by ID.
DECLARE @Date DATE = '2014-02-21'
SELECT
h.*, i.SomeColumn
FROM SomeTable h
LEFT OUTER JOIN SomeTableFunction(h.SomeDate) I ON i.ID = h.ID
WHERE h.SomeDate = @DateHi
NO you cant pass a table function parameter like this?
As When you declare @date assign value to it and pass as a parameter it will return table which you can use for join as you did it in first code
But when you pass date from some other table for generating table from your funtion it doesnt have date as it is not available there
Ref :
http://www.codeproject.com/Articles/167399/Using-Table-Valued-Functions-in-SQL-Server
http://technet.microsoft.com/en-us/library/aa214485(v=sql.80).aspx
http://msdn.microsoft.com/en-us/library/ms186755.aspx
https://www.simple-talk.com/sql/t-sql-programming/sql-server-functions-the-basics/
http://www.sqlteam.com/article/intro-to-user-defined-functions-updated
Mark
as answer if you find it useful
Shridhar J Joshi Thanks a lot -
How to pass a table as parameter on a stored procedure
Hello all,
I want to pass the name of a table as parameter into a stored procedure, that will be used for cursors etc.
But when i pass the parameter and i compile the S.P. it give me error (error: table not existing...)
Any Help?
Thanks in advance, MarcoMarco wrote:
As i've written above, i'm using stored procedures like 'batch' programs which will be executed with oracle scheduler (passing to s.p. the name of the 'input' tables)
These input tables are 'external' tables which have got the same structure; for example i've got TABLEX_001, TABLEX_002, XXTAB etc. with the same structure.
This is the the reason... what do you think?An external table definition can reference multiple files via the LOCATION definition or you can user "ALTER TABLE" to alter the location and change the file that the external table points to.
Thus you only need one static External Table and use an alter table (via execute immediate) to change the file location it points to, or if you want all the data together, just specify all the files in the location.
That would be clean design, using one fixed table, without the need to pass any table names, just dynamically altering the file names if necessary at run time. -
Passing selection table as parameter to function modules
i tried to pass a selection table as a parameter to a function module but there is a problem stating the eror the table length is different.
*& Report ZSFSELECT_OPTIONS_PGM
REPORT zsfselect_options_pgm.
TABLES zselect_options.
SELECT-OPTIONS sop FOR zselect_options-id.
DATA : fname(15) TYPE c.
*CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = fname
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME =
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
DATA lth(2) TYPE c.
DATA ty TYPE i.
DATA o TYPE i.
DATA l TYPE i.
DATA k TYPE c.
DESCRIBE FIELD sop-sign TYPE lth LENGTH ty IN CHARACTER MODE.
CALL FUNCTION fname
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS =
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS =
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO =
JOB_OUTPUT_OPTIONS =
TABLES
sf_sop =sop
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
in the smart form i have tried to pass the sp as the table.
i have created a program line node
:SELECT * FROM zselect_options INTO TABLE it_tab WHERE id IN sf_sop.Hi,
If i understand ur problem correctly u r trying to pass a select-option to Tables for a smartform function module. It gives an error & it correct.
If u understand the structure of a select option, it will have 4 fields in it & the structure will be
SIGN CHAR1
OPTION CHAR2
LOW Type Zfield
HIGH Type Zfield
But ur receiving Table paramter of the smnartform FM will be having only 1 field - Type Zfield
So this mismatch gives u an error.
Solution:
Case1:
Write code outsied th FM in ur program to get all the values & build an internal table & pass that to the FM.
Case2:
Define the Structure of table in the smartforms as tols earlier & then try passsig the Select option.
Thanks & Regards,
Bhargava -
Pass Structured table into dynamic table parameter in public method
Ladies and Gentlemen,
I have a requiremet to pass (1 at a time) any number of tables into a reuseable method in a custom class. The Method code is as follows:
method CREATE_OUTBOUND_FILE.
* Importing VALUE( IV_PATHNAME ) TYPE PATHEXTERN File Destination
* Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATA Table with Output
* Importing VALUE( IV_RECORD_STRUCTURE ) TYPE STRING OPTIONAL Record Structure
* Importing VALUE( IV_DELIMITER ) TYPE STRING File Delimiter
* Exporting VALUE( EV_RECORD_CNT ) TYPE STRING Record Count
Data:
ls_line_cnt(6) type n,
lt_data_struc type zty_ddic_struc_T,
ls_string type string.
field-SYMBOLS: <fs_string> type any.
* Open Dataset for outputting file details
Open dataset iv_pathname for output in text mode encoding default.
Assign ls_string to <fs_string> CASTING TYPE (iv_record_structure).
loop at it_file_record into <fs_string>.
transfer <fs_string> to iv_pathname.
Add 1 to ls_line_cnt.
clear <fs_string>.
endloop.
ev_record_cnt = ls_line_cnt.
where IV_PATHNAME = output destination & filename
IT_FILE_REC = data table
IV_RECORD_STRUCTURE = is ddic structure definition for the data table
IV_DELIMITER = file delimiter, in this case, let's say it's C (for CSV)
and EV_RECORD_CNT is a count of numbe of records processed.
Lets say, for example, I wish to load data from table SFLIGHT into the method when program A is executed. Then another time I wish to excute Program B which is passing in data of table SFLCONN2. I hope that by using the "type ref to data" defintion, I can pass the table contents through. Is this true?
Secondly, I'm getting a syntax error saying that "IT_FILE_RECORD" is not defined as a table (and therefore can't be looped at), and therefore can't be read. How can I access the data in this table in preparation for output.
Any assistance or thoughts would be greatly appreciated.
Regards,
SteveHi Stephen ,
Graham already gve part of the solution.
If you declare
Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATA
it does not make sense to declare to pass by VALUE because you will not change this refernce in the method. Calling this method, you must pass a refefernce.
data:
lr_ref type ref to data.
get reference of <your itab here> into lr_ref.
CREATE_OUTBOUND_FILE( ...IT_FILE_RECORD = lr_ref ... )
In the method, it goes as graham explained.
Anyway, I would declare the table parameter as
Importing IT_FILE_RECORD TYPE TABLE
The your code could work, but you will have troube with any non-character fields in the tables.
Regards,
Clemens -
Passing Internal table as parameter to a Method
Hi,
Can somebody tell me how to pass an Internal table as a parameter to a method?
Thanks in advance,
Best Regards,
Manishdata: itab1 type string occurs 0 with header line.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
exporting
FILENAME = 'C:\ftext.txt'
APPEND = 'X'
changing
DATA_TAB = <b>itab1[].</b>
Svetlin -
Passing different tables as a input parameter
HI,
I've 5 tables TAB1, TAB2, TAB3, TAB4, TAB5
and I created 5 store procedures to generate 5 file.txt with utl_file utility.
Now I'd like to know if possible create just one stored procedure (or package) with just one cursor
that passing different tables as a input parameter.
Have you any idea?
Thanks in advance!Here you go...
SQL> create table tab1 as select 1 as x, 'A' as y from dual union
2 select 2, 'B' from dual union
3 select 3, 'C' from dual;
Table created.
SQL>
SQL> create table tab2 as select 4 as x, 'D' as y from dual union
2 select 5, 'E' from dual union
3 select 6, 'F' from dual;
Table created.
SQL>
SQL> CREATE OR REPLACE PROCEDURE output_tbl (p_table_name IN VARCHAR2) IS
2 v_cur SYS_REFCURSOR;
3 x NUMBER;
4 y VARCHAR2(10);
5 BEGIN
6 OPEN v_cur FOR 'SELECT x, y FROM '||p_table_name||' ORDER BY x';
7 LOOP
8 FETCH v_cur INTO x, y;
9 EXIT WHEN v_cur%NOTFOUND;
10 -- Here you would output to your file, but for ease of
11 -- demonstration I'll just dbms_output the data
12 DBMS_OUTPUT.PUT_LINE(x||' : '||y);
13 END LOOP;
14 END;
15 /
Procedure created.
SQL> exec output_tbl('TAB1');
1 : A
2 : B
3 : C
PL/SQL procedure successfully completed.
SQL> exec output_tbl('TAB2');
4 : D
5 : E
6 : F
PL/SQL procedure successfully completed.
SQL> -
Whats the difference betweeen passing the table variable and table valued parameter?
Hi Everbody
Can someone one tell me what's the difference between passing a table variable and table valued parameter to a stored procedure or function? Can both be used to pass a table to a stored procedure/function?
Regards
RegardsThey are essentially the same. What we call a table variable is a local
variable. A table-valued parameter is an incoming parameter to the
procedure. The only difference is that the parameter is readonly.
When you call a stored procedure, you can pass a table variable as the
actual parameter. Or a table-valued parameter that you pass on.
CREATE PROCEDURE nisse_sp @tvp sometype READONLY AS
DECLARE @local someothertabletype
EXEC pelle_sp @tvp, @local
Erland Sommarskog, SQL Server MVP, [email protected] -
Passing a table as a procedure parameter
I'm trying to pass a table_name as a parameter but it is not working. Any idea ???
CREATE OR REPLACE PROCEDURE SIMM.populate_field
( field_name IN all_tab_columns.column_name%TYPE)
IS
v_a part_index_temp.no_dossier%TYPE;
CURSOR c_temp IS
SELECT no_dossier FROM part_index_temp FOR UPDATE;
BEGIN
OPEN c_temp;
LOOP
FETCH c_temp INTO v_a;
EXIT WHEN c_temp%NOTFOUND;
UPDATE part_index_temp a
SET
a.nouv_nom = (
SELECT field_name
FROM part_index_temp
WHERE rnum= (SELECT (1+ABS(MOD(dbms_random.random,10)))
FROM dual)
WHERE CURRENT OF c_temp;
END LOOP;
CLOSE c_temp;
END;What are you trying to accomplish?
Describe the business requirement and we can help you.
The way you are trying to pass in a Column name (not the table name) requires dynamic sql... -
Help passing table name as parameter to a procedure
Hello,
i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
CREATE OR REPLACE
PROCEDURE excur(
p_tbl user_tables.table_name%type )
AS
type rc is ref cursor;
c rc;
res BOOLEAN;
BEGIN
open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
close c;
END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.vishm8 wrote:
Hello,
i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
CREATE OR REPLACE
PROCEDURE excur(
p_tbl user_tables.table_name%type )
AS
type rc is ref cursor;
c rc;
res BOOLEAN;
BEGIN
open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
close c;
END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.Generally speaking, Dynamic code is a bad idea for a staggering number of reasons.
That aside, what do you want to return? You're selecting a column and applying an aggregate function (count) but you're not grouping, that doesn't usually work out too well.
TUBBY_TUBBZ?select owner, count(*) from all_objects;
select owner, count(*) from all_objects
ERROR at line 1:
ORA-00937: not a single-group group functionWhy do you perceive the need to be able to take in ANY table name, can't you design an application where table names are known at compile time and not run time?
Maybe you are looking for
-
Received "1d.so.1 malloc failed killed just before my system went down. Booted into single user with the cd, fsck on unstable disk, tried rebooting the system back into multi- user, but it still won't boot up. Anyone knows what else I should be doing
-
Issue with exception Handling in GG
Hi, I have bi-directional DML replication setup. I have written a code in replication parameter for handling the exception , Exception handling is working fine my replicate process is not getting ABENDED but Issue is I am not geeting any rows in EXCE
-
Hi experts, I am working on cFolders 4.0 When I create a material, data sheet, discussion, upload is hapenning properly and I am able to see the version of the created object. How ever, when I create a document, I get the screen to browse for a file
-
How install flash player for linux
I need command information for install in linux system ! thanks
-
Hi Team, Any one can share the Anchor WLCs LLD Documents. Regards,