Author |
Message
|
Kool-Aid |
Posted: Fri May 21, 2004 7:25 am Post subject: STRING Manipulation: Evaluating the leading character. |
|
|
 Novice
Joined: 22 Apr 2004 Posts: 22
|
I am trying to code the following rule:
Example
If leading character of FIELD = "H" then set FIELD ='1', else ='0'
Pretty simple stuff. For some reason it is not giving me the output I expect. My code is as follows:
DECLARE LeadingMatnr CHAR;
SET LeadingMatnr=
TRIM(LEADING FROM "InputBody"."BBC.OC.TEST"."BBCTEST.OC"."Field_2");
IF LeadingMatnr = 'L'
THEN
SET "OutputRoot"."XML"."IDOC"."MTART".(XML.Content) = '1';
ELSE
SET "OutputRoot"."XML"."IDOC"."MTART".(XML.Content) = '0';
END IF;
My input data is: ILOVEYOU. The word LOVE is in field_2 and its leading character is "L".
I would expect MTART to equal 1 instead I am getting zero.
Do you know a better way to code this or so I have something syntactically wrong? |
|
Back to top |
|
 |
JT |
Posted: Fri May 21, 2004 7:58 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
Instead of this
Code: |
SET LeadingMatnr=TRIM(LEADING FROM "InputBody"."BBC.OC.TEST"."BBCTEST.OC"."Field_2"); |
Try this:
Code: |
SET LeadingMatnr=SUBSTRING("InputBody"."BBC.OC.TEST"."BBCTEST.OC"."Field_2" FROM 1 FOR 1); |
|
|
Back to top |
|
 |
Kool-Aid |
Posted: Fri May 21, 2004 8:50 am Post subject: THIS ISSUE HAS BEEN RESOLVED. |
|
|
 Novice
Joined: 22 Apr 2004 Posts: 22
|
Thanks it worked perfect. I am just curious. What is the LEADING used for and when should it be used? |
|
Back to top |
|
 |
JT |
Posted: Fri May 21, 2004 9:02 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
The only time I've used the LEADING parameter was on a TRIM command to remove the leading value that I specified on the TRIM command.. Optionally you can also use the LTRIM & RTRIM commands. |
|
Back to top |
|
 |
kspranava |
Posted: Sun May 23, 2004 6:20 pm Post subject: LEADING |
|
|
 Centurion
Joined: 27 Apr 2003 Posts: 124
|
Hi KoolAid,
What a LEADING specification in TRIM command does is, it will remove the leading singleton from the input field.
As per the code,
SET LeadingMatnr=
TRIM(LEADING FROM "InputBody"."BBC.OC.TEST"."BBCTEST.OC"."Field_2");
LeadingMatnr will be set to LOVE if "Field_2" has "LOVE" and will not contain L as per your requirement. Since, there is no singleton mentioned it takes the default one 'space'. As expected, command removes the leading spaces, if any and sets the rest to the field.
Pranava. |
|
Back to top |
|
 |
|