|
Hi Lakshmi, > I understood what you are saying. My problem is the third party(PC) they do > not want to do the bytes swapping, so my end (On AS/400) need to do the > swapping and send.Is there any other way to do the bytes swapping on > AS/400. Oh, so you want to just reverse the order of the bytes from what it is? That's not hard to do, just copy the bytes from one end to the other end. Here's a general-purpose routine for reversing the order of bytes in a field. As you'll see by the example code at the top, it can be used to reverse integers, character strings, etc. Since it operates on the underlying bytes, it doesn't matter what type of data the variable is. It's also deliberately intended to work on any size variable, rather than hardcoding 2 or 4 bytes, etc. Here it is: H DFTACTGRP(*NO) D Reverse PR D Input * value D Output * value D Size 10I 0 value D Test1 s 5I 0 D Test2 s 5I 0 D Test3 s 26A D Test4 s 26A D Test5 s 10I 0 D Test6 s 10I 0 * * test1 = 16384 (x'4000') * test2 will be 64 (x'0040') * c eval test1 = 16384 c callp Reverse( %addr(test1) c : %addr(test2) c : %size(test1) ) c dsply test2 * * test3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' * test4 will be 'ZYXWVUTSRQPONMLKJIHGFEDCBA' * c eval test3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' c callp Reverse( %addr(test3) c : %addr(test4) c : %size(test3) ) c dsply test4 * * Test5 = 2130772483 (x'7F010203') * Test6 will be 50463103 (x'0302017F') * c eval Test5 = 2130772483 c callp Reverse( %addr(test5) c : %addr(test6) c : %size(test5) ) c dsply test6 c eval *inlr = *on *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Reverse(): This routine copies the bytes from a input buffer * to an output buffer in reverse order. * * Input = pointer to start of input buffer * Output = pointer to start of output buffer * Size = size of input buffer. (output buffer must * be at least this large as well) *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P Reverse B D Reverse PI D Input * value D Output * value D Size 10I 0 value D x s 10I 0 D InByte s 1A based(input) D OutByte s 1A based(output) c eval Output = Output + (Size - 1) c for x = 1 to Size c eval OutByte = InByte c eval Input = Input + 1 c eval Output = Output - 1 c endfor P E
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.