Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skip Null Field using AS400 Date Conversion

Status
Not open for further replies.

jpals

MIS
Jun 19, 2006
5
US
I am using this date conversion to convert AS400 dates to a calendar date:
Function (numberVar ConvertDate)
// @ConvertDate

// substitute {the AS400 date field} for the number field that is to be converted to a date
local numbervar AS400date := ConvertDate;

// converts the number to a text field
// this is so that the field can be parsed out into year, month, day
local stringvar AS400string := totext(AS400date, 0, "");
local numbervar fieldlength := length(AS400string);

// determines the year
local numbervar ASyear := 1900 + tonumber((AS400string)[1 to fieldlength - 4]);

// determines the day
local numbervar ASday := tonumber(right(AS400string, 2));

// determines the month
local numbervar ASmonth := tonumber(AS400string[(fieldlength - 3) to (fieldlength - 2)]);

// truedate is the final result in the formula that displays
// the date into a true date type in Crystal Reports
local datevar truedate := date(ASyear, ASmonth, ASday);

truedate;


My problem is the field I am trying to convert has some null values for this date and it returns an error that the subscript must be between 1 and the length of the script. Any ideas how to make get past the null fields?

Thanks,
 
Precede it with a null check, as in;

Function (numberVar ConvertDate)
// @ConvertDate

// substitute {the AS400 date field} for the number field that is to be converted to a date
local datevar truedate;
if isnull(ConvertDate)
or
ConvertDate < (whatever value is the minimum possible) then
Truedate:= date(0,0,0)
else
(
local numbervar AS400date := ConvertDate;

// converts the number to a text field
// this is so that the field can be parsed out into year, month, day
local stringvar AS400string := totext(AS400date, 0, "");
local numbervar fieldlength := length(AS400string);

// determines the year
local numbervar ASyear := 1900 + tonumber((AS400string)[1 to fieldlength - 4]);

// determines the day
local numbervar ASday := tonumber(right(AS400string, 2));

// determines the month
local numbervar ASmonth := tonumber(AS400string[(fieldlength - 3) to (fieldlength - 2)]);

// truedate is the final result in the formula that displays
// the date into a true date type in Crystal Reports
truedate := date(ASyear, ASmonth, ASday);
);
truedate;

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top