IBM Support

ILE RPG Example of QCAPCMD API

Troubleshooting


Problem

This document contains an example written in ILE RPG of calling the QCAPCMD API. This API can be used as an alternative to QCMDEXC.

Resolving The Problem

The advantage of using the QCAPCMD versus QCMDEXC is that you can pass the error code parameter. The error code parameter allows you to check for any errors that can occur on the command.

RPGLE:
fnewfile   if   e           k disk    usropn
     dcommand          s             40    inz(' ')
     dcmdlng           s             10i 0 inz(40)
     docb              ds
     d type                          10i 0 inz(0)
     d DBCSdh                         1    inz('0')
     d prompt                         1    inz('0')
     d cmdsyntax                      1    inz('0')
     d msgrtvkey                      4    inz(x'00000000')
     dccsidcmdst                     10i 0 inz(0)
     d reserve1                       5    inz(x'0000000000')
     docblength        s             10i 0 inz(x'00000020')
     docbfmt           s              8    inz('CPOP0100')
     dchgcmd           s              1    inz(' ')
     dlngchgcmd        s             10i 0 inz(0)
     dlngchgrtn        s             10i 0 inz(0)
     D ErrorCode       DS                                          
     D  BytesProvided                10I 0 inz(%size(ErrorCode))    
     D  BytesAvail                   10I 0                          
     D  ExceptionID                   7                            
     D  RESERVED                      1                            
     D  ExceptionData               256                            
     c                   eval      command = 'OVRDBF NEWFILE SHARE(*YES)'
     c                   call      'QCAPCMD'
     c                   parm                    command
     c                   parm                    cmdlng
     c                   parm                    ocb
     c                   parm                    ocblength
     c                   parm                    ocbfmt
     c                   parm                    chgcmd
     c                   parm                    lngchgcmd
     c                   parm                    lngchgrtn
     c                   parm                    ErrorCode
     c     BytesAvail    ifgt      0
     c     'Error on API'DSPLY
     c     ExceptionID   dsply
     c                   end
     c                   open      newfile
     c     *loval        setll     fmt1
     c                   read      fmt1                                   30
     c     *in30         ifeq      '0'

               c     fld1          dsply
               c                   else
               c     'No Records'  dsply
               c                   end
               c                   close     newfile
               c                   eval      *INLR = '1'

          DDS for newfile:

                          R FMT1                              
                            FLD1          10                  
                  FLD2          10                  
                K FLD1                              

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]

Historical Number

405981682

Document Information

Modified date:
18 December 2019

UID

nas8N1015122