View previous topic :: View next topic
|
Author |
Message |
manishm
New User
Joined: 31 Mar 2005 Posts: 5
|
|
|
|
I need to write few numeric fields in my output file along with a few Alphanumeric fields. The problem is that the numeric fields must be written without any leading zeros or spaces, so if the field is defined as S9(09)V99 and the actual value of the field is 178.75, it must be written in the file as 178.75 only, and not as 000000178.75. I also can't use zero suppressors because that will convert leading zeros to leading spaces. I have already implemented the idea of using an array and then getting rid of leading zeros, but looking for a better solution now. |
|
Back to top |
|
|
SHAILESH OZA
New User
Joined: 10 Jun 2005 Posts: 21 Location: Mumbai
|
|
|
|
Hi ManishM,
You can do one thing by using Inspect
Inspect Variable(000000178.75) tallying counter for all leading zeros.
You will get the counter value as 6. So after that you can use the reference modication as Variable(6: L) and use that for your operations. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
ManishM,
what does your output file field structure look like?
what kind of field do you want to populate with the space/zero trimmed numeric edited value? |
|
Back to top |
|
|
manishm
New User
Joined: 31 Mar 2005 Posts: 5
|
|
|
|
The Output file is a comma separated file with all the fields compressed to their actual lengths (Though they are defined with their maximum possibl e lengths)
The problem in using INSPECT command is that I don't know how many bytes of actual data is present in the field so I can't use reference modification also. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Based on what you're saying, you can either pick a language other than COBOL to write this in, or you can use reference modification to do it. Build your output record one field at a time via reference modification; you can use the INSPECT for leading zeroes to know where to start moving from; the length of the sending field minus the starting position for the move tells you how many bytes you're moving.
This would be a pretty trivial task in SAS, by the way. |
|
Back to top |
|
|
SHAILESH OZA
New User
Joined: 10 Jun 2005 Posts: 21 Location: Mumbai
|
|
|
|
Hi Manish,
Var1 = 000000178.75
Length = Use Length of (Var1) to calulate the length = its 12 in this case
By using inspect tally count for leading zeroes you will get counter = 6
Now Reference modification is like this Var1(counter+1 : length)
i.e Var1(7:12) which contains exactly 178.75 which can used for the operation. Does it make any sense ?
Regards,
Shailesh |
|
Back to top |
|
|
manishm
New User
Joined: 31 Mar 2005 Posts: 5
|
|
|
|
Shailesh,
Let me know if I am wrong but when you try to use the reference modification, the second value which you provide (in the braces), should be the actual length which you want to pull and not the total length of the field. So Var(7:12) means that it'll try to pick-up 12 bytes starting at position 7. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Manish,
Guess you missed this one....
Robert Sample wrote: |
Based on what you're saying, you can either pick a language other than COBOL to write this in, or you can use reference modification to do it. Build your output record one field at a time via reference modification; you can use the INSPECT for leading zeroes to know where to start moving from; the length of the sending field minus the starting position for the move tells you how many bytes you're moving. |
|
|
Back to top |
|
|
|