Dynamic selection of tables
Hi
Is it possible to create a dynamic selection of tables in the 'from' clause.
Thanks in advance
Hi,
Thanks for the reply.
I have two tables. Currently in our existing production system we have two different procedures for example say, P1 and P2. These procedures have the same logic except that the data is retrieved from two different tables.
I felt that if there is a possibility to select data from the tables dynamically then i could just use one common procedure and pass the tables as parameters to that.
To make it more clear, please see the following.
I have two tables , say T1, T2.
I have two procedures P1, P2 in one package.
P1 procedure
Procedure P1 is
cnt number := 0;
Begin
select count(*) into cnt from T1;
if cnt = 0 then
IF GVAR.T1_RecordNbr <= '1' -- GVAR is Global Variable package
THEN
IF NAME_IN('T1.col_name') IS NULL
THEN
display_msg('Error');
END IF;
end if;
end if;
end;
[\pre]
P2 procedure
[pre]
Procedure P2 is
cnt number := 0;
Begin
select count(*) into cnt from T2;
if cnt = 0 then
IF GVAR.T2_RecordNbr <= '1'
THEN
IF NAME_IN('T2.col_name') IS NULL
THEN
display_msg('Error');
END IF;
end if;
end if;
end;
[\pre]
Now I want to write only one procedure and just change the table names dynamically. Could you please suggest.
Similar Messages
-
Hi there,
I'm only using a read-only account, which means I can only execute SELECT statements. I also can't create any stored procedures.
I have been given a database to worked on with this kind of schema. The database has one main table and 20 sub tables. On the main table, there a column for category.
If it's CategoryA, my query should be using the main table and subTableA.
If it's CategoryB, my query should be using the main table and subTableB.
If it's CategoryC, my query should be using the main table and subTableC.
and so on...
My question is: how can I make a simple SELECT statement with this kind of schema? The relation between the main_table and sub_tables is one to many (by the 100k rows) records.
SELECT *
FROM main_table a, subTableX b
WHERE a.item_id = b.item_idIs this possible by just using a SELECT statement?
Thanks in advance.But u can use substitution variable like this..
SQL> select * from merge_test;
ITEM_ID PROP_NAME PROP_VALUE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa5776 STATUS NOT_DONE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa789 STATUS_Test DONE
SQL> select * from merge_t;
ITEM_ID PROP_NAME PROP_VALUE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa5776 STATUS NOT_DONE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa1234 ASTATUS NOT_DONE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa1234 ASTATUS NOT_DONE
SQL> select merge_test.item_id, merge_test.prop_name, merge_test.prop_value
2 from merge_test,&table_name b
3 where merge_test.prop_name=b.prop_name;
Enter value for table_name: merge_t
old 2: from merge_test,&table_name b
new 2: from merge_test,merge_t b
ITEM_ID PROP_NAME PROP_VALUE
1ec8add9-fd2d-4b8d-8fb0-ca2fb1aa5776 STATUS NOT_DONE
SQL> Refer the link for more info on substitution variable
http://www.oracle-base.com/articles/misc/LiteralsSubstitutionVariablesAndBindVariables.php
Regards
Umesh -
Exclude one field from Logical Database's dynamic selection screen
Hi Guru,
I have a requirement to amend a program to exclude the document number field (bsik-belnr) from the dynamic selection-screen of the logical database KDF(Vendor Database) so that the program will not filter according to the document number.
I have use the below syntax in my zprogram.
selection-screen exclude select-options: doc-no.
However I get syntax error "The addition EXCLUDE is only allowed in INCLUDE DBKDFSEL".
Please advice.
Best Regards,
FungThe selection part of the logical database defines input fields for selecting data.
The runtime environment displays these on the selection screen when you run an executable program linked to the logical database.
Include called DB<ldbname>SEL.
SELECTION-SCREEN BEGIN OF VERSION ver TEXT-xxx.
SELECTION-SCREEN EXCLUDE ... .
SELECTION-SCREEN END OF VERSION ver.
Defines a selection screen version (with a three-character name ver ). Between BEGIN OF VERSION and END OF VERSION , you can exclude selection screen objects for the version ver , i.e. remove them from the selection screen with SELECTION-SCREEN EXCLUDE.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE dbtab
If one of these tables is active in the report (i.e. it is declared under TABLES or lies somewhere on the path from the root of the database hierarchy to a table declared with TABLES ), a pushbutton called 'Dynamic selections' appears on the selection screen. -
How to control the dynamic selections in FBL3N?
When I execute the Selection screen of the logical Database SDF, it shows me all the 4 segments - GL Master Record, Compnay Code, Document, Custom (I added this descritption).
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE SKA1.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE SKB1.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE BSIS.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE FAGLFREESEL.
but when I execute FBL3N, I am not able to see the 4th segment fields (FAGLFREESEL).
Pl advise where it is gettig suppressed in the code.
Also is there a way to use the fields from the following in Dynamic Selections?
SELECTION-SCREEN FIELD SELECTION FOR TABLE SKA1.
SELECTION-SCREEN FIELD SELECTION FOR TABLE SKB1.
SELECTION-SCREEN FIELD SELECTION FOR TABLE BSIS.
SELECTION-SCREEN FIELD SELECTION FOR TABLE BSISEXT.
SELECTION-SCREEN FIELD SELECTION FOR TABLE BKPF.
SELECTION-SCREEN FIELD SELECTION FOR TABLE BSEG.
SELECTION-SCREEN FIELD SELECTION FOR TABLE GSEG.
Thanks,
Venno solution so far. clsong as it is waiting for a long time
-
ABAP Help: Dynamic Selection Screen
Hi,
I have a requirement to be able to pick the list of fields in a selection screen. (List processing)
Similar to SE16 choosing "fields for selection".
I've debugged SE16 and realized it deletes the report and regenerates a new report with the updated selection screen.
I could not do the same as it will also delete all the variants users have created in the report.
Has anyone done something similar before?
What is the best approach for this scenario?
Regards,
Michael PangHi Michael
Hoping you have solved your problems with ALVs, I think it may be helpful to inspect FMs <b>"FREE_SELECTIONS_INIT"</b> and <b>"FREE_SELECTIONS_DIALOG"</b> for this issue. They have some <i>Function Module Documentation</i>.
If you are dealing with logical databases, then only in the INCLUDE program DB<i>ldb</i>SEL of logical database <i>ldb</i>, you can use some selection-screen definition variants as:
1.SELECTION-SCREEN BEGIN OF VERSION vers TEXT-xxx.
2.SELECTION-SCREEN END OF VERSION vers.
3.SELECTION-SCREEN EXCLUDE ... .
4.SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE dbtab.
5.SELECTION-SCREEN FIELD SELECTION FOR TABLE dbtab.
6.SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE node.
7.SELECTION-SCREEN FIELD SELECTION FOR NODE node.
You can get more info from SAPHelp for these...
*--Serdar -
Add field in dynamic selections of FBL3N
Hi,
I know this question has been post before and i have followed the sap note 188663 and 832997, and also I read it in the wiki tab, "Enhancing Selection Views in the dynamic selection of FB03, FBL3n, FBL5n and etc".
But no available for me.
Requirement: Accounting document entry date(BKPF-CPUDT) need to be added in the dynamic selection in FBL3N.
I did the following customizations, but it doesn't work.
1.Execute Transaction code SE36. Enter "SDF" in Logical database field.
2.From the initial screen of SE36, Choose from the path EXTRAS>> Selection Views
3.Change the selection views "CUS".
4.double click table BKPF, and enter "02" in function group of Accounting document entry date(BKPF-CPUDT).
But, when I execute FBL3N, the custmized filed was not displaying in dynamic selection.
And then, I found there is no BKPF table in dynamic selections setting in front screen of SE36. ( Menu path : Extras >>Dynamic selections ).
So, I modified the Selections of Subobjects as belows.
"SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE BKPF."
When I use a test run(F8) in SE36, I could get the additional field in the dynamic selection.
However, I still could not get it in executing FBL3N.
I see that there is a Edit -> generate -> selections and program in front screen of SE36, and when I selected, the message was displayed as "The slections for LDB SDF cannot be generated (already exist)".
Please assist me.
Thanks in advance.
WeiyangDear Weiyang
kindly note that as per SAP note 310886 Only certain tables or fields are permitted
Permitted tables:
SKA1: all fields
SKB1: all fields
BSIS: all fields
no other table is allowed
so your field BKPF-CPUDT is not allowed in dynamic selection
Hope your query is solved
Cheers
IMK -
Dynamic Selection Screen Fields
Hi All,
I have made a copy of the program FI_RFSOPO00. This report uses dynamic selection screen. I wanted to know the names of these dynamic selection screen. As I have to make some database selections based on the user entries in these fields.
Is there a way to find this out?
Regards,
StephenHi Stephen,
1) FI_RFSOPO00 is unknown- i think you mean <b>RFSOPO00</b>
2) RFSOPO00 uses logical datbase SDF, which uses
free or dynmaic selections from the tables ska1,skb1
and bsis.
see F1 to <i>SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE dbtab </i> and ta SE36 to SDF too.
regards Andreas -
Adding a BSEG field to the FB03 dynamic selection screen
Hello,
We have a requirement wherein we want to add a field from BSEG in the dynamic selection screen of FB03.
We found that the logical database behind this is BRF. So we created a u2018CUSu2019 selection view for the logical database and added the field from BSEG to the functional group
and checked the checkbox u201CPreselectu201D for it to appear automatically in the FB03 screen.
But we still couldnu2019t see the field in FB03 dynamic selection.
On analysis, we found that only tables are that are defined in the nodes (Extras Selection views) can be used to create the dynamic selection and BSEG was not available
as one of the node. So we added BSEG as one of the node by adding the below code to the SELECTION of the logical database.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE BSEG.
Even after that, we couldnu2019t see the field from BSEG in the dynamic selection.
Are we missing anything here?
I see many threads here on similar lines but no one has posted the exact step. Any help is highly appreciated.
Thanks a lot.
Regards,
SuganyaHi
If you want to take the line item details than you can refer these t-codes rather than customizing.
S_AC0_52000887 - Receivables: Profit Center
S_AC0_52000888 - Payables: Profit Center
S_ALR_87012332 - G/L Account Statements
Here by using the dynamic selection you can get the results. Use object list display and select the layout for more fields.
Thanks -
Dynamically selecting column names in report builder ???
Dear members,
I have a requirement in which the user dynamically selects the tables column names. Like suppose take DEPT table. My query would be
select &P Report from dept;
so if the user selects DNAME then i would get the dname values and so on... This is fine but if one gives the value for the lexical parameter as DEPTNO,DNAME then i should get two columns in my report output. The select statement then becomes
select DEPTNO,DNAME Report from dept;
But i am not able to do this in report builder(6i). If i use just one value for the parameter then i get the o/p but if i use more than one (eg: DEPTNO,DNAME) then its giving an error.when i run this query through toad or sql plus then i am getting the desired o/p but wher as in report builder i am not able to get the o/p.
My report triggers are :
Before Parameter form :
:P := NULL;
After parameter Form :
function AfterPForm return boolean is
begin
IF :P = 'DNAME,DEPTNO' THEN
:P := ' DNAME,DEPTNO ' ;
ELSE
:P := NULL;
END IF;
return (TRUE);
end;
Your comments and suggestions are welcomed.
thanks
regards
sandeepNumber of columns can not be changed at run time. If your data model has three columns, lexical parameter should pass 3 values. If you have query like this in data model:
select &p_1 from table
Whatevere you have as initial value in user parameter p_1, data model captures that info. -
Program with Dynamic selection but no LDB is used
Hello Friends,
Can any one tell me the any standard program name, In which Dynamic selection (Free Selection) is used but LDB(Logical Data Base) is not used.
Lalit SoniNot possoble with out LDB, it uses selection-screen dynamic selections for table <tabname> in ldb, one alternative is using the screen table to hide selection.
E,.g
loop at screen.
if screen-group1 = 'FS1' .
screen-active = 1.
modify screen.
endif.
endloop. -
Dynamic Select query is failing with error "Invalid Table Name"
OPEN rc FOR 'SELECT count(*) from :s' USING tab_name;
fetch rc into rec_count;
CLOSE rc;
my requirement is to build dynamic select query to retrieve the total count of rows in each table ( variable tab_name contains the table_name )
But I am getting stuck by this errror, not sure if there is any alternative !
ORA-00903: invalid table name
ORA-06512: at line 43OPEN rc FOR 'SELECT count(*) from '||tab_name;
fetch rc into rec_count;
CLOSE rc;
-- This will work
1. Create a sql statement.
2. Open ref cursor for that statement. -
Dynamic selection screen fetching the value from table fields
hi gurus,
i have one table say ztable...and i should create a dynamic selection screen which should populate the selection screen by the table field names.
example..if i have 3 fields im my table..my selection screen should have three selection option fields..and in future if i add one more field in my table it should automatically create another slection-option in selection screen..
thanks
SudheerDo you mean like SE16 works. If so, you should notice that if you amend the selection fields, the screen program is actually re-generated.
That is what is happening. A program is being created and re-generated.
To create a dynamic selection screen in a single program is not possible ( I may be wrong ). If it is possible, then you would have problems in defining selection screen field names and using them. -
Which table the dynamic selection view will be stored
Dear Freinds,
I have created a dynamic selections view form Se80 > Editobject>Selection view > Created by adding the required tables pa0002,pa006,pa0009 . But the transport request we have saved it locally
now i want to create a transport request for the dynamic view . Could any please let me know how to create transport reqest for the Dynamic selection
View which has been created.
regards
divyaHiDivya,
yo have saved the changes into local object and now you want to generate the TRN and for the save you have to change the attribute > GOTO > Other object Entry and changed the package and TRN will generate .
Regards
Sheetal -
Extend dynamic selection for a field added on PRPS table
Hi Gurus,
I want to see the field that I've added in PRPS table as part of dynamic selection on the reports like S_ALR_87013542/ S_ALR_87013532. The LDB for project systems is PSJ. How do I make it appear as a dynamic selection on the selection-screen criteria for these reports?
Thanks...Hi,
We have done this a lot on my project. Follow these steps:
(1) Transaction SE36 for logical database PSJ
(2) Choose menu path Extras -> Selection views (Ctrl+F7)
(3) Change the "Origin of view" to SAP
(4) Find the PRPS_R node in the top, right "Tables/nodes" view.
(5) Double-click PRPS_R.
(6) Find your custom field that you added in PRPS (in the bottom "Table fields/node fields" view.
(7) Choose and enter a 2-character Function Group ID (see the top, left view) next to the new field.
(8) Save and transport...
Best Regards,
James Gaddis -
Dynamic selection need from a table
Hi,
I have a requirement to select the data from a table dynamically. Only during run time I will know the structure of that table & table name. In this case can anyone give any tips/sample code how it can be accomplished. Help appreciated.
Thanks,
AbhiSure, check out this sample program. It is a dynamic table read.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
* 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.
Welcome to SDN. Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.
Regards,
Rich Heilman
Fixed Code
Message was edited by: Rich Heilman
Maybe you are looking for
-
How to make list view the default in finder?
Is there a way to make "List view" be the default view for all folders opened? I know that with a window open, you can hit CMD-1, 2, 3 or 4 for icon, list, column, or cover view, but I want "list view" to be the default. I know that in some windows I
-
Error while reading USB Port : using JSR80
Hi Everybody Iam trying to read the data from a usb device [a fingerprint scanner] by using jsr80 with the help of following files which are in my classpath 1) jsr80-1.0.1.jar 2) jsr80_ri-1.0.1.jar 3) jsr80_windows.jar 4) commons-logging-api-1.1.1.ja
-
when i put a new hard drive in my macbook i had to reinstall OS X. It seems the software updates didn't get backed up with time machine meaning that I have outdated software for safari and especially itunes. I used time machine to transfer all my fil
-
Guided Procedure based on NetWeaver 7.0
Hello experts, could you please let me know if there are any tutorials to implement a GP based on the NetWeaver Version 7.0. The best would be if I had an overview about all Layers. Servce, User Interface and Process Layer. Thanks a lot. Regards Marc
-
I was trying to create a list manager with the values from this sql stmt select vb.vcbauto, v.vendor_name, c.contact_name, b.bid_number, b.contract_description from purch_vendor_bid vb, purch_vendor v, purch_contact c, purch_bid b, purch_vendor_conta