CREATE OR REPLACE PACKAGE BODY CK_BWALK AS procedure CK_BWALK(P_SEQ number, P_FOLDER_ID number) is -- P_SEQ is the unique sequence id for the report session -- P_FOLDER_ID is the folder irid of the container whose atomic functions are being processed -- Cursor to get all unprocessed flows cursor GET_FLOW is select TMP_ID, TMP_PROCESSED_FLAG, TMP_START_END_FLAG from CDI_TEMP_ATOMIC_ELEMENTS where TMP_CONTEXT_TYPE = 'D' and TMP_DIRECTION_FLAG = 'I' and TMP_SEQ = P_SEQ and TMP_FOLDER_ID = P_FOLDER_ID and TMP_PROCESSED_FLAG is null for update; -- DONE is used to indicate when no unprocessed flows exists DONE boolean; begin DONE := true; while DONE loop DONE := false; -- for each unprocess flow (Incomming flows) for THIS_FLOW in GET_FLOW loop DONE := true; -- trace all other incomming flows -- where a flow is from a DATASTORE, EXTERNAL mark it as a -- START flow and PROCESSED insert into CDI_TEMP_ATOMIC_ELEMENTS (TMP_SEQ, TMP_FOLDER_ID, TMP_ID, TMP_CONTEXT_TYPE, TMP_START_END_FLAG, TMP_DIRECTION_FLAG, TMP_FLOW_TYPE_FLAG, TMP_PROCESSED_FLAG) select P_SEQ, P_FOLDER_ID, D.ID, 'D', DECODE(D.SOURCE_TYPE,'FUNCTION',null,'S'), 'I', DECODE(D.SOURCE_TYPE,'DATASTORE','D','FUNCTION','F','E'), DECODE(D.SOURCE_TYPE,'FUNCTION',null,'Y') from CI_DATAFLOWS S, CI_DATAFLOWS D where S.ID = THIS_FLOW.TMP_ID and D.FUNCTION_DEST_REFERENCE = S.FUNCTION_SOURCE_REFERENCE and not exists (select TMP_ID from CDI_TEMP_ATOMIC_ELEMENTS where TMP_ID = D.ID and TMP_SEQ = P_SEQ AND TMP_FOLDER_ID = P_FOLDER_ID and TMP_CONTEXT_TYPE = 'D'); if sql%notfound then -- If no incomming flows were found then THIS_FLOW must be a START flow -- therefore update it to reflect this and mark it as processed update CDI_TEMP_ATOMIC_ELEMENTS set TMP_START_END_FLAG = 'S', TMP_PROCESSED_FLAG = 'Y' where current of GET_FLOW; else -- otherwise mark THIS_FLOW as processed update CDI_TEMP_ATOMIC_ELEMENTS set TMP_PROCESSED_FLAG = 'Y' where current of GET_FLOW; end if; end loop; commit; end loop; insert into CDI_TEMP_ATOMIC_ELEMENTS (TMP_SEQ, TMP_FOLDER_ID, TMP_ID, TMP_CONTEXT_TYPE, TMP_START_END_FLAG, TMP_DIRECTION_FLAG, TMP_FLOW_TYPE_FLAG, TMP_PROCESSED_FLAG) select P_SEQ, P_FOLDER_ID, NVL(S.FUNCTION_SOURCE_REFERENCE,-1), 'F', NULL, 'I', NULL, 'T' from CI_DATAFLOWS S where S.ID IN (select TMP_ID from CDI_TEMP_ATOMIC_ELEMENTS where TMP_SEQ = P_SEQ AND TMP_FOLDER_ID = P_FOLDER_ID and TMP_CONTEXT_TYPE = 'D' AND TMP_DIRECTION_FLAG = 'I'); end; END CK_BWALK; /