cancel
Showing results for 
Search instead for 
Did you mean: 

Unique Alphanumeric Value for a fieldname

former_member650236
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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.

  • StructureNode node = ((StructureNode) container.getParameter("STRUCTURE_NODE"));

          Applicable to fields having child or sub-fields.

  • LeafStructureNode node = ((LeafStructureNode)container.getParameter("STRUCTURE_NODE"));

          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.

former_member650236
Participant
0 Kudos

Hi Anupam,

Thanks for the reply. Actually am not getting any source field for the target field. I have to use constant and pass the value in the file.

Can I use this UDF ?

Ex:   constant ---> UDF---->Uniquevalue

Regards,

Shaik

anupam_ghosh2
Active Contributor
0 Kudos

sure you can instead of "value" field to the UDF pass a constant.

Regards

Anupam

former_member650236
Participant
0 Kudos

Hi Anupam,

As you said I mapped the UDF to the fields but the value is not generating at target header file.

I need the value at target side.Pls can you help how to achieve.

Regards,

Shaik

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shaik,

                What is the scenario? Please provide screen shots for error you are getting.

Regards

Anupam

former_member650236
Participant
0 Kudos

Hi,

My scenario is file to file

Header

  Uniquenumber -->  Target number (I want to generate the unique number in target side).But whenever I map it is changing it the field name.

but I need to populate it to target side. pls help in achieving the value at target level.

Regards,

Shaik

anupam_ghosh2
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

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.