Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

iSeries / AS400 FAQ : Programming : RPG : How can I locate a fields value by the fields name?

0
10 Posted

iSeries / AS400 FAQ : Programming : RPG : How can I locate a fields value by the fields name?

0

You can’t do this in general in RPG (or any compiled language), but if the field is in an externally-described file, you can define an externally-described data structure for the file to get the fields in the same layout in the program as they are in the file. Then you can call the QUSLFLD API to find where that field is in the data structure. You can also use this technique to do generic processing on files. For example, if you want to check several files to ensure that all zoned fields have valid data, you could use the program below. It uses a program described file, and calls QUSLFLD to find out the location and length of all the zoned fields in the file. Then it reads the file and checks the zoned fields in every record. If you wanted to find a particular field or set of fields by name, rather than looking for type = ‘S’ as this program does, you’d look for the name you were interested in (subfield fieldName).

0

You can’t do this in general in RPG (or any compiled language), but if the field is in an externally-described file, you can define an externally-described data structure for the file to get the fields in the same layout in the program as they are in the file. Then you can call the QUSLFLD API to find where that field is in the data structure. You can also use this technique to do generic processing on files. For example, if you want to check several files to ensure that all zoned fields have valid data, you could use the program below. It uses a program described file, and calls QUSLFLD to find out the location and length of all the zoned fields in the file. Then it reads the file and checks the zoned fields in every record. If you wanted to find a particular field or set of fields by name, rather than looking for type = ‘S’ as this program does, you’d look for the name you were interested in (subfield fieldName).

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.