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!

How to convert flat file value into RPG decimal value??

Status
Not open for further replies.

jsplice

Programmer
Jun 3, 2003
88
US
I am processing a flat file that has several decimal fields. I used a data structure to break each field down based on its location. One particular field has values that look like this:
000000001764.0000
000000001404.0000
000000001068.0000
000000000828.0000
000000013320.0000
000000007488.0000
000000003264.0000


I'm trying to move these values in a 13,5 Packed Decimal field in a file. I tried converting each to a string, stripping the decimal point, the using %DEC to convert to decimal, but it doesn't acknowledge the zeros to the left of the actual number. Here is the code I used:

PodOrdMsrTemp = %Subst(PodOrdMsr:1:12) + %Subst(PodOrdMsr:14:4);
P3ORIN = %Dec(PodOrdMsrTemp:16:4);

And here are the values that I get from this:

PODORDMSRTEMP = '0000000017640000'
P3ORIN = 17640000.00000

Does anyone know how I can get this value into the decimal field properly?
 
What release are you on? And I'm confused when you say "[%DEC] doesn't acknowledge the zeros to the left of the actual number". %DEC coverts a character dtring to a numeric value; leading zeros are not an issue in packed or zoned fields.

The parameters for %DEC or %DECH refer to the length and decimal places of the numeric field, not the character field.

We use a procedure called GetNum. It was written by Barbara Morris (who works in IBM's Toronto lab).



Sumptum fac donec consumptus sis.

-- my wife's motto
 
jsplice,

The %dec() BIF works perfectly well. Just do so.

Code:
 * New variable MyNum309 :
d  MyNum309       s             30p 9                  

 /free    
    // Convert from alphameric to long packed fld 30,9  
    [COLOR=red]// Note. Precision (21) + Decimal places (9) = 30 
    //       30 = length of variable MyNum309 [/color]              
    MyNum309 = %dec( PodOrdMsr : 21 : 9 );   
    // Convert from packed fld 30,9 to packed fld 13,5                      
    P3ORIN = MyNum309;

 
P3ORIN = %Dec(odOrdMsr:16:4)

%dec will automatically align the decimal. It will also ignore any blanks, and doesn't care if the field is left or right justified.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top