Special character in a PF

385 pts.
Tags:
Database
IBM iSeries
iSeries database
PF/LF
Physical File
Hi, Is there any way to know if a file has any carriage return on any of the records? I have a file which is populated bby front end users and sometimes when they copy paste an item it also picks up the carriage return. any way to find out if file is having any of these in iseries

Answer Wiki

Thanks. We'll let you know when a new response is added.

Use Notepad ++’s find and replace! …

=================================================

Since Notepad++ has no relevance to the question, I’m replacing almost all of the previous “Answer”.

The real answer is to stop allowing invalid characters from being accepted at the point of entry. If you would simply validate the input properly, it would never get into the PF in the first place. Failure to validate input can conceivably be grounds for termination under various circumstances.

In RPG, use the %xlate() BIF:<pre>
string = %XLATE( invalid : valid : InputString );</pre>
Create a variable named INVALID (or a name of your choice) that contains all characters that you consider to be invalid. Create another variable named VALID (or whatever) that contains the characters you want in place of each invalid character. If you are scanning a field named InputString, the result will be placed in the field named string.

If a carriage return (x’0D’) is the only character that you’re concerned about, the statement might simply be:<pre>
string = %XLATE( x’0D’ : ‘ ‘ : InputString );</pre>
The carriage returns will be replaced by spaces.

You can do similarly with SQL using the TRANSLATE() function. In COBOL, use INSPECT … REPLACING. In CL, call QDCXLATE. (Any other language can also do that call.).

ILE languages can also call the XLATEB MI builtin function. One advantage for RPG, for example, is that the translation occurs directly in the source variable. This might be the most flexible of the various methods here. It accepts addresses of variables and translates based on a length parameter. Any number of different variables can be handled by the same procedure without any data movement.

Tom

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • LHrabar
    You could also write a quick RPG program to scan the fields fora HEX '0D' (X'0D'). This is a carriage return. You can use the scan opcode, or BIF %scan, to search for this char in your file.
    95 pointsBadges:
    report
  • philpl1jb
    Looks like my original response was wiped out. Yes - RPG or COBOL Can find and remove the characters
    50,385 pointsBadges:
    report
  • Koohiisan
    We had this issue a few times and the invalid characters would blow up our RPG programs. You can hop into an interactive SQL session (STRSQL), and do something like: update [file] set [field with odd char] = trim([field with odd char] There probably is some way in SQL to specify a character code, and using that you could do something like: update [file] set [field with odd char] = replace([field with odd char], [odd char], '') I may be off a bit with the syntax on 'replace', but the principle should be valid nonetheless.
    5,020 pointsBadges:
    report
  • Rockleadme
    Thanks Gents ..help much appreciated. Can anyone put some RPG code which has worked for you.
    385 pointsBadges:
    report
  • philpl1jb
    Sorry, I don't have code .. Here's a rough draft of the routine to remove a bad character Read every record and pass the character string to this routine. RmvBadChar Begsr Position = 1 UpdRcd = *off Do while Position <> 0 Eval Position = %SCAN( badchar1, MyCharField) select when Position > 0 and Position < %length(MyCharField) UpdRcd = *on MyCharField = %subst(MyCharField:1: Position -1 ) + ' ' + %subst(MyCharField:Position +1 ) when Position > 0 UpdRcd = *on MyCharField = %subst(MyCharField:1: Position -1 ) + ' ' ENDSL if UpdRcd = *on Update MyFile endif EndDo EndSr
    50,385 pointsBadges:
    report
  • GreenleeB
    We have had a similar problem, too, and it would be best to replace anything that is less than a blank (hex 40), in general, since these will be invalid characters when sent to a display device. Sample RPG code: I just set-up a simple character field and initialized it with a string but inserted a hex 0D after the last 'C' in 'ASSOC' * Initialize to 'CHANGE MANAGEMENT ASSOC ' D fld_in_q S 100A INZ(x'C3C8C1D5C7C540D4C1D5C1+ D C7C5D4C5D5E340C1E2E2D6+ D C30D404040404040') D ix S 3P 0 * A blank D ablank C x'40' /FREE // Parse through the field replacing anything lower than // a blank with a blank. For ix=1 to %size(fld_In_Q); If %subst(fld_in_q:ix:1)<ablank; %subst(fld_in_q:ix:1)=ablank; EndIf; EndFor; *InLR=*On; /END-FREE Here are the debug displays before and after the change. Note that the oD is now a blank . Before: 00000 C3C8C1D5 C7C540D4 C1D5C1C7 C5D4C5D5 - CHANGE MANAGEMEN 00010 E340C1E2 E2D6C30D 40404040 4040 - T ASSOC. After: 00000 C3C8C1D5 C7C540D4 C1D5C1C7 C5D4C5D5 - CHANGE MANAGEMEN 00010 E340C1E2 E2D6C340 40404040 4040 - T ASSOC
    95 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following