× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



<snip>
I have a vendor that wants to send me a file to be uploaded to our
iSeries.
The problem is with the dates that get sent. Normally, today's date
would be
08/07/2007 which the %date biff would handle just fine. Unfortunately,
the
dates I'm receiving drop the leading 0 in both the month and day,
resulting
in 8/7/2007 which the %date doesn't like. Any ideas how to handle this
other
then parsing it out?
</snip>

Depends on where the data is being read from. If from a table, my iDate
User Defined function available at www.think400.dk/downloads will handle
the date correctly and convert it to a date data type that you can use
as you which.

Exec Sql Select iDate('8/7/2007') from TableX;

You could, also, use it inside your RPG Program as

Exec Sql Set DateField = Select iDate('8/7/2007') From SYSIBM/SYSDUMMY1;

As long as the date is reasonable, it can handle it.

An alternative is the following code from my iDate function.

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
* StripCharacters.
* This function removes any characters except number from an
incoming
* character field but in order to do so it must normalize the
data.
* For example, "9-5-2007" must be normalized to "09052007" or
we
* will get garbage.
* Input - iSeries Date in Character Format, blanks
trimmed.
* Date Format
* Output - None
* Returns - Value in Decimal(8,0).
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
p StripCharacters...
p b
d pi 8p 0
d InCharacterString...
d 10a Varying
d Value
d InDateFormat...
d 10a Varying
d Value
d OutSQLState...
d Like(StdSQLState)
d OutDiagnosticMessage...
d 70a Varying

d cNumbers...
d c '0123456789'
d x...
d s Like(StdInt)
d aChar...
d s Like(StdChr)
d Buffer...
d s 8a
d Count...
d s Like(StdInt)
d Separator...
d s Like(StdChr)
d SepCount...
d s Like(StdIntSml)
d String1...
d s 4a Varying
d String2...
d s 4a Varying
d String3...
d s 4a Varying
/Free

// If blanks, return a zero.
If InCharacterString = *Blanks;
Return 0;
EndIf;

// If nothing but numbers return as decimal.
If %Check(cNumbers:InCharacterString) <= 0;
Return %Dec(InCharacterString:8:0);
EndIf;

// Separators in Julian or CYMD dates make no sense
// so return zero.
If InDateFormat = '*CYMD' Or
InDateFormat = '*JUL' Or
InDateFormat = '*LJUL' Or
InDateFormat = '*CJUL' Or
InDateFormat = '*JDEJUL';
OutSQLState = '38501';
OutDiagnosticMessage = 'Date Format ' +
%Trim(InDateFormat) +
' cannot have separators';
Return 0;
EndIf;

// Get out the string pieces and do some reasonableness
// checking. Must have something like xx/xx/xxxx or
// xxxx-xx-xx or x/x/xx or xx/x/xxxx. Anything else is
// going to be invalid.
For x = 1 To %Len(InCharacterString);
aChar = %Subst(InCharacterString:x:1);
If aChar = *Blank; // Embedded blanks are not allowed.
OutSQLState = '38501';
OutDiagnosticMessage = 'Date Format ' +
%Trim(InDateFormat) +
' cannot have embedded blank for
separators';
Return 0;
EndIf;

If %Check(cNumbers:aChar) = 0; // Found a number.
Count += 1;
%Subst(Buffer:Count:1) = aChar;
Iter;
EndIf;

// Something beside a number found. If we have seen
// something before must be same character.
If Separator <> *Blank;
If Separator <> aChar;
OutSQLState = '38501';
OutDiagnosticMessage = 'Date Format ' +
%Trim(InDateFormat) +
' separators must have the same';
Return 0;
EndIf;
EndIf;

// Save the separator character and extract string piece.
Separator = aChar;
SepCount += 1;
Select;
When SepCount = 1;
String1 = %Subst(Buffer:1:Count);
When SepCount = 2;
String2 = %Subst(Buffer:1:Count);
Other;
Return 0;
EndSl;
Buffer = *Blanks;
Count = 0;
EndFor;

// Error check. If nothing in buffer (No third piece) or
// two separators not seen, invalid date. Return 0.
If Count = 0 Or
SepCount <> 2;
OutSQLState = '38501';
OutDiagnosticMessage = 'Date Format ' +
%Trim(InDateFormat) +
' has an invalid formatted date';
Return 0;
EndIf;

// Extract last piece.
String3 = %Subst(Buffer:1:Count);

// Anything that is 1 byte should be two bytes with a zero
// in front.
If %Len(String1) = 1;
String1 = '0' + String1;
EndIf;
If %Len(String2) = 1;
String2 = '0' + String2;
EndIf;
If %Len(String3) = 1;
String3 = '0' + String3;
EndIf;

// Ok, now we can string back together and return result
Monitor;
Return %Dec(String1 + String2 + String3:8:0);
On-Error;
OutSQLState = '38501';
OutDiagnosticMessage = 'Date Format ' +
%Trim(InDateFormat) +
' has an invalid formatted date';
Return 0;
EndMon;

/End-Free
p e





As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.