public static int calcLengthFromPicture(
            final Map < Character, Integer > charNum,
            final boolean isSignSeparate, final String currencySign,
            final char currencySymbol, final boolean calcStorageLength) {

        int length = 0;

        /* character position occupied by each picture symbol */
        Map < Character, Integer > charLen = new HashMap < Character, Integer >();
        charLen.put('A', 1);
        charLen.put('B', 1);
        charLen.put('G', (calcStorageLength) ? 2 : 1);
        charLen.put('N', (calcStorageLength) ? 2 : 1);
        charLen.put('X', 1);
        charLen.put('P', 0);
        charLen.put('Z', 1);
        charLen.put('0', 1);
        charLen.put('/', 1);
        charLen.put('+', 1);
        charLen.put('-', 1);
        charLen.put('*', 1);
        charLen.put('C', 2);
        charLen.put('D', 2);
        charLen.put('.', 1);
        charLen.put(',', 1);
        charLen.put('9', 1);
        charLen.put('E', 1);
        charLen.put('S', (isSignSeparate) ? 1 : 0);
        charLen.put('V', 0);
        charLen.put(currencySymbol, 1);

        for (Map.Entry < Character, Integer > entry : charNum.entrySet()) {
            length += entry.getValue() * charLen.get(entry.getKey());
        }
        if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) {
            length += currencySign.length() - 1;
        }
        return length;
    }
public static int calcLengthFromPicture ( final Map < Character , Integer > charNum , final boolean isSignSeparate , final String currencySign , final char currencySymbol , final boolean calcStorageLength ) { int length = 0 ; Map < Character , Integer > charLen = new HashMap < Character , Integer > ( ) ; charLen . put ( 'A' , 1 ) ; charLen . put ( 'B' , 1 ) ; charLen . put ( 'G' , ( calcStorageLength ) ? 2 : 1 ) ; charLen . put ( 'N' , ( calcStorageLength ) ? 2 : 1 ) ; charLen . put ( 'X' , 1 ) ; charLen . put ( 'P' , 0 ) ; charLen . put ( 'Z' , 1 ) ; charLen . put ( '0' , 1 ) ; charLen . put ( '/' , 1 ) ; charLen . put ( '+' , 1 ) ; charLen . put ( '-' , 1 ) ; charLen . put ( '*' , 1 ) ; charLen . put ( 'C' , 2 ) ; charLen . put ( 'D' , 2 ) ; charLen . put ( '.' , 1 ) ; charLen . put ( ',' , 1 ) ; charLen . put ( '9' , 1 ) ; charLen . put ( 'E' , 1 ) ; charLen . put ( 'S' , ( isSignSeparate ) ? 1 : 0 ) ; charLen . put ( 'V' , 0 ) ; charLen . put ( currencySymbol , 1 ) ; for ( Map . Entry < Character , Integer > entry : charNum . entrySet ( ) ) { length += entry . getValue ( ) * charLen . get ( entry . getKey ( ) ) ; } if ( currencySign . length ( ) > 1 && charNum . get ( currencySymbol ) > 1 ) { length += currencySign . length ( ) - 1 ; } return length ; }
The COBOL picture clause determines the length, in number of characters,
for all alphanumeric and numeric-edited data items.
<p/>
The length evaluated here is either the number of character positions
(which corresponds to the size constraint on the client side) or the byte
size of the storage needed on z/OS for the data item. You select between
one or the other with the calcStorageLength parameter.
<p/>
When the currency sign is more than a single character, then the first
occurrence of the currency symbol counts for more than one byte of
storage.

@param charNum map of all characters in the picture string
@param isSignSeparate if sign occupies a separated position (no
overpunch)
@param currencySign the currency sign
@param currencySymbol the currency symbol
@param calcStorageLength when true the length returned is the z/OS
storage length
@return the length, in number of characters, of the data item