Sponsored Links
Sponsored Link

sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Zero suppress in CL

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zero suppress in CL

    I want to retrieve the number of records in a file and use that to build a text message. If I use RTVMBRDSC tot get the record count into &RCDCNT and then use CHGVAR to move &RCDCNT to an alpha variable, I get all of the leading zeroes. What is the easiest way to suppress the leading zeroes? I know I can do some looping to remove the leading zeroes but is there an easier way?

  • #2
    I was just re-reading my post and can't edit it ....... retrieving record count with RTVMBRD, not RTVMBRDSC.

    Comment


    • #3
      I just found the following: CHGVARVAR(&MSG)VALUE('Number of records: '*BCAT%CHAR(&RCDCNT))

      Unfortunately, %CHAR is not supported on our system. I assume that it is a 7.2 feature and we are at 7.1.

      Comment


      • #4
        The following works:

        CHGVARVAR(&RCDCNTA)VALUE(&RCDCNT)

        LOOP:IFCOND(%SST(&RCDCNTA11)*EQ'0'*AND%SST(&RCDCNTA21)*NE' ')THEN(DO)

        CHGVARVAR(&RCDCNTA)VALUE(%SST(&RCDCNTA29))

        GOTOCMDLBL(LOOP)

        ENDDO

        CHGVARVAR(&MSG)VALUE('Record count: '*BCAT&RCDCNTA)

        Comment


        • #5
          I believe at 7.1 you have the %TRIML function in CL, so an alternative would be:
          Code:
          CHGVAR     VAR(&RCDCNTA) VALUE(&RCDCNT)
          CHGVAR     VAR(&MSG) VALUE('Record count:' *BCAT %TRIML(&RCDCNTA '0'))

          Comment


          • #6
            If there's a possibility of &RCDCNT being zero, the %TRIML would trim off all the zeros, leaving blank. This version checks in advance for zero.

            Code:
            IF &RCDCNT *eq 0 THEN(CHGVAR VAR(&RCDCNTA) VALUE('0'))
            ELSE DO
               CHGVAR VAR(&RCDCNTA) VALUE(&RCDCNT)
               CHGVAR VAR(&RCDCNTA) VALUE(%TRIML(&RCDCNTA '0'))
            ENDDO
            CHGVAR     VAR(&MSG) VALUE('Record count:' *BCAT &RCDCNTA)

            Comment


            • #7
              Good point about a possible zero value for the record count. Here's a version without that pesky DO and ENDDO (sorry, I couldn't help myself ):
              Code:
              CHGVAR     VAR(&RCDCNTA) VALUE(&RCDCNT)
              CHGVAR     VAR(&RCDCNTA) VALUE(%TRIML(&RCDCNTA '0'))
              IF         COND(&RECCNTA = ' ') THEN(CHGVAR VAR(&RCDCNTA) VALUE('0'))
              CHGVAR     VAR(&MSG) VALUE('Record count:' *BCAT &RCDCNTA)

              Comment

              sponsored links

              Collapse

              Working...
              X