Page tree
Skip to end of metadata
Go to start of metadata
Introduction:

In this example, we’ll show you how to pass multiple parameters in the pui.download() API. For this example, we will be making use of the pui.download() API and the PUIDNLEXIT program.


The pui.download() API:

In this example, we will pass a string that contains parameters into the id property of pui.download().

An example of the string that we are passing is below:


"generatePDF:parm1:parm2:parm3:"

In our exit program, we will be looking for “generatePDF” and if it is found, we will extract the parameters and pass them into an external program that will generate a PDF.

*One thing to note about the id property is that you can pass any string or “key” value. In your download exit program, you can look for the string or “key” value and call other programs or create temporary files. 


The PUIDNLEXIT Program:

Below is the PUIDNLEXIT program we set up for this example in its entirety:

      **********************************************************************************************
      *                                                                                            *
      *   Description: Profound UI File Download Exit Program                                      *
      *                                                                                            *
      *                Compile as PUIDNLEXIT in PROFOUNDUI product library using CRTBNDRPG.        *
      *                                                                                            *
      *                Return 1 in 'Allow' parameter to allow the download, any other value will   *
      *                prevent the download                                                        *
      *                                                                                            *
      **********************************************************************************************
 
     D InputData_t     ds                  qualified
     D                                     based(Template)
     D   fileid                     640a   varying
     D   userid                      10a
     D   ipAddr                      15a
     D   inline                       1n
 
     D Main            PR                  ExtPgm('PUIDNLEXIT')
     D   timingFlag                  10i 0 const
     D   inputData                         likeds(InputData_t) const
     D   stmfDir                    640a   varying
     D   stmfName                   256a   varying
     D   attName                    256a   varying
     D   contentType                255a   varying
     D   allow                        5i 0
 
     D Main            PI
     D   timingFlag                  10i 0 const
     D   inputData                         likeds(InputData_t) const
     D   stmfDir                    640a   varying
     D   stmfName                   256a   varying
     D   attName                    256a   varying
     D   contentType                255a   varying
     D   allow                        5i 0
 
     D myFile          DS                  qualified
     D   directory                         like(stmfDir)
     D   fileName                          like(stmfName)
     D   attachName                        like(attName)
 
     d myParms         S             25A   dim(3)
     d fileGenerated   S               N   inz(*off)
     d extracted       S               N   inz(*off)
 
     D generatePDF     PR              N
     D parameters                    25A   dim(3)
     D fileInfo                            likeds(myFile)
 
     D extractParms    PR              N
     D fileId                              like(inputData.fileId) const
     D parmsArray                    25A   dim(3)
 
      /free
       if %subst(inputData.fileId: 1: 11) = 'generatePDF';
         extracted = extractParms(inputData.fileId: myParms);
         if extracted = *on;
           fileGenerated = generatePDF(myParms: myFile);
           if fileGenerated = *on;
             stmfDir = myfile.directory;
             stmfName = myfile.fileName;
             attName = myfile.attachName;
             allow = 1;
           else;
             allow = 0;
           endif;
         else;
           allow = 0;
         endif;
       endif;
 
       *INLR = *on;
       Return;
      /end-free
 
     P extractParms    B
     D extractParms    PI              N
     D fileId                              like(inputData.fileId) const
     D parmsArray                    25A   dim(3)
     D strStartIdx     S              5I 0 inz(0)
     D strEndIdx       S              5I 0
     D i               S              5I 0 inz(1)
     D success         S               N   inz(*off)
 
      /free
         strStartIdx = %scan(':': fileId: 1);
         dou strEndIdx = 0;
           if (strStartIdx = 0) or ((strStartIdx + 1) > %len(fileId));
             strEndIdx = 0;
             iter;
           endif;
           strEndIdx = %scan(':':fileId: strStartIdx + 1);
           if strEndIdx = 0;
             iter;
           endif;
           parmsArray(i) =
            %subst(fileId: strStartIdx + 1: strEndIdx - strStartIdx - 1);
           i += 1;
           strStartIdx = strEndIdx;
           success = *on;
         enddo;
         return success;
      /end-free
 
     P extractParms    E

 

We won’t go into detail about the parameters set in this exit program. You can learn more about the different parameters for the PUIDNLEXIT program in the documentation. It’s also important to note that we did not change any of the parameters in the PUIDNLEXIT program we used for this, we kept them the same as they were in the sample PUIDNLEXIT program that is shipped with Profound UI.

The changes that we made are the following:

  • We added a data structure named myFile. This will be passed to an external program that will provide it with the directory, filename, and attachment name of the PDF that is generated.
  • We added an array called myParams which will contain the extracted parameters from the value passed into the id property of pui.download().
  • We added a procedural interface for a custom external program that will generate a PDF depending on the parameters in the array that is passed.
  • We added a sub procedure that will extract the parameters from the string that is passed using “:” as a delimiter.

In our exit program, we will check if the string that is passed in starts with “generatePDF”, and if it does, we will then try to extract the trailing parameters. If we have successfully extracted the parameters, we will pass the parameters array and the myFile data structure to an external program. The external program will generate a PDF and populate the fields in the data structure with the appropriate directory, file name, and attachment name for the file in the IFS.

After we received the populated data structure, we will need to set the following fields with the information in the data structure so that the browser can download the correct file:

  • stmfDir – the directory of the file in the IFS. 
  • stmfName – the file name of the file. 
  • attName (Optional) – the attachment name of the download.