Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C format cobol InputMask
How to?
 
Cobol has an input mask format similar to the following:
Using integer 345
picture "99999" yields 00345
picture "zzzz9" yields 345
or even "zzzVzz" yields 3.45
 
"9zzzVzz" invalid (9 to the left of z).
 
"$zzVzz" floating dollar $3.45
 
integer 1234567
 
picture "$zzzTzzzVzz"
 
results in $12,345.67

V is dot in non metric countries, and
Some software uses the T to indicate comma. T is comma , in USA, and dot . in metric countries.
 
Is there already a routine that does this? something like
 
picformat(Result, Picture,integer),
 
There is a rule for sign (when integer was negative). S
$SzzzTzzzVzz or $zzzTzzzVzzS
$-12,345.67 $12,345.67-
Posted 15-Feb-13 3:44am
Edited 15-Feb-13 4:29am
v2
Comments
Marcus Kramer at 15-Feb-13 9:28am
   
The term you are using is incorrect. What you are looking for is a "Mask", not a "Picture".
nv3 at 15-Feb-13 10:08am
   
Marcus, I think he is referring to the COBOL picture clause (PIC). Yes, it was really called "PIC"!.
Chris Reynolds (UK) at 15-Feb-13 9:58am
   
The nearest you'll get is sprintf for formatting output and sscanf for parsing an input string. You could probably write a routine to convert standard COBOL picture formats to a sprintf format specifier, the commas will be a problem though.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

These features of COBOL are built into the compiler, and are not generally available in other languages (with some exceptions: PL/I, ADA).
 
You flagged "C" as your language of interest. These features are not built into the C language, but you might be able to find a library somewhere that has implemented similar functionality.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Adding commas using sprintf(), was no challenge. I have tested it with positive and negative numbers between one digit and 16 digits.
 
I need to remove the debugging code and post it here in the next day or two.
 
I have almost completed the formating using the Cobol Picture clause. The rules allow for truncation.
 
My first step was to edit the picture clause to insure the format was correct and not illegal.
 
The second step is to actually doing the formatting.
 
This will come in the next day or so as well.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100