You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Need to trap CR/LF characters on input to AE pgm from db staging table

3 replies [Last post]
Larry's picture
User offline. Last seen 2 years 31 weeks ago. Offline
Joined: 03/18/2008
Posts: 19

Hi all!

I have an AE that is getting input from a database staging table which is populated from an external system. One of the fields is a Char(400) text field which will potentially have CR/LF characters in it. These are causing significant errors, as the AE pgm which processes the data sees the CR/LF and assumes a new record of data has been encountered.

So I find that I need to trap the CR/LF characters and handle them somehow (temporary translation?) to prevent these issues.

I'm stuck on how to isolate the CR/LF characters in the field in question. There may be multiple occurrences of the CR/LF in the field. I reviewed the CHAR(), CODE(), and STRING() Peoplecode functions but either I'm missing something or they won't do the trick.

Anyone dealt with this previously? Any ideas?

Regards,

Larry

Lepa's picture
User offline. Last seen 1 year 32 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Need to trap CR/LF characters on input to AE pgm from db ...

Larry, I've used a function that was created by PeopleSoft at one point to clean some strings. See function below. I think char(13) is ascii for CR so something like the code below might work!

I know i have something else that I have done but can't find it at the moment. Let me know if the below helps!

Declare Function string_scrubber PeopleCode FUNCLIB_LCINTFC.NUM_CHECK FieldFormula;

&CHAR_SET = char(13);
&cleanString = string_scrubber(&StringValue, &CHAR_SET);

Function string_scrubber(&STRING, &CHAR_SET) Returns string
&LENGTH = Len(&STRING);
For &X = 1 To (&LENGTH)
&CHAR = Substring(&STRING, &X, 1);
&TEST = Find(&CHAR, &CHAR_SET);
If &TEST = 0 Then
&RESULT_STRING = &RESULT_STRING | &CHAR;
End-If;
End-For;
Return &RESULT_STRING;
End-Function;

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Lepa's picture
User offline. Last seen 1 year 32 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Need to trap CR/LF characters on input to AE pgm from db ...

Larry i think i found what you are looing for.

take a look at the delivered PS function ContainsOnlyCharType in Peoplebooks. I've created a method that uses that function and basically loop through the text and remove none Alphanumeric (7-bit ASCII codes; A-Z, a-z, 1-9, punctuation) characters from the string.

Here is my code below:

/***************************
*  class BadChar
*     Remove none Alphanumeric (7-bit ASCII codes; A-Z, a-z, 1-9, punctuation) characters from a string
* @author Maher Ardat
* @version 1.0
* @created 03/01/2010
**************************************/


class BadChar
   method RemoveBadChar(&text As string, &replaceValue As string) Returns string;
   
end-class;

method RemoveBadChar
   /+ &text as String, +/
   /+ &replaceValue as String +/
   /+ Returns String +/
   
   Local string &charValue, &takeValue, &cleantext;
   Local number &i, &goodChar, &badChar;
   
   /* checking if the passed string has any none Alphanumeric (7-bit ASCII codes; A-Z, a-z, 1-9, punctuation)*/
   &badChar = ContainsOnlyCharType(&text, 0);
   If &badChar <> 1 Then
      MessageBox(0, "Invalid Character Being Saved", 20090, 100, "message not found", &text);
     
      /*unwanted character exists. Loop through the string, find it and remove it*/
      For &i = 1 To Len(&text)
         &charValue = Substring(&text, &i, 1);
         &goodChar = ContainsOnlyCharType(&charValue, 0);
         If &goodChar = 1 Then
            &takeValue = Substring(&text, &i, 1);
            &cleantext = &cleantext | &takeValue;
         Else
            &cleantext = &cleantext | &replaceValue;
         End-If;
      End-For;
      Return &cleantext;
   Else
      /*no bad characters in string*/
      Return &text;
     
   End-If;
end-method;

n/a
Ashar's picture
User offline. Last seen 4 years 13 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Need to trap CR/LF characters on input to AE pgm from db ...

How about the function Clean(&string);