IC SunsetThe developerWorks Connections platform will be sunset on December 31, 2019. On January 1, 2020, this community and its apps will no longer be available. More details available on our FAQ.
Topic
  • 7 replies
  • Latest Post - ‏2019-09-13T17:17:04Z by OSROMI
OSROMI
OSROMI
37 Posts

Pinned topic Problems compiling it my program

‏2019-09-11T23:37:54Z | compiling it my problems program

Sorry i'm learning
I want to create only one procedure that any program can call it, when I compile it as a module it asks me to come back or * INLR I don't want to create a CRTSRVPGM service program.
ERROR = Error, the compiler does not know where to end
I compile it with 15 and it doesn't work

My code

type is SQLPRGLE

 

   dcl-proc BCH_Convierte Export;

         dcl-pi *N;
           PCLDOC char(18);
           PCLNOMB char(60);
           PCTEDIT char(15);
           PDPAGEN PACKED(3:0);
         end-pi;

          DCL-F CLMCTE DISK(*EXT) KEYED USAGE(*INPUT);
          DCL-F DPCTAS DISK(*EXT) KEYED USAGE(*INPUT);
          DCL-S WCTEDIT CHAR(15);
          DCL-S WMONCOD CHAR(3);
          DCL-S WDPAGEN PACKED(4:0);
          DCL-S WCLDOC CHAR(18);
          DCL-S WCLNOMB CHAR(60);
          DCL-S WNUM PACKED(4:0);

          EXEC SQL
          DECLARE CURC1 CURSOR FOR
          SELECT CLDOC, CLNOMB
          FROM CLIDAT.CLMCTE
          WHERE CLDOC = :PCLDOC
          FOR FETCH ONLY;
           EXEC SQL
             OPEN CURC1;
              EXEC SQL
               FETCH CURC1 INTO  :WCLDOC, :WCLNOMB;
              IF SQLCOD = 0;
                 PCLDOC = WCLDOC;
                 PCLNOMB = WCLNOMB;
                 PDPAGEN = WDPAGEN;
               ENDIF;
                EXEC SQL
                 CLOSE CURC1;

        EXEC SQL
         DECLARE CURC2 CURSOR FOR
         SELECT CTEDIT, DPAGEN, MONCOD, DPAGEN
          FROM DP054DAT.DPCTAS
          WHERE CLDOC = :WCLDOC AND TIPPRO = 2 AND CTSTA <> 'C'
          FOR FETCH ONLY;
           EXEC SQL
             OPEN CURC2;
           EXEC SQL
           FETCH CURC2 INTO  :WCTEDIT, :WDPAGEN, :WMONCOD, WDPAGEN;
               IF SQLCOD = 0;
                WNUM = WNUM + 1;
               IF WNUM = 1;
                PCTEDIT = WCTEDIT;
                ENDIF;
               EXEC SQL
               FETCH CURC2 INTO  :WCTEDIT, :WDPAGEN, :WMONCOD;
               ENDIF;
                EXEC SQL
                 CLOSE CURC2;

        END-PROC BCH_Convierte;

 

Updated on 2019-09-12T22:40:30Z at 2019-09-12T22:40:30Z by OSROMI
  • Francesco_Toppan
    Francesco_Toppan
    1 Post
    ACCEPTED ANSWER

    Re: Problems compiling it my program

    ‏2019-09-12T09:32:09Z  

    you may want to add some control option, at the beginning of your service program?

     

        ctl-opt NOMAIN option(*srcstmt: *nodebugio)  debug(*yes)
        pgminfo(*pcml:*module) copyright('ACME ltd 2019')  ;  

     

    have a quick look here, it should give you an idea: https://www.mcpressonline.com/programming/rpg/rpg-fundamentals-tip-3-working-with-nomain-modules

     

  • JonParis
    JonParis
    345 Posts
    ACCEPTED ANSWER

    Re: Problems compiling it my program

    ‏2019-09-12T18:15:43Z  

    You are correct.  You need to create a Service Program if you want to make this function easily reusable.

    In addition to the NoMain mentioned earlier you should also consider changing this to a function and returning a value rather than passing the value back in the parameters. With program calls that is all you can do but a function call is better and more obvious to those who maintain the code later as you know what field was input to the function and what changed as a result.

    dcl-proc BCH_Convierte  Export;
             dcl-pi *N LikeDS(PCL_Data_T);
               PCLDOC char(18);
             end-pi;
    
    dcl-ds PCL_Data_T Template;
              PCLNOMB char(60);
              PCTEDIT char(15);
              PDPAGEN PACKED(3:0);
    end-ds;
    
    dcl-ds PCL_Data  LikeDS(PCL_Data_T);
    
    // Logic stuff
    
    Return PCL_Data;
    
    

    Then in the calling program you do:
    Result = BCH_Convierte(PCLDOC);

     

    Can't get the text align to work but hopefully you can see what Io mean.  The template would normally =be in a /Copy so that callers and callee can easily share the  same definition.

     

  • Francesco_Toppan
    Francesco_Toppan
    1 Post

    Re: Problems compiling it my program

    ‏2019-09-12T09:32:09Z  

    you may want to add some control option, at the beginning of your service program?

     

        ctl-opt NOMAIN option(*srcstmt: *nodebugio)  debug(*yes)
        pgminfo(*pcml:*module) copyright('ACME ltd 2019')  ;  

     

    have a quick look here, it should give you an idea: https://www.mcpressonline.com/programming/rpg/rpg-fundamentals-tip-3-working-with-nomain-modules

     

  • OSROMI
    OSROMI
    37 Posts

    Re: Problems compiling it my program

    ‏2019-09-12T15:57:56Z  

     Thanks Francesco for the valuable information and comments

     

    I want to have a procedure which can be called by several programs but in this case I just think it must be a service program so that several programs can call it.
    I hope to be correct if you have any observations is welcome.

     

     

    Updated on 2019-09-12T16:13:11Z at 2019-09-12T16:13:11Z by OSROMI
  • JonParis
    JonParis
    345 Posts

    Re: Problems compiling it my program

    ‏2019-09-12T18:15:43Z  

    You are correct.  You need to create a Service Program if you want to make this function easily reusable.

    In addition to the NoMain mentioned earlier you should also consider changing this to a function and returning a value rather than passing the value back in the parameters. With program calls that is all you can do but a function call is better and more obvious to those who maintain the code later as you know what field was input to the function and what changed as a result.

    dcl-proc BCH_Convierte  Export;
             dcl-pi *N LikeDS(PCL_Data_T);
               PCLDOC char(18);
             end-pi;
    
    dcl-ds PCL_Data_T Template;
              PCLNOMB char(60);
              PCTEDIT char(15);
              PDPAGEN PACKED(3:0);
    end-ds;
    
    dcl-ds PCL_Data  LikeDS(PCL_Data_T);
    
    // Logic stuff
    
    Return PCL_Data;
    
    

    Then in the calling program you do:
    Result = BCH_Convierte(PCLDOC);

     

    Can't get the text align to work but hopefully you can see what Io mean.  The template would normally =be in a /Copy so that callers and callee can easily share the  same definition.

     

  • OSROMI
    OSROMI
    37 Posts

    Re: Problems compiling it my program

    ‏2019-09-12T20:21:43Z  

    A question this code are the parameters
      Parameters is what I need
    input / output
    dcl-ds PCL_Data_T Template;

               PLCDOC CHAR(18);
               PCLNOMB char (60);
               PCTEDIT char (15);
               PDPAGEN PACKED (3: 0);
    end-ds;

     

    I want to send the four parameters

     

    I think that's what I would call in another program and my procedure in the service program would receive PCLDOC and send the four parameters.

    I am right?

     

    D BCH_Convierte                   PR                
    D WCLDOC                        18 
    D WCLNOMB                     60   
    D WCTEDIT                       15
    D WDPAGEN                       3 0

     

        WCLDOC = CLDOC;

        WCLNOMB = *BLANKS;

        WCTEDIT  = *BLANKS

        WDPAGEN  = *ZEROS; 

     

     

     BCH_Convierte(WCLDOC : WCLNOMB : WCTEDIT : WDPAGEN);

     

    HELP  How do I write this code in full free-form RPG

    D BCH_Convierte                   PR                
    D WCLDOC                        18 
    D WCLNOMB                     60   
    D WCTEDIT                       15
    D WDPAGEN                       3 0

     

    Updated on 2019-09-12T21:31:21Z at 2019-09-12T21:31:21Z by OSROMI
  • JonParis
    JonParis
    345 Posts

    Re: Problems compiling it my program

    ‏2019-09-12T21:47:50Z  

    Why do you _want_ to send four parameters when only one of them supplies an input value?  In your code only WCLDOC supplies a value to the code - the other three are populated by the routine's logic.

    IF you were calling a program you would have no choice but to have all four as parms because programs cannot return values. But since you are creating this as a procedure in a Service Program you can take advantage of return values and have a cleaner more intuitive interface.

  • OSROMI
    OSROMI
    37 Posts

    Re: Problems compiling it my program

    ‏2019-09-12T22:37:18Z  

    If I apologize for this procedure, I use it to send a customer code to the service program procedure, the procedure receives the customer code and with that it consults the agency table and the client account table and the procedure returns:
    Client code
    Customer name
    Customer account
    Agency Code

  • OSROMI
    OSROMI
    37 Posts

    Re: Problems compiling it my program

    ‏2019-09-13T17:17:04Z  

    Regards JonParis
     
    I'm going to study the ILE concept

    prototype
    module
    service program

    BNDDIR

    ACTGRP

    ETC

     

    Use CRTPGM as CRTSRVPGM

    Then I will program

     

    Best regards