>>source format is free *>********************************************************************* *> Author: jrls (John Ellis) *> Date: Oct-2008 *> Purpose: formated output examples using pic strings. *>********************************************************************* identification division. program-id. picstring. data division. working-storage section. *> 01 header. 05 pic xxx value "ln". 05 pic x(11) value " disp1". 05 pic x(11) value " disp2". 05 pic x(11) value " disp3". 05 pic x(11) value " disp4". 05 pic x(12) value " disp5". 05 pic x(9) value " an1". 05 pic x(14) value " phone". 05 pic x(10) value " date". *> 01 headerLines pic x(90) value all "-". *> 01 displayformats. 05 linenum pic 99 value 1. 05 disp1 pic zzz,zz9.99 value zero. 05 pic x value spaces. 05 disp2 pic $zz,zz9.99 value zero. 05 pic x value spaces. 05 disp3 pic ---,--9.99 value zero. 05 pic x value spaces. 05 disp4 pic $-z,zz9.99 value zero. 05 pic x value spaces. 05 disp5 pic -zz,zz9.zz- blank zero value zero. 05 pic x value spaces. *><*an1 is actually a string field because of the embedded blanks, thus you put value spaces. 05 an1 pic 99b99b99 value spaces. 05 pic x value spaces. 05 phone pic bxxxbxxxbxxxx value spaces. 05 pic x value spaces. 05 dispdate pic 99/99/9999 value zero. *> procedure division. 0000-start. *> display headerLines. display header. display headerLines. *><**************************************************** move 220.22 to disp1, disp2. move -220.22 to disp3, disp4, disp5. inspect disp5 replacing first "-" by "(", first "-" by ")". move 10122008 to dispdate. *><**************************************************** *><*Please note the results of moving 'abcd' to an1. *><*an1 will show up as 00 00 00 because alpha data was *><*moved into instead of numeric data. *><* *><*The phone field will display " abc def ghij" because *><*'b' in the pic string. *><**************************************************** move "abcd" to an1. move "abcdefghij" to phone. display displayformats. add 1 to linenum. move zero to disp4, disp5. *><**************************************************** *><*Here after moving data to an1 and phone, I use the *><*inspect statement to replace the blanks. *><**************************************************** move "123456" to an1. move "5555551234" to phone. inspect an1 replacing all " " by "-". inspect phone replacing first " " by "(", first " " by ")", first " " by "-". display displayformats. inspect phone converting "23456789" to "adgjmptw". display phone. perform 0010-endProgram. *> 0010-endProgram. stop run. *> *><* output *><* ------------------------------------------------------------------------------------------ *><* ln disp1 disp2 disp3 disp4 disp5 an1 phone date *><* ------------------------------------------------------------------------------------------ *><* 01 220.22 $220.22 -220.22 $-220.22 (220.22) 00 00 00 abc def ghij 10/12/2008 *><* 02 220.22 $220.22 -220.22 $ 0.00 12-34-56 (555)555-1234 10/12/2008 *><* (jjj)jjj-1adg