IBM Support

Retrieving the Row/Column of a Field Using the QDFRTVFD API

Troubleshooting


Problem

This document contains an example of how to retrieving the Row/Column of a Field Using the QDFRTVFD API.

Resolving The Problem

The QDFRTVFD API documentation in the AS/400 System API Reference states that the structures in the WHERE USED section of a display file can be used to retrieve the row/column of a field. The following C/400 program illustrates a technique for doing so. The program could be modified to have it accept the library, file, record, and field name from a parameter list.


/*** START OF SPECIFICATION ******************************************/
/* */
/* Source File Name: CDFRTVFD */
/* */
/* Program Name: Retrieve the Row/Col for a selected field in a */
/* display file record format. The column number */
/* reported is the field attribute column, which is */
/* one column to the left of the position defined in */
/* the DDS for the field. */
/* */
/* Function: This program uses the QDFRTVFD API to return the */
/* structure of a display file. It then determines the */
/* Row/Col of a selected field in a record format in the file. */
/* */
/* Output: printf statements, routed to spoolfile. See the */
/* OVRPRTF command in the "main" function. */
/* */
/*** END of SPECIFICATIONS *******************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "QSYSINC/H/QUSEC"
#include "QSYSINC/H/QDFRTVFD"
#define fail() do { printf("\nLine %d FAILED in file %s", \
__LINE__,__FILE__); \
} while(0)

/* Pointers to structures required to be used by this program. */
QDFFBASE_t *BasePtr;
QDFFINFO_t *InfoPtr;
QDFARFTE_t *RftePtr;
QDFFRINF_t *RinfPtr;
QDFFRDPD_t *RdpdPtr;
QDFFRCTB_t *RctbPtr;
QDFWFLEI_t *FleiPtr;
QDFFNTBL_t *NtblPtr;
QDFWRCDI_t *RcdiPtr;
QDFWFLDI_t *FldiPtr;
QDFFRCTE_t *RctePtr;

/* Global variables */

int RecIndex;
/* The following defines an area into which the QDFRTVFD returns */
/* the requested data. Your display file may require a different*/
/* size than this. */
char ReturnVar[5000]; /* The first 8 bytes are: */
/* 4 bytes WDFFRETN Length of the returned data. */
/* 4 bytes WDFFSIZE Size of the display file description */
int ReturnLen;
char Format[8];
char FileName[20];
/* DSPF information */
char MyRec[] = "REC1 "; /* Test name */
char MyField[] = "FLD2A "; /* Test name */

int FindRec (void);
int FindField (void);

main()
{
Qus_EC_t Error_Code = {0};

/* Change standard out to route printf statements to spool file */
system("OVRPRTF FILE(STDOUT) TOFILE(QSYSPRT) \
USRDTA(CDFRTVFD) PRTTXT(*BLANK) MAXRCDS(*NOMAX)");

/* Define the API format requested and the display file to access */
memcpy(Format,"DSPF0100",8);

/* Point to your DSPF */
memcpy(FileName,"DSPFILE3 RWOLIB ",20);
ReturnLen = sizeof(ReturnVar);
/* Invoke the API. */
QDFRTVFD (ReturnVar,
ReturnLen,
Format,
FileName,
&Error_Code);
if ( Error_Code.Bytes_Available != 0 ) {
fail();
printf( "\nExcId: %s" , Error_Code.Exception_Id );
exit (1);
}

FindRec();
printf("\nEnd of test");
}


int FindRec() {
int i;
/* Access returned structures. The base structure starts at */
/* the begining of the returned space. */
BasePtr = (QDFFBASE_t *)ReturnVar;
InfoPtr = (QDFFINFO_t *)((char *) BasePtr + BasePtr->WDFFINOF);
RftePtr = (QDFARFTE_t *)((char *) InfoPtr + InfoPtr->WDFFDFLO);
/* While there are records, look for the requested record name */
/* in the QDFARFTE structure. */
for (i=0; i<BasePtr->WDFFRCS; ++i) {
if (strncmp(RftePtr->WDFARFNM,MyRec,10) == 0) {
RecIndex = i + 1; /* Entry in QDFARFTE table for the requested name*/
/* Access additional structures. */
RinfPtr = (QDFFRINF_t *)((char *) InfoPtr + RftePtr->WDFARFOF);
RdpdPtr = (QDFFRDPD_t *)((char *) RinfPtr + RinfPtr->WDFFRAOF);
/* Find RowColumn table. Note: this is the first row/col table */
/* so this code only works for the PRIMARY DISPLAY SIZE. */
/* See QDFFRDPD.WDFFDRCO field description for finding the */
/* correct QDFFRCTB structure if more than one screen size is */
/* used. */
RctbPtr = (QDFFRCTB_t *)((char *) RinfPtr + RdpdPtr->WDFFDRCO);
FindField(); /* Find the requested field */
return(0); /* Task is done. */
}
else
RftePtr = (QDFARFTE_t *)((char *) RftePtr + sizeof(QDFARFTE_t));
}
/* If this point is reached, there was no match for the requested */
/* record. */
printf("\nThe requested record was not found %s",MyRec);
return(0);
}

int FindField () {
int j;
int k;
int NtblIndex;
char *NamePtr;
int RCIndex;
int RecNumber;
/* Find where used section */
FleiPtr = (QDFWFLEI_t *)((char *) InfoPtr + InfoPtr->WDFFWUOF);
/* Find name table. There is one entry for each unique field */
/* name used in the file. A given name may be used in more than */
/* one record format. */
NtblPtr = (QDFFNTBL_t *)((char *) FleiPtr + FleiPtr->WDFWNTBO);
/* Prepare to search table. Start search after the fixed portion. */
NamePtr = (char *) NtblPtr + sizeof(QDFFNTBL_t);
NtblIndex = 0;
/* Find requested name */
for (j=0; j<NtblPtr->WDFFNMS; ++j) {
if (strncmp(NamePtr,MyField,10) == 0) {
NtblIndex = j + 1;
/* The requested name was found */
/* Get first QDFWRCDI structure. */
RcdiPtr = (QDFWRCDI_t *)((char *) FleiPtr + FleiPtr->WDFWXLEN);
RecNumber = 1;
/* For each record, find the first field structure. Then, find a */
/* match for the field name table index for the requested field. */
/* If found, the field structure containing the matched index */
/* also contains the row/column index. */
for (j=0; j<BasePtr->WDFFRCS; ++j) {
/* Make sure the field matching is for the correct record. */
if (RecNumber == RecIndex) {
FldiPtr = (QDFWFLDI_t *)((char *) RcdiPtr + RcdiPtr->WDFWRLEN);
/* Search for the correct field structure */
for (k=0; k<RinfPtr->WDFFFLD; ++k) {
/* Find the correct structure by finding a match for the */
/* index into the field name table. */
if (NtblIndex == FldiPtr->WDFWNMEI) {
RCIndex = FldiPtr->WDFWRRDX; /* Row/Col index */
/* Point to first Row/Col Entry */
RctePtr = (QDFFRCTE_t *)((char *) RctbPtr + sizeof(QDFFRCTB_t));
/* Point to correct Row/Col Entry. Each entry is 2 bytes. */
RctePtr = (QDFFRCTE_t *)((char *) RctePtr + ((RCIndex - 1) * 2 ));
printf("\n%s %s Row and column (hex) %02x %02x",MyRec,MyField,
*(char *)RctePtr,*((char *)RctePtr+1));
return(0); /* Task is done */
}
else
FldiPtr = (QDFWFLDI_t *)((char *) FldiPtr + FldiPtr->WDFWFLDL);
}
}
else {
/* Bump ptr to next record structure */
RcdiPtr = (QDFWRCDI_t *)((char *) RcdiPtr + RcdiPtr->WDFWNXTR);
RecNumber = RecNumber + 1;
}
}
}
else
NamePtr = NamePtr + 10; /* Size of field name*/
}
/* If this point is reached, the field was not found */
printf("\nThe requested field was not found %s %s",MyRec,MyField);
return (0);
}

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"6.1.0"}]

Historical Number

22543439

Document Information

Modified date:
18 December 2019

UID

nas8N1017486