AS400 %trim

335 pts.
Tags:
AS/400
AS/400 database
AS400 Data Definitions
Hi I have a question,i wanted to right trim the field to remove the spaces. but when iam doing it ,iam unable to do it. i did like this eval fld1 = %trimr(fld1). so please suggest whether this is correct or not?      #TBLDGH       KLIST                                                                      KFLD                    DGHCOD                          *   *LOVAL         SETLL     TBLDGH                                                           READ      TBLDGH                                                           DOW       NOT %EOF(TBLDGH)                                                 EVAL      DGHCOD   = DGHCOD                                  #TBLDGH       CHAIN     TBLDGHB                            93                            IF        *IN93 = *ON                                                      EXSR      WRITE                                                            ELSE                                                    * N93              EXSR      UPDMOD                                                           ENDIF                                                                      READ      TBLDGH                                                           ENDDO                                                                      SETON                                        LR         *************************************************     WRITE         BEGSR                                          93              EVAL      DGHCOD   = DGHCOD                    93              EVAL      DGHDSC   = %TRIMR(DGHDSC)             93              write       rTBLDGHb                                             Endsr      please check and let me know,wat else i can do in the coding?                                 

Answer Wiki

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

What it looks like you want to do is not possible.
You source and target field names are the same.
So if you start with ‘ABC ‘ you will end with ‘ABC ‘
Something has to go in the last 3 spaces.
%TRIIM is used you you are putting two fileds together.
Something like this:
Work6 = %trimr(DGHCOD) + anotherfield

Also you should start using free form
If you insist on fixed form, get rid of the indicator 93 in your subroutine. You already have code that says you cannont execute the code unless *IN93 is on.

Discuss This Question: 12  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
  • philpl1jb
    RTRIM takes off spaces from the right but the eval statement loads data from the left. So if the value was 'ABCssssss' The RTRIM of it would be 'ABC' And eval myfield = %RTRIM(myField) would still contain 'ABC' You want myfield to contain 'ssssssABC' Perhaps eval myfield = %subst(' ':1: %len(myfield) - %len(trim(myfield) + %trim(myfield) This frontloads the number of blank spaces needed to right justify the the field. Phil
    50,860 pointsBadges:
    report
  • philpl1jb
    One of those senior moments..%TRIMR not %RTRIM Phil
    50,860 pointsBadges:
    report
  • TomLiotta
    93 EVAL DGHDSC = %TRIMR(DGHDSC) In order to understand the purpose of that statement, we need to know the definition of DGHDSC. Please show the definition. Also, please describe what you intend to do with the value. A useful answer needs an objective. Tom
    125,585 pointsBadges:
    report
  • iiiiiiiiiiiii
    Hi Everyone thanks for answer. But still unable to do the requirement Actually my DGHCOD is dept code which is length of 3,0 and DGHDSC is dept decription which is 30 length. Actually the data lokks like this. Dept Group Code Description 100 Hard Goods 200 Home Furnishings 300 Apparel 400 Underwear & Accessories 500 Jewelry 600 Supermarket, Pharmacy & HABA 650 Food 660 Non-Food & HABA 670 Staple Food 690 Pharmacy 700 Food Outlets actually when iam exporting the file to excel iam getting extra spaces in the last field.So thats y i wanted to trim the field.So please help me out. Thanks
    335 pointsBadges:
    report
  • CharlieBrowne
    What exactly do you want the final output to look like?
    41,380 pointsBadges:
    report
  • iiiiiiiiiiiii
    the field should not contain the spaces on right side
    335 pointsBadges:
    report
  • BigKat
    how are you exporting to EXCEL? flat-file? csv? ODBC query?
    8,350 pointsBadges:
    report
  • brettharris
    I think the key to your problem is in how you extract the data. The %TRIM command won't help what it sounds like you are trying to do.
    40 pointsBadges:
    report
  • CharlieBrowne
    If a field in a DB on the AS400 is 20 characters long and you put in a value in the 1st 10 positions, by defalt the last 10 will have blanks. Something has to go there. :-) I think BIGKAT's question is the one you need to answer. What are you doing with the data after you build this file?
    41,380 pointsBadges:
    report
  • philpl1jb
    exporting to excel iam getting extra spaces in the last field .. change the field to VARCHAR or use the TRIM function in Excel Phil
    50,860 pointsBadges:
    report
  • TomLiotta
    DGHDSC is dept decription which is 30 length. If it is fixed-length at 30 characters, it will always be 30 characters wide. If you need it to be shorter after removing blanks, then it needs to be defined as variable-length. There must always be something in the bytes on the right-hand side of the field. That's how a fixed-length field works. If you don't want blanks there, then what characters should you put in their place? That's a short description of the source of your problem. The appropriate fix for your problem will be some variation of comments already given. If you created the output file, you might need to recreate it with a variable-length DGHDSC. Or you might want to change how you export that file, as BigKat is working towards in his comment. Tom
    125,585 pointsBadges:
    report
  • iiiiiiiiiiiii
    [...] 3. CharlieBrowne, Philpl1jb, TomLiotta, BigKat, and Brettharris give pointers on AS/400 trim. [...]
    0 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