Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Defining Data Structure Parameters in a Prototype or Procedure Interface

Defining Data Structure Parameters in a Prototype or Procedure Interface
Defining Data Structure Parameters in a Prototype or Procedure Interface, data structure in PR and PI parameters and return value, rpgle, as400, introduction, how, what, about, create,Using a data structure parameter in a subprocedure, likeds
Defining Data Structure Parameters in a Prototype or Procedure Interface

In the ILE procedure prototype (PR) and procedure interface (PI), we can define different types of parameters to the procedures such as CHAR, INTEGER, etc. But, How do we pass the data structure as the parameter to the PR and PI of the ILE procedure? So, In this blog, we will talk about the same.

  • To pass or define a parameter as a data structure to the PR and PI, first, we need to define the data structure.
  • After that, we can define a data structure as a PR and PI parameter using the LIKEDS keyword.
  • To use the parameter DS subfield, specify the subfield qualified with the parameter name.
  • For Example

    Let's define a Qualified data structure named DS1 having two subfields of type char and packed.

    Define a data structure in RPG Fixed Format

         D  DS1            DS                   QUALIFIED
         D  subfield1                    10a
         D  subfield2                     5p 0
    

    Define a data structure in RPG Fully Free Format

    **Free
    dcl-ds DS1 Qualified;
      subfield1 char(10);
      subfield2 packed(5:0);
    end-ds;
    

    Define a procedure prototype (PR) in RPG Fixed Format

         D DSparmDemo      PR
         D Inds1                                LIKEDS(DS1)
    

    Define a procedure prototype (PR) in RPG Fully Free Format

    **Free
    dcl-pr DSparmDemo;
     Inds1 likeds(DS1);  
    end-pr;
    

    Define a procedure Interface (PI) within Procedure Begin and End in RPG Fixed Format

         P DSparmDemo      B
         D DSparmDemo      PI
         D  Inds1                               LIKEDS(DS1)
         C                   IF        DS1.subfield1 = 'TEST'
         C     DS1           DSPLY  
         C                   ENDIF
         C                   IF        DS1.subfield2 > 0
         C     DS1           DSPLY
         C                   ENDIF
         C                   SETON                                        LR
         P DSparmDemo      E
    

    Define a procedure Interface (PI) within Procedure Begin and End in RPG /Free Format

         P DSparmDemo      B
         D DSparmDemo      PI
         D  Inds1                               LIKEDS(DS1)
          /Free
           if DS1.subfield1 = 'TEST';
              DSPLY DS1;
           endif;
           if DS1.subfield2 > 0;
              DSPLY DS1;
           endif;
           *INLR =  *ON;
          /End-Free
         P DSparmDemo      E
    

    Define a procedure Interface (PI) within Procedure Begin and End in RPG Fully Free Format

    **Free
    dcl-proc DSparmDemo;
      dcl-pi *N;
         inds1 likeds(DS1);
      end-pi DSparmDemo;
           if DS1.subfield1 = 'TEST';
              DSPLY DS1;
           endif;
           if DS1.subfield2 > 0;
              DSPLY DS1;
           endif;
           *INLR =  *ON;  
    end-proc;       
    

    Related Post

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain