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,

You could use two data structures. Something like:

D Date1 DS 6 0
D MM1 2 0
D YY1 2 0
D DD1 2 0

D Date2 DS 8 0
D CC2 2 0
D YY2 2 0
D MM2 2 0
D DD2 2 0

Then move the sub-fields from the first date to the proper postions in the second date.

HTH,
MdnghtPgmr
 
you could alway use the multiplication trick,, and then move into a data structure..
 
If you're using RPG IV, check out the date functions.

RedMage1967
IBM Certifed - RPG IV Progammer
 
This puts it into a text field:
Code:
         // Convert the date to ISO to get the 4 digit year, then
         // convert it to text to parse
         TempDateTxt = %char(%date(TempDate6:*MDY));

I think this would put it into a numeric field:
Code:
         // Convert the date to ISO to get the 4 digit year, then
         // convert it to text to parse
         TempDate8 = %dec(%date(TempDate6:*MDY):8:0);

Let me know if you need any other help. This should at least get you on the path.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
iSeries, there is a substring date bif
%SUBDT

That way, you can avoid the extra step of converting the date to text, and then extracting the year.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Sorry about that..
Been busy trying to get all of these tax forms out on time, not had a lot of time to look here.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Hi,

This is what I tried. It did not compile. The msg said The first parameter for %dec is not valid. cuactv is external field 6.0

D tempdatetxt s 6a
D ccyymmdd s 8s 0

tempdatetxt = %char(%date(cuactv:*mdy));
ccyymmdd = %dec(%date(cuactv:*mdy):8:0);
 
A quick question, what kind of field is CUACTV???

RedMage1967
IBM Certifed - RPG IV Progammer
 
ahh, packed 6,0 that holds a mmddyy date, correct?



RedMage1967
IBM Certifed - RPG IV Progammer
 
It would help if I read your original post. :)
Sorry about that.
I might have a solution for you later today, if no tomorrow.

RedMage1967
IBM Certifed - RPG IV Progammer
 
rapeek, RedMage1967 & iSeriesCodePoet:

First off, Hi!

Second, since the field is not a date data type, rapeek can't use the date BIFs can he? Doesn't he have to use the data structure method? Perhaps I'm not understanding... ;)

Are you suggesting he convert his 6,0 into a date data type, then manipulate it that way?

Can you use a 6,0? How will the BIF figure out the century? Does it use the 1940 window thing I once heard about years ago?

That's the main reason I suggested the data structure way was so that he could use his companies own formula or rules for handling the century conversion.

Thanks,
MdnghtPgmr

 
rapeek, try this, it does compile:
Code:
D CurActv         S              6P 0
D WorkActv        S              6S 0 Inz(*Zeros)
D DateMDY         S               D   DatFmt(*MDY)
D DateUSA         S               D   DatFmt(*USA)
D                    
D CharYear        S              4    Inz(*Blanks)
D Century         S              2    Inz(*Blanks)
 //--------------------------------------------------------
 /Free               
                          
  WorkActV = %Int(CurActv);
  DateMdy = %Date(WorkActv:*MDY);
  DateUSA = DateMDY; 
                          
  CharYear = %EditC(%SubDt(DateUSA:*Y):'X');
  Century = %Subst(CharYear:1:2);
                          
 /End-Free

Do you think that will work to solve your issue?

RedMage1967
IBM Certifed - RPG IV Progammer
 
Thank RedMage1967. This is the line that have problem when
my date field, in your sample WorkActv, contain 0.
DateMdy = %Date(WorkActv:*MDY);

Some of the record have date and some doesn't. The pgm failed on the record that have 0 value. Here is the msg:
Date, Time or Timestamp value is not valid.

thanks,
 
Using %DEC to convert a character field to a numeric field does not work prior to V5R2.

I found a function on the 'Net that will work at releases below that.






"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,

Forgot to mention this, I would like the way to avoid this error without having to check if the field is not 0 then perform the %Date convertion.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top