Special character in a PF

385 pts.
IBM iSeries
iSeries database
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.


Discuss This Question: 7  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.
  • 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:
  • philpl1jb
    Looks like my original response was wiped out. Yes - RPG or COBOL Can find and remove the characters
    54,090 pointsBadges:
  • 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,045 pointsBadges:
  • Rockleadme
    Thanks Gents ..help much appreciated. Can anyone put some RPG code which has worked for you.
    385 pointsBadges:
  • 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
    54,090 pointsBadges:
  • 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:
  • ToddN2000
    This is a program we use to replace bad chars when users cut and paste from an outside source into a green screen application.
    HDEBUG OPTION(*SRCSTMT:*NODEBUGIO)                                       
    FCNOTES    UF   E           K DISK                                       
    FQSYSPRT   O    F  132        PRINTER OFLIND(*INOF)                      
    D CNDESCSV        S             50                                       
    D IChar           C                   Const(                             
    D                                     X'000102030405060708090A0B0C0D0E0F+
    D                                       101112131415161718191A1B1C1D1E1F+
    D                                       202122232425262728292A2B2C2D2E2F+
    D                                       303132333435363738393A3B3C3D3E3F+
    D                                       404142434445464748494A4B4C4D4E4F+
    D                                       505152535455565758595A5B5C5D5E5F+
    D                                       606162636465666768696A6B6C6D6E6F+
    D                                       707172737475767778797A7B7C7D7E7F+
    D                                       808182838485868788898A8B8C8D8E8F+
    D                                       909192939495969798999A9B9C9D9E9F+
    D                                       A0A1A2A3A4A5A6A7A8A9AAABACADAEAF+
    D                                       B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF+
    D                                       C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF+
    D                                       D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF+
    D                                       E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF+
    D                                       F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'
    D OChar           C                   Const(                             
    D                                     X'40404040404040404040404040404040+
    D                                       40404040404040404040404040404040+
    D                                       40404040404040404040404040404040+
    D                                       40404040404040404040404040404040+
    D                                       404040404040404040404A4B4C4D4E4F+
    D                                       504040404040404040405A5B5C5D5E5F+
    D                                       606140404040404040406A6B6C6D6E6F+
    D                                       404040404040404040797A7B7C7D7E7F+
    D                                       40818283848586878889404040404040+
    D                                       40919293949596979899404040404040+
    D                                       40A1A2A3A4A5A6A7A8A9404040404040+
    D                                       40404040404040404040404040404040+
    D                                       C0C1C2C3C4C5C6C7C8C9404040404040+
    D                                       D0D1D2D3D4D5D6D7D8D9404040404040+
    D                                       E040E2E3E4E5E6E7E8E9404040404040+       
    D                                       F0F1F2F3F4F5F6F7F8F9404040404040')      
    C     *ENTRY        PLIST                                                       
    C                   PARM                    CUST#             6                 
    C     CUST#         SETLL     CNOTES                                             
    C     CUST#         READE     CNOTES                                             
    C                   DOW       NOT %EOF                                          
    C                   EVAL      CNDESCSV = CNDESC                                 
    C                   EVAL      CNDESC = %xlate(IChar: Ochar: CNDESC)             
    C                   IF        CNDESCSV <> CNDESC                                
    C                   UPDATE    RF$CN                                             
    C                   EXCEPT    DETAIL                                            
    C                   ENDIF                                                       
    C     CUST#         READE     CNOTES                                             
    C                   ENDDO                                                       
    C                   EVAL      *INLR = '1'
    82,620 pointsBadges:

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.

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


Share this item with your network: