
Proudly Serving Colorado
Colorado AS/400 Control Language (CL) Overview
AS/400 Control Language (CL) is a scripting language used for system administration, automation, and job control tasks on IBM AS/400 (now IBM i) systems.
Common Uses of AS/400 CL:
- System Administration: CL programs are used for various system administration tasks such as creating and managing user profiles, managing libraries and objects, configuring system settings, managing backups, and monitoring system performance.
- Job Control: CL programs define and control batch jobs and job schedules on the AS/400 system. This includes submitting, monitoring, and managing the execution of batch jobs, handling job dependencies, and scheduling.
- Automation: CL programs automate repetitive tasks and workflows on the AS/400 system, including data processing, report generation, file management, and data transfers.
- Integration: CL programs integrate with other systems and applications, both within the AS/400 environment and externally. This involves executing commands or programs on remote systems, exchanging data with external databases or file systems, and interfacing with middleware or messaging systems.
- Customization: CL programs customize and extend the functionality of the AS/400 system to meet specific business requirements. This may involve creating custom utilities, interfaces, or applications tailored to the organization's needs.
- Scripting: CL provides a scripting environment for executing sequences of commands and controlling the flow of execution based on conditions and logic. It enables the implementation of complex business processes and workflows.
Overall, AS/400 CL is a versatile scripting language that plays a central role in managing and automating the operation of IBM i systems, enabling administrators to efficiently manage resources, automate tasks, and ensure the smooth operation of their IT infrastructure.
Arithmetic Operations
-
ADD: Adds values together.
ADD VAR1(&VAR1) VAR2(&VAR2) RESULT(&RESULT)
-
SUB: Subtracts one value from another.
SUBTRACT VAR1(&VAR1) FROMVAR(&VAR2) RESULT(&RESULT)
-
MULT: Multiplies values together.
MULT VAR1(&VAR1) VAR2(&VAR2) RESULT(&RESULT)
-
DIV: Divides one value by another.
DIV VAR1(&VAR1) BYVAR(&VAR2) RESULT(&RESULT)
Comparison Operations
-
CHGVAR: Changes the value of a variable.
CHGVAR VAR(&VAR) VALUE('new_value')
-
IF: Performs conditional processing based on a specified condition.
IF COND((&VAR *GT 100) *AND (&VAR *LT 200)) THEN(SNDPGMMSG MSG('Variable is between 100 and 200'))
String Manipulation
-
CAT: Concatenates two or more strings.
CAT VAR(&STRING1) VALUE(' ') VAR(&STRING2) RESULT(&RESULT)
-
SCAN: Searches a string for a specified substring.
SCAN VAR(&STRING) VALUE('substring')
Object Allocation
-
ALCOBJ: Allocates an object for exclusive use.
ALCOBJ OBJ((&OBJ)) SCOPE(*JOB) ALCTYPE(*EXCL)
-
DLCOBJ: Deallocates an object.
DLCOBJ OBJ((&OBJ))
Data Area Allocation
-
CRTDTAARA: Creates a data area.
CRTDTAARA DTAARA(MYLIB/MYDATA) TYPE(*CHAR) LEN(50)
-
DLTDTAARA: Deletes a data area.
DLTDTAARA DTAARA(MYLIB/MYDATA)
Program Flow Control
-
DO: Begins a DO-group.
DO FOR(&INDEX) FROM(1) TO(10) BY(1)
-
ENDDO: Ends a DO-group.
ENDDO
-
GOTO: Branches to a specified label.
GOTO LABEL(END)
-
LEAVE: Exits a DO-group or iterative process.
LEAVE
-
RETURN: Exits a subroutine.
RETURN
Database Commands
-
Run SQL Command (RUNSQL): Executes an SQL command within a CL program.
RUNSQL SQL('SELECT * FROM my_table') COMMIT(*NONE)
-
Declare Cursor (DECLSQ): Declares a cursor for processing rows returned by an SQL query.
DECLSQ CURSOR(C1) SQL('SELECT * FROM my_table')
-
Open Cursor (OPNSQ): Opens a cursor for fetching rows from a result set.
OPNSQ CURSOR(C1)
-
Fetch Cursor (FETSQ): Fetches the next row from a result set into specified variables.
FETSQ CURSOR(C1) INTO(&VAR1 &VAR2 &VAR3)
-
Close Cursor (CLOSQL): Closes a cursor.
CLOSQL CURSOR(C1)
File and Data Management
-
Create Physical File (CRTPF): Creates a physical file.
CRTPF FILE(MYLIB/MYFILE) RCDLEN(100)
-
Create Logical File (CRTLF): Creates a logical file.
CRTLF FILE(MYLIB/MYLFILE) SRCFILE(MYLIB/QDDSSRC) SRCMBR(MYLOGIC)
-
Display File (DSPF): Displays the contents of a source or object file.
DSPF FILE(MYLIB/MYFILE)
-
Print File (PRTF): Prints the contents of a spooled file.
PRTF FILE(MYLIB/MYFILE)
Job and Program Control
-
Call Program (CALL): Calls another program from within a CL program.
CALL PGM(ANOTHERPGM)
-
Call Command (CALL): Calls a CL command from within a CL program.
CALL CMD(QSYS/CRTLIB LIB(MYLIB))
-
Execute Command (EXECCMD): Executes a command.
EXECCMD CMD(DSPUSRPRF)
-
Retrieve Job Attribute (RTVJOBA): Retrieves job attributes into CL variables.
RTVJOBA JOB(&JOBNUM) USER(&USER)
Prompting User Commands
-
RTVMSG (Retrieve Message): Retrieves a message text from a message file.
RTVMSG MSGID(message_id) MSGF(message_file) MSGDTA(&message_text)
-
RTVPROMPT (Retrieve Prompt): Retrieves a prompt text from a message file.
RTVPROMPT PGM(&program_name) MSGID(prompt_id) MSGF(message_file) RTNVAR(&prompt_text)
-
RTVPFKEY (Retrieve PF Key): Retrieves the function key text from a message file.
RTVPFKEY PGM(&program_name) KEYNBR(function_key_number) MSGF(message_file) RTNVAR(&function_key_text)
-
RTVDFTMSG (Retrieve Default Message): Retrieves a default message from a message file.
RTVDFTMSG MSGID(default_message_id) MSGF(message_file) RTNVAR(&default_message_text)
-
RTVCLRSCN (Retrieve Clear Screen Message): Retrieves the clear screen message text.
RTVCLRSCN RTNVAR(&clear_screen_message_text)
-
RTVPAGSEG (Retrieve Page Segment): Retrieves a page segment text from a source file.
RTVPAGSEG PAGSEG(page_segment_name) SRCFILE(source_file) RTNVAR(&page_segment_text)
-
RTVFLD (Retrieve Field Prompt): Retrieves the prompt text for a field from a display file.
RTVFLD FILE(display_file) FLD(field_name) RTNVAR(&field_prompt_text)
Display Menu at the Top of the Screen
The following example demonstrates how to display a menu at the top of the screen:
/* DDS file (QDSPLYF) */ A DSPSIZ(24 80 *DS3) A INDARA A CA03(03 'Exit') A CA04(04 'Option 1') A CA05(05 'Option 2') A CF01(01) A 1 1'-----------------------------' A 2 1'Menu Options ' A 3 1'-----------------------------' /* CL program to handle menu options */ PGM /* Display menu */ DSPSFLD QDSPLYF /* Wait for user input */ RCVF /* Check for function keys */ IF COND(&IN03) THEN(DO) /* Function key F3 (Exit) pressed */ SNDBRKMSG MSG('Exiting program...') ENDPGM ENDDO /* Add logic for other function keys as needed */ ENDPGM
Display Product Data by Row and Column Placement
The following example demonstrates how to display product data by row and column placement:
/* DDS file (QDSPLYF) */ A DSPSIZ(24 80 *DS3) A INDARA A R HEADER A PRODUCT 5A O 1 1 A R PRODUCT1 A PRODUCT1 5A O 3 5 A R PRODUCT2 A PRODUCT2 5A O 4 5 A R PRODUCT3 A PRODUCT3 5A O 5 5 /* CL program to display product data */ PGM /* Display header */ SNDRCVF FILE(QDSPLYF) RCDFMT(HEADER) /* Display product data */ SNDRCVF FILE(QDSPLYF) RCDFMT(PRODUCT1) SNDRCVF FILE(QDSPLYF) RCDFMT(PRODUCT2) SNDRCVF FILE(QDSPLYF) RCDFMT(PRODUCT3) ENDPGM
CRUD Commands for a DB2 Database Connection
The following example demonstrates how to perform CRUD operations in AS/400 CL for a DB2 database:
/* CL program to perform CRUD operations on a DB2 database */ /* Add Employee */ ADDEMP: PGM /* Declare variables */ DCL VAR(&EMPNO) TYPE(*CHAR) LEN(5) DCL VAR(&EMPNAME) TYPE(*CHAR) LEN(30) DCL VAR(&SALARY) TYPE(*DEC) LEN(7 2) DCL VAR(&SQL) TYPE(*CHAR) LEN(1000) /* Prompt user for employee details */ CHGVAR &EMPNO VALUE('00001') /* Example value */ CHGVAR &EMPNAME VALUE('John Doe') /* Example value */ CHGVAR &SALARY VALUE(50000.00) /* Example value */ /* Construct SQL statement to insert employee record */ CHGVAR &SQL VALUE('INSERT INTO Employee (EmpNo, EmpName, Salary) VALUES (''' + &EMPNO + ''', ''' + &EMPNAME + ''', ' + %CHAR(&SALARY) + ')') /* Execute SQL statement */ RUNSQL SQL(&SQL) /* Check for SQL error */ IF COND(&SQLCOD *NE 0) THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('SQL Error: ' + %CHAR(&SQLCOD) + ' ' + &SQLCMSG) GOTO CMDLBL(ENDPGM) ENDDO SNDPGMMSG MSG('Employee added successfully.') GOTO CMDLBL(ENDPGM) ENDPGM: ENDPGM /* Update Employee */ UPDEMP: PGM /* Declare variables */ DCL VAR(&EMPNO) TYPE(*CHAR) LEN(5) DCL VAR(&SALARY) TYPE(*DEC) LEN(7 2) DCL VAR(&SQL) TYPE(*CHAR) LEN(1000) /* Prompt user for employee number and new salary */ CHGVAR &EMPNO VALUE('00001') /* Example value */ CHGVAR &SALARY VALUE(55000.00) /* Example value */ /* Construct SQL statement to update employee record */ CHGVAR &SQL VALUE('UPDATE Employee SET Salary = ' + %CHAR(&SALARY) + ' WHERE EmpNo = ''' + &EMPNO + '''') /* Execute SQL statement */ RUNSQL SQL(&SQL) /* Check for SQL error */ IF COND(&SQLCOD *NE 0) THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('SQL Error: ' + %CHAR(&SQLCOD) + ' ' + &SQLCMSG) GOTO CMDLBL(ENDPGM) ENDDO SNDPGMMSG MSG('Employee updated successfully.') GOTO CMDLBL(ENDPGM) ENDPGM: ENDPGM /* Delete Employee */ DELEMP: PGM /* Declare variables */ DCL VAR(&EMPNO) TYPE(*CHAR) LEN(5) DCL VAR(&SQL) TYPE(*CHAR) LEN(1000) /* Prompt user for employee number to delete */ CHGVAR &EMPNO VALUE('00001') /* Example value */ /* Construct SQL statement to delete employee record */ CHGVAR &SQL VALUE('DELETE FROM Employee WHERE EmpNo = ''' + &EMPNO + '''') /* Execute SQL statement */ RUNSQL SQL(&SQL) /* Check for SQL error */ IF COND(&SQLCOD *NE 0) THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('SQL Error: ' + %CHAR(&SQLCOD) + ' ' + &SQLCMSG) GOTO CMDLBL(ENDPGM) ENDDO SNDPGMMSG MSG('Employee deleted successfully.') GOTO CMDLBL(ENDPGM) ENDPGM: ENDPGM /* Display Employees */ DSPEMPS: PGM /* Declare variables */ DCL VAR(&SQL) TYPE(*CHAR) LEN(1000) DCL VAR(&EMPNO) TYPE(*CHAR) LEN(5) DCL VAR(&EMPNAME) TYPE(*CHAR) LEN(30) DCL VAR(&SALARY) TYPE(*DEC) LEN(7 2) /* Construct SQL statement to select all employees */ CHGVAR &SQL VALUE('SELECT EmpNo, EmpName, Salary FROM Employee') /* Execute SQL statement */ RUNSQL SQL(&SQL) + + CHGVAR(&EMPNO *CHAR 5) + + CHGVAR(&EMPNAME *CHAR 30) + + CHGVAR(&SALARY *DEC (7 2)) /* Check for SQL error */ IF COND(&SQLCOD *NE 0) THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('SQL Error: ' + %CHAR(&SQLCOD) + ' ' + &SQLCMSG) GOTO CMDLBL(ENDPGM) ENDDO /* Display employee data */ /* Add logic to display data as needed */ GOTO CMDLBL(ENDPGM) ENDPGM: ENDPGM
Connect to DB2 Database and Display Data
The following example demonstrates how to connect to a DB2 database and display data from it using SQL within a CL program:
PGM /* Define variables */ DCL VAR(&SQL) TYPE(*CHAR) LEN(1000) DCL VAR(&RESULT) TYPE(*CHAR) LEN(1000) /* Connect to DB2 database */ RUNSQL SQL('CONNECT TO your_db2_database') COMMIT(*NONE) + + CHGVAR(&RESULT *SYS) + + CHGVAR(&SQL 'SELECT * FROM your_table') + + RUNSQL SQL(&SQL) COMMIT(*NONE) + + CHGVAR(&RESULT *SYS) /* Display data */ DSPLY &RESULT ENDPGM
In this example:
- We declare variables for holding SQL statements and result.
- We use the `RUNSQL` command to connect to the DB2 database and execute the SQL statement to retrieve data from the specified table.
- The retrieved data is stored in the variable `&RESULT`.
- Finally, we use the `DSPLY` command to display the retrieved data.
This is a basic example. You may need to adjust the SQL statement and error handling based on your specific requirements.
CRUD Data Entry
The following example demonstrates a basic CRUD data entry screen:
/* CL program to display a CRUD data entry screen */ PGM /* Declare variables */ DCL VAR(&CHOICE) TYPE(*CHAR) LEN(1) DCL VAR(&EMPNO) TYPE(*CHAR) LEN(5) DCL VAR(&EMPNAME) TYPE(*CHAR) LEN(30) DCL VAR(&SALARY) TYPE(*DEC) LEN(7 2) DCL VAR(&STATUS) TYPE(*CHAR) LEN(10) /* Display menu options */ DSPMENU: CHGVAR &CHOICE '*' SNDRCVF FILE(QDSPLYF) IF COND(&CHOICE *EQ '1') THEN(GOTO ADD_Product) IF COND(&CHOICE *EQ '2') THEN(GOTO UPDATE_Product) IF COND(&CHOICE *EQ '3') THEN(GOTO DELETE_Product) IF COND(&CHOICE *EQ '4') THEN(GOTO DISPLAY_ProductS) IF COND(&CHOICE *EQ 'X') THEN(GOTO END_PROGRAM) GOTO DSPMENU /* Add Product */ ADD_Product: SNDPGMMSG MSG('Enter Product Information to Add:') RCVF PARM(&EMPNO &EMPNAME &SALARY) /* Add code to validate and add Product */ SNDPGMMSG MSG('Product added successfully.' + ' Press Enter to return to the main menu.') RCVF GOTO DSPMENU /* Update Product */ UPDATE_Product: SNDPGMMSG MSG('Enter Product Number to Update:') RCVF PARM(&EMPNO) /* Add code to retrieve and update Product */ SNDPGMMSG MSG('Product updated successfully.' + ' Press Enter to return to the main menu.') RCVF GOTO DSPMENU /* Delete Product */ DELETE_Product: SNDPGMMSG MSG('Enter Product Number to Delete:') RCVF PARM(&EMPNO) /* Add code to delete Product */ SNDPGMMSG MSG('Product deleted successfully.' + ' Press Enter to return to the main menu.') RCVF GOTO DSPMENU /* Display Products */ DISPLAY_ProductS: SNDPGMMSG MSG('Displaying Products:') /* Add code to display Products */ RCVF GOTO DSPMENU /* End Program */ END_PROGRAM: ENDPGM
List of AS/400 CL Date Commands
-
RTVSYSVAL (Retrieve System Value): Retrieves the current date and time from the system.
RTVSYSVAL SYSVAL(QDATE) RTNVAR(&DATE)
-
CVTDAT (Convert Date): Converts a date from one format to another.
CVTDAT DATE(input_date) TOVAR(output_date) FROMFMT(*ISO) TOFMT(*MDY)
-
RTVDTAARA (Retrieve Data Area): Retrieves the value of a date stored in a data area.
RTVDTAARA DTAARA(data_area_name) RTNVAR(&date)
-
RTVDAT (Retrieve Date): Retrieves the current date from the system.
RTVDAT DATE(&DATE)
-
ADDDAT (Add Date): Adds a specified number of days to a date.
ADDDAT DATFMT(*MDY) FROMDAT(&date) DAYS(10) TOVAR(&new_date)
-
DAYS360 (Days Between Dates): Calculates the number of days between two dates using a 360-day year.
DAYS360 DATE(&start_date) TO_DATE(&end_date) RTNVAR(&days)
-
CHGDTAARA (Change Data Area): Changes the value of a date stored in a data area.
CHGDTAARA DTAARA(data_area_name) VALUE(&new_date)
-
DAYS (Day of Week): Returns the day of the week for a given date.
DAYS DATE(&date) DAYNBR(&day_number)
-
CVTDATD (Convert Date Description): Converts a date from a date format to a date description.
CVTDATD DATE(&date) TOVAR(&date_description)
-
CVTDATDT (Convert Date to Date): Converts a date from one date format to another date format.
CVTDATDT DATE(&date) FROMFMT(*MDY) TOFMT(*ISO) TOVAR(&new_date)
Time Commands
-
RTVSYSVAL (Retrieve System Value): Retrieves the current time from the system.
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
-
RTVSYSVAL (Retrieve System Value): Retrieves the current time and stores it in a variable.
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&HOURS &MINUTES &SECONDS)
-
CVTTIME (Convert Time): Converts time from one format to another.
CVTTIME TIME(&TIME) TOVAR(&new_time) FROMFMT(*HMS) TOFMT(*ISO)
-
RTVDTAARA (Retrieve Data Area): Retrieves the value of a time stored in a data area.
RTVDTAARA DTAARA(data_area_name) RTNVAR(&time)
-
CHGDTAARA (Change Data Area): Changes the value of a time stored in a data area.
CHGDTAARA DTAARA(data_area_name) VALUE(&new_time)
-
CVTTIM (Convert Time): Converts time from one time format to another.
CVTTIM TIME(&time) FROMTIMFMT(*HMS) TOTIMFMT(*ISO) TOVAR(&new_time)
-
CVTDAT (Convert Date): Converts a date from one format to another.
CVTDAT DATE(input_date) TOVAR(output_date) FROMFMT(*ISO) TOFMT(*MDY)
-
CVTDATDT (Convert Date to Date): Converts a date from one date format to another date format.
CVTDATDT DATE(&date) FROMFMT(*MDY) TOFMT(*ISO) TOVAR(&new_date)
-
RTVDAT (Retrieve Date): Retrieves the current date from the system.
RTVDAT DATE(&DATE)
-
RTVSYSVAL (Retrieve System Value): Retrieves the current date and time from the system.
RTVSYSVAL SYSVAL(QDATETIME) RTNVAR(&DATETIME)
User-Specific Commands
-
CHGUSRPRF (Change User Profile): Changes the attributes of a user profile.
CHGUSRPRF USRPRF(user_profile_name) PASSWORD(new_password)
-
CRTUSRPRF (Create User Profile): Creates a new user profile on the system.
CRTUSRPRF USRPRF(new_user_profile) PASSWORD(initial_password)
-
DLTUSRPRF (Delete User Profile): Deletes a user profile from the system.
DLTUSRPRF USRPRF(user_profile_name)
-
RTVUSRPRF (Retrieve User Profile): Retrieves information about a user profile.
RTVUSRPRF USRPRF(user_profile_name) OUTVAR(&profile_info)
-
CHGOWN (Change Object Ownership): Changes the ownership of an object.
CHGOWN OBJ(object_name) OBJTYPE(*FILE) NEWOWN(new_owner)
-
CHKPWD (Check Password): Checks the password for a user profile.
CHKPWD USRPRF(user_profile_name) PASSWORD(password_to_check) RTNVAR(&password_status)
-
WRKUSRPRF (Work with User Profiles): Displays a list of user profiles and allows for interactive management.
WRKUSRPRF
-
WRKUSRJOB (Work with User Jobs): Displays a list of jobs for a specified user.
WRKUSRJOB USER(user_profile_name)
-
GRTOBJAUT (Grant Object Authority): Grants authority to an object to a user profile or group profile.
GRTOBJAUT OBJ(object_name) OBJTYPE(*FILE) USER(user_profile_name) AUT(*CHANGE)
-
CHGSYSVAL (Change System Value): Changes the value of a system value.
CHGSYSVAL SYSVAL(QPWDEXPITV) VALUE(90)
List of AS/400 CL File Commands
-
CPYF (Copy File): Copies records from a source file to a target file.
CPYF FROMFILE(source_file) TOFILE(target_file) MBROPT(*REPLACE)
-
CRTPF (Create Physical File): Creates a physical file.
CRTPF FILE(library/physical_file) RCDLEN(112) TEXT('Description')
-
DLTF (Delete File): Deletes a file.
DLTF FILE(library/file_name)
-
RGZPFM (Reorganize Physical File Member): Reorganizes a physical file member to reclaim unused space.
RGZPFM FILE(library/physical_file) MBR(member_name)
-
RGZPF (Reorganize Physical File): Reorganizes a physical file to reclaim unused space.
RGZPF FILE(library/physical_file)
-
CHGPF (Change Physical File): Changes the attributes of a physical file.
CHGPF FILE(library/physical_file) SRCFILE(new_source_file)
-
WRKF (Work with File): Displays a list of files and allows you to perform various actions on them.
WRKF FILE(library/*ALL)
-
CPYFRMIMPF (Copy From Import File): Copies records from an import file to a database file.
CPYFRMIMPF FROMSTMF(import_file) TOFILE(library/database_file) MBROPT(*REPLACE) INDDS(indicator_data_structure)
-
CPYTOIMPF (Copy To Import File): Copies records from a database file to an import file.
CPYTOIMPF FROMFILE(library/database_file) TOSTMF(export_file) STMFCODPAG(*PCASCII)
Prepend Data to File using AS/400 CL Commands
-
Create Temporary File: Create a temporary file to hold the prepended data.
CRTPF FILE(library/temp_file) RCDLEN(100) TEXT('Temporary file for prepended data')
-
Copy Existing Data: Copy existing data from the original file to the temporary file.
CPYF FROMFILE(library/original_file) TOFILE(library/temp_file) MBROPT(*REPLACE)
-
Prepend New Data: Prepend new data to the temporary file (example: using CPYF command).
CPYF FROMFILE(library/prepend_data_file) TOFILE(library/temp_file) MBROPT(*ADD)
-
Replace Original File: Replace the original file with the contents of the temporary file.
DLTF FILE(library/original_file)
REN FILE(library/temp_file) TOFILE(library/original_file)
Append Data to File using AS/400 CL Commands
-
Open File: Open the file to which data will be appended.
OPNQRYF FILE(library/original_file) QRYSLT(*NONE) QRYSLT(*ALL)
-
Write Records: Write new data records to the end of the file.
CPYF FROMFILE(library/append_data_file) TOFILE(library/original_file) MBROPT(*ADD)
-
Close File: Close the file.
CLOF FILE(library/original_file)
Transfer Files Between Servers using FTP
The following example demonstrates how to transfer files between servers using FTP:
FTP RMTSYS('destination_server') 1 'destination_user' 'destination_password' 2 'ASCII' 3 'PUT /source_folder/source_file destination_file' 4 'QUIT'
In this example:
RMTSYS
: Specifies the destination server.destination_user
: Specifies the username for the destination server.destination_password
: Specifies the password for the destination server.ASCII
: Sets the transfer mode to ASCII (text mode). Alternatively, you can useBIN
for binary mode.PUT /source_folder/source_file destination_file
: Command to transfer the file from the source server to the destination server. Replacesource_folder
,source_file
, anddestination_file
with appropriate paths.QUIT
: Command to quit the FTP session.
This is just a basic example. You may need to adjust the commands based on your specific requirements, such as authentication methods, directory structures, and error handling.
Encryption
-
Prepare Data: Prepare the data you want to encrypt (e.g., in a physical file).
CRTPF FILE(library/data_file) ...
-
Call Encryption Utility: Call an external encryption utility or program from CL.
CALL PGM(YourEncryptionProgram) PARM('input_file' 'output_file')
- Handle Encrypted Data: Handle the encrypted data as needed (e.g., send it securely).
List of AS/400 CL Screen/Display Commands
-
Sound Indication: Sends an audible 'Ding!' to the system operator (*SYSOPR)
SNDMSG MSG('Ding!') TOUSR(*SYSOPR)
-
DSPF (Display File): Displays a display file.
DSPF FILE(library/display_file)
-
DSPFMT (Display Format): Displays a specific record format from a display file.
DSPFMT FILE(library/display_file) RECORDFORMAT(record_format)
-
DSPFD (Display File Description): Displays information about a file.
DSPFD FILE(library/file_name)
-
DSPDBR (Display Database Relations): Displays the relationships between files.
DSPDBR FILE(library/file_name)
-
DSPFFD (Display File Field Description): Displays the field descriptions of a file.
DSPFFD FILE(library/file_name)
-
DSPJOB (Display Job): Displays information about a specific job.
DSPJOB JOB(job_number)
-
DSPMSG (Display Message): Displays messages sent to the current user or job.
DSPMSG
-
DSPUSRPRF (Display User Profile): Displays information about a user profile.
DSPUSRPRF USRPRF(user_profile_name)
-
DSPNETA (Display Network Attributes): Displays network attributes.
DSPNETA
-
DSPFDLCK (Display File Locks): Displays file locks.
DSPFDLCK FILE(library/file_name)
Displaying Text in Color using AS/400 CL
Below is an example of using escape sequences to display text in color:
Note: This example demonstrates the concept of using escape sequences for color formatting. Actual implementation may vary based on terminal emulator or display device support.
-
CHGPRTF (Change Printer File): Changes attributes of a printer file.
/* Define a message with color escape sequences */ CRTMSG MSGID(COLOREXAMPLE) MSGF(QSYS/QCPFMSG) MSG('This is a message in color') + SEV(00) MSGTYPE(*INFO) TEXT('Message in color') /* Display the message */ SNDMSG MSGID(COLOREXAMPLE) MSGF(QSYS/QCPFMSG) TOMSGQ(*SYSOPR)
Prompt User to Select Printer
The following example demonstrates how to prompt the user to select a printer using the CHGPRTF
command:
This command prompts the user to select a printer when printing the my_report
file.
-
CHGPRTF (Printer Selection): Dialog
/* Prompt user to select printer */ CHGPRTF FILE(my_report) OUTQ(*SELECT)
List of AS/400 CL Printer Commands
-
CHGPRTF (Change Printer File): Changes attributes of a printer file.
CHGPRTF FILE(library/printer_file) DEV(device_name) ...
-
CHGOUTQ (Change Output Queue): Changes attributes of an output queue.
CHGOUTQ OUTQ(output_queue_name) ...
-
CRTPRTF (Create Printer File): Creates a printer file.
CRTPRTF FILE(library/printer_file) DEV(device_name) ...
-
CRTPRTDEV (Create Printer Device): Creates a printer device.
CRTPRTDEV PRTDEV(device_name) DEV(device_type) ...
-
DLTPRTF (Delete Printer File): Deletes a printer file.
DLTPRTF FILE(library/printer_file)
-
DLTOUTQ (Delete Output Queue): Deletes an output queue.
DLTOUTQ OUTQ(output_queue_name)
-
OVRPRTF (Override Printer File): Overrides printer file attributes.
OVRPRTF FILE(library/printer_file) ...
-
STRPRTWTR (Start Printer Writer): Starts a printer writer.
STRPRTWTR PRTDEV(device_name)
-
ENDPRTWTR (End Printer Writer): Ends a printer writer.
ENDPRTWTR PRTDEV(device_name)
-
WRKOUTQ (Work with Output Queue): Displays or manages output queues.
WRKOUTQ OUTQ(output_queue_name)
-
WRKWTR (Work with Writer): Displays or manages printer writers.
WRKWTR PRTDEV(device_name)
List of AS/400 CL Library Commands
-
ADDLIBLE (Add Library): Adds a library to the library list.
ADDLIBLE LIB(library_name)
-
CLRLIB (Clear Library): Deletes all objects from a library.
CLRLIB LIB(library_name)
-
CRTLIB (Create Library): Creates a new library.
CRTLIB LIB(library_name)
-
CRTDTAARA (Create Data Area): Creates a data area object.
CRTDTAARA DTAARA(data_area_name) TYPE(*CHAR) LEN(50) TEXT('Description')
-
CRTJOBQ (Create Job Queue): Creates a job queue.
CRTJOBQ JOBQ(job_queue_name) MAXACT(maximum_active_jobs)
-
CRTOUTQ (Create Output Queue): Creates an output queue.
CRTOUTQ OUTQ(output_queue_name)
-
CRTSRCPF (Create Source Physical File): Creates a source physical file.
CRTSRCPF FILE(library/source_file) RCDLEN(112)
-
DLTLIB (Delete Library): Deletes a library.
DLTLIB LIB(library_name)
-
DLTOBJ (Delete Object): Deletes an object from a library.
DLTOBJ OBJ(object_name) OBJTYPE(*ALL) + LIB(library_name)
-
RTVJOBA (Retrieve Job Attributes): Retrieves information about the current job.
RTVJOBA JOB(&JOBNBR) USER(&USER) NBR(&JOBNBR) TYPE(&TYPE)
-
RTVDTAARA (Retrieve Data Area): Retrieves the value from a data area.
RTVDTAARA DTAARA(data_area_name) RTNVAR(&variable)
-
SBMJOB (Submit Job): Submits a job to run in batch.
SBMJOB CMD(command_to_execute) JOB(job_name)
-
WRKACTJOB (Work with Active Jobs): Displays a list of active jobs.
WRKACTJOB
-
WRKUSRJOB (Work with User Jobs): Displays a list of jobs for a specific user.
WRKUSRJOB USER(user_name)
-
WRKSPLF (Work with Spooled Files): Displays a list of spooled files.
WRKSPLF SELECT(job_name)
Server Commands (ATTENTION! - Be careful with these
-
CHGNETA (Change Network Attributes): Changes the network attributes of the system.
CHGNETA CFGTCP OPTION(*IFC) OUTLMTWRK(150)
-
ENDTCPSVR (End TCP/IP Server): Ends a TCP/IP server on the system.
ENDTCPSVR SERVER(*HTTP)
-
STRTCPSVR (Start TCP/IP Server): Starts a TCP/IP server on the system.
STRTCPSVR SERVER(*FTP)
-
ENDSBS (End Subsystem): Ends a subsystem on the system.
ENDSBS SBS(subsystem_name) OPTION(*IMMED)
-
STRSBS (Start Subsystem): Starts a subsystem on the system.
STRSBS SBSD(subsystem_description)
-
ENDJOB (End Job): Ends a specified job on the system.
ENDJOB JOB(job_number/user_name)
-
ENDJOBABN (End Job Abnormally): Ends a specified job abnormally on the system.
ENDJOBABN JOB(job_number/user_name)
-
ENDSYS (End System): Ends the system and powers down the hardware.
ENDSYS OPTION(*CNTRLD)
-
RCLSTG (Reclaim Storage): Reclaims unused storage space on the system.
RCLSTG SELECT(*ALL) SEQ(*YES)
-
WRKSBS (Work with Subsystems): Displays a list of subsystems on the system.
WRKSBS
PGM /* Declare variables */ DCL VAR(&InputString) TYPE(*CHAR) LEN(50) DCL VAR(&OutputString) TYPE(*CHAR) LEN(50) DCL VAR(&Length) TYPE(*DEC) LEN(3 0) DCL VAR(&Index) TYPE(*DEC) LEN(3 0) /* Input string */ CHGVAR VAR(&InputString) VALUE('hELlo WoRlD') /* Convert to upper case */ CVTDBCS FROMCODEPAGE(37) TOCODEPAGE(37) FROMVAR(&InputString) + TOVAR(&OutputString) LEN(&Length) CHGVAR VAR(&OutputString) VALUE(%SST(&OutputString 1 &Length)) CHGVAR VAR(&OutputString) VALUE(%UCS2(&OutputString)) /* Proper case */ CHGVAR VAR(&OutputString) VALUE(%SST(&OutputString 1 1)) /* First character always upper case */ CHGVAR VAR(&Index) VALUE(1) LOOP: IF COND(&Index *LT &Length) THEN(DO) CHGVAR VAR(&Index) VALUE(&Index + 1) CHGVAR VAR(&Char) VALUE(%SST(&OutputString &Index 1)) IF COND(%BIN(&Char *GE x'41') *AND %BIN(&Char *LE x'5A')) THEN(CHGVAR VAR(&Char) VALUE(%UCS2(&Char))) /* Upper case */ ELSE CHGVAR VAR(&Char) VALUE(%LCASE(&Char)) /* Lower case */ CHGVAR VAR(&OutputString) VALUE(%SST(&OutputString 1 &Index - 1) || &Char || %SST(&OutputString &Index + 1)) GOTO CMDLBL(LOOP) ENDDO /* Output result */ SNDPGMMSG MSG(&OutputString) ENDPGM
Need Assistance?
Ever have an idea about a product or service but lack the ability to develop that idea? Are you looking for a reliable person/firm to build your software? Perhaps you are in need of someone to manage projects and teams?
Word of Mouth
[ Latest 10 ]