DataLoader/MX Reference Manual (G06.24+)
Creating a Customized Version of DataLoader/MX
DataLoader/MX Reference Manual—525872-002
5-18
Data Conversion
Buf is a pointer to the record whose fields are to be converted. NumFields is the
number of fields to be converted. Offsets is a pointer to NumFields 32-bit values
that give the offsets (counting from zero) of the fields to be converted. FieldSizes is
a pointer to NumFields 32-bit values that give the sizes of the fields whose offsets are
in the corresponding position of Offsets.
Example
This example uses the DTLSwitchEndian function in a CONVERTIT user exit to
reverse the bytes of binary integer fields when the data is being moved from a system
with one byte order to a system with another byte order.
Although it is extra work in set up, it is more efficient to use the compiler to compute
the offsets and lengths. Remember that filler bytes are dropped in when a field has to
be a multiple of 2, 4, or 8 bytes from the beginning of the structure. Therefore, it is not
accurate to count the bytes in a structure declaration.
sizes, offsets,arrays, and NumFields are declared static and are set up in the
initial data of the program so that they are not computed on every entry to
CONVERTIT.
#include "dtload.h" nolist
#include <assert.h> nolist
DTLEXP
void WINAPI CONVERTIT(
char* RecIn,
long* RecInLen,
char* RecOut,
long* RecOutLenMax,
long* RecOutLen,
short* Status
)
{
/* This is the record structure */
typedef struct
{
char c1[10];
long c2;
long c3;
char c4[20];
long long c5;
short c6[3];
} input_record;
input_record* i_r;
/*
This array holds the offset from the beginning of the
record of each field to be switched.
*/
static DTLLEN offsets[] = { offsetof( input_record, c2 ),
offsetof( input_record, c3 ),
offsetof( input_record, c5 ),
offsetof( input_record, c6[0] ),