Setting Common Variables in Routines

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Setting Common Variables in Routines

Post by Latha1919 »

Hi,

At present, I am working on controller jobs. Within, these there are common variables set. Would please through some light on setting the common variables in routines.

Thanks in advance,
Latha
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

You can also view KeyMgt routine code in manager to learn how to use common variables.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I created a copy of the existing routine and included the following code:

! REPORTING PERIOD VALIDATION AGAINST CURRENT PERIOD
If currentperiodstatus = 1 Then
Reason := "Reporting period start and End date must be within 2 years."
Status = @TRUE
End


! CE STATUS UPDATE VALIDATION FOR ALL THE REPORTING PERIODS FALLING WITHIN THE REPORTING PERIOD DURATION
If cestatusupdatestatus = 1 Then
Reason := "Add Operation Failed. No Published Status."
Status = @TRUE
End


! VALIDATION OF REPORTING PERIOD START AND END DATES WITH CURRENT DATE

If futuredatestatus = 1 Then
Reason := "Future Dated Metrics."
Status = @TRUE
End

When I compiled this, its done successfully. When I am testing, its not returning the right values.
Reason and Status are common variables. I called this routine, in one of the transformer stage.

Please advise.

Thanks,
Latha
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

Reason and Status are common variables. I called this routine, in one of the transformer stage.
Then you need to use the common command prior to their use, I can't find that within your code :?
Success consists of getting up just one more time than you fall.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

First line in the routine, is that COMMON statement. Its already there.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

First line in the routine, is that COMMON statement. Its already there.
Atleast I can't see that in the code you have posted :evil:
May be I need spectacles :cry:
When I am testing, its not returning the right values.
How do you know that?
What output you are expecting, and what is it giving?
Can you show us an example what are you trying to achieve?
Success consists of getting up just one more time than you fall.
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Latha1919 wrote:I created a copy of the existing routine and included the following code:
Which routine copy you have created ?

! REPORTING PERIOD VALIDATION AGAINST CURRENT PERIOD
If currentperiodstatus = 1 Then
Reason := "Reporting period start and End date must be within 2 years."
Status = @TRUE
End


! CE STATUS UPDATE VALIDATION FOR ALL THE REPORTING PERIODS FALLING WITHIN THE REPORTING PERIOD DURATION
If cestatusupdatestatus = 1 Then
Reason := "Add Operation Failed. No Published Status."
Status = @TRUE
End


! VALIDATION OF REPORTING PERIOD START AND END DATES WITH CURRENT DATE

If futuredatestatus = 1 Then
Reason := "Future Dated Metrics."
Status = @TRUE
End

Which return value, you want from routine ?


Thanks,
Anupam
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

Its a big routine, following is the modified routine:

COMMON /Val4/ Status, Reason, TotalRows, RejectRows

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! VALIDATION STEP 4
! - VALIDATION FOR CLIENT, REPORTING PERIOD, CURRENT PERIOD, Metric Elements!
! Command ==> 1 ==> set common and return status
! 2 ==> set common and return reason
! 3 ==> return status
! 4 ==> return reason
!
!
!ClientId ==> FromValidationStepThree.client_id
! MetricElementCount ==> FromLookupElementsPerMetric.metric_element_count
! MetricElementValue1 ==> FromValidationStepThree.metric_element_value_1
! Lookup1MetricElementType ==> FromLookupMetricElementId1.validation_data_type
! Lookup1MetricElementMethod ==> FromLookupMetricElementId1.validation_method
! Lookup1MetricElementValues ==> FromLookupMetricElementId1.validation_values
! MetricElementValue2 ==> FromValidationStepThree.metric_element_value_2
! Lookup2MetricElementType ==> FromLookupMetricElementId2.validation_data_type
! Lookup2MetricElementMethod ==> FromLookupMetricElementId2.validation_method
! Lookup2MetricElementValues ==> FromLookupMetricElementId2.validation_values
! MetricElementValue3 ==> FromValidationStepThree.metric_element_value_3
! Lookup3MetricElementAggMethod ==> FromLookupMetricElementId3.aggregation_method
! LookupSiteClientId ==> FromLookupSiteClient.entity_id
! LookupSiteAllClientId ==> FromLookupSiteAllClients.entity_id
! currentperiodstatus ==>
! CEstatusupdatestatus ==>
! futuredatestatus ==>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


! COMMANDS 1 AND 2 WILL PERFORM THE REQUIRED VALIDATIONS AND SET THE VALUE OF THE COMMON
! AREA VARIABLES - REASON (CONTAINS ERROR MSGS) AND STATUS ('TRUE' = ERRORS WERE FOUND).
! COMMANDS 3 AND 4 WILL ONLY ACCESS THE VALUES ALREADY SET IN THE COMMON AREA VARIABLES
! AND RETURN THE REQUESTED VALUE.

If Command = 1 Or Command = 2 Then
Reason = ""
Status = @FALSE

Reason = PreviousErrors
If Trim(PreviousErrors) <> "" Then
Status = @TRUE
End

! CLIENT VALIDATION
If IsNull(NewClientId) Then
Reason := "Client not valid. "
Status = @TRUE
End Else
If NewClientId <> (ClientId + 0) Then
Reason := "Supplied Client Id does not match Client. "
Status = @TRUE
End
End

! REPORTING PERIOD VALIDATION AGAINST CURRENT PERIOD
If currentperiodstatus = 1 Then
Reason := "Reporting period start and End date must be within 2 years."
Status = @TRUE
End


! CE STATUS UPDATE VALIDATION FOR ALL THE REPORTING PERIODS FALLING WITHIN THE REPORTING PERIOD DURATION
If CEstatusupdatestatus = 1 Then
Reason := "Add Operation Failed. There is no Published Status for the reporting period selected."
Status = @TRUE
End


! VALIDATION OF REPORTING PERIOD START AND END DATES WITH CURRENT DATE

If futuredatestatus = 1 Then
Reason := "Reporting period start and end date must not be in the future as per PLANO timings."
Status = @TRUE
End

! METRIC ELEMENT 1 VALIDATION
If MetricElementCount >= 1 Then
If IsNull(Lookup1MetricElementId) Then
Reason := "Metric Element 1 not valid. "
Status = @TRUE
End Else
If MetricElementId1 <> Lookup1MetricElementId Then
Reason := "Supplied Metric Element Id 1 does not match Metric Element. "
Status = @TRUE
End

WhichMetric = 1
Value = MetricElementValue1
Type = Lookup1MetricElementType
Method = Lookup1MetricElementMethod
Values = Lookup1MetricElementValues

Goto ValidateElementValue:
Element1:

If ReturnCode = @FALSE Then
Reason := "Metric Element Value 1 fails Validation Method check. "
Status = @TRUE
End
End
End Else
If Not(IsNull(MetricElementValue1)) Then
Reason := "Metric Element 1 supplied and not required for Metric. "
Status = @TRUE
End
End

! METRIC ELEMENT 3 VALIDATION
If MetricElementCount >= 3 Then
If IsNull(Lookup3MetricElementId) Then
Reason := "Metric Element 3 not valid. "
Status = @TRUE
End Else
If MetricElementId3 <> Lookup3MetricElementId Then
Reason := "Supplied Metric Element Id 3 does not match Metric Element. "
Status = @TRUE
End

WhichMetric = 3
Value = MetricElementValue3
Type = Lookup3MetricElementType
Method = Lookup3MetricElementMethod
Values = Lookup3MetricElementValues

Goto ValidateElementValue:
Element3:

If ReturnCode = @FALSE Then
Reason := "Metric Element Value 3 fails Validation Method check. "
Status = @TRUE
End
End
End Else
If Not(IsNull(MetricElementValue3)) Then
Reason := "Metric Element 3 supplied and not required for Metric. "
Status = @TRUE
End
End

! METRIC ELEMENT AGG METHOD VALIDATION
If MetricElementCount >= 1 Then
If IsNull(Lookup1MetricElementAggMethod) Then
Reason := "Aggregation Method not found for Metric Element 1. "
Status = @TRUE
End Else
If (Trim(Lookup1MetricElementAggMethod) <> "accumulation" AND Trim(Lookup1MetricElementAggMethod) <> "max" AND Trim(Lookup1MetricElementAggMethod) <> "min") Then
Reason := "Aggregation Method not valid for SPI for Metric Element 1. "
Status = @TRUE
End
End
End
If MetricElementCount >= 2 Then
If IsNull(Lookup2MetricElementAggMethod) Then
Reason := "Aggregation Method not found for Metric Element 2. "
Status = @TRUE
End Else
If Lookup1MetricElementAggMethod <> Lookup2MetricElementAggMethod Then
Reason := "Aggregation Method not consistent across Metric Elements for this Metric. "
Status = @TRUE
End
If (Trim(Lookup2MetricElementAggMethod) <> "accumulation" AND Trim(Lookup2MetricElementAggMethod) <> "max" AND Trim(Lookup2MetricElementAggMethod) <> "min") Then
Reason := "Aggregation Method not valid for SPI for Metric Element 2. "
Status = @TRUE
End
End
End
If MetricElementCount >= 3 Then
If IsNull(Lookup3MetricElementAggMethod) Then
Reason := "Aggregation Method not found for Metric Element 3. "
Status = @TRUE
End Else
If Lookup1MetricElementAggMethod <> Lookup3MetricElementAggMethod Then
Reason := "Aggregation Method not consistent across Metric Elements for this Metric. "
Status = @TRUE
End
If (Trim(Lookup3MetricElementAggMethod) <> "accumulation" AND Trim(Lookup3MetricElementAggMethod) <> "max" AND Trim(Lookup3MetricElementAggMethod) <> "min") Then
Reason := "Aggregation Method not valid for SPI for Metric Element 3. "
Status = @TRUE
End
End
End


! SITE-CLIENT VALIDATION
If Not(IsNull(LookupSiteAllClientId)) Then
If IsNull(LookupSiteClientId) Then
Reason := "Site not authorized to send data for this Client. "
Status = @TRUE
End
End

! SITE-PERSON VALIDATION
If IsNull(LookupSitePersonId) Then
Reason := "Submitted By Person is not authorized to send data for this Site. "
Status = @TRUE
End


Reason = Trim(Reason)

TotalRows += 1
If Status Then
RejectRows += 1
End
End

Begin Case
Case Command = 1
Ans = Status
Case Command = 2
Ans = Reason
Case Command = 3
Ans = Status
Case Command = 4
Ans = Reason
End Case

Goto EOP:


! METRIC ELEMENT DATA TYPE VALIDATION
ValidateElementValue:

ReturnCode = @TRUE

Begin Case

Case Type = "char"
NULL

Case Type = "numeric"
If Num(Value) and not(isnull(Value)) Then
Begin Case

Case Method = "minimum"
If (Value + 0) < (Values + 0) Then
ReturnCode = @FALSE
End

Case Method = "maximum"
If (Value + 0) > (Values + 0) Then
ReturnCode = @FALSE
End

Case Method = "range"
MinValue = Field(Values,",",1) + 0
If (Value + 0) < MinValue Then
ReturnCode = @FALSE
End Else
MaxValue = Field(Values,",",2) + 0
If (Value + 0) > MaxValue Then
ReturnCode = @FALSE
End
End

Case Method = "list"
Convert "," to @FM in Values
Locate (Value + 0) in Values Setting Location Then
NULL
End Else
ReturnCode = @FALSE
End

Case 1
! Invalid method.
ReturnCode = @FALSE
End Case
End Else
ReturnCode = @FALSE
End

Case 1
! Invalid type.
ReturnCode = @FALSE

End Case

Begin Case
Case WhichMetric = 1
Goto Element1:
Case WhichMetric = 2
Goto Element2:
Case WhichMetric = 3
Goto Element3:
End Case

EOP:
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Please edit your post and put code tags around the program list. This will save you indentation. Makes it easier for us to understand. Thanks.
Mamu Kim
Post Reply