on 07-03-2017 7:30 AM
Hi All,
There's a issue and I need help in fixing that.
Scenario :
There's a source column of varchar(8000) length. Now target accepts maximum 132 char in one column. So, if there's a string coming >132 characters in input column, the String Must be broken down in SEQUENCE of 132 character segments and loaded in output columns(which are of varchar(132) size).
For example :
If input came 600 characters long in source Column. Then this input must be sequentially splitted into 5 output columns (132+132+132+132+72). First four columns should contain 132 characters each and Fifth column should contain leftover 72 characters.
Request you all to help me asap. Please help me in building Custom function for this.
Thank you in advance.
Samarth
You cannot solve this in a custom function, because a DS function returns a single value only.
You can solve that by writing Python code in a User_Defined transform.
Or map all output columns individually in a Query transform:
No need for any ifthenelses. If the starting position is higher than the source_column length, the result will be null. If the length of the segment is less than 132, only the existing content is copied.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Firstly, Thanks a lot Dirk for sharing your immense knowledge in solutions.
There's extension to this scenario. Request you to please help.
1. For example input string is of 200 characters. In First segment of 132 characters, if last word is getting cut i.e last word is getting few characters missed, then it must be considered as starting word of next segment. It should not come in first segment then i.e. first segment length will be less than 132 characters in this case. This should be taken care in all output columns.
2. Is there any way in BODS, where we can make this dynamic? I mean no fix output columns. If source string length is 600 characters, then it generates output in 5 columns, if it is 700 characters then 6 columns and so on. I mean otherwise, how to certain the no. of output columns? If I define column mappings for 5 columns today and next time a bigger input comes, then it's a problem. Can we generate the output structure dynamically depending on input?
It's urgent. Your help is deeply appreciable.
See my answer to Any ideas on a Smart Splitter for Text fields for an alternative approach.
Hi Saxena,
I am also having the same requirement. Could you please tell me how did you implement this in BODS?
Regards,
KT
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
8000 char is a too long string and if you try to break down to 132 chars each there will be around 60 columns for you to store data in.
If you are OK with having 60 columns then you can have a check in each column on length and use substring function to populate that.
Column 1 - ifthenelse(length(source_column) > 132, SUBSTR(source_column,1,132), SUBSTR(source_column, 1, length(source_column)) )
Column 2 - ifthenelse(length(source_column) > 132*2, SUBSTR(source_column,132+1,132*2), SUBSTR(source_column, 132+1, length(source_column)) )
Column 3 - ifthenelse(length(source_column) > 132*3, SUBSTR(source_column,132*2 + 1,132*3), SUBSTR(source_column, (132*2)+1, length(source_column)) )
....and so on.
Alternatively you might want to have a look at Pivot Transform for your task.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.