on 05-25-2016 9:11 AM
Hi Experts,
I need to generate a Unique Alphanumeric uppercase 16 digit value for a fieldname in mapping. Which should not be used in present/future files.
Can we achieve using ABAP function modules or we can use UDF's also ?
Please guide...how can we achieve.
Regards,
Shaik
Hi Shaik,
This requirement can be met with UDF. First let me explain the source and target structure
This is really one to one mapping with a UDF shown below.
The task of the UDF is to generate new values for the name of target field "Value".
The field value is copied as is to the target but the field name changes.
public String ChangeTargetNodeName(String val, Container container) throws StreamTransformationException{
String alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String num="0123456789";
String targetFieldName="";
long time;
java.util.Random randomGenerator = new java.util.Random();
int randomInt,pos=0;
for(int i=0;i<16;++i)
{
time=System.currentTimeMillis()%100;
randomInt = randomGenerator.nextInt(100);
if(i%2==0)
{
pos=(int)(time+randomInt);
pos=pos%26;
targetFieldName=targetFieldName+alpha.charAt(pos);
}
else
{
pos=(int)(time+randomInt);
pos=pos%10;
targetFieldName=targetFieldName+num.charAt(pos);
}
}//for
LeafStructureNode node =((LeafStructureNode) container.getParameter("STRUCTURE_NODE"));
node.setQName(targetFieldName);
return val;
}
The other mapping are simple one to one as shown below
Now "Value" field is leaf node where as "Header" is a structure node. The UDF needs change depending on type of node.
How the UDF works?
ans)
To access target field in udf, there is getParameter method of Container with parameter STRUCTURE_NODE that returns access to target field/node to which the UDF is being directly mapped to. The node needs to be type casted to structure/leaf as per the type of target field.
Applicable to fields having child or sub-fields.
Applicable to fields having no child or sub-fields.
Output
---------
Please see the change in field name after mapping
Regards
Anupam
NB- Please kindly if possible close the thread in case you got resolution to your question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shaik,
Plesae use this UDF
constant--------->udf--------->target field
public String ChangeTargetNodeValue(String val, Container container) throws StreamTransformationException{
String alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String num="0123456789";
String targetFieldValue="";
long time;
java.util.Random randomGenerator = new java.util.Random();
int randomInt,pos=0;
for(int i=0;i<16;++i)
{
time=System.currentTimeMillis()%100;
randomInt = randomGenerator.nextInt(100);
if(i%2==0)
{
pos=(int)(time+randomInt);
pos=pos%26;
targetFieldValue=targetFieldValue+alpha.charAt(pos);
}
else
{
pos=(int)(time+randomInt);
pos=pos%10;
targetFieldValue=targetFieldValue+num.charAt(pos);
}
}//for
val= targetFieldValue;
return val;
}
Regards
Anupam
Hi Shaik,
If you can use numeric values, not alphanumeric, the NRO utility can be helpful for you
On another way you can use, as you mentioned, you can do a RFC lookup and to have a Z table with the last alphanumeric field passed.
Regarding Anupam suggestio, i haven't so clear how to solve the unique value between different mappings or simultaneous callings over the scenario.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.