Tuesday, May 13, 2008

Using SQL to color Source Code:

For all those programmers using emulators other than Client Access (and other similar advanced emulators), you can color your source code/inline comments using SQL. The color codes for some are as given below:
Red X'28'
White X'22'
Blue X'3A'
Pink X'38'
Turquoise X'34'
Code:
In SQL/400, create an alias of the source member you want to color in QTEMP. If I want to color source member PGM1 in QRPGSRC my SQL statement would be something like:
Query 1: CREATE ALIAS QTEMP/ALIAS# FOR LIB/QRPGSRC (PGM1)
The alias would enable us to access different members of file using SQL.
Query 2: UPDATE QTEMP/ALIAS# SET SRCDTA = SUBSTR(SRCDTA,1,4)||X'22'||SUBSTR(SRCDTA,6,94) WHERE SUBSTR(SRCDTA,7,1) = '*'
We are updating the source line by including hex color code in sixth byte of the source.
This query would change the color of all comment line to white.
Condition your query as you like based on any field SRCDTA, SRCSEQ, SRCDAT.
Query 3: DROP ALIAS QTEMP/ALIAS#
This drops the alias file created in QTEMP.

1 comment:

kapil said...

Hello,

When I give this query this error comes



‘Token ,1 was not valid. Valid tokens: ) ,. ‘











UPDATE QTEMP/ALIAS# SET SRCDTA =

SUBSTR(SRCDTA,1 , 4 ) || X'22' || SUBSTR(SRCDTA,6,94) WHERE

SUBSTR(SRCDTA,7,1) = '*'







Help me to sort out this