Tip

Convert cases in CLP

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        &ReqUpper  *char   22
             dcl        &ReqLower  *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        &Reserved  *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     &ReqUpper      (&CCSIDReq       || +
                                        &CCSIDInp       || +
                                        &Uppercase      || +
                                        &Reserved)
             chgvar     &ReqLower      (&CCSIDReq       || +
                                        &CCSIDInp       || +
                                        &Lowercase      || +
                                        &Reserved)
             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)  &len
                 Call       Pgm(QLGCNVCS)                  +
                              parm(&Reqlower               +
                                   &input                  +
                                   &output                 +
                                   &Datalen                +
                                   &ErrCde  )
                 chgvar     %sst(&CvtText &Posl &len)      &Output
               enddo
               chgvar     &upper            '1'
               chgvar     &Pos              (&Pos + 1)
             enddo
          /*----------------------------------------------*/
          /*  Convert to Upper                            */
          /*----------------------------------------------*/
             if         (%sst(&CvtText &Pos 1) *ne ' ')    do
             if         &upper                             do
               chgvar     &input            %sst(&CvtText &Pos 1)
               chgvar     &output           ' '
               chgvar     %bin(&Datalen)    1
               Call       Pgm(QLGCNVCS)                    +
                            parm(&ReqUpper                 +
                                 &input                    +
                                 &output                   +
                                 &Datalen                  +
                                 &ErrCde  )
               chgvar     %sst(&CvtText &Pos 1)  %sst(&Output  1 1)
               chgvar     &Pos              (&Pos + 1)
               chgvar     &Posl             &Pos
               chgvar     &upper            '0'
               chgvar     &len              0
             enddo
             else       do
               chgvar     &len              (&len + 1)
               chgvar     %sst(&input &len 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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

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
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.