简体   繁体   中英

Converting C prototype to RPG

I am trying to use QsyFindFirstValidationLstEntry in RPG, however despite being sure of the existence of the validation list I am getting error 3025, which according to documentation means "The validation list object was not found." The only thing that I can think of is that there is a problem on how I try to pass the qualified name over.

According to the documentation:

  int QsyFindFirstValidationLstEntry
         (Qsy_Qual_Name_T        *Validation_Lst,
          Qsy_Rtn_Vld_Lst_Ent_T  *First_Entry);

where

Validation_Lst (Input)

A pointer to the qualified object name of the validation list to find the first entry in. The first 10 characters specify the validation list name, and the second 10 characters specify the library.

Here is my attempt at calling it from RPG:

     H option(*srcstmt: *nodebugio)
     H DFTACTGRP(*NO)
      /COPY QSYSINC/QRPGLESRC,QUSEC
      /COPY QSYSINC/QRPGLESRC,QSYVLDL
      
      /free
        DCL-PR FindFstValLstEn INT(10) 
                            EXTPROC('QsyFindFirstValidationLstEntry');
          QualName    pointer const options(*STRING);
          Entry       pointer;
        END-PR;
        
        DCL-PR errno pointer EXTPROC('__errno');
        END-PR;

        DCL-DS FirstEntry LikeDS(QSYRVLE) based(fe_ptr);
        dcl-s fe_ptr pointer;
        DCL-S result INT(10);
        
        dcl-s errno_val INT(10) based(errno_ptr);
        dcl-s errno_ptr pointer;
        //                         "WEBUSRS   WEBLIB    "
        dcl-s vldl varchar(20) inz('USERPRF   QUSRSYS   ');

        result = FindFstValLstEn(vldl:fe_ptr);
        
        if (result<>0);
            errno_ptr = errno;
            dsply errno_val;
        endif;
        
        *InLR=*On;
      /end-free

As I said this gives me error code 3025 even though the validation list QUSRSYS/USRPRF exists and I am able to read it using QSYOLVLE API.

Thing to remember is that by default, RPG passes parameters by reference; aka a pointer...

your prototype should have at the most basic, just a couple of CHAR() params,

dcl-pr QsyFindFirstValidationLstEntry extproc('QsyFindFirstValidationLstEntry');
  list char(20) const;
  entry char(2000);  // doesn't matter how big, just has to be bigger than needed
end-pr;

For ease of use you could (should) break down the parms

dcl-ds validationList_t qualified template;
  name char(10);
  library char(10);
end-ds;  

dcl-ds validationListEntry_t qualified template;
  dcl-ds entryIdInfo;
    length int(10);
    ccsid  uns(10);
    id     char(100);
  end-ds;
  dcl-ds entryEncrDataInfo;
    length int(10);
    ccsid  uns(10);
    data   char(600);
  end-ds;
  dcl-ds entryDataInfo;
    length  int(10);
    ccsid   uns(10);
    data    char(1000);
  end-ds;
  *n char(4);  // reserved
  moreInfoPtr pointer;
end-ds;
    
dcl-pr QsyFindFirstValidationLstEntry extproc('QsyFindFirstValidationLstEntry');
  list likeds(validationList_t) const;
  entry likeds(validationListEntry_t);
end-pr;

dcl-ds vldl likeds(validationList_t);
dcl-ds entry likeds(validationListEntry_t);

vldl.library = 'QUSRSYS';
vldl.name = 'USRPRF';
QsyFindFirstValidationLstEntry(vldl:entry);

Here's a tutorial in the RPG Cafe about converting C prototypes to RPG. https://ibm.biz/Convert_C_Prototypes_To_RPG (The actual URL is https://www.ibm.com/support/pages/node/1117461 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM