RPG

By kimot, 21 March, 2023
dcl-pr ShowMSG extpgm('QMHSNDPM');      
 *n char(7) const;                      
 *n char(20) const;                     
 *n char(32767) const options(*varsize);
 *n int(10) const;                      
 *n char(10) const;                     
 *n char(10) const;                     
 *n int(10) const;                      
 *n char(4);                            
 *n char(32767) options(*varsize);      
end-pr;                                 
                                        
                                        
dcl-ds ErrorCode;                 
By kimot, 27 December, 2022
ctl-opt ALWNULL(*USRCTL) ;

dcl-ds ASP_INFO qualified inz ;
  ASPnum        int(5) ;
  TotCap        int(20) ;
  TotCapa       int(20) ;
  Threshold     int(5) ;
  ErrorLogSpc   int(5) nullind ;
  MachineLogSpc int(5) nullind ;
  MachineTrcSpc int(5) nullind ;
  MainDmpSpc    int(5) nullind ;
  MicrocodeSpc  int(5) nullind ;
end-ds ;

exec sql declare ASPspace cursor for SELECT ASP_NUM, TOTCAP, TOTCAPA,
   THRESHOLD, VALUE(ERROR_LOG_SPACE,0), VALUE(MACHINE_LOG_SPACE,0),
   VALUE(MACHINE_TRACE_SPACE,0), VALUE(MAIN_STORAGE_DUMP_SPACE,0),
   VALUE(MICROCODE_SPACE,
By kimot, 25 December, 2022
//Program interface declaration
dcl-pi *n ;
    Library           char(10) ;       // Library name
end-pi ;

dcl-s Filename   char(21) ;

dcl-f TheFile usropn extfile(Filename) usage(*delete) ;


Filename = Library + '/File_name' ;
open TheFile;
read TheFile;
    dow not %eof;
         read TheFile;
    enddo;
close TheFile;
By kimot, 25 December, 2022
dcl-s CursorRows int(10) ;

...

exec sql declare C1 INSENSITIVE cursor for .........;  // INSENSITIVE if we want exact count of rows fetched into cursor

...

exec sql open C1 ;
exec sql GET DIAGNOSTICS :CursorRows = DB2_NUMBER_ROWS ;
By kimot, 25 December, 2022
dcl-s Time       time ;        
dcl-s Today      date;
dcl-s Date30     date ;        
dcl-s Timestamp  timestamp(0) ;

​​​​​​​Timestamp = %date() + %time() ; 
Today = %date() ;               
Date30 = Today - %Days(30); 
By kimot, 24 December, 2022
// declare variable for command

dcl-s cmd   varchar(100);

// declare QCMDEXC interface 

dcl-pr qcmdexc extpgm('QCMDEXC');      
  theCmd char(3000) const;             
  cmdLen packed(15 : 5) const;         
  dbcs char(3) const options(*nopass); 
end-pr;                      
          
// create command and run it 

cmd = 'STRBKUBRM CTLGRP(' + ctlgrp + ') SBMJOB(*NO)' ; 
qcmdexc (cmd : %len(cmd)) ;