It is a 128 bit quantity, better to pass as argument.
This example does not implement the clock sequence part per rfc4122,
and use cpu serial in place of MAC address.
*PROCESS LIMITS(FIXEDBIN(63));
guid: package;
define structure
1 guid
,3 time_low unsigned fixed bin(32)
,3 time_mid unsigned fixed bin(16)
,3 time_hi_and_version unsigned fixed bin(16)
,3 clock_seq_hi_and_reserved unsigned fixed bin(8)
,3 clock_seq_low unsigned fixed bin(8)
,3 node char(6)
;
define structure
1 _FEEDBACK
,3 tok_sev fixed bin(15)
,3 tok_msgno fixed bin(15)
,3 *
,5 tok_case bit(2) unaligned
,5 tok_sever bit(3) unaligned
,5 tok_ctrl bit(3) unaligned
,3 tok_facid(3) char
,3 tok_isi fixed bin(31)
;
dcl CEEGMT entry(fixed bin(31) byaddr, real float decimal(16) byaddr,
1 optional type _FEEDBACK byaddr) options(assembler);
dcl getcpuid ext('__get_cpuid') entry(char(11) byaddr)
returns(optional fixed bin(31))
options( linkage(optlink) nodescriptor );
guidfmt: proc(u,out);
dcl u type guid byvalue;
dcl out char(*) varz byaddr;
out='';
out=heximage(addr(u.time_low),4); out||='-';
out||=heximage(addr(u.time_mid),2); out||='-';
out||=heximage(addr(u.time_hi_and_version),2); out||='-';
out||=heximage(addr(u.clock_seq_hi_and_reserved),2); out||='-';
out||=heximage(addr(u.node),6);
end guidfmt;
genguid: proc(u);
dcl u type guid;
dcl lilgmt fixed bin(31);
dcl secgmt real float decimal(16);
dcl t unsigned fixed bin(64);
dcl fb type _FEEDBACK;
dcl buf char(11);
dcl rc fixed bin(31);
dcl pid fixed unsigned bin(32);
call CEEGMT(lilgmt,secgmt,fb);
if (fb.tok_sev = 0 & fb.tok_msgno = 0) then do;
end;
else stop;
call getcpuid(buf);
u.node=substr(buf,1,6);
t=secgmt*10000000;
u.time_low=iand(t,'00000000ffffffff'xn);
u.time_mid=iand(isrl(t,32),'000000000000ffff'xn);
u.time_hi_and_version=iand(isrl(t,48),'0000000000000fff'xn);
u.time_hi_and_version=ior(isll(1,12),u.time_hi_and_version);
u.clock_seq_low=0;
u.clock_seq_hi_and_reserved = 0;
u.clock_seq_hi_and_reserved =
iand(u.clock_seq_hi_and_reserved,'3f'xn);
u.clock_seq_hi_and_reserved =
ior(u.clock_seq_hi_and_reserved,'80'xn);
end genguid;
test: proc options(main);
dcl u type guid;
dcl out char(100) varz;
call genguid(u);
call guidfmt(u,out);
display("guid:"||out);
end test;
end guid;
ccw