Finding column count with dynamic columns and dynamic tables
I've done some PL/SQL for awhile now but was trying to devise a solution for the following problem:
I wish to find the number of times a specific value for a column exists in all the tables that contain the field and I have access to see with the current user. The column name and value will be passed in via parameters.
I was hoping to use something like
select table_name from all_tab_columns where column_name = <variable table name>;
then use the results from this to create a select statment based off the tables from the select above. I know the difference between dba_tab_columns and all_tab_columns - I want to make sure that I only retrieve the values i have access to.
Can anyone point me to some guide / website / reference material I can read to catch up on the idea of creating this statment?
Thank you.
Hi,
it's a test version.
You can naturally tune it, but it seemed to work:
declare
pi_column VARCHAR2(30) := 'DEPTNO';
pi_value VARCHAR2(4000) := '20';
v_count NUMBER := 0;
v_count_tab NUMBER;
BEGIN
FOR I IN (select owner, table_name from dba_tab_columns
where column_name = pi_column
LOOP
EXECUTE IMMEDIATE 'SELECT count(*) FROM '||i.owner||'.'||i.table_name||
' WHERE '||pi_column||' = :pi_value' INTO v_count_tab USING pi_value;
v_count := v_count + v_count_tab;
END LOOP;
dbms_output.put_line(v_count);
END;Regards
Similar Messages
-
I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??
Hi Kishore,
First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table. -
Function with for loop and parameter table/column names ... syntax help
I'm trying to create a function that returns the distinct values and counts from a user defined schema/table/column.
The code below defines an object type [stats_on_column_obj] and creates a single table of this type [stats_on_column_tab].
The function is supposed to take three input variables: p_schema_name, p_table_name, p_column_name and return a table (above).
I can hard code a SELECT statement into the () ... but once I try to convert it to parameters & exec immediate I am stuck. The red section is where the issue is (i think).
Oracle 10g.
CREATE TYPE stats_on_column_obj IS OBJECT(
COL_VAL VARCHAR2(500),
COL_VAL_CNT NUMBER (7)
CREATE TYPE stats_on_column_tab IS TABLE OF stats_on_column_obj;
CREATE OR REPLACE FUNCTION get_STATS_ON_COLUMN
p_schema_name IN varchar2,
p_table_name IN varchar2,
p_column_name IN varchar2
RETURN STATS_ON_COLUMN_tab
IS
l_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab := STATS_ON_COLUMN_tab ();
n INTEGER := 0;
str_select_tbl varchar2(5000);
BEGIN
str_select_tbl := 'SELECT '||p_column_name||' as col_val, count(*) as col_val_cnt FROM '||p_schema_name||'.'||p_table_name||' group by '||p_column_name;
FOR r IN (str_select_tbl)
LOOP
l_STATS_ON_COLUMN_tab.EXTEND;
n := n + 1;
l_STATS_ON_COLUMN_tab (n) := STATS_ON_COLUMN_obj (r.col_val, r.col_val_cnt);
END LOOP ;
RETURN l_STATS_ON_COLUMN_tab;
END;
[Error] PLS-00103 (124: 4): PLS-00103: Encountered the symbol "LOOP" when expecting one of the following: * & - + / at mod remainder rem .. <an exponent (**)> || multiset year DAY_
[Error] PLS-00103 (126: 9): PLS-00103: Encountered the symbol "=" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestam
[Error] PLS-00103 (127: 29): PLS-00103: Encountered the symbol "(" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestam
[Error] PLS-00103 (128: 4): PLS-00103: Encountered the symbol "END" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form
SELECT * FROM TABLE (get_STATS_ON_COLUMN('SCHEMAS_X','TABLE_X','COLUMN_X'));SCOTT@orcl > CREATE OR REPLACE
2 FUNCTION get_STATS_ON_COLUMN(
3 p_schema_name IN varchar2,
4 p_table_name IN varchar2,
5 p_column_name IN varchar2
6 )
7 RETURN STATS_ON_COLUMN_tab
8 IS
9 v_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab := STATS_ON_COLUMN_tab ();
10 v_n INTEGER := 0;
11 v_str_select_tbl VARCHAR2(5000);
12 BEGIN
13 v_str_select_tbl := 'SELECT stats_on_column_obj(' || p_column_name || ',count(*)) FROM ' ||
14 p_schema_name || '.' || p_table_name || ' group by ' || p_column_name;
15 EXECUTE IMMEDIATE v_str_select_tbl
16 BULK COLLECT
17 INTO v_STATS_ON_COLUMN_tab;
18 RETURN v_STATS_ON_COLUMN_tab;
19 END;
20 /
Function created.
SCOTT@orcl > select *
2 from table(
3 get_STATS_ON_COLUMN(
4 'SCOTT',
5 'EMP',
6 'JOB'
7 )
8 )
9 /
COL_VAL COL_VAL_CNT
CLERK 4
SALESMAN 4
PRESIDENT 1
MANAGER 3
ANALYST 2
SCOTT@orcl >
Or better change it to pipelined function.
SY. -
ALV column header with multiple rows and ALV column header span
How could I have in an ALV a column header on several lines and/or a column header that spans on multiple columns?
i.e. I would like to have in an ALV two columns, each with it's own distinct header and additionally another column header for both of the columns, that spans across both columns. How could I program this?Hi,
follow below mentioned code
SET THE LABEL OF THE COLUMN
DATA: hr_weeknum TYPE REF TO cl_salv_wd_column_header.
CALL METHOD lr_weeknum->get_header
RECEIVING
value = hr_weeknum.
CALL METHOD lr_weeknum->set_resizable
EXPORTING
value = abap_false.
hr_weeknum->set_prop_ddic_binding_field(
property = if_salv_wd_c_ddic_binding=>bind_prop_text
value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
set the text of the column
CALL METHOD hr_weeknum->set_text
EXPORTING
value = 'C Form'.
Regards,
Srini. -
Dynamic source and destination tables
Hi all
I've got to import 142 tables from csv into SQL 2008 on a regular basis.
I was looking at building a 142-part SSIS package to do this, then thought there must be a dynamic way of doing it.
Is there any way of dynamically changing the source and and destination tables?
The csv filenames will remain identical, the SQL tables will be the same names but with "_Staging" at the end of them (e.g. SRSection.csv will always go into SRSection_Staging).
I can then write MERGE statements to update the main tables from the staging data.
Any help on this would be greatly appreciated.
I get the the feeling I would need a FOREACH LOOP container but I'd really aprreciate a step-by-step guide if you can.Please check this :- http://sql-bi-dev.blogspot.com/2010/07/dynamic-database-connection-using-ssis.html
STEP1:
To begin, Create two tables as shown below in on of the environment:
-- Table to store list of Sources
CREATE TABLE SourceList (
ID [smallint],
ServerName [varchar](128),
DatabaseName [varchar](128),
TableName [varchar](128),
ConnString [nvarchar](255)
GO
-- Local Table to store Results
CREATE TABLE Results(
TableName [varchar](128),
ConnString [nvarchar](255),
RecordCount[int],
ActionTime [datetime]
GO
STEP 2:
Insert all connection strings in SourceList table using below script:
INSERT INTO SourceList
SELECT 1 ID,
'(local)' ServerName,
--Define required Server
'TestHN' DatabaseName,--Define DB Name
'TestTable' TableName,
'Data Source=(local);Initial Catalog=TestHN;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;' ConnString
Insert as many connections as you want.
STEP 3:
Add new package in your project and rename it with ForEachLoopMultipleServers.dtsx. Add following variable:
Variable
Type
Value
Purpose
ConnString
String
Data Source=(local);
Initial Catalog=TestHN;
Provider=SQLNCLI10.1;
Integrated Security=SSPI;
Auto Translate=False;
To store default connection string
Query
String
SELECT '' TableName,
N'' ConnString,
0 RecordCount,
GETDATE() ActionTime
Default SQL Query string.
This can be modified at runtime based on other variables
SourceList
Object
System.Object
To store the list of connection strings
SourceTable
String
Any Table Name.
It can be blank.
To store the table name of current connection string.
This table will be queried at run time
STEP 4:
Create two connection managers as shown below:
Local.TestHN: For local database which has table SourceList. Also this will be used to store the result in Results table.
DynamicConnection: This connection will be used for setting up dynamic connection with multiple servers.
Now click on DynamicConnection in connection manager and click on ellipse to set up dynamic connection string. Map connection String with variable
User::ConnString.
STEP 5:
Drag and drop Execute SQL Task and rename with "Execute SQL Task - Get List of Connection Strings". Now click on properties and set following values as shown in snapshot:
Result Set: Full Result Set
Connection: Local.TestHN
ConnectionType: Direct Input
SQL Statement: SELECT ConnString,TableName FROM SourceList
Now click on Result Set to store the result of SQL Task in variable User::SourceList.
STEP 6:
Drag and drop ForEach Loop container from toolbox and rename with "Foreach Loop Container - DB Tables". Double click on ForEach Loop container to open Foreach Loop Editor. Click on Collection and select
Foreach ADO Enumerator as Enumerator. In Enumerator configuration, select User::SourceList as ADO object source variable as shown below:
STEP 7: Drag and drop Script Task inside ForEach Loop container and double click on it to open Script Task Editor. Select
User::ConnString,User::SourceTable as
ReadOnlyVariables and User::Query as
ReadWriteVariables. Now click on Edit Script button and write following code in Main function:
public void Main()
try
String Table = Dts.Variables["User::SourceTable"].Value.ToString();
String ConnString = Dts.Variables["User::ConnString"].Value.ToString();
MessageBox.Show("SourceTable = " + Table +
"\nCurrentConnString = " + ConnString);
//SELECT '' TableName,N'' ConnString,0 RecordCount,GETDATE() ActionTime
string SQL = "SELECT '" + Table +
"' AS TableName, N'" + ConnString +
"' AS ConnString, COUNT (*) AS RecordCount, GETDATE() AS ActionTime FROM " + Dts.Variables["User::SourceTable"].Value.ToString() +
" (NOLOCK)";
Dts.Variables["User::Query"].Value = SQL;
Dts.TaskResult = (int)ScriptResults.Success;
catch (Exception e)
Dts.Log(e.Message, 0,
null);
STEP 8:
Drag and drop Data Flow Task and double click on it to open Data Flow tab. Add OLE DB Source and Destination. Double click on OLE DB Source to configure the properties. Select
DynamicConnection as OLE DB connection manager and
SQL command from variable as Data access mode. Select variable name as User::Query. Now click on
columns to genertae meta data.
Double click on OLE DB Destination to configure the properties. Select Local.TestHN as
OLE DB connection manager and Table or view - fast load as
Data access mode. Select [dbo].[Results] as Name of the table or the view. now click on
Mappings to map the columns from source. Click OK and save changes.
Finally DFT will look like below snapshot:
STEP 9: We are done with package development and its time to test the package.
Right click on the package in Solution Explorer and select execute. The message box will display you the current connection string.
Once you click OK, it will execute Data Flow Task and load the record count in Results table. This will be iterative process untill all the connection are done. Finally package will execute successfully.
You can check the data in results table:
Here is the result:
SELECT *
FROM SourceList
SELECT *
FROM Results
Regards, Pradyothana DP. Please Mark This As Answer if it solved your issue. Please Mark This As Helpful if it helps to solve your issue. ========================================================== http://www.dbainhouse.blogspot.in/ -
Dynamic ALV and internal table.
Hi all,
I have a requirement of creating a dynamic field catelog based on input values in selection screen.
Example:
1) When I enter date range, say 20/03/2008 to 25/03/2008 I should have 6 columns in the output for each date with column heading as date itself.
2) For entering values for these date columns, i need to create an dynamic internal table.(values in the column will be some numbers like 10 on 20/03/2008, 15 on 21/03/2008 etc)
A rough output format would look like this:
Component | 20/03/2008 | 21/03/2008 | ..... |25/03/2008
comp1 | 10 | 15 | | 5
comp2 | 20 | 10 | | 10
Please let me know how can i achieve this...
Need it very urgently..
Regards,
DhareppaHi Dhareppa,
Refer the code below. Its almost on the same line as your requirments.
REPORT zglo2fr_master_planing_sedul NO STANDARD PAGE HEADING.
P R O G R A M H E A D E R *
ArthroCare Corporation *
Program : ZGLO2FR_MASTER_PLANING_SEDUL *
Author : Munvar Basha *
Creation Date : 11Mar08 *
Release : SAP ECC 6.0 *
Request : D01K904032 *
Description : Master Schedule Planning *
Change log (Revisions) *
Author Date Request Description *
P R O G R A M *
DATA DECLARATION *
**--Structure to hold matrial & plant combination records.
TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
dispo TYPE dispo,
beskz TYPE beskz,
mtart TYPE mtart,
END OF ty_marc.
**--structure to hold MRP LIST Data.
TYPES : BEGIN OF ty_mrp_list,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
delkz TYPE delkz,
END OF ty_mrp_list.
**--structure to hold no of weeks.
TYPES: BEGIN OF ty_week,
week TYPE kweek,
END OF ty_week.
**--structure to hold output data.
TYPES : BEGIN OF ty_final,
matnr TYPE matnr,
werks TYPE werks_d,
maktx TYPE maktx,
meins TYPE meins,
mtart TYPE mtart,
week TYPE kweek,
mng01 TYPE mng01,
END OF ty_final.
TYPES : BEGIN OF ty_range,
sign TYPE sign,
option TYPE option,
low TYPE sy-datum,
high TYPE sy-datum,
END OF ty_range.
Definitions of Table types. *
TYPES : ty_marctab TYPE STANDARD TABLE OF ty_marc.
Definitions of Ranges *
*RANGES ran_delkz FOR mdez-delkz.
DATA : i_ran_delkz TYPE RANGE OF mdez-delkz,
wa_ran_delkz LIKE LINE OF i_ran_delkz,
wa_date type ty_range.
Definitions of internal tables. *
data : i_marc type standard table of ty_marc,
i_mrp_list type standard table of ty_mrp_list,
i_week type standard table of ty_week,
i_final type standard table of ty_final,
i_mdps type standard table of mdps,
i_mdez type standard table of mdez,
i_mdsu type standard table of mdsu.
Definitions of work areas for internal tables *
DATA : wa_marc TYPE ty_marc,
wa_mrp_list TYPE ty_mrp_list,
wa_week TYPE ty_week,
wa_final TYPE ty_final,
wa_mt61d TYPE mt61d,
wa_mdez TYPE mdez.
Definitiions of General variables *
DATA : v_matnr TYPE mara-matnr, " Material Number
v_mtart TYPE mara-mtart, " Material Type
v_beskz TYPE marc-beskz, " Procurement Type
v_werks TYPE marc-werks, " Plant
v_dispo TYPE marc-dispo. " MRP Controller (Materials Planner)
DATA : v_mng01 TYPE mng01. "Requirement Quantity
DATA : v_year TYPE char4,
v_week TYPE char2,
v_ok_code TYPE sy-ucomm.
Definitiions of Constants *
CONSTANTS : k_slash TYPE c VALUE '/',
k_6 TYPE char8 VALUE '6',
k_x TYPE c VALUE 'X'.
Definitiions of Field Catlog *
DATA : wa_fieldcat TYPE lvc_s_fcat,
i_fieldcat TYPE lvc_t_fcat,
v_container TYPE scrfname VALUE 'CONTAINER_OUTPUT',
v_custom_container TYPE REF TO cl_gui_custom_container,
v_grid TYPE REF TO cl_gui_alv_grid,
i_gp_table TYPE REF TO data,
wa_gp_line TYPE REF TO data.
FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
<gwa_table> TYPE ANY,
<l_field> TYPE ANY,
<l_matnr> TYPE ANY,
<l_werks> TYPE ANY,
<l_maktx> TYPE ANY,
<l_meins> TYPE ANY,
<l_mtart> TYPE ANY.
DECLERATIONS FOR SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR v_matnr,
s_mtart FOR v_mtart NO INTERVALS,
s_beskz FOR v_beskz NO INTERVALS NO-EXTENSION,
s_werks FOR v_werks NO INTERVALS NO-EXTENSION
OBLIGATORY,
s_dispo FOR v_dispo,
s_date FOR sy-datum OBLIGATORY.
PARAMETERS : p_dattp TYPE dattp OBLIGATORY DEFAULT '1'.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION EVENT *
INITIALIZATION.
CALL FUNCTION '/BEV4/PLPS__ADD_MONTH_TO_DATE'
EXPORTING
months = k_6
olddate = sy-datum
IMPORTING
newdate = wa_date-high.
wa_date-low = sy-datum.
wa_date-option = 'EQ'.
wa_date-sign = 'I'.
APPEND wa_date to s_date.
SELECTION SCREEN EVENT *
**--Validation for Material
AT SELECTION-SCREEN ON s_matnr.
PERFORM validate_material.
**--Validation for Plant
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_plant.
AT SELECTION-SCREEN ENENT *
AT SELECTION-SCREEN.
IF s_matnr IS INITIAL AND s_dispo IS INITIAL.
MESSAGE text-002 TYPE 'E'.
ENDIF.
IF s_date-low LT sy-datum.
MESSAGE text-003 TYPE 'E'.
ENDIF.
START-OF-SELECTION EVENT *
START-OF-SELECTION.
**--refreshing the internal tables
REFRESH : i_marc,
i_mrp_list,
i_week,
i_final,
i_mdps,
i_mdez,
i_mdsu.
**--clearing the work areas of internal tables.
CLEAR : wa_marc,
wa_mrp_list,
wa_week,
wa_final,
wa_mt61d,
wa_mdez.
To get all the matrial(s) and plant combination records
SELECT a~matnr
a~werks
a~dispo
a~beskz
b~mtart
INTO TABLE i_marc
FROM marc AS a INNER JOIN
mara AS b
ON a~matnr = b~matnr
WHERE a~werks IN s_werks AND
a~matnr IN s_matnr AND
a~dispo IN s_dispo AND
a~beskz IN s_beskz AND
b~mtart IN s_mtart.
IF sy-subrc <> 0.
MESSAGE text-005 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT i_marc BY matnr werks.
Ranges to Filter the MRP list only for the following MRP Elements.
MRP Elements are : BA, BE, FE, LE and PA
wa_ran_delkz-sign = 'I'.
wa_ran_delkz-option = 'EQ'.
wa_ran_delkz-low = 'BA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'BE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'FE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'LE'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
wa_ran_delkz-low = 'PA'.
APPEND wa_ran_delkz TO i_ran_delkz.
CLEAR wa_ran_delkz-low.
LOOP AT i_marc INTO wa_marc.
CALL FUNCTION 'MD_MRP_LIST_API'
EXPORTING
matnr = wa_marc-matnr
werks = wa_marc-werks
sinfg = k_x
inper = p_dattp
IMPORTING
e_mt61d = wa_mt61d
TABLES
mdpsx = i_mdps
mdezx = i_mdez
mdsux = i_mdsu
EXCEPTIONS
mrp_list_not_found = 1
material_plant_not_found = 2
error = 3
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT i_mdez INTO wa_mdez WHERE dat00 IN s_date AND
delkz IN i_ran_delkz.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = wa_mdez-dat00
IMPORTING
week = wa_mrp_list-week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc = 0.
wa_mrp_list-matnr = wa_mt61d-matnr.
wa_mrp_list-werks = wa_mt61d-werks.
wa_mrp_list-maktx = wa_mt61d-maktx.
wa_mrp_list-meins = wa_mt61d-meins.
wa_mrp_list-mtart = wa_mt61d-mtart.
wa_mrp_list-delkz = wa_mdez-delkz.
wa_mrp_list-mng01 = wa_mdez-mng01.
APPEND wa_mrp_list TO i_mrp_list.
CLEAR : wa_mrp_list,
wa_mdez.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: wa_marc.
ENDLOOP.
IF i_mrp_list IS INITIAL.
MESSAGE text-006 TYPE 'S'.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR : v_mng01.
LOOP AT i_mrp_list INTO wa_mrp_list.
v_mng01 = v_mng01 + wa_mrp_list-mng01.
AT END OF week.
wa_final-matnr = wa_mrp_list-matnr.
wa_final-werks = wa_mrp_list-werks.
wa_final-maktx = wa_mrp_list-maktx.
wa_final-meins = wa_mrp_list-meins.
wa_final-mtart = wa_mrp_list-mtart.
wa_final-week = wa_mrp_list-week.
wa_final-mng01 = v_mng01.
wa_week-week = wa_mrp_list-week.
APPEND : wa_final TO i_final,
wa_week TO i_week.
CLEAR : v_mng01,
wa_final,
wa_week.
ENDAT.
CLEAR : wa_mrp_list.
ENDLOOP.
**-- Populate the Field catalog
PERFORM populate_fieldcat.
**--Create table dynamically
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcat
IMPORTING
ep_table = i_gp_table.
ASSIGN i_gp_table->* TO <gt_table>.
**--fill table with final output data
PERFORM fill_table.
CALL SCREEN 100.
SUB ROUTINES *
*& Form validate_material *
Validating Material Number(s) *
FORM validate_material .
TYPES : BEGIN OF l_ty_matnr,
matnr TYPE matnr,
END OF l_ty_matnr.
DATA : l_i_matnr TYPE STANDARD TABLE OF l_ty_matnr.
SELECT matnr
FROM mara
INTO TABLE l_i_matnr
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE text-004 TYPE 'E'.
ENDIF.
ENDFORM. " validate_material
*& Form validate_plant *
Validating Plant Number *
FORM validate_plant .
DATA : l_v_werks TYPE werks_d.
SELECT SINGLE werks
FROM t001w
INTO l_v_werks
WHERE werks = s_werks-low.
IF sy-subrc <> 0.
MESSAGE e019(zartc) WITH s_werks-low.
ENDIF.
ENDFORM. " validate_plant
*& Form populate_fieldcat
text
--> p1 text
<-- p2 text
FORM populate_fieldcat .
DATA : l_v_colname TYPE char7.
SORT i_week BY week.
DELETE ADJACENT DUPLICATES FROM i_week COMPARING week.
LOOP AT i_week INTO wa_week.
AT FIRST.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_l = text-007.
wa_fieldcat-scrtext_m = text-007.
wa_fieldcat-scrtext_s = text-007.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-tooltip = text-007.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-scrtext_l = text-008.
wa_fieldcat-scrtext_m = text-008.
wa_fieldcat-scrtext_s = text-008.
wa_fieldcat-fix_column = 'X'.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-008.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'MAKTX'.
wa_fieldcat-scrtext_l = text-009.
wa_fieldcat-scrtext_m = text-010.
wa_fieldcat-scrtext_s = text-011.
wa_fieldcat-tooltip = text-009.
wa_fieldcat-outputlen = 40.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_l = text-012.
wa_fieldcat-scrtext_m = text-013.
wa_fieldcat-scrtext_s = text-014.
wa_fieldcat-outputlen = 4.
wa_fieldcat-tooltip = text-012.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-scrtext_l = text-015.
wa_fieldcat-scrtext_m = text-015.
wa_fieldcat-scrtext_s = text-016.
wa_fieldcat-tooltip = text-015.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
ENDAT.
v_year = wa_week-week+0(4).
v_week = wa_week-week+4(2).
CONCATENATE v_week k_slash v_year INTO l_v_colname.
wa_fieldcat-row_pos = 0.
wa_fieldcat-col_pos = 6 + sy-index.
wa_fieldcat-fieldname = wa_week-week.
wa_fieldcat-quantity = 'X'.
wa_fieldcat-outputlen = 18.
wa_fieldcat-scrtext_l = l_v_colname.
wa_fieldcat-tooltip = l_v_colname.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR : wa_fieldcat,
l_v_colname,
wa_week.
ENDLOOP.
ENDFORM. " populate_fieldcat
*& Form fill_table
text
--> p1 text
<-- p2 text
FORM fill_table .
**--Create Work Area Dynamically
CREATE DATA wa_gp_line LIKE LINE OF <gt_table>.
ASSIGN wa_gp_line->* TO <gwa_table>.
DATA : l_v_col TYPE char25,
l_v_val TYPE char25.
LOOP AT i_final INTO wa_final.
l_v_col = wa_final-week.
ASSIGN COMPONENT l_v_col OF STRUCTURE <gwa_table>
TO <l_field>.
IF <l_field> IS ASSIGNED.
l_v_val = wa_final-mng01.
CONDENSE l_v_val.
<l_field> = l_v_val.
clear : l_v_val,
l_v_col.
ENDIF.
AT END OF matnr.
READ TABLE i_final INTO wa_final WITH KEY matnr = wa_final-matnr
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gwa_table>
TO <l_matnr>.
IF <l_matnr> IS ASSIGNED.
<l_matnr> = wa_final-matnr.
ENDIF.
ASSIGN COMPONENT 'WERKS' OF STRUCTURE <gwa_table>
TO <l_werks>.
IF <l_werks> IS ASSIGNED.
<l_werks> = wa_final-werks.
ENDIF.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <gwa_table>
TO <l_maktx>.
IF <l_maktx> IS ASSIGNED.
<l_maktx> = wa_final-maktx.
ENDIF.
ASSIGN COMPONENT 'MEINS' OF STRUCTURE <gwa_table>
TO <l_meins>.
IF <l_meins> IS ASSIGNED.
<l_meins> = wa_final-meins.
ENDIF.
ASSIGN COMPONENT 'MTART' OF STRUCTURE <gwa_table>
TO <l_mtart>.
IF <l_mtart> IS ASSIGNED.
<l_mtart> = wa_final-mtart.
ENDIF.
APPEND <gwa_table> TO <gt_table>.
CLEAR <gwa_table>.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " fill_table
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZMUNNA'.
SET TITLEBAR 'MRP'.
IF v_custom_container IS INITIAL.
CREATE OBJECT v_custom_container
EXPORTING
container_name = v_container.
CREATE OBJECT v_grid
EXPORTING
i_parent = v_custom_container.
CALL METHOD v_grid->set_table_for_first_display
CHANGING
it_outtab = <gt_table>
it_fieldcatalog = i_fieldcat.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
v_ok_code = sy-ucomm.
CLEAR sy-ucomm.
CASE v_ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
SET SCREEN 000.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form exit_program
text
--> p1 text
<-- p2 text
FORM exit_program .
CALL METHOD v_custom_container->free.
CALL METHOD cl_gui_cfw=>flush.
ENDFORM. " exit_program
Reward points if that helps.
Manish -
Dynamic Ranges and Dynamic SQL
Hi,
I have built a table of ranges and would like to use them in an sql query. Ive had a look but cannot think of a way to get this to work.
I have a table of fieldnames and a table of ranges. Does abap have a way of selecting a element from a table so I can generate the following sql.
select * from table
into some_table
where
'FIELD0' IN range[0] AND
'FIELD1' IN range[1] AND
'FIELD2' IN range[2] AND
'FIELD3' IN range[3] AND
I know how to build dynamic sql thats the easy bit. The hard bit is inserting a reference to a table element dynamically into the sql :S
Any help would be much appretiated,
Thanks,
Jameshi,
Yes, We can make use of Subroutine pools.
This is from F1 help about dynamic where..
1. This variant is exclusively for use with SELECT. The
internal table itab can only have one field which must be of
type C and not be greater than 72 characters. itab must be
specified in parentheses with no blanks between the
parentheses and the table name. The condition specified in
the internal table itab must have the same form as a
condition in the ABAP/4 source code. The following
restrictions apply:
- You can only use literals as values, not variables.
<b> - The operator IN cannot be used in the form f1 IN itab1. </b>
Regards,
Sailaja. -
Columns merged with other columns?
how do I achieve the following?
I want to have a tabular form as following
The first line of the tabular form will only be 3 columns (eg. col1,col2,col3). those three columns will then be broken down into 9 columns (ed. col1 - no column, col2 will have col4,col5,col6, and col7, col3 wil have col8 to col12.) on the second line.
Any ideas? I know it is possible to do with html but i'm not sure how to process it in APEXWhat I typically do first is to look at a report template from the current theme and see what CSS classes they are using against the tables, headers and rows. I will copy the entries to a text document so I can easily reference them.
The you create a new report template from scratch and as a Named Column (row template).
This type template allows you to specify where each column goes by using a substitution variable for the selected column.
The query I used in the example was
select ename, job, sal
from emp
For the Row Template 1 field under Row Template section, I put
<tr><td>#ENAME#</td><td>#JOB#</td><td>#SAL#</td></tr>
In the Before first and after last row text section I put
1. in the Before rows field
<style type="text/css">
table.outln {border-collapse:collapse;}
table.outln td {border: solid #000 1px;padding:5px;}
</style>
<table cellpadding="0" border="0" cellspacing="0" summary="" class="t9standardalternatingrowcolors outln" border="1">
<tr><th class="t9header" colspan="2">Name / Job</th><th class="t9header">Salary</th></tr>
2. In the After Rows field
</table>
This type of template is REALLY powerful. The only issues that I have run into in the past is that the order of the columns in your query should be the same as the order in which they are used in your row template. I am not sure if it is still an issue, but I have experience issues in the past that when you later change the query and the order is different then the rows are actually put in by position and not by name. To fix that problem I just drop the report and recreate.
If you happen to have my book by Oracle Press, HTML DB Handbook, there is a good description of this type of template on pages 211- 215.
The book is a little old now (almost 2 years). Just happened that they renamed HTML DB to ApEx the month before the book was published. It covers ver 2.0, but still has some good info in it. -
Add each column record with next column record
Dear all,
I have created a crosstab with the column "Order Numbers". Each Order number is calculated per day.
I would like to know how can I create a formula so that each record in the column field is calculated by adding the next column field.
For example
Order numbers
1
2
3
4
5
Formula should display the records like this
Order Numbers
1
3 (12)+
6 (123)
10 (1234)+
15 (12345)
So in other words each record in each field of the column is adding the next field.
Something like ColumnRecord= Column Record+Next column Record.
How can we achieve this?
Many thanks
Regards
JehanzebHellooo,
I have sorted it.
here is what I did
Firstly I selected the Column field (percentage field).
Clicked format -
> then Suppress and clicked on x+2
added the following formula
whileprintingrecords;
numbervar x := x + currentfieldvalue;
false
Then I clicked on Display String x+2 and entered this.
whileprintingrecords;
numbervar x;
totext(x,2)+"%"
Then I clicked on border->background> and added this formula
whileprintingrecords;
numbervar x := 0;
defaultattribute
all set and it is working perfectly.
I hope this helps someone who is seeking this type of formula
Regards
Jehanzeb -
Dynamic Structures and Internal Tables
Hi All,
I am doing a report to create condition records based on the condition type and condition table. Assume the condition type as PR00 and it as condition table of 304,305,306.Each condition table as its own header and item fields.Based on the condition table that the user specifies in the selection screen
the header and item structures of my report should change dynamically and these should be moved to the dynamic internal table that contains both header and item fields.Can anyone give an idea how to achieve it. Thanks in advance.
Regards,
Chakradhar.Hi All,
Thanks for your replies.
SPLIT i_string_line-input_str AT cl_abap_char_utilities=>horizontal_tab
INTO i_header_line-header
i_header_line-vkorg
i_header_line-vtweg
i_header_line-pltyp
i_header_line-waerk.
In the above syntax based on the condition table I selected on selection screen my flat file is as below.
case 1: If condition table given is 304
H SalesOrganization DistributionChannel Customer
I Material Releasestatus Amount Currency ValidFrom ValidTo
case 2: If condition table given is 305
H SalesOrganization DistributionChannel
I Material Releasestatus Amount Currency ValidFrom ValidTo
case 3: If condition table given is 306
H SalesOrganization DistributionChannel PriceListType DocumentCurrency
I Material Releasestatus Amount Currency ValidFrom ValidTo
In the above code i_string_line-input_str contains the following heading of fields based on the condition table we select in selection screen.when I want to split them into respective fields
using INTO clause my structure should change dynamically.How can I achieve it and my entire program is in OOPS ALV.Thanks in Advance.
Regards,
Chakradhar. -
Help with drop create and update table
Sir/Madam,
I have joined 5 tables and selected some columns ,then I need to update some columns in that. After updating I need to create a report with the new column values.
To do this my method is to create temp table with the select statement then update the temp table , use this temp table for the report and then drop the temp table.
Is there anyother way to do this ??
Can I create a cursor and update the cursor column ??
Does dynamic sql always be created as procedure ??Hi,
you need to understand how eventing works in BSP and MVC architecture. Pls refer to the below link for a basic understanding of how BSP works - View, Controller and Model class concepts.
http://www.sapdev.co.uk/webapps/bsp/washome.htm
For your requirement -
1. you need a view on which you will create a drop down list UI element and a table view element
2. you will need to create a contoller class - this will be used to handle the event that will be triggered when user selects an entry from drop down list
3. you will need a model class in which you will write the business logic to retrieve employees of selected department.
Pls search this forum or blogs for - data binding with BSPs, Table View. Pls read these concepts and try to develop your requirement. You can come back to this forum if you face any issues during development.
hope this helps. -
Authentication & Authorization with SSO, JAAS and Database Tables mix
Hi,
I'm looking for how manage Authentication & Authorization in a J2EE ADF+Struts+JSP application.
I'm interested in use SSO for authentication (I just did it programatically & dynamically already), and now I would like to could define authorization using database tables with users, groups, profiles, individual permissions, ..., (maitanined dynamically by web application admin) throught JAZN (JAAS or however is said) but not statically defining roles, groups, users, ... in jazn xml files.
I saw that exists the possibility to create a custom DataSourceUserManager class to manage all this, and this gave me the idea that this could be possible to do (I was thinking in make a custom Authorization API over my application tables, without JAZN) but what is better that use and extended and consolidated aprox like JAZN.
Anybody could tell me if my idea could be possible, and realizable, and maybe give me some orientation to build this approach.
A lot of thanks in advanced.
And sorry, excuse my so bad english.
See you.Marcel,
Originally the idea was to create a post to only explain how to do authentication using a Servlet filter. However,
I have recently added code to the JHeadstart runtime and generators to enable both JAAS and 'Custom' authentication AND authorization in generated applications. Therefore, this post will be made after we have released the next patch release, as it will depend on these code changes.
We currently plan to have the patch release available sometime in the second half of May.
Kind regards,
Peter Ebell
JHeadstart Team -
How to find the interface with the help of target table name
Hi friends,
Whether with the help of target table name, is it possible to find the interface name that invokes this target table in ODI 11.1.1.7.
Thanks in advance.
Regards,
Sarohighlight the datastore in the navigator, expand its sub tree, there is a 'populated by' node, under the node, it will list all datastores which are used as sources to the current datastore
then expand 'used by'->interfaces, it will show all interfaces which include current datastore(but maybe current datastore is used as source)
that's all you can get from UI, otherwise I suppose you can use SDK. -
How to create report with Fixed Labels and Dynamic Columns
I have static column labels in left side of report and field in 3 columns coming dynamically from 3 different command queries.
Please let me know how to create it..Following is the sample data for report.Following is the sample report. Left side lables are fixed.
I tried using pivot table functionality, earlier discussed in the forum.
But they are creating huge no.of records. As it will turn the rows into columns.
Is there any way to get this report done normally.? -
ORA-01008 with ref cursor and dynamic sql
When I run the follwing procedure:
variable x refcursor
set autoprint on
begin
Crosstab.pivot(p_max_cols => 4,
p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by job order by deptno) rn from scott.emp group by job, deptno',
p_anchor => Crosstab.array('JOB'),
p_pivot => Crosstab.array('DEPTNO', 'CNT'),
p_cursor => :x );
end;I get the following error:
^----------------
Statement Ignored
set autoprint on
begin
adsmgr.Crosstab.pivot(p_max_cols => 4,
p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by
p_anchor => adsmgr.Crosstab.array('JOB'),
p_pivot => adsmgr.Crosstab.array('DEPTNO', 'CNT'),
p_cursor => :x );
end;
ORA-01008: not all variables bound
I am running this on a stored procedure as follows:
create or replace package Crosstab
as
type refcursor is ref cursor;
type array is table of varchar2(30);
procedure pivot( p_max_cols in number default null,
p_max_cols_query in varchar2 default null,
p_query in varchar2,
p_anchor in array,
p_pivot in array,
p_cursor in out refcursor );
end;
create or replace package body Crosstab
as
procedure pivot( p_max_cols in number default null,
p_max_cols_query in varchar2 default null,
p_query in varchar2,
p_anchor in array,
p_pivot in array,
p_cursor in out refcursor )
as
l_max_cols number;
l_query long;
l_cnames array;
begin
-- figure out the number of columns we must support
-- we either KNOW this or we have a query that can tell us
if ( p_max_cols is not null )
then
l_max_cols := p_max_cols;
elsif ( p_max_cols_query is not null )
then
execute immediate p_max_cols_query into l_max_cols;
else
RAISE_APPLICATION_ERROR(-20001, 'Cannot figure out max cols');
end if;
-- Now, construct the query that can answer the question for us...
-- start with the C1, C2, ... CX columns:
l_query := 'select ';
for i in 1 .. p_anchor.count
loop
l_query := l_query || p_anchor(i) || ',';
end loop;
-- Now add in the C{x+1}... CN columns to be pivoted:
-- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"
for i in 1 .. l_max_cols
loop
for j in 1 .. p_pivot.count
loop
l_query := l_query ||
'max(decode(rn,'||i||','||
p_pivot(j)||',null)) ' ||
p_pivot(j) || '_' || i || ',';
end loop;
end loop;
-- Now just add in the original query
l_query := rtrim(l_query,',')||' from ( '||p_query||') group by ';
-- and then the group by columns...
for i in 1 .. p_anchor.count
loop
l_query := l_query || p_anchor(i) || ',';
end loop;
l_query := rtrim(l_query,',');
-- and return it
execute immediate 'alter session set cursor_sharing=force';
open p_cursor for l_query;
execute immediate 'alter session set cursor_sharing=exact';
end;
end;
/I can see from the error message that it is ignoring the x declaration, I assume it is because it does not recognise the type refcursor from the procedure.
How do I get it to recognise this?
Thank you in advanceThank you for your help
This is the version of Oracle I am running, so this may have something to do with that.
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
I found this on Ask Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3027089372477)
Hello, Tom.
I have one bind variable in a dynamic SQL expression.
When I open cursor for this sql, it gets me to ora-01008.
Please consider:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
JServer Release 8.1.7.4.1 - Production
SQL> declare
2 type cur is ref cursor;
3 res cur;
4 begin
5 open res for
6 'select * from (select * from dual where :p = 1) connect by 1 = 1'
7 using 1;
8 end;
9 /
declare
ERROR at line 1:
ORA-01008: not all variables bound
ORA-06512: at line 5
SQL> declare
2 type cur is ref cursor;
3 res cur;
4 begin
5 open res for
6 'select * from (select * from dual where :p = 1) connect by 1 = 1'
7 using 1, 2;
8 end;
9 /
PL/SQL procedure successfully completed.
And if I run the same thing on 10g -- all goes conversely. The first part runs ok, and the second
part reports "ORA-01006: bind variable does not exist" (as it should be, I think). Remember, there
is ONE bind variable in sql, not two. Is it a bug in 8i?
What should we do to avoid this error running the same plsql program code on different Oracle
versions?
P.S. Thank you for your invaluable work on this site.
Followup June 9, 2005 - 6pm US/Eastern:
what is the purpose of this query really?
but it would appear to be a bug in 8i (since it should need but one). You will have to work that
via support. I changed the type to tarray to see if the reserved word was causing a problem.
variable v_refcursor refcursor;
set autoprint on;
begin
crosstab.pivot (p_max_cols => 4,
p_query =>
'SELECT job, COUNT (*) cnt, deptno, ' ||
' ROW_NUMBER () OVER ( ' ||
' PARTITION BY job ' ||
' ORDER BY deptno) rn ' ||
'FROM emp ' ||
'GROUP BY job, deptno',
p_anchor => crosstab.tarray ('JOB'),
p_pivot => crosstab.tarray ('DEPTNO', 'CNT'),
p_cursor => :v_refcursor);
end;
/Was going to use this package as a stored procedure in forms but I not sure it's going to work now.
Maybe you are looking for
-
What is the return policy for products purchased from the US iStore?
Hi. I purchased a product fro an iStore in New York city (Apple Airport express). Actually required a router and was advised by staff it was a router (it is infact a wifi base station that will plug into an existing router). I'd like to return it/ex
-
PDF wont run on mac w/safari after update
I had no problem with PDFs until today. I just updated Adobe Reader to 11.0.03 a couple of days ago, and followed directions to update a couple of other adobe apps (acrobat?) that same day. Pls note, I also have an Adobe reader 9 that I updated to 9.
-
Still in infinite loop after recovery. Battery still won't charge
i I have read several discussions on this issue. My iPad 2 ,64gb ios 7.1 turned off like the battery died. I put it back on charger and after a few minutes it booted back up. The next day the same thing happened. This time it ''twas caught in an i
-
Clip from Timeline not showing up in the Viewer
why in Final Cut Pro when i have a clip in the time line and i want to add an effect or slow the clip down or speed it up, i double click on my clip in the timeline and it doesn't show up in the Viewer as only the clip. it is the entire footage that
-
Adobe Acrobat 8.1 reprompts for license accept every morning
Good morning everyone, I have a user who is getting prompted every morning to accept the Adobe license. They click Accept and it goes away. They can continue to work the rest of the day in and out of Adobe Acrobat Standard no problems. They can even