Home > AS/400 Tips > iSeries programmer tips > Check & run commands in RPG
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Check & run commands in RPG


Victor Roig
06.21.2001
Rating: -3.79- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Sometimes you need to ask the user for a command or simply run a command saved previously. This function gives you the option in a very simple way.



Code

 
'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*   EUR
'    '*sChecking and / or running a command                              '*   EUR
'    '*-------------------------------------------------------------------*   EUR
'    '*  Module. . . . . . . . .  AUX017R1                         *   EUREUR
'    '*  Aplication. . . . . . .  GPI400                                  *   EUREUR
'    '*  Company . . . . . . . .  Aunde, S.A.                             *   EUREUR
'    '*  User. . . . . . . . . .  Victor Roig Lopez                       *   EUREUR
'    '*  Date. . . . . . . . . .  11/05/2001                              *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
'    '*     D E S C R I P T I O N                                        *   EUR
'    '*-------------------------------------------------------------------*   EUR
'    '*  We define This BIF                                               *   EUR
'    '*                                                                   *   EUREUR
'    '*   * Chk_Cmd  Check command                                        *   EUREUR
'    '*   * Run_Cmd  Ejecutar mandato.                                    *   EUREUR
'    '*                                                                   *   EUREUR
'    '*  And the internal function:                                       *   EUR
'    '*   * Call_API   call to QCAPCMD API                                *   EUREUR
'    '*                                                                   *   EUREUR
'    '*  This functions return the ID of error if there are. also, if the *   EUREUR
'    '*  user change some parm in th original, the final command is returned*   EUREUR
'    '*                                                                   *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
'    '*      U P D A T E S   &   P A T C H S                              *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
'    '* Date     | Programmer|Mark  |Description                    *   EUREUR
'    '*----------|-----------|------|-------------------------------------*   EUR
'    '*          |           |      |                                     *   EUREUR
'    '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*   EUR
     HCopyRight('(c) Aunde, S.A.')
     HDatFmt(*EUR) DatEdit(*DMY) DecEdit(',') Debug(*Yes)
      * Compiler instructions
     HOption(*ShowCpy) Indent('|') Optimize(*Full)
     HBndDir('*LIBL/BNDDIR')
     H NoMain

     D Chk_Cmd         PR             7A
     D    Aux_Cmd                   255A
     D    Aux_Tip                     9B 0 Const Options(*NoPass)
     D    Aux_Prompt                   N   Const Options(*NoPass)

     D Run_Cmd         PR             7A
     D    Aux_Cmd                   255A
     D    Aux_Prompt                   N   Const Options(*NoPass)

     D Proc_Cmds       PR                  ExtPgm('QCAPCMD')
     D    CA_Cmd                    255A   Const
     D    CA_CmdL                     9B 0 Const
     D    CA_OCB                     20A   Const
     D    CA_OCBL                     9B 0 Const
     D    CA_OCBF                     8A   Const
     D    CA_CmdC                   255A
     D    CA_CmdCL                    9B 0 Const
     D    CA_CmdCL1                   9B 0
     D    CA_Err                     16A

     D Call_API        PR             7A
     D    Aux_Cmd                   255A
     D    Aux_Tip                     9B 0 Const
     D    Aux_Prompt                   N   Const
'    '*-------------------------------------------------------------------*   EUR
'    '* Call_API      Internal call to API                                *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
     P Call_API        B
     D Call_API        PI             7A
     D    Aux_Cmd                   255A
     D    Aux_Tip                     9B 0 Const
     D    Aux_Prompt                   N   Const

'    '* User space error code                                                 EUREUR
      /Copy QSYSINC/QRPGLESRC,QUSEC
'    '*                                                                       EUREUR
     D QCA_CMD         S            255A
     D QCA_CMDL        S              9B 0 Inz(%Size(QCA_Cmd))
     D QCA_OCB         S             20A   Based(pQCPOP0100)
     D QCA_OCBL        S              9B 0 Inz(%Size(QCA_OCB))
     D QCA_OCBF        S              8A   Inz('CPOP0100')
     D QCA_CMDR        S            255A   Inz(*Blanks)
     D QCA_CMDRL       S              9B 0 Inz(%Size(QCA_CMDR))
     D QCA_CMDRL1      S              9B 0 Inz(%Size(QCA_CMDR))

     D PQCPOP0100      S               *   Inz(%Addr(QCPOP0100))
     D QCPOP0100       DS
     D   QCPO_TYPE                    9B 0 Inz
     D   QCPO_DBCS                    1A   Inz('0')
     D   QCPO_PRMT                    1A
     D   QCPO_STX                     1A   Inz('0')
     D   QCPO_MKEY                    4A   Inz(*Blanks)
     D   QCPO_RSV                     9A   Inz(x'000000000000000000')

     c                   Eval      QUsBPrv   = %Size(QUSEC)
     c                   Eval      QCA_CMD   = Aux_Cmd
     c                   Eval      QCPO_TYPE = Aux_Tip
     c                   Eval      QCPO_PRMT = Aux_Prompt

     c                   CallP     Proc_Cmds(QCA_CMD: QCA_CMDL:
     c                                       QCA_OCB: QCA_OCBL: QCA_OCBF:
     c                                       QCA_CMDR: QCA_CMDRL: QCA_CMDRL1:
     c                                       QUSEC)

     c                   Eval      Aux_Cmd = QCA_CMDR
     c                   Return    QUSEI

     P Call_API        E

'    '*-------------------------------------------------------------------*   EUR
'    '* Chk_Cmd       Check command                                       *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
     P Chk_Cmd         B                   Export
     D Chk_Cmd         PI             7A
     D    Aux_Cmd                   255A
     D    Aux_Tip                     9B 0 Const Options(*NoPass)
     D    Aux_Prompt                   N   Const Options(*NoPass)
'    '* fields for the call                                                   EUREUR
     D Cmd             S            255A   Inz
     D Tip             S              9B 0 Inz(1)
     D Prompt          S               N   Inz(*ON)
     D Err             S              7A   Inz

     c                   If        %Parms > 1
     c                   Eval      Tip = Aux_Tip
     c                   EndIf
     c                   If        %Parms > 2
     c                   Eval      Prompt = Aux_Prompt
     c                   EndIf

     c                   Eval      Cmd  = Aux_Cmd
     c                   If        (Tip < 0) OR (Tip > 9)
     c                   Return    'CPF0008'
     c                   EndIf

     c                   Eval      Err = Call_API(Cmd: Tip: Prompt)

     c                   If        Err <> *Blanks
     c                   Return    Err
     c                   Else
     c                   Eval      Aux_Cmd  = Cmd
     c                   Return    *Blanks
     c                   EndIf

     P Chk_Cmd         E
'    '*-------------------------------------------------------------------*   EUR
'    '* Run_Cmd       Run the command                                     *   EUREUR
'    '*-------------------------------------------------------------------*   EUR
     P Run_Cmd         B                   Export
     D Run_Cmd         PI             7A
     D    Aux_Cmd                   255A
     D    Aux_Prompt                   N   Const Options(*NoPass)
'    '* fields for the call                                                   EUREUR
     D Cmd             S            255A   Inz
     D Prompt          S               N   Inz(*OFF)
     D Err             S              7A   Inz

     c                   If        %Parms > 1
     c                   Eval      Prompt = Aux_Prompt
     c                   EndIf

     c                   Eval      Cmd  = Aux_Cmd
     c                   Eval      Err = Call_API(Cmd: 2: Prompt)

     c                   If        Err <> *Blanks
     c                   Return    Err
     c                   Else
     c                   Eval      Aux_Cmd  = Cmd
     c                   Return    *Blanks
     c                   EndIf

     P Run_Cmd         E 

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
RPG iSeries programming
Enhancing RPG with external SQL stored procedures
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
Taking advantage of CL advancements, starting with V5R3
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i

iSeries ILE programming
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
How to use an embedded SQL statement and display the result in a subfile
Eight steps for creating program documentation using AS/400 utilities
Searching fields for values
Searching part of a name or address in AS/400
Top 10 programmer tips YTD
How to use the binder language to manage service programs -- Part 3: Examples and pitfalls
Top 10 programmer tips of 2005
Understanding the binder language on AS/400

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts