mainframe - How to display the actual value of a comp variable in cobol -
i have following variable in cobol program gets value file, when read:
01 employee-number pic 09(8) comp 01 employee-number-x redefines employee-number pic x(04)
i have variable in same program:
01 d-element-number pic 9(04)
now,
move employee-number
d-element-number
then write d-element-number
file
value read input file :
0013 0024
so value comes employee-number
, employee-number-x
, move value d-element-number
, write variable output file.
but in output file:
4660 ffff 4660
4660
decimal equivalent of x'1234'
but want see like:
1234 ffff 1234
how can achieve ?
i allowed change definition of d-element-number
nothing else.
assuming when have x'00001234' want c'00001234', have here. http://ibmmainframes.com/viewtopic.php?p=234231#234231
ignore rest of discussion now, concentrate on post.
this key part:
perform until x-ws-1000 > x-ws-1000-max move ws-1000-byte-tbl (x-ws-1000) ws-packed-x (1:1) move ws-packed ws-display move ws-display-x ws-2000-byte-tbl (x-ws-2000) set x-ws-1000 1 set x-ws-2000 1 end-perform
you need exact storage definitions go (don't "correct" anything).
it works getting compiler use "unpack" instruction (unpk). 1 working 1 byte @ time, simple explain.
x'12' (an example on-byte field) put in two-byte field. x'12ii' (where value of ii "irrelevant").
unpk turn "packed" number "zoned" number. "zone" first 4 bts of byte, , zoned number, 4 bits set one. f. left-most digit first byte. second output byte, first 4 bits set f, second input digit.
then unpk continues final byte, contains 1 irrelevant digit, , irrelevant sign. zoned number, sign , right-most digit occupy same byte (the sign in zone) whole byte of irrelevance.
x'12' -> x'12ii' -> x'f1f1ii'.
the first 2 bytes of three-byte output c'12'.
nos, fine numbers, letters make mess:
x'ab' -> x'abii' -> x'fafbii'
although f , digits gives displayable number, f , letter, result not mean directly.
now inspect ... converting comes rescue: fa gets translated c'a' (x'c1), , same letters through f.
your results after converting c'ab'.
should give enough work on.
there other methods, fair cobol approximation classic assembler technique unpk , translate (tr) , table of translation values.
if use favourite search engine. should able fine more methods, using calculation (more one), table-lookups, i've seen 256-when evaluate "works", guess little on "slow" side.
thinking further, have bcd (binary coded decimal) don't you? packed decimal, without sign. don't have alphas in field.
this simpler convert.
01 the-converted-value packed-decimal pic 9(8)v9 value zero. 01 filler redefines the-converted-value. 05 the-binary-value pic x(4). 05 filler pic x. move employee-number-x the-binary-value move the-converted-value d-element-number (with gilbert's correction pic 9(8)).
the "decimal place" ii, ignore value , ignore sign. no longer need inspect ... converting ... have numeric digits. if have bcd...
a way have answered own question have been find out how number created in binary field in first place.
Comments
Post a Comment