You forgot to give back just one tiny little information ..
does the message buffer You just built conform to the sequence of instructions used
and to what You are expecting you are expecting
if NO post the displays You got so that we have something to work on
show both the char format and the hex format
if YES You are writing what You built, but unfortunately what You built is wrong
I just run a quick and dirty test using rexx on my pc
to show what the buffers should look like given Your info
the script
r = "ZOS4"
l = length(r)
buff = "ZBXD" || "01"x || x2c(d2x(l,2)) || "000000"x || "00000000"x || r
say"******"
temp = c2x(buff)
say temp
say buff
buf0 = ""
buf1 = ""
do i = 1 to length(temp) - 1 by 2
buf0 = buf0 || substr(temp, i , 1 )
buf1 = buf1 || substr(temp, i + 1, 1 )
end
say buf0
say buf1
the result
5A42584401040000005A4F5334
ZBXD.........ZOS4
54540000000005453
A284140000000AF34
the pc is ascii the mainframe is ebcdic,
just forget the difference in the hex representation of the chars
what counts are the binary values