Search code examples
ibm-midrangecobol

How to compile (and link) a COBOL program in an IBMi from the command line?


I have a COBOL program:

 IDENTIFICATION DIVISION.        
 PROGRAM-ID. HELLO1.             
 AUTHOR. MYSELF.                 
 PROCEDURE DIVISION.             
*    SHOW BEGINS                 
     DISPLAY 'HELLO WORLD RUN'.
     STOP RUN.                   

If I compile it with the option 14 of the STRPDM it runs. But if I try this from the command line(F10):

CRTPGM PGM(HIGINIO1/HELLO2) MODULE(*PGM) ENTMOD(*FIRST) BNDSRVPGM(*NONE) BNDDIR(*NONE) ACTGRP(*ENTMOD) TGTRLS(*CURRENT)

It fails: Program HELLO2 not created. Any idea?


Solution

  • all the ILE languages, you first have to compile the module. Then create the program from the module.

    use CRTCBLMOD command to create the module:

    CRTCBLMOD MODULE(yourlib/TEST0007B) SRCFILE(QCBLLESRC)
              OPTION(*SOURCE) DBGVIEW(*SOURCE)
    

    run CRTPGM command to create executable program from the module:

    CRTPGM PGM(TEST0007B) MODULE(*PGM) 
    

    Here is a cobol sql example ( did not get too far because I do not fully understand how to perform a loop in cobol ). Use theCRTSQLCBLI command to create the module. Then CRTPGM to create the program.

    CRTSQLCBLI OBJ(TEST0008B) SRCFILE(QCBLLESRC)
              SRCMBR(TEST0008B) OBJTYPE(*MODULE) REPLACE(*YES)            
    crtpgm  test0008b   
    
         IDENTIFICATION DIVISION.                                 
           PROGRAM-ID. TEST0008B.                                 
           ENVIRONMENT DIVISION.                                  
           CONFIGURATION SECTION.                                 
             SOURCE-COMPUTER. IBM-ISERIES.                        
             OBJECT-COMPUTER. IBM-ISERIES.                        
           DATA DIVISION.                                         
           WORKING-STORAGE SECTION.                               
           01  A     PIC X(80) VALUE " ".                         
           01  B     PIC S9(8) VALUE 10.                          
           01  C     PIC S9(8) VALUE 5.                           
             01  SR_FILLER.                                       
                 05  sr_srcdta               PIC x(100) VALUE " ".
               EXEC SQL                                           
                    INCLUDE SQLCA                                 
               END-EXEC.                                          
           PROCEDURE DIVISION.                                    
           MAINLINE.                                              
               MOVE B TO C.                                       
               exec sql                                           
                    declare c1 cursor for                         
                    select  a.srcdta                              
                    from    qrpglesrc a                           
               end-exec.                   
               exec sql                    
                    open    c1             
               end-exec.                   
                                           
               EXEC SQL                    
                    fetch  c1              
                    into   :sr_srcdta      
               END-EXEC.                   
                                           
               if      sqlcode not = 0     
               display 'end of input file' 
               else                        
               DISPLAY sr_srcdta           
               END-IF.                     
                                           
               EXEC SQL                    
                    close  c1              
               END-EXEC.                   
                                           
               EXEC SQL                    
                    SELECT a.srcdta        
                      INTO :sr_srcdta      
                      FROM qrpglesrc a                     
                      fetch first row only 
               END-EXEC.                   
               DISPLAY sr_srcdta.          
               STOP RUN.