Summary:
This document provides Custom function capability in SAP BODS, when existing transforms doesn't provide solution for requirement where Input Field with Large data set to be divided into multiple Output Fields with equal length.
Constraint:
1. Input data set would be having single space in between the words.
2. Output data in each field should be of meaningful words & No splitting in-between the words.
Introduction:
In BODS, we don't have any specific Logic or Transform or rules to split words equally into meaningful manner. So as per the requirement, we need to develop a Custom Function to provide possible solution.
Case Study:
Input Field – TEXT varchar (160)
Output Fields – Output1 varchar (40), Output2 varchar (40), Output3 varchar (40), Output4 varchar (40)
Custom Function Logic:
#################### Declaration ####################
$Input = ‘’;
$Input_Len = 0;
$Incr = 1;
$Output1 = '';
$SubStr1 = '';
$SubStr2 = '';
####################### Logic #########################
While ($Incr < $Input_Len)
Begin
$SubStr2 = word_ext ($Input, $Incr,'\' \'');
if ((length($SubStr1)+length($SubStr2))>= 60)
Begin
$Output1 = $SubStr1;
$T_Len = length (rtrim_blanks ($Output1)) +1;
$Text_Output = substr ($Input, $T_Len, Input_Len);
$Output1 = rtrim_blanks (rtrim_blanks ($Output1));
Return $Output1;
Return $Text_Output;
End
Else
Begin
$SubStr1 = $SubStr1||' '||$SubStr2;
$SubStr1 = rtrim_blanks ($SubStr1);
$Output1 = $SubStr1;
$Output1 = ltrim_blanks (rtrim_blanks ($Output1));
End
$Incr = $Incr+1;
End
Return $Output1;
Return $Text_Output;
####################################################
Implementation in SAP BODS:
Step1: Right click on Custom Functions Library in SAP BODS & Click for New & provide Function Name to
Meaningful name. (Example: DS_WordSplit.)
Step2: Copy Paste above Custom Function Code inside the window.
Step3: Declare all the below Parameters & Local Variables.
Return | Int |
$Input | Varchar (8000) |
$Output1 | Varchar (8000) |
$Text_Output | Varchar (8000) |
$Incr | Int |
$Input_Len | Int |
$SubStr1 | Varchar (8000) |
$SubStr2 | Varchar (8000) |
$T_Len | Int |
Step4: Create a BODS Batch Job & create a dataflow.
Step5: Create an Input File or table to extract Input Field value data.
Step6: Call Custom Function DS_WordSplit separately for Output1, Output2, & Output3 Fields to store accordingly.
Step7: Validate & Run the Job to check the results.
Final Analysis:
Input Text is of total 120 characters & its divide into 3 different fields of approx. 40 character length depending on the split mechanism in meaningful words.