Convert cases in CLP

This is a quick sample CL program that uses QLGCNVCS to convert upper and lower cases.

This is a quick sample CL program that uses QLGCNVCS to convert upper and lower cases, such as names. The program accepts text like "ALEX NUBLA" and returns it with "Alex Nubla".


   

pgm        (&CvtText)     /* Convert this text     */

/*--------------------------------------------------------*/
/*  declaration                                           */
/*--------------------------------------------------------*/
             dcl        &CvtText   *char   80
             dcl        ℜqUpper  *char   22
             dcl        ℜqLower  *char   22
             dcl        &Pos       *dec     3   1
             dcl        &Posl      *dec     3   0
             dcl        &Len       *dec     3   0
             dcl        &upper     *lgl

             dcl        &CCSIDReq  *char    4 x'00000001'
             dcl        &CCSIDInp  *char    4 x'00000000'
             dcl        &Uppercase *char    4 x'00000000'
             dcl        &Lowercase *char    4 x'00000001'
             dcl        ℜserved  *char   10 x'00000000000000000000'

          /*----------------------------------------------*/
          /*  QLGCNVCS - Convert Case QlgConvertCase      */
          /*----------------------------------------------*/
             dcl        &Input     *char   80
             dcl        &Output    *char   80
             dcl        &DataLen   *char    4 x'00000050'
             dcl        &ErrCde    *char    4 x'00000000'

/*--------------------------------------------------------*/
/*  Setup Request Control Block                           */
/*--------------------------------------------------------*/
             chgvar     ℜqUpper      (&CCSIDReq       || +
                                        &CCSIDInp       || +
                                        &Uppercase      || +
                                        ℜserved)
             chgvar     ℜqLower      (&CCSIDReq       || +
                                        &CCSIDInp       || +
                                        &Lowercase      || +
                                        ℜserved)
             chgvar     &upper          '1'

/*--------------------------------------------------------*/
/*  Convert Upper (First letter), then lower case         */
/*--------------------------------------------------------*/
 loop:
             if         (&Pos *ge 80)       goto endloop
          /*----------------------------------------------*/
          /*  Convert to Lower                            */
          /*----------------------------------------------*/
             if         (%sst(&CvtText &Pos 1) = ' ')      do
               if         (*Not &Upper)                    do
                 chgvar     &output         ' '
                 chgvar     %bin(&Datalen)  ≤n
                 Call       Pgm(QLGCNVCS)                  +
                              parm(ℜqlower               +
                                   ∈put                  +
                                   &output                 +
                                   &Datalen                +
                                   &ErrCde  )
                 chgvar     %sst(&CvtText &Posl ≤n)      &Output
               enddo
               chgvar     &upper            '1'
               chgvar     &Pos              (&Pos + 1)
             enddo
          /*----------------------------------------------*/
          /*  Convert to Upper                            */
          /*----------------------------------------------*/
             if         (%sst(&CvtText &Pos 1) *ne ' ')    do
             if         &upper                             do
               chgvar     ∈put            %sst(&CvtText &Pos 1)
               chgvar     &output           ' '
               chgvar     %bin(&Datalen)    1
               Call       Pgm(QLGCNVCS)                    +
                            parm(ℜqUpper                 +
                                 ∈put                    +
                                 &output                   +
                                 &Datalen                  +
                                 &ErrCde  )
               chgvar     %sst(&CvtText &Pos 1)  %sst(&Output  1 1)
               chgvar     &Pos              (&Pos + 1)
               chgvar     &Posl             &Pos
               chgvar     &upper            '0'
               chgvar     ≤n              0
             enddo
             else       do
               chgvar     ≤n              (≤n + 1)
               chgvar     %sst(∈put ≤n 1)    %sst(&CvtText &Pos 1)
               chgvar     &Pos              (&Pos + 1)
             enddo
             enddo

             goto       loop
 endloop:

             EndPgm
  
  

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was first published in March 2003

0 comments

Oldest 

Forgot Password?

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

Your password has been sent to:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close