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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move numeric field to short numeric field

Status
Not open for further replies.

thelearner

Programmer
Jan 10, 2004
153
US
Hi,

I need help, again. I have a date field, 6.0 pack, which contian mmyydd. I need to convert to ccyymmdd so I can use it for comparison.
In fix format I can just do 'move' the 2 right positions to another 2 digit field. Then I can use this new field to calculate for the century. The free format won't allow me to move from 6.0 to 2.0 field. Any suggestion will be appreciate.

Thanks
 
rapeek:

OK, we are at V5R1, so I have to use the user function instead of %DEC.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Hi,

Ok, this is what I have. It's work and no data structure needed. However I just don't like it that I have to compare the field first.

D ccyymmdd s d
D newdate s 8s 0

// this return value in cymd format to numeric field

if cuactv > 0;

ccyymmdd = %date(cuactv:*mdy);
newdate = %int(%char(ccyymmdd:*iso0));
endif;
 
There is no way around having to check and see if the field is zero or not. RPG IV assumes that your trying to convert a valid date from a numeric to a date field. Therefore, it doesn't check the field prior to converting it. You're going to have to make sure the field is not zero.

RedMage1967
IBM Certifed - RPG IV Progammer
 
You can check a numeric field to see if it is a valid date, but you have to do that in fixed format. In the following example, Ftucdt is numeric, 8,0 in yyyymmdd format, and Signdate is a native date field. If the numeric date field is invalid, use today's date instead:

Code:
     C     *ISO          Test(DE)                Ftucdt         
     C                   If        Not %ERROR                   
     C                   Eval      Signdate = %DATE(Ftucdt:*ISO)
     C                   Else                                   
     C                   Eval      Signdate = %DATE             
     C                   Endif


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
To clarify my previous post: not only should you be checking a numeric date to see if it's non-zero, you should be making sure it's a valid date. TEST(DE) does both.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
TEST does convert to free form:
Code:
Test(DE) *ISO FtuCdt;
If Not %Error;
  SignDate = %Date(FtuCdt:*ISO);
Else;
  SignDate = %Date();
EndIf;

Just a minor note, flapeyre, you have to have the () after the %DATE, or the compiler will error.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Hi RedMage1967,

This is not relate to my original post. Do you have the free form for TESTN. I want to perform check if my char. field contain digit.

Thank.
 
rapeek,
There is no free form replacement for TESTN. You might want to try using a %CHECK, to find a digit in your string.
Code:
D Numbers            C        '0123456789'
 //-----------------------------------------------
 /Free
  
  If %Check(Number:String) > 0;  // no digits found
 //  do something

  Else;  // digits found
  // do something else
EndIf;

Does this help?


RedMage1967
IBM Certifed - RPG IV Progammer
 

Just a minor note, flapeyre, you have to have the () after the %DATE, or the compiler will error.


I copied and pasted that code from a V5R1 program that has been in production for 6 months. %DATE without the () does work.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
That's odd.


Either the compiler, or the Code/400 editor (I don't remember which) gives me an error if I omit the ().

RedMage1967
IBM Certifed - RPG IV Progammer
 
Must be Code400. I mostly use SEU because Code400 tends to crash on me.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top