Recursive logic
Hi,
I have the code below that does recursive calls. The final expression evaluates to a boolean when the recursion ends. However, there is loop hole in the logic below, that I have recognized but couldn't resolve though.
private boolean isMoClassFoundInAnyDepthInThisBaseMim(String notFoundMo, ContainmentDef[] containmentRelDef){
for (ContainmentDef conDef : containmentRelDef){
ClassDef[] classDefs = conDef.getToClasses();
for (ClassDef csDef : classDefs){
boolean moFound = false;
if ( csDef != null){
moFound = (csDef.getMIM().getClass(notFoundMo)) != null;
if (moFound) return true;
else{
final ContainmentDef[] containmentRelDefForChild = csDef.getContainments();
if (!moFound || containmentRelDefForChild.length > 0)
return ( isMoClassFoundInAnyDepthInThisBaseMim(notFoundMo, containmentRelDefForChild) || false );
}//end of inner if
}//end of outer if
}//end of inner loop
}//end of outer loop
return false;
The code logic is..
I loop over an array of containments. For each of the containments, I get their children which are the classDefinitions. I check to see if the classDefinition, csDef, contains something that I wanted, if not, I recurse the call to check, if any of the classDef's children, which are containments again, has got what I wanted.
The logic fails, when one of the containments has no child. It basically exits the outer for loop and returns false which should not happen, as I still have other containments to check.
I have tweaked the code in different ways, however, I am exhausted of ideas.
I request your help here.
Thanks in Advance...
Hey,
It's a bit weard... It's like you never read all objects. I rewrite your code a bit:
private boolean isMoClassFoundInAnyDepthInThisBaseMim(
final String notFoundMo, ContainmentDef[] containmentRelDef) {
boolean returnValue = false;
boolean moFound;
ClassDef[] classDefs;
ContainmentDef[] containmentRelDefForChild;
if (containmentRelDef != null){
for (ContainmentDef conDef : containmentRelDef) {
classDefs = conDef.getToClasses();
for (ClassDef csDef : classDefs) {
moFound = (csDef.getMIM().getClass(notFoundMo)) != null;
if (moFound){
returnValue = true;
}else{
containmentRelDefForChild = csDef.getContainments();
returnValue = isMoClassFoundInAnyDepthInThisBaseMim(notFoundMo, containmentRelDefForChild) || false;
return returnValue;
}But I think it's still weard code (Check the complete array, if it's false I return false, it means the parent is false to and his parent...) ==> so normally you have to quit the loop if one of the lines return false... (this isn't checked here, and I didn't find this check in your code to...)
Normally this code should ends normally, except if the method csDef.getContainments() return the parent object to... The problem is that I doesn't have this objects, and it's a bit work to create all your objects just to check this function...
Similar Messages
-
Hello All,
I need a logic for re-cursive call.I am drilling down the BOM components.Example as below.
If I have A as header with B as component and again B may have C as component again C may have D and E as components in it.
Now if I pass A i should find B,C,D,E,F.
Please suggest somebody some idea how to get this logic?
I am using the function module CS_BOM_EXPL_MAT_V2 to get the components of a BOM.
Regards
MaheshHello Mahesh
I would assume that if you set IMPORTING parameter MEHRS ( Multi-level explosion ) = 'X' and do not restrict the multi-level explosion then you should get the entire hierarchy.
Regards
Uwe -
Hi All,
I have a peculiar requirement
Please find it below.
There is a Select Options for Material.
Based on the Material BOM Explosion should happen.
Now in the resultant set of Materials if the Material (in Select Options) is present and this is treated as Recursive.
For Ex:
s_matnr = 1
now when material 1 is exploded its giving
2 3 4 1
Hence in the above case since 1 is appearing in the exploded set it is treated as "Directly Recursive"
Now again when 2 is exploded
we get 5 6 7
and when 3 is exploded
we get 8 9 10
and so on so forth.
If in any hierarchy / level the material in s_matnr ( 1 ) is appearing then its "Indirectly recursive".
The Explosion will continue for all the resultant set of exploded materials.
Please give me some kind of clue about this.'
The report they want is to display all the Materials with Direct/Indirect Recursive.
Waiting eagerly for your Hints/Replies
Hope you all have understood the requirement.
Please revert for further clarification i shall articulate the requirement .
Thanks
SriCheck this wiki for recursive logic link:[http://wiki.sdn.sap.com/wiki/display/Snippets/InverseBOMExplosion-ABAP]
For sequential logic use function CSAP_MAT_BOM_READ instead of fm CS_WHERE_USED_MAT used in the above link. -
How do I delete cascade with a PL/SQL procedure?
This script will create a PL/SQL procedure that deletes cascade. This is a post to contribute to the Oracle community. Take the code as is and test it before you use it in production. Make sure this is what you want.
Procedure Delete Cascade (prc_delete_cascade)
Description
=============
The principle is very simple. The procedure uses a table called TO_BE_DELETED to keep a list of records to be deleted. This
table keeps the table name and the rowid of those records that need to be deleted. The procedure also uses a function called
DELETE_BOTT_ROW which takes one record of the table and tries to delete it. If the deletion fails with a foreign key constraint
violation, the function parses the SQL error message (SQLERRM) to get the name of the constraint. With the name of the constraint,
the function finds the name of the child table, all the child records that have references to the parent table primary or unique key,
and the parent key primary or unique key column name. Once the child records of the failed delete are identified, the function takes their table name and rowids
and records them into the TO_BE_DELETED table by inserting records of their table name and their rowids. Al the records inserted also contain the level (which
is 1 for the original records, 2 for child records, 3 for granchild records, etc.) and the sequence number of the order in wich they
are recorded. This way, when the function picks up a record to be deleted, it takes the one with the highest level and the highest
inserted sequence, or the "bottom" record. Once all the child records of the failed delete are appended to the TO_BE_DELETED table, it calls itself
recursevely, and the function takes the record at the "bottom" of the table and tries to delete it. If it succeeds, it calls
itself recursevely to delete the next record. If it fails, it goes and finds the child records as described before and once they are
inserted into the TO_BE_DELETED table, it calls itself again recursevely to try to delete again the "bottom" record. All records
that are successfully deleted are flagged as deleted usig the flag_del column so they are not pickt up again. Once all the (parent,
child, grandchild, etc.) records are deleted, the procedure ends without commiting, giving the option to the user to commit or
rollback deletions. The table TO_BE_DELETED is, at the end of the procedure, a list of all the records that were deleted, including their table names
and the order in with they were deleted. The user then can review its content and decide to commit or rollback.
Restrictions
============
1. Single tables only. The procedure only takes one table name and a WHERE clause to identified the records to be deleted.
2. Single columns only. Ther procedure only works with single-column primary, unique and foreign key constraints.
3. Single schema only.
4. Unpredictable results with circular references.
drop table to_be_deleted purge;
create table to_be_deleted
(tname varchar2(30) -- table name
,rid rowid -- rowid
,lvl number -- level: 1=parent, 2=child, 3=grandchild, etc.
,seq_ins number -- sequence order of record inserted
,flg_del char -- flag deleted: Y=record deleted
,seq_del number -- global order of record deletion
set serveroutput on size 1000000
create or replace procedure prc_delete_cascade
(p_tname varchar2 -- table name
,p_where varchar2 -- where clause identifying records to be cascade deleted
is
dummy char;
v_sqlcode number;
v_sqlerrm varchar2(32767);
v_param_val integer := 0;
v_sql varchar2(4000);
v_ret_cde number;
e_bad_params exception;
v_iter number;
v_plvl number;
v_seq_del number;
v_max_iter number := 1000000000;
function delete_bott_row
return number
is
v_sql varchar2(4000);
v_ptname varchar2(30); -- parent table name
v_ppkname varchar2(30); -- parent primary key constraint name
v_ppkcname varchar2(30); -- parnet primary key column name
v_prowid rowid;
v_crowid rowid;
v_ctname varchar2(30); -- child table name
v_cfkname varchar2(30); -- child foreign key constraint name
v_cfkcname varchar2(30); -- child foreign key column name
v_ins number;
v_seq_ins number;
v_sqlerrm varchar2(4000);
v_sqlcode number;
e_const_viol exception;
pragma exception_init(e_const_viol, -2292);
e_max_iter_reached exception;
begin
v_iter := v_iter + 1;
if v_iter >= v_max_iter then
raise e_max_iter_reached;
end if;
dbms_output.put_line('- Iter '||to_char(v_iter));
dbms_output.put_line('----------');
dbms_output.put_line('- Starting function delete_bott_row');
v_sql := 'select tname, rid, lvl, seq_ins from (select * from to_be_deleted where flg_del = ''N'' order by lvl desc, seq_ins desc) where rownum=1';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql into v_ptname, v_prowid, v_plvl, v_seq_ins;
dbms_output.put_line('- Selected row: table name: '||v_ptname||', level: '||v_plvl||', seq: '||v_seq_ins);
v_sql := 'delete from '||v_ptname||' where rowid='''||v_prowid||'''';
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Row deleted !!!');
v_ret_cde := 1;
v_seq_del := v_seq_del + 1;
dbms_output.put_line('- Mark the row deleted');
v_sql := 'update to_be_deleted set flg_del = ''Y'', seq_del = '||to_char(v_seq_del)||' where tname='''||v_ptname||''' and rid='''||v_prowid||'''';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
-- dbms_output.put_line('- Updated table to_be_deleted, row marked deleted');
-- dbms_output.put_line('- End of iter '||to_char(v_iter));
dbms_output.put_line('----------');
-- call function delete_bott_row recursively
v_ret_cde := delete_bott_row;
return 0;
exception
when no_data_found then
dbms_output.put_line('- Table to_be_deleted is empty, delete cascade has completed successfully.');
v_ret_cde := 0;
return 0;
when e_const_viol then
v_sqlcode := SQLCODE;
v_sqlerrm := SQLERRM;
v_ret_cde := v_sqlcode;
dbms_output.put_line('>Constraint Violation. Record has children');
-- dbms_output.put_line('Error code: '||to_char(v_sqlcode));
v_cfkname := substr(v_sqlerrm,instr(v_sqlerrm,'.')+1,instr(v_sqlerrm,')') - instr(v_sqlerrm,'.')-1);
dbms_output.put_line('>Child FK name: '||v_cfkname);
select table_name, column_name
into v_ctname, v_cfkcname
from user_cons_columns
where constraint_name=v_cfkname;
dbms_output.put_line('>Child table name: '||v_ctname||'. FK column name: '|| v_cfkcname);
select constraint_name, column_name
into v_ppkname, v_ppkcname
from user_cons_columns
where constraint_name = (select r_constraint_name
from user_constraints
where constraint_name=v_cfkname);
dbms_output.put_line('>Parent PK/UK name: '||v_ppkname||'. Parent PK/UK column: '||v_ppkcname);
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) '||
'select '''||v_ctname||''', rowid, '||to_char(v_plvl+1)||', rownum, ''N'' '||
'from '||v_ctname||' '||
'where '||v_cfkcname||' =any (select '||v_ppkcname||' from '||v_ptname||' where rowid =any (select rid from to_be_deleted where tname = '''||v_ptname||'''))';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
select count(*)
into v_ins
from to_be_deleted
where lvl = v_plvl+1
and tname = v_ctname
and flg_del = 'N';
dbms_output.put_line('>Found '||to_char(v_ins)||' child records which were added to table to_be_deleted');
v_ret_cde := delete_bott_row;
return v_ret_cde;
when e_max_iter_reached then
dbms_output.put_line('Maximum iterations reached. Terminating procedure.');
raise;
when others then
raise;
end delete_bott_row;
begin
dbms_output.put_line('Beginning');
dbms_output.put_line('================================');
-- validate p_table
begin
select 'Y'
into dummy
from user_tables
where table_name=upper(p_tname);
exception
when no_data_found then
v_param_val := 1;
dbms_output.put_line('Table '||p_tname||' does not exist.');
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_tname validated');
-- validate p_where
begin
execute immediate 'select ''Y'' from '||p_tname||' where '||p_where INTO dummy;
exception
when no_data_found then -- where clause returns no records
dbms_output.put_line('Record(s) not found. Check your where clause parameter');
v_param_val := 2;
raise e_bad_params;
when too_many_rows then -- found multiple records means it is ok
null;
when others then -- any other records means where clause has something wrong.
dbms_output.put_line('Where clause is malformed');
v_param_val := 2;
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_where validated');
if v_param_val > 0 then raise e_bad_params; end if;
v_iter := 0;
v_plvl := 1;
v_seq_del := 0;
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) select '''||upper(p_tname)||''', rowid, '||to_char(v_plvl)||', rownum, ''N'' from '||p_tname||' where '||p_where;
dbms_output.put_line('- Inserting initial record');
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Record(s) inserted');
dbms_output.put_line('- Calling function delete_bott_row to delete last row of table to_be_deleted');
dbms_output.put_line('-----------------------------------');
v_ret_cde := delete_bott_row;
-- dbms_output.put_line('- Back from function delete_bott_row');
-- dbms_output.put_line('Return code: '||to_char(v_ret_cde));
dbms_output.put_line('- End of procedure');
exception
when e_bad_params then
dbms_output.put_line('Bad parameters, exiting.');
end;
show errors
spool prc_delete_cascade.log
-- Call to the procedure
exec prc_delete_cascade('xent','xent_id between 1669 and 1670')
select tname "Table Name", count(*) "Rows deleted"
from to_be_deleted
group by tname;
spool off
set lines 120
select *
from to_be_deleted
order by seq_del;
prompt Now commit or rollaback deletions.
-- commit;
-- rollback;Edited by: Rodolfo4 on Mar 23, 2011 10:45 AMInteresting.
I see a few areas where this could be useful. Elimiating specific test records from a Test DB for example.
Some comments:
<li>Since this is a recursive logic you must add a stop criteria. In this case I would add a max iteration variable. If that one is reached, raise an error message and let the procedure stop with that error.</li>
<li>The when others exception at the end should be removed completely</li>
<li>The when others exception in the middle should be replaced by a specific exception that handles the -2292 error</li>
<li>A list of tables where no record should be deleted could be usefull. If the logic would encounter such a table, it should also stop. This would be to prevent that data from some system critical tables could be deleted per accident.</li>
<li>The reference from the FK constraint to the PK constraint should include the table name and if possible the owner (as long as you use user_* views the owner is always the same. But we could extend this to the ALL_* views). I never met a system where different tables have the identical FK constraint names, however just make this fool proof.</li> -
How to read the hierarchy data from the same table using loop in AMDP method
Hi All,
We have a requirement to get the top partner from BUT050 table.
Here the Top parent is nothing but the top most in the hierarchy of the partners from BUT050.
Example:
For partner 1234 (BUT050-PARTNER1) there is partner 3523(BUT050-PARTNER2) one level above
For partner 3523(BUT050-PARTNER1) there is partner 4544 (BUT050-PARTNER2) last level .
so in this case for the partner 1234 the Top parent is 4544 .
I have created AMDP Procedure method to get the top-parnet and below given is the logic implemented in AMDP method.
Here i have implemented a recursive logic with the WHILE loop to get the top most hierarchy partner from the same table BUT050
IV_Parent is the input partner and ev_top_parent is the output value.
AMDP Procedure Method:
DECLARE lv_date VARCHAR(8) := TO_VARCHAR (current_date, 'YYYYMMDD');
DECLARE found INT := 1;
iv_partner1 = SELECT partner1 FROM but050
WHERE partner2 = iv_partner
AND reltyp = :iv_hierarchy
AND date_to >= :lv_date
AND date_from <= :lv_date;
WHILE found <> 0 do
select partner1 into ev_top_parent from :iv_partner1;
iv_partner1 = SELECT partner1 FROM but050
WHERE partner2 in ( select partner1 from :iv_partner1 where partner1 is not null)
AND reltyp = 'ZBP004'
AND date_to >= :lv_date
AND date_from <= :lv_date;
select COUNT ( partner1 ) INTO found FROM :IV_PARTNER1;
END WHILE;
This method is working fine, but here it is only taking one single partner and getting the top parent as output.
Now i would like to convert this mehtod so as to accept n number of partners (not one single partner) as input and should process each partner to get the top parent.
Could anyone guide me how can i handle the given AMDP method further so as to work some how it is within another loop from other AMDP method.
Thanks.
Regards,
Laxman.PHi
Go to SE11 and enter the hierarchy table name.
/BIC/H....(infoobject name)...and execute the table and select table entry and delete all....
Thanks
TG -
A help with a hierarchical query
I've got two tables:
FOLDERS where relevant fields are: folderId, parentFolderId, folderQuota
and DOCUMENTS where the relevant fields are: folderId, size
FOLDERS is hierarchical - parentFolderId of a child's folder is set to folderId of the parent
folderQuota is nullable (quota not set)
Now, I need to execute a query with the following recursive logic
<i>function calcQuota (folderIdpar, isFirstpar) {
if (not isFirstpar) and (folderQuota of folder with folderIdpar is not null) return folderQuota;
return size of all documents where folderId = folderIdpar + calcQuota (folderId of all children, false);
}</i>
(I hope the pseudocode is understandable - the query is executed as <i>calcQuota(originalFolderId, true)</i>).
Now, my question is if I can achieve it with a single hierarchical query, or if I have to implement it as a recursive stored procedure.
Thanks!
P.S. I'm using Oracle XE (10g)OK,
I will need to create it (in real life it is created by an application), so I hope I will make it correct. If not, it should be easy to fix.
create table folders (
folder_id number primary key
parent_folder_id number,
quota number
create table documents (
document_id number primary key
folder_id number,
size number
INSERT INTO folders (folder_id, quota) VALUES (1, 1);
INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (2, 1, 2);
INSERT INTO folders (folder_id, parent_folder_id) VALUES (3, 1);
INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (4, 2, 4);
INSERT INTO folders (folder_id, parent_folder_id) VALUES (5, 2);
INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (6, 3, 8);
INSERT INTO folders (folder_id, parent_folder_id) VALUES (7, 3);
INSERT INTO documents (document_id, folder_id, size) VALUES (1, 1, 16);
INSERT INTO documents (document_id, folder_id, size) VALUES (2, 2, 32);
INSERT INTO documents (document_id, folder_id, size) VALUES (3, 3, 64);
INSERT INTO documents (document_id, folder_id, size) VALUES (4, 3, 128);
INSERT INTO documents (document_id, folder_id, size) VALUES (5, 4, 256);
INSERT INTO documents (document_id, folder_id, size) VALUES (6, 5, 512);
INSERT INTO documents (document_id, folder_id, size) VALUES (7, 6, 1024);
INSERT INTO documents (document_id, folder_id, size) VALUES (8, 7, 2048);
running the query for folder_id = 1 should return 1 + 2 + 64 + 128 + 8 + 2048 = 2251
running the query for folder_id = 2 should return 4 + 512 = 516
I have decided for this data, because it allows to track what values (folder.quota or document.size) is included in the result.
(it is the knapsack problem - see http://en.wikipedia.org/wiki/Knapsack_problem)
P.S. I'm leaving for three weeks, so I will come back after that. -
I'm trying to create a zip utility which takes in a certain directory's location and zips up all files and sub-directories. I have coded the recursive logic needed to also zip the subdirectories but I'm getting a FileNotFound exception with the sub-directories. here is an example: "java.io.FileNotFoundException: C:\out\images (Access is denied)" Please let me know if there is any security settings which I can override to prevent this error.
Looks like you are trying to open a directory.
You should only open files.
if (a_file.isDirectory()) {
zipDirectory(a_file.toString(), out);
else {
// do the file-zipping stuff
// method checks recursively for dirs
zipDirectory(File fi, ZipOutputStream out){
// loop through the dir entries : String[] entries = fi.list();
if(entry.isDirectory())
zipDirectory(..)// recursive call
else
// fo the file-zipping stuff
}Try that if you're doing it already, and repost if problem subsists. -
How to build query to get tree architecture of self referencing table
Dear all,
I have the following table design :
This is a self referencing table representing a set of SubCategories which can have parent sub categories or not. I did not show here the Category table.
If the Subcategory has the ParentSubCategory ID = null, then this is a root subcategory otherwise it is a child of a parent sub category.
What I am looking for is the easy way to display the structure level by ProductCategoryID ?
Thanks for helpsyou can use a recursive logic based on CTE for that
something like this would be enough
;WITH ProdSubCat_Hiererchy
AS
SELECT psc.ProductSubCategoryID,c.CategoryName,psc.ParentSubCategoryID, psc.Name,CAST(psc.Name AS varchar(max)) AS [Path],1 AS [level]
FROM ProductSubCategory psc
INNER JOIN Category c
ON c.CategoryID = psc.ProductCategoryID
WHERE psc.ParentSubCategoryID IS NULL
UNION ALL
SELECT psc.ProductSubCategoryID,c.CategoryName,psc.ParentSubCategoryID, psc.Name,CAST(psch.[Path] + '/' + psc.Name AS varchar(max)) AS [Path],psch.[level] + 1
FROM ProductSubCategory psc
INNER JOIN Category c
ON c.CategoryID = psc.ProductCategoryID
INNER JOIN ProdSubCat_Hiererchy psch
ON psch.ProductSubCategoryID = psc.ParentSubCategoryID
SELECT *
FROM ProdSubCat_Hiererchy
ORDER BY LEFT([Path],CHARINDEX('/',[Path]+'/')-1),[Level]
OPTION (MAXRECURSION 0)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Advice needed on large volume of data coming from aRFC.
Hi Experts,
Using NWDS 7.0.18, EP 7.00 SPS 18
I am calling an rfc to bring back a table structure to the front end and then I am building a tree hierarchy out of it. Everything was fine with small amounts of records (100-200).
But in real life, we will have approx 300,000 records coming in. As a test, we tried it with just 50,000 but the application wasnt able to cope. I just got the web dynpro spinning wheel for almost an hour and then nothing!
Can anyone provide me with some advice on how this can be resolved? Is there a way to preload the data before the user accesses the app? Can I bulk load small sections of data at a time?
Thanks in advance.
Marshall.Hi,
As per my guess,
Most of the time is taking at recursive call and inner for loop at UI side.
Just put these statements and calcuate the time taking as below for both BAPI call and logic at WD side.
long before=System.currentTimeMillis();
long after=System.currentTimeMillis();
long totalTimeTaken=System.currentTimeMillis();
For example your method is
getDatafromBackend()
//Code for model execution
long before=System.currentTimeMillis();
long after=System.currentTimeMillis();
long totalTimeTaken=System.currentTimeMillis();
Similarly for your recursive logic also.
Using these checks you can findout..where is the issue.
Note if you are facing issue for 50,000 records..then check for 40000 first.
As per my analysis if you are calling the method recursively for 50,000 records.
*Then the for loop will execute 50,000 * 50,000 times. This is very minimum. There are many chances like one parent can have many childs. Those childs can have again childs. So this number will increate drastically based on the parent and child relationships in the data.*
Better not to use recursive for this much of data records. So dont populate the records at the beginning. Populate when user expands the parent.
Regards,
Charan -
Select employee list on HR portal
Hi Experts,
We have a customizing process on our HR portal about performance appraisal with ADOBE form. The manager can select the employee list by choosing level one employee list or level 2, 3...employee list. For example, one general manager A can choose manager B as N1 employee or engineer C under manager B as N2 list.
The situation is, when one of our general manager want to display N2 employee list, it needs to spend a lot of time since there are many emploees under his position, sometimes it will time out. I tried to get the SQL trace from ST05, and there are always one SQL statement during the N2 employee list select process is to select data by jion table HRP1001 and PA0001.
I have no idea how can I improve the seletion process to make list easlier, please give me your command if possible.
Thank you very much.Hi Joseph
It seems you are using your own ABAP / recursive logic to retrieve 2 or more levels below the department head.
Had you explored using standard SAP structural authorizations in your set up ? Just my 2 cents.
Gregg -
How to Get days of Month in SSRS
How can I get days of Month in SSRS report...?
Hi RedZinc,
You can do it by writing a SQL query to generate days of month. For doing recursive to generate days,
Use CTE with recursive logic:
Declare @StartDate as DATE, @EndDate as DATE;
SET @StartDate = CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()),101)
SET @EndDate = CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,Getdate()))),DATEADD(mm,1,Getdate())),101)
;WITH cte AS (
SELECT @StartDate AS myDate
UNION ALL
SELECT DATEADD(Day,1,myDate)
FROM cte
WHERE DATEADD(Day,1,myDate) <= @EndDate
Select * from CTEtested the above sql code and it is working. CTE will be easy to implement recursive stuff.
Maruthi... http://www.msbimaru.blogspot.com/ -
Loading a tree of objects from a cache in a single call using an aggregator
Hi,
I currently have the following problem. I am trying to load a tree of objects from coherence by recursing up an object tree from a child object.
What is currently in place is something like this (not actual implementation).
Child child...// initialisation of Child;
List<Parent> parents = new LinkedList<Parent>();
Parent parent = null;
int parentId = child.getParentId();
while (true) {
parent = cache.get(parentId);
if (parent != null) {
parents.add(parent);
parentId = parent.getParentId();
} else {
break;
However, this results in a number of calls over the network to the coherence cache and is proving to be quite inefficient. What I would like is to be able to write something like a filter or an aggregation function which will simply take in the child, or the parent id of the child, and return a list of all the parents (with the recursion logic taking place on the coherence node). This will hopefully reduce network latency considerably.
Does anybody know how to go about doing this within coherence?XML might be a better solution, but using tags should work.
The Sun tutorial at http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags5.html#68205 should be helpful to you.
When processing a tag, determine if there is a parent tag by using getParent() or findAncestorWithClass().
If there is no parent, instantiate your site navigation object based on the tag arguments and save a reference within the tag object. You'll probably want to also add the reference to page or session scope as an attribute for later use.
If there is a parent, instantiate the new navigation object and then retrieve the parent navigation object from the parent tag (create a getNavigation() method in tag?). Then add the new navigation object to the array in the parent navigation object. -
Tree.isSetOpen() problems...
Ok - here's the URL where you can see this in action...
http://www.ambientdesignstlouis.com/recent.php?category=C&group=blue
If you open and close folders with the arrows, it works
perfectly. Each folder you open automatically closes the old
folder. If, however, you just click on the names of the folders,
you have to click several times to achieve the same end.
Any suggestions?
Here's the code....It is possible to add functions directly into a jsp page. I forget what the keywords to do this are but you basically create a scriplet and tag it (somehow) as a java method. You can add all your recursive logic to the page like that. Generally, it's not very advisable to do this, but your situation may warrent it.
-
Hi everyone,
I'm developing integration application under .net with Primavera EPPM by using p6 web service. I'm getting the list of EPS and Projects, and then the list of WBS by selected Project.
But I noticed that WBS name in P6 client consist of the ProjectName + WBS code on the parent Code + WBS code on required level.
How I can get the whole WBS name on each level without using any recursion logic, only from p6 web service?
Best regards,
Dmitrij.Hi Sachin Gupta,
Actually i tried this. But there is no field in the WBSFieldType list which could me show the full WBS path on each Level.
Best regards,
Dmitrij -
Logic ?? Recursive Method
The recursive programming below is supposed to print
the elements in reverse order. Can someone please
explain the logic behind it. Thanks.
public void printRevList() {
if (next != null)
next.printRevList();
System.out.println(element + " " );
}It's a little incomplete, but if it truly is a piece of functioning recursive code, then you're basically pushing everything onto a stack, first element first, last element last, and then popping it off from the most recently pushed element down to earliest pushed element.
Assume 3 elements
1) call printRevlist on first element.
2) since the next element is not null, we go on to call next.printRevList()--remember, this must complete before we can call println, and notice that since there are no braces, println is called regardless of whether or not next was null
3) We are now in the second element's printRevList, as called from the first. The first has not yet printed. Next is not null, so we call next.printRevList. We won't print element 2 until element 3's printRevList completes
4) We are now in elem 3's printRevList. This time, next is null, so we don't recurse anymore--nothing else get's pushed on the stack. We simply print "el3 " and return
5) Now we're back in elem 2's printRevList, after having just completed elem 3's printRevList. So we print "el2 " and return
6) I'll let you fill this one in.
Let me know if it's still not making sense--recursion is not the easiest thing to get your brain around.
Jeff
Maybe you are looking for
-
How can i get my data back if i didnt back up my ipod?
I went to the apple store a couple hours ago and they reformated my iPod but i didn't save the pictures in it. Is there any way i can get back the data?
-
Scheduled Backup & Manual Backup not Inintiating for CM
I am trying to do a Backup for CM. But it is not getting started it showd the error "Backup initiation timed out. Master agent might still be processing this operation or may be down.". I checked the DRF Master and Local services- it was up and runni
-
Heat comparison between a macbook and a dell
Hi all, Found this on digg. Interesting comparison of core duo heat issues between a macbook and a dell. http://iith096.blogspot.com/2006/07/macbook-vs-dell-heated-battle.html
-
Photoshop-time display problem
Since the last security upgrade 2006-7, running Photoshop CS kills the time display on the menu bar. It does not affect the internal clock; the correct time is reflected for saved files, etc. Also, when shutting down, my Palm Hot Sync Manager refuses
-
How can i create i-views?
Hii Give me some explanation on how to create i-views??