Commonly Used Mapping User Exits in Sterling Integrator


Commonly used Mapping User Exits in IBM Sterling Integrator. Sample User Exits examples. 


1. User Exits to Convert the decimal value to whole number by padding zero’s with sign(+/-).



The below logic will help you out to convert the decimal value to whole number 
by padding zero’s with sign(+/-).
Input (R6 format)
117.45~
-117.45~
Output(string format)

11745
-11745
Integer Pos;
String[8] Var_Value;
Integer  i,j,k,Rec_Length,pos_neg;
string[100] Input_Record,Padding_Char;        
i=0;
j=0;
k=0;
Rec_Length=0;
pos_neg=0;
Input_Record="";
Padding_Char="";
pos_neg = strstr(#AMOUNT_BILLED,"-");
#AMOUNT_BILLED = Trimleft(#AMOUNT_BILLED,"-");
Pos = strstr(#AMOUNT_BILLED,".");
if len(mid(#AMOUNT_BILLED,Pos+1,2)) > 1 then 
Var_Value = left(#AMOUNT_BILLED,Pos) + mid(#AMOUNT_BILLED,Pos+1,2);
else
Var_Value = left(#AMOUNT_BILLED,Pos) + mid(#AMOUNT_BILLED,Pos+1,1) + "0";
Input_Record = trim(Var_Value);
i = len(Input_Record);
Padding_Char="0";
j = 8 - i;
k=1;
IF i < 10 THEN
 Begin
   While k < j Do
   Begin
    Rec_Length=len(Input_Record);
    concat(Padding_Char,Input_Record,Rec_Length);
    Input_Record=Padding_Char;
    Padding_Char="0";
    k = k + 1;
   End
 End
IF pos_neg != -1 Then
#AMOUNT_BILLED = "-" + Input_Record;
else
#AMOUNT_BILLED = "+" + Input_Record;



2. User Exits to Check whether the given field is numeric or not


To check whether the given field is numeric

  integer a,c,l;                                                                                                                                                                                        
  string [1] b,num_flag1;                                                                                                                                                                               
  String[100] Space;                                                                                                                                                                                    
  Space = "      ";                                                                                                                                                                                     
  a = 0;                                                                                                                                                                                                
  num_flag1 = "Y";                                                                                                                                                                                  
                                                                                                                                                                                                        
  l = len(#ORDER_QTY);                                                                                                                                                                                  
                                                                                                                                                                                                        
  while a < l do                                                                                                                                                                                        
  begin                                                                                                                                                                                                 
    a = a + 1;                                                                                                                                                                                          
    b = mid(#ORDER_QTY,(l-a),1);                                                                                                                                                                        
    c = strstr("0123456789",b);                                                                                                                                                                         
    if c != -1 then                                                                                                                                                                                     
      continue;                                                                                                                                                                                         
    if c = -1 then                                                                                                                                                                                      
    begin                                                                                                                                                                                               
      num_flag1 = "N";                                                                                                                                                                                  
      break;                                                                                                                                                                                            
    end                                                                                                                                                                                                 
  end 

3. User Exist to Storing Multiple values in Variable by using Counters in variable


In Pre - Session:
string[30] L103[999];
real L102[999];

while Z < 999 do                                                                                                                                                                                       
begin 
Z = Z + 1;
L103[Z] = "";
L102[Z] = 0;
end

In 1st Multiple looping record:
Integer X;
X = X + 1;
TotalStops = X;
L103[X] = #L103;
L102[X] = #L102;

In 1st Multiple looping record:

if DFUT32 = "Y" & #L901 = "MI" then
begin
$Temp_L1[D4B_CNT].#Temp_L103 = #L901;
$Temp_L1[D4B_CNT].#Temp_L102 = #L902;
end
else 
begin
While C < TotalStops do
Begin
C = C+1;
$Temp_L1[D4B_CNT].#Temp_L103 = L103[C];
$Temp_L1[D4B_CNT].#Temp_L102 = L102[C];
end
end

4. User Exists to How to use Code list in the map


These are the field names that are available when using the select extended rule 
on Trading Partner Code Lists: 

DESCRIPTION
NAME (this is the "list name" of the codelist)
RECEIVERCODE
SENDERCODE
TEXT1
TEXT2
TEXT3
TEXT4

Syntax:

select fieldname into receiverlist from tablename where key = 
expression [and key = expression]; 

Example:
      select Text1 into $ORDERS.#TEMP_NAD02_SNDPRN from CODELIST 
where sendercode = #3039 and name = "DIAG_DKORDS";

5. User Exists to Formatting - Code when expected output is  "0.48" instead of ".48"


Integer j;

j = strstr(#DMEA03,".");
var_MEA = left(#DMEA03,j);
var_MEA1 = mid(#DMEA03,j,10);

 code when expected output is expecting ".48" instead of "0.48"
 Integer Decimal_Pos,length;

length =Len(#FLD4);

Decimal_Pos = strstr(#FLD4, ".");

If Decimal_Pos > -1 then
Begin
  If aton(#FLD4) < 1 then
    #FLD4 = MID(#FLD4,1,length);
  Else if right(#FLD4,2) = ".0" then
     #FLD4 = LEFT(#FLD4,length-2);
End

6. User Exists to Incrementing the date


     $POSFILE.#TEMP_0373:18 = date("%Y%m%d",Var_DT) << days(4)  ;

7. User Exists to Rounding the value from "1.569" format to "1.57"

object df;
string[50] tmp_val,var,temp,i;
integer var_str; 
real var1;
if exist(#TD1_7:2) & #TD1_7:2 != 0.0 then
begin
  df = new("java.text.DecimalFormat", "0.000"); 
  tmp_val = df.format(#TD1_7:2);
  var_str = strstr(tmp_val,".");
  var = mid(tmp_val,var_str+3,1);
  if aton(var)<4 | aton(var) = 4 then
  temp = mid(tmp_val,0,var_str+3);
  else
  begin
  i = mid(tmp_val,0,var_str+3);
  var1 = aton(i) + 0.01;
  ntoa(var1,temp);
  end
  
#TD1_7:2 = aton(temp);
End

8. User Exists to Logic for adding check digit value


String[256] var,modulus,Temp_check,var1;
Integer l,sum1,sum2,i,j,k,odd,even,odeve,mod;
real mod1;
sum1 = 0;
l = 0;
i = 0;
j = 1;
sum2 = 0;
k = 0;
odd = 0;
even = 0;
odeve = 0;

var = "0010016000" + right(#EXIDV,9);
l = len(var);

while i < l do
begin
sum1 = sum1 + Atoi(Mid(var,i,1));
i = i + 2;
end
odd = sum1 * 3;

while j < l do 
begin
sum2 = sum2 + atoi(mid(var,j,1));
j = j + 2;
end
even = sum2;
odeve = odd + even;
mod1 = odeve *.10;
ntoa(mod1,modulus);
k = strstr(modulus,".");
mod = 10 - atoi(mid(modulus,k+1,len(modulus)));
ntoa(mod,var1);
Temp_check = var + var1;

$TEMP_MAN[lx_ctr][man_ctr].#TEMP_EXIDV_MAN02_FIELD = Temp_check;


The output will be:

   MAN*GM*00100160008501433615

Here 5 is the check digit value.


Please see the following link for the SSCC-18 check digit calculator, the first two zeroes 
would not be included so if the Pallet was 00
10016000850143361 you would only use the following 17 digits
10016000850143361 and it would calculate to 10016000850143361 5 
so the 20 Digit SSCC-18 would be 00100160008501433615.

http://www.gs1.org/barcodes/support/check_digit_calculator#sscc


9. User Exists to Populate the characters between "/" and "-":



integer temp_a1,temp_a2;

temp_a1 = strstr(#TRAID, "/");
temp_a2 = strstr(#TRAID, "-");


if (temp_a1 > -1) then
begin
    if (temp_a2 > -1) then
    begin

     $ZDELVRY5.#TEMP_TRAID_W2707_FIELD = mid(#TRAID, temp_a2 + 1, 7);
     $ZDELVRY5.#TEMP_TRAID_W2706_FIELD  = mid(#TRAID, temp_a1 + 1, temp_a2 - temp_a1 - 1);
    end
    else
    begin
        $ZDELVRY5.#TEMP_TRAID_W2707_FIELD  = mid(#TRAID, temp_a1 + 1, 7);
        $ZDELVRY5.#TEMP_TRAID_W2706_FIELD = "NA";
    end
end
else
begin
    $ZDELVRY5.#TEMP_TRAID_W2707_FIELD = left(#TRAID, 7);
    $ZDELVRY5.#TEMP_TRAID_W2706_FIELD  = "NA";
end

The output will be:

Example:           93367/SNLU-330720
Equipment Number:   330720
Equipment Initial:  SNLU

 Example:           1125/53979
 Equipment Number:   53979
 Equipment Initial:  NA

  Example:           5636064
 Equipment Number:   5636064
 Equipment Initial:  NA

10. User Exists to Addition of Syntax Tokens


To add range 0x01-0xFF to Syntax Tokens.

Syntax Tokens : Go to Edit > Syntax Tokens

Syntax Tokens


11. User Exists to Addition of Syntax Tokens


To add range 0x01-0xFF to Syntax Tokens.

Syntax Tokens : Go to Edit > Syntax Tokens



12. User Exits to Converting the lower case to uppercase and vice versa Using Java 


object upper_ob;
upper_ob = new("java.lang.String",#EXDT0);
#EXDT0= upper_ob.toUpperCase();


object lower_ob;
upper_ob = new("java.lang.String",#EXDT0);
#EXDT0= lower_ob.toLowerCase();

13. User Exists to Removal of "/" or any special in a string


object rem_ob;
rem_ob = new("java.lang.String",#Name);
#Name = rem_ob.replaceAll("\/","");

For any spl characters “\splchar”

14.User Exits to Convert to R2 format rule using Java


object R2;
R2 = new("java.text.DecimalFormat", "0.00");
#MENGE:5 = R6.format($8000_PO1.#0330);

15. User Exits to Populate the current system date and time Using Java


        object TMP_DATEFORMAT;
        object TMP_CURRENTDATE;
        object TMP_TIMEFORMAT;
        object TMP_CURRENTTIME;
        string[8] SYS_DATE;  
        string[6] SYS_TIME;
       
       TMP_DATEFORMAT = new("java.text.SimpleDateFormat","yyyyMMdd");
       TMP_TIMEFORMAT = new("java.text.SimpleDateFormat","HHmmss");
       TMP_CURRENTDATE = new("java.util.Date");                    
       TMP_CURRENTTIME = new("java.util.Date");                    
       SYS_DATE = TMP_DATEFORMAT.format(TMP_CURRENTDATE );          
       SYS_TIME = TMP_TIMEFORMAT.format(TMP_CURRENTTIME );

16. User Exits to convert From R2 and R6 format using Java



    real temp_HL_VL1;
     string [20] temp_HL_VL2;
        temp_HL_VL1= accum;
      ntoa(temp_HL_VL1,temp_HL_VL2);
     #0628:17 =temp_HL_VL2;
     R2 = new("java.text.DecimalFormat", "0.00");
     R6 = new("java.text.DecimalFormat", "0.000000");

     //for fields using R2 format
    object R2;
    R2 = new("java.text.DecimalFormat", "0.00");
    #MENGE:5 = R2.format($8000_PO1.#0330);

    //for fields using R5 format
     object R6;
     #MENGE:5 = R6.format($8000_PO1.#0330);

17. User Exists to for adding trailing zeroes with Java code 


Object  Ob;
Ob = new(“java.text.DecimalFormat”,”.000”);
 #ANY_STRING_FIELD = Ob.format (#ANY_REAL_FIELD);

EX: we have 1234 and we have to get 1234.00


18. Simple Java code to convert the formats of Real Field in the input layout


If we want to convert a element in R4(1.0000) format but the validation of the element
in the input layout is in R6(1.000000) format
then

In presession rule(Declare and initilize):
object R4;
R4 = new("java.text.DecimalFormat", "0.0000");

Create a temp field:
#Temp_POC05 = R4.format(#0212);

Hence the output will be 1.0000

In this way the format of any Real fields can be converted only in the input layout.
Note:
This will work only when the Output field is in String Format.

19. User Exists to give Filename Logic


// Set the FileName for the BP to use
string[20] ProcessID, stringDate, stringTime;
string[200] FileName;

ProcessID ="";
FileName = "";

STRDATE(#Temp_SysDate, "%Y%m%d", stringDate);
STRDATE(#Temp_SysTime, "%H%M%S", stringTime);

select xpathresult into ProcessID from processdata where Xpath="ProcessID";

//FileName = <ST01 Doc Type> + "_" + <GS02 Sender> + "_" + <GS03 Receiver> +  "_" +
//<DateTime YYYYMMDDHHMMSS> + "_" + <ProcessID> + <GS06 Control Number> + ".txt";

FileName = #0143:2 + "_" + #G142 + "_" + #G124 +  "_" + stringDate + stringTime + "_" +
                  ProcessID + #0028:2 + ".txt";

update processdata set xpathresult = FileName where xpath="TranslationOutput/FileName";  

20. User Exits to Getting Time using Java code


String[4] var_time;
object ob_time , ob_date;
string[10]  temp_time;

var_time = "";

 
ob_date = new ("java.util.Date");
ob_time = new("java.text.SimpleDateFormat", "hhmm");
temp_time = ob_time.format(ob_date);

if #QUALF:4 = "006" then                                                                                                                                                                            
Begin                                                                                                                                                                                                
  $DELVRY03.#SHIP_DATE:2 = date("%Y%m%d",#IEDD);
  $DELVRY03.#SHIP_TIME = date("%H%M",left(#NTANZ,4));



strdate($DELVRY03.#SHIP_TIME, "%H%M", var_time);
 
  If  var_time = "0000" | var_time = ""  then
    Begin
      $DELVRY03.#SHIP_TIME = date("%H%M", temp_time);
    End
End                      

21. User Exists to Setting up Business Reference


All app to app maps need to contain the following updates to process data.

App to App Maps (That don’t go through any Envelop Processing)
Field                                                          XPATH
Sender ID                                                   TranslationOutput/SenderID
Receiver ID                                                 TranslationOutput/ReceiverID
Doc Type                                                    TranslationOutput/DocumentType
Unique Identifier      (Invoice #, PO # etc.) TranslationOutput/BusinessReference


So in the case of this request you can use the following extended rule for the SenderID,
ReceiverID and DocType.  The Business Reference will need to be pulled from the data.

UPDATE PROCESSDATA SET XPATHRESULT= "CPTOOLS"
WHERE XPATH="/TranslationOutput/SenderID";

UPDATE PROCESSDATA SET XPATHRESULT= "SIEMENSAG"
WHERE XPATH="/TranslationOutput/ReceiverID";

UPDATE PROCESSDATA SET XPATHRESULT= "ORDERS"
WHERE XPATH="/TranslationOutput/DocumentType";


We can also set the business reference as part of the standard rule.

22. Rule to remove dash or any special character



//Rule to remove dash

STRING[35] LT,RT;
INTEGER LENGTH,DASH_POS,REMAIN;

LT=””;
RT=””;
REMAIN =0;
DASH_POS=0;
LENGTH = 0;

LENGTH = LEN(#0116:6);
DASH_POS = STRSTR(#0116:6,"-");
REMAIN = LENGTH - DASH_POS;

LT = LEFT(#0116:6,DASH_POS);
RT = RIGHT(#0116:6,REMAIN - 1);

#0116:6 = LT + RT;


23. User Exists to How to calculate the difference between 2 dates


//********************************************************************************************************************
//Shipment->ExpectedDeliveryDate minus Shipment->ActualShipmentDate –
//Calculating the value for TD511 - Transit time
//********************************************************************************************************************

// Extended rule to calculate the number of days
// between two date fields
//
// sd1, sd2, sy1, sy2: string variables for the
// days and years of the 2 date fields
//
// id1, id2, iy1, iy2: integer variables for the
// days and years of the 2 date fields
//
// testdate: date variable to test for leap year
// stestdate: string variable for test date
// itestdate: interchange variable for test date
//
// total: total number of days

strdate($Temp_ExpectedDeliveryDate:2.#Temp_ExpectedDeliveryDate:2,"%j",sd1);
//calculate the day variables
strdate($Temp_ActualShipmentDate:2.#Temp_ActualShipmentDate:2,"%j",sd2);
//with the julian day value

strdate($Temp_ExpectedDeliveryDate:2.#Temp_ExpectedDeliveryDate:2,"%Y",sy1);
//calculate the year variables
strdate($Temp_ActualShipmentDate:2.#Temp_ActualShipmentDate:2,"%Y",sy2);//with 4 digit year

id1 = atoi(sd1); //convert the string variables
id2 = atoi(sd2); //to the integer variables
iy1 = atoi(sy1); //to allow for comparison and
iy2 = atoi(sy2); //subtraction

if $Temp_ExpectedDeliveryDate:2.#Temp_ExpectedDeliveryDate:2 >=
$Temp_ActualShipmentDate:2.#Temp_ActualShipmentDate:2 then //checks to see which
begin //which date is later
total = id1 - id2; //to subtract properly
stestdate = "1231" + sy2;
end
else
begin
total = id2 - id1;
stestdate = "1231" + sy1;//sets the test date to
end //Dec 31 of the year
//being subtracted


If total < 0 then //if the second date is in the
begin //previous year, add 365
total = total + 365;

testdate = date("%m%d%Y",stestdate);//checks the test
strdate(testdate,"%j",stestdate); //date to see if
itestdate= atoi(stestdate); //the day is 366, meaning
if itestdate = 366 then //it is a leap year, and adds
total = total + 1; //1 day accordingly
end


$Temp_Transit_Time.#Temp_Transit_Time  = total;

24. User Exists to Logic to populate the first day of the week from a year and a week


STRING[56] Bdate,Sdateofyear,var_weeks,totaldays,Juldate;
integer var_weeki,Sdayofyear,var_week_int,total_daysint;
datetime mondayofweek;

object dateformat,ID;

dateformat = new ("java.text.SimpleDateFormat","yyyyMMdd");

Sdateofyear = left(#2380:3,4) + "0101";
var_weeks = right(#2380:3,2);
var_weeki = atoi(var_weeks);
var_week_int = var_weeki * 7;

dateformat = new ("java.text.SimpleDateFormat","yyyyMMdd");
ID = dateformat.parse(Sdateofyear);
Sdayofyear = ID.getDay();

if Sdayofyear = 0 then
total_daysint = var_week_int - 5;
else
if Sdayofyear = 1 then
total_daysint = var_week_int - 6;
else
if Sdayofyear = 2 then
total_daysint = var_week_int - 7;
else
if Sdayofyear = 3 then
total_daysint = var_week_int - 8;
else
if Sdayofyear = 4 then
total_daysint = var_week_int - 9;
else
if Sdayofyear = 5 then
total_daysint = var_week_int - 3;
else
if Sdayofyear = 6 then
total_daysint = var_week_int - 4;

ntoa(total_daysint,totaldays);
Juldate = mid(#2380:3,2,2) + totaldays;
mondayofweek = date("%y%j",Juldate);
strdate(mondayofweek,"%Y%m%d",Bdate);

#DAILY_DATE = Bdate;