我正在尝试更多地了解在调用和执行过程时如何使用参数/参数。我理解包含带有冒号(:)的参数的过程将值传递回调用DO
命令,但是我觉得它有点令人困惑的是,变量名称来自调用DO
命令的问题,以及程序(由DO
调用)返回不一定必须是同一个名称。如果有人可以帮助阐明以下示例并解释传递给/来自哪些值或者如何通过发布DO
命令引用它们将会有所帮助。
它看起来像是运行Get-Recursive-Reports-To
的调用(do Get-Recursive-Reports-To($Recursive_Line, $_POSITION_NBR, #_Global_Counter)
将这3个变量作为参数发布到Get-Recursive-Reports-To
程序,但是当我查看Get-Recursive-Reports-To
程序时,我没有在此程序中看到变量$Recursive_Line
的任何引用,所以程序也是如此实际上使用它或包含它的目的是什么?与$_val_Position_NBR
类似的问题,这个变量从哪里得到它的值?
然后在Get-Recursive-Reports-To
程序中我看到一个参数 - :$var_Next_EMPLID
我相信在Run-Recursion过程中被传递回调用DO,但是我无法弄清楚它是如何/在何处使用传递给它的值...
begin-procedure Run-Recursion
let #_Global_Counter = 0
let $Recursive_Line = ''
let $Data_Line_EMPL = ''
let $Data_Line_EMPL = $_BUSINESS_UNIT || '|' || $_BUSINESS_UNIT_DESCR || '|' || '2019' || '|' ||
$_EMPLID || '|' || $_NAME || '|' || $_DEPTID || '|' || $_DEPT_DECSR || '|' || $_JOBCODE || '|'
do Get-Recursive-Reports-To($Recursive_Line, $_POSITION_NBR, #_Global_Counter)
let $Data_Line_EMPL = $Data_Line_EMPL || $Recursive_Line
do Write-Data-Line($Data_Line_EMPL)
end-procedure
begin-procedure Get-Recursive-Reports-To(:$val_Data_Line, $val_Current_Position_Nbr, #Recursion_Counter)
let #Recursion_Counter = #Recursion_Counter + 1
do Get-the-ReportsTo-for-the-Current-Position($val_Current_Position_Nbr, $Next_Position_Nbr, $Next_EMPLID)
do Check-For-Stop($Stop_Recursion, $val_Current_Position_Nbr, $Next_Position_Nbr, #Recursion_Counter)
if $Stop_Recursion = 'N'
let $val_Data_Line = $val_Data_Line || $Next_EMPLID || '|'
do Get-Recursive-Reports-To($val_Data_Line, $Next_Position_Nbr, #Recursion_Counter)
end-if
end-procedure
begin-procedure Get-the-ReportsTo-for-the-Current-Position($_val_Position_NBR, :$var_ReportsTo, :$var_Next_EMPLID)
let #local_counter = 0
begin-select
G.REPORTS_TO &G.Reports_to
let $var_ReportsTo= &G.Reports_To
from PS_POSITION_DATA G
WHERE G.POSITION_NBR = $_val_Position_NBR
and G.EFF_STATUS = 'A'
AND (G.EFFDT =
(SELECT MAX(G_ED.EFFDT) FROM PS_POSITION_DATA G_ED
WHERE G.POSITION_NBR = G_ED.POSITION_NBR
AND G_ED.EFFDT <= $_As_OF_Date))
end-select
begin-select
H.EMPLID &H.EMPLID
Z.NAME &Z.NAME
let $var_Next_EMPLID= &H.EMPLID
let #local_counter = #local_counter + 1
from PS_JOB H !, PS_EMPLOYEES Z
WHERE H.POSITION_NBR = $var_ReportsTo
and H.EMPL_STATUS not in ('D', 'R', 'T')
and (H.EFFDT =
(SELECT MAX(H_ED.EFFDT) FROM PS_JOB H_ED
WHERE H.EMPLID = H_ED.EMPLID
AND H.EMPL_RCD = H_ED.EMPL_RCD
AND H_ED.EFFDT <= $_As_Of_Date))
end-select
if #local_counter > 1
let $var_Next_EMPLID = $local_counter || ' ' || 'Employees in this Position'
end-if
if #local_counter = 0
let $var_Next_EMPLID = 'Position Vacant'
end-if
end-procedure
从主过程第一次调用Get-Recursive-Reports-To使用$ Recursive_Line变量。它不必再次引用,因为它是程序的内部。
一旦IN过程Get-Recursive-Reports-To,此变量的名称变为$ val_Data_Line,并用于回调相同的过程Get-Recursive-Reports-可以更改它。我猜错了名字,Get-Recursive-Reports-To。
递归是一个痛苦的问题,但看起来它被用来建立一个组织链,找到员工身份的报告,然后得到那个人的名字。
变量$ var_Next_EMPLID作为变量$ Next_Emplid从Get-the-ReportsTo-for-Current-Position传递回调用者,然后再次使用它来调用Get-Recursive-Reports-To。
由于您没有包含“Check-For-Stop”程序,我无法判断Recursion何时或为何停止。看起来有一些检查 - 可能是$ Val_Current_Position_Nbr或$ Next_Position_Nbr是空白或等于什么。