cancel
Showing results for 
Search instead for 
Did you mean: 

STRING FUNCTIONS in SCREEN PERSONAS

m4abrams
Participant
0 Kudos

Hi,

I have a requirement where I need to get the EQUIPMENT Number  from a long string found in SAP. Please view ATTACHMENT.

This is my Input string from Tcode IA02.

Input: Equipment   149054              KOMATSU-PC1250LC-8

I need the Equipment Number 149054 and the Description KOMATSU-PC1250LC-8 separately for my output.

I am not sure if Javascript with string functions will work, since the input has multiple spaces.

Any ideas on how to go about this in PERSONAS???

Thanks

Abraham

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos


Hi Startlet,

As Steve suggested, you can use javascript for this.

Check the below example code and you can combine what you want:

1. Find out the first occurrences of numbers in a string:

   var r = /\d+/;

   var s = "149054 KOMOATEST";

   alert (s.match(r));

2. You want all the numbers in your string

   var r = /\d+/g;

   var s = "635 this is personas 1012";

   var m;

   while ((m = r.exec(s)) != null) {

     alert(m[0]);

    }

3. Remove whitespace from string

   var s = "this is my test        personas";

   alert(s.replace(/ /g,''));

if you want to learn more about regex in js, you might want to check:

JavaScript RegExp Reference

Regards,

Sushant

m4abrams
Participant
0 Kudos

Hi Sushant,

This is my code in the script button:

STEP1: COPY_VALUE from textbox and assign to "input".

STEP2: Calculate in JavaScript:

var r = /\d+/;

var args.output = input.match(r);

STEP3: PASTE_VALUE "output" to textbox I am getting an error in STEP2. Could you help me out here ?

0 Kudos

STEP1: COPY_VALUE from textbox and assign to "input".

STEP2: Calculate in JavaScript:

var r = /\d+/;

args.output = args.input.match(r);

STEP3: PASTE_VALUE "output"

Try now?

m4abrams
Participant
0 Kudos

Hi Sushant,

I tried as you said in PERSONAS. Now the Javascript error has disappeared but my output is "System.Windows.Browser.ScriptObject"

Do you know what would be wrong here.

Thanks

Abraham

FYI: The javascript code#1 works perfectly to fetch the Equip# from the string. I tested it on one of the online test environments and it works perfectly.

0 Kudos

var r = new RegExp('\\d+');

args.output = parseInt(args.input.match(r));

or

args.output = args.input.match(r).toString();



Should work!!

m4abrams
Participant
0 Kudos

Works perfectly.!

Thanks Sushant

Answers (1)

Answers (1)

Former Member
0 Kudos

You will need to use a JavaScript action for this. How you parse it in JS will depend on the structure, but you can certainly do it with JS string functions. You will probably want to use indexOf and lastIndexOf string methods to pick the string apart.

Steve.