Skip to Content
Author's profile photo Former Member

Meaningful word split in SAP BODS using Custom Function


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.)

/wp-content/uploads/2016/04/1_934087.jpg


Step2:    Copy Paste above Custom Function Code inside the window.

/wp-content/uploads/2016/04/2_934106.jpg

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

/wp-content/uploads/2016/04/3_934107.jpg

Step4:    Create a BODS Batch Job & create a dataflow.

/wp-content/uploads/2016/04/4_934108.jpg

Step5:    Create an Input File or table to extract Input Field value data.

/wp-content/uploads/2016/04/5_934109.jpg

Step6:    Call Custom Function DS_WordSplit separately for Output1, Output2, & Output3 Fields to store accordingly.

/wp-content/uploads/2016/04/6_934068.jpg

/wp-content/uploads/2016/04/7_934075.jpg/wp-content/uploads/2016/04/8_934115.jpg

Step7:    Validate & Run the Job to check the results.

/wp-content/uploads/2016/04/9_934116.jpg


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.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ravi Verma
      Ravi Verma

      Thanks for sharing!