TechTip: Same Screen, New Colors

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
There are many ways to make iSeries and AS/400 screens look friendlier to users: pull-down menus, menu bars, scroll bars, push buttons, and moving letters/words in display files. You may also add colors to displayed messages or data extracts in SQL.

Colors in CL Programs

Are you bored with reading messages in black and white? Try this code to assign colors to message text:

PGM  PARM(&LIB) 
          DCL &LIB    *CHAR  10
          DCL &R       *CHAR  1 
          DCL &Y       *CHAR  1 
          DCL &W      *CHAR  1 

          CHGVAR &R VALUE(X'28')  /*  Red */ 
          CHGVAR &W VALUE(X'22')  /*White */ 
          CHGVAR &Y VALUE(X'33')  /*Yellow*/ 
  /* Check if library exists           */ 
          IF  COND(&LIB = '   ') THEN(GOTO CMDLBL(EOJ)) 
          CHKOBJ QSYS/&LIB  *LIB 
          MONMSG CPF9801 EXEC(DO) 
          ERR1:    SNDUSRMSG  MSG(&W||'Library' *BCAT &Y||&LIB *BCAT +
                    &R||'does not exist') 
   /* Or display message on Line #24     */
        ERR2:    SNDPGMMSG MSG(&W||'Library' *BCAT &Y||&LIB *BCAT &R|| + 
                          'does not exist')
          ENDDO
 EOJ: ENDPGM 

Colors in SQL Statements

Table ZD: MAKE(10A), MODEL(10A), MLS1(5 0) , MLS2(5 0) is used in the following examples:

MAKE
MODEL
MLS1
MLS2
Toyota
COROLLA
2
8
Nissan
MAXIMA
3
5
Toyota
4RUNNER
2
5
Ford
F150
3
3
Toyota
AVALON
2
2



Now, add colors via hexadecimal values x'22', x'28', x'38', x'20'. (See the CL Reference Manual for a complete list of hexadecimal values for colors.) In order to concatenate a hexadecimal value to a numeric data column, it must first be converted using the CHAR function.

SELECT   x'33'||MAKE MAKE,                                         
  (CASE when make='Nissan' then x'28'||model
              when  make='Toyota' then x'38'||model
              else x'22'||model end) model, x'22'||CHAR(mls1) mls1, x'20'||CHAR(mls2) mls2
 FROM ZD                                                        
 ORDER  BY x'33'||MAKE


You may highlight an entire row for specific selection:

 SELECT
     (CASE when make = 'Nissan'  then 
             x'33'||make else make end) make,

      model, mls1, mls2  FROM ZD                    


Note that columns with added hexadecimal characters are shifted to the right.

Assigning colors is useful to set up visual alerts when exceptions occur. For example: values outside of a specified range, or a JOIN statement that does not return data from a joined table, etc.

--Issak Brender
This email address is being protected from spambots. You need JavaScript enabled to view it.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$