Using a result of a substring for the length value of another substring

I am sure that the person who asked me if this was possible is not the first person to have tried, and was unable to get it to “work”.

They had been presented with a “flat” file where the first two characters denoted the length of the key value. What they need to do was to extract the variable length key into another value they could use.

The file was like this:

DATA
———————————-
10<– 10 –>XXXXXXXXXXXXXXXXXXX…
05<-5->XXXXXXXXXXXXXXXXXXXXXXXX…
20<——- 20 ——->XXXXXXXXX…

It is easy to extract the first two characters from DATA using the following SQL Select statement:

01 SELECT SUBSTR(DATA,1,2) AS “Length”,
02 DATA
03 FROM TESTFILE ;

Which returns:

Read more »

Seeing which index or logical file is being used by a SQL statement

I was asked if it was possible to see which DDS file or SQL index was used by a SQL statement?

Fortunately it is easy to see. But before I show how to do it, let me set up my “test data”.

I have my physical file, TESTFILE, which has no key:

A R TESTFILER
A FLD001 6P 0
A FLD002 10A
A FLD003 L

I built two logical files built over this physical file. TESTFILEL0 has the field FLD001 as its only key:

A R TESTFILER PFILE(TESTFILE)
A K FLD001

And TESTFILEL1, which has the key field FLD003:

Read more »

Verified by MonsterInsights