Get started Bring yourself up to speed with our introductory content.

Using SQL on System i to create multicolored comment lines

When using SQL to color source code on the AS/400, it is also possible to create multicolored comment lines. This System i tip provides the queries to do so.

In addition to what I wrote about in my tip, Using SQL on System i to color source code and inline comments, it is also possible to have multicolored lines for comments using SQL, like the one shown below:

The key to this is inserting hexadecimal codes in the byte prior to the text.

For instance, if you want to highlight some part of the text for source program PGM1 in source file QRPGSRC in library LIB1, use the following queries:


Now taking the example of the above text, get the position of the text, * on the left is in position 7, M (of MODIFICATION) is in Position 11, D (of DESCRIPTION) is in position 41 and * on the right is in position 70.

If we insert hexadecimal codes into the bytes before the text, we can get multicolored lines.

Position of insertions:
For * Insert White (X'22') in position 6
For M insert Blue (X'3A') in position 10
For D insert Red (X'28') in position 40
For * on right insert White (X'22') in position 69 The query should be built like this:

||X'22'||SUBSTR(SRCDTA,70,30) WHERE SRCSEQ = 25 

After the query, the line will appear as below:

Although the query looks quite complex, it's simple once you understand that the first parameter in SUBST should be position of character and the second parameter should be the difference between the next position of insertion and the position of the character.

The query shown in the example is done on a source file with a length of 112 (100 bytes for SRCDTA). If your source file length is different, change your query accordingly.

Use this query only if your alias is not created in QTEMP. Otherwise it is optional.


Please note:

  1. Although the example shown above might not appear very useful, it may be worth a try if you want to highlight something important, such as compilation instructions, during code documentation.
  2. Always perform a backup before running the queries in case the query is not built correctly.
  3. For users using Client Access emulators, there is an easy option available from the keyboard map for multicolored comment lines that you can use without running the queries.

We encourage readers to submit a tip on use of the AS/400 system for potential publication. Just click on "Submit a Tip" below.

Dig Deeper on iSeries SQL commands and statements

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.