Writing Subroutine in CL program

Writing Subroutine in CL program
Writing Subroutine in CL program, subroutine, CL subroutine, subroutine in CL as400, ibmi, introduction,, CALLSUBR, ENDSUBR, SUBR, RTNSUBR, cl command, clp, clle, ile cl
Writing Subroutine in CL program

Subroutines in CL

  • SUBR (Subroutine) command is used in CL program to begin the subroutine block.
  • ENDSUBR (EndSubroutine) command is used in CL program to end the subroutine block.
  • CALLSUBR(CallSubroutine) command is used in CL program to execute/call a subroutine.
  • RTNSUBR command is used to return a value and exit the subroutine when RTNVAL is optional to use.
  • Command Syntax for Calling Subroutine

    CALLSUBR SUBR(Subroutine_Name)

    Command Syntax for Begin Subroutine

    SUBR SUBR(Subroutine_Name)

    Command Syntax for End Subroutine

    ENDSUBR

    Command Syntax for the Return value from Subroutine

    RTNSUBR RTNVAL(INTVALUE)

    Example of Writing Subroutine in CL program

    Write a program to create the duplicate object of an object in Qtemp library with Data /without Data

    PGM PARM(&LIBNAME &OBJNAME)
    
     /*Library Name :I/P parameter*/ 
    DCL VAR(&LIBNAME) TYPE(*CHAR) LEN(10) 
    
    /*Object Name :I/P parameter*/ 
    DCL VAR(&OBJNAME) TYPE(*CHAR) LEN(10) 
    DCL VAR(&QTEMPLIB) TYPE(*CHAR) LEN(10) VALUE('QTEMP')
    
    /*Call Subroutine to Create Duplicate Object in Qtemp library*/ 
    CALLSUBR SUBR(CreateDupObj) 
    
    /*begin Subroutine */
    SUBR SUBR(CreateDupObj) 
    /*With Data: */
    CRTDUPOBJ OBJ(&OBJNAME) FROMLIB(&LIBNAME) +
    OBJTYPE(*FILE) TOLIB(&QTEMPLIB) DATA(*NO) 
    
    /*OR Without Data: */
    CRTDUPOBJ OBJ(&OBJNAME) FROMLIB(&LIBNAME) +
    OBJTYPE(*FILE) TOLIB(&QTEMPLIB) DATA(*NO)
    
    /*End Subroutine :Exit */
    ENDSUBR
    
    ENDPGM

    Related Post

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain