trim string values in rpg/400

60 pts.
Tags:
CLP
RPG/400
RPGILE
Strings
how to trim string values in rpg/400 or RPGILE OR CLP

Answer Wiki

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

Use RPG-IV (aka RPG ILE)

shortfield = %TRIM(longfield)

You can also trim only Left or only Right, and you can specifiy what char to trim. The RPG manual (on the IBM website) has examples.

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

RPG/400 (OPM RPG) doesn’t have a “trim” function. It does, however, have a SUBST operation and other op-codes to help in determining the start and end of substrings.

CL doesn’t have a “trim” function. It generally doesn’t need one nor could it make much use of one except when concatenating strings. For that, use the *BCAT or *TCAT constructs. When using replacement data in message texts, the message description will perform automatic trims.

 

Minor addition — ILE CL (and any ILE language) can call the builtin ‘triml’ procedure to find the length of a “trimmed” variable. With the length known, the %SST() function gives an effective trim.

 

pgm

 

 dcl &str  *char 10 value( ‘abc’ )

 dcl &stri *char 11

 dcl &Trim *char  1 value( ‘ ‘ )

 dcl &len  *int     value( 0 )

 dcl &x00  *char  1 value( x’00′ )

 

 chgvar &stri ( &str *cat &x00 )

 

 callprc ‘triml’ ( +

                   &stri +

                   ( &Trim *byval ) +

                 ) +

           rtnval( &len )

 

 dmpclpgm

 return

endpgm

 

Note that a null terminator x’00′ is required. The length is returned as an *INT. Compile as a *MODULE, then use CRTPGM with BNDDIR(QC2LE) to find ‘triml’.

 

RPG IV (ILE RPG) uses the %trim() builtin function and its variants are as noted above.

 

Tom

Discuss This Question: 2  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
  • tahirliaqat1
    Please give me example how we can Trim string start from left or right
    150 pointsBadges:
    report
  • TomLiotta
    Please give me example...   The language reference manual already gives a number of examples. How will it help if we simply copy/paste them here?   Tom
    125,585 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