SAP Technology: Using Intelligent Mail Bar Codes (IMB) in SAP Forms

//SAP Technology: Using Intelligent Mail Bar Codes (IMB) in SAP Forms

SAP Technology: Using Intelligent Mail Bar Codes (IMB) in SAP Forms

By |2018-12-29T15:42:09+00:00January 17th, 2014|SAP|0 Comments

As of January 28, 2013, the United States Postal Service requires use of the Intelligent Mail bar code to qualify for automation prices on mailed documents.  This has impacted many SAP customers who mail large volumes of invoices, checks, etc.  In order to integrate the IMB bar code into your existing SAP forms, follow these steps:

  1. Download the appropriate IMB encoder for your server’s platform from the USPS website along with the fonts for the bar code.  The fonts need to be installed on any printer where you will output your forms.
  2. Extract the contents to a directory on your SAP application server.
  3. Run the test programs included in the download to verify that the encoder works correctly on your server.
  4. Compile a C or Java program on your server to accept Tracking Number and Routing Number as parameters and returning the bar code string.  Here is a sample C program compiled on Linux using the GCC compiler:
char TrackString[21];     /* Input parameter Track String + 1 null*/
char RouteString[12];     /* Input parameter Route String + 1 null*/
char BarString[66];       /* Output parameter Bar String + 1 null */
int RetCode;              /* Return code from the usps4cb encoder */
int USPS4CB( char *TrackPtr, char *RoutePtr, char *BarPtr);
int main( int argc, char *argv[] )
–argc; /* subtract 1 from argc (arg count) because the program name is stored as arg 1.*/
if ( argc != 2 ) /* argc should be 2 for correct execution */
/* We print argv[0] assuming it is the program name */
printf( “Invalid arguments:\n%i arguments passed. Expecting 2 arguments.\nRequired format is <TrackingNumber RoutingNumber>\n”, argc );
// Open the library.
char* lib_name = “./”;
void* lib_handle = dlopen(lib_name, RTLD_NOW);
if (lib_handle) {
//printf(“[%s] dlopen(\”%s\”, RTLD_NOW): Successful\n”, __FILE__, lib_name);
else {
printf(“[%s] Unable to open library: %s\n”,
__FILE__, dlerror());
// Get the symbol addresses.
int (*USPS4CB)(char*, char*, char*) = dlsym(lib_handle, “USPS4CB”);
if (USPS4CB) {
//printf(“[%s] dlsym(lib_handle, \”USPS4CB\”): Successful\n”, __FILE__);
else {
printf(“[%s] Unable to get symbol: %s\n”,
__FILE__, dlerror());
/* Call the usps4cb encoder */
printf( “Input values are: Tracking = %s Routing = %s\n”, TrackString,RouteString );
RetCode = USPS4CB(TrackString,RouteString,BarString);
//printf(“Outputs are:\n”);                  /* Print the outputs */
//printf(“Encoded Bar String: %s\n”,BarString);
// Close the library.
if (dlclose(lib_handle) == 0) {
//printf(“[%s] dlclose(lib_handle): Successful\n”, __FILE__);
else {
printf(“[%s] Unable to open close: %s\n”,
__FILE__, dlerror());

5.  In SM69, create a customer command that points to the location of your compiled program:


6.  In the initialization routine of your form, call function module SXPG_COMMAND_EXECUTE as follows:

call function ‘SXPG_COMMAND_EXECUTE’
commandname                   = ‘ZIMB_ENCODE’
additional_parameters         = ‘<Pass Tracking Number> <Pass Routing Number>‘
operatingsystem               = sy-opsys
status                        = lv_status
exitcode                      = lv_exitcode
exec_protocol                 = lt_eprot. <== This internal table contains the bar code that should be place on your form

You may need to make some minor tweaks to fit your platform, but this is all you need to create the IMB bar code on your forms.

About the Author:

I have always been passionate about fixing broken business processes and cleaning up the mess left by enterprise software. It honestly bothers me to see companies spending hundreds of millions of dollars on IT projects, which motivated me to start Clear Software. Prior to founding Clear, I was a Senior Manager at Deloitte, where my teams implemented SAP at some of the largest organizations in the world.

Leave A Comment

This website uses cookies and third party services. Please review our privacy policy for additional information. Do you consent? Yes