Você está na página 1de 12

1.

To display the total size of the library:


2. How to send an E-mail from AS/400

3. How we can use EXCEPT Opcode with respect to data base operations.
4. To update particular field in the file using the EXCEPT Opcode
5. If we need a continuation field say of length 250, but after the column 12, then code the
program as follows.
6. iSeries (AS/400) FTP Tips and Techniques
7. How are the indicators accessed in the program?
8. File exception (INFDS) codes for database file.
9. How to look for OUTQ & Printer device for your AS/400 interactive job.
10. How to Debug a Batch Job
11. How to access user ID in RPG.

12. Can we dynamically use the dataarea in RPG?

13. How to know the caller of the calling program.


14. 14. How to downloading reports to pdf (Acrobat reader)
15. INFDS for Printer files.16. Information available is Program status data structure.
(PSDS)17. To convert the contents of the database field from Lower case to Upper case.
18) How to conditionally prompt a parameter in a command in CL?

1. To display the total size of the library:


Ans) DSPLIB LIB(libname) OUTPUT(*PRINT), then go to the spool and look the last
line of the spool, where you will be able to see a line like this: total : 1253376
2. How to send an E-mail from AS/400
Ans) PGM
PARM(&EMAIL &SUBJECT &MESSAGE)
DCL
VAR(&EMAIL) TYPE(*CHAR) LEN(50)
DCL
VAR(&SUBJECT) TYPE(*CHAR) LEN(44)
DCL
VAR(&MESSAGE) TYPE(*CHAR) LEN(250)
SNDDST TYPE(*LMSG) TOINTNET((&EMAIL)) +
DSTD(&SUBJECT) LONGMSG(&MESSAGE)
ENDPGM
Before running this enroll your profile in directory using WRKDIRE command.
3. How we can use EXCEPT Opcode with respect to data base operations.
Ans) EXCEPT opcode can be used to add/Update/delete a record in a file
Ex:Ftest
UF E
DISK
C
READ
test
C
IF
not %eof()
C
Except suri
C
ENDIF
C
SETON
LR
OREC1
EDEL
SURI
Where TEST is the name of the data base file and REC1 is the name of the record format.
4. To update particular field in the file using the EXCEPT Opcode

test

REC1

UF E
DISK
READ
test
IF
not %eof()
Eval
fld1 = '11111'
Except suri
ENDIF
SETON
E
SURI
fld1

LR

5. If we need a continuation field say of length 250, but after the column 12, then code the
program as follows.
DDS
A
DSPSIZ(24 80 *DS3)
A
CA03(03 'EXIT')
A
R CNTFLDA
A
FLD001
250 B 5 3CNTFLD(60)
A 90
DSPATR(UL)
A N90
DSPATR(PR)
RPG
FCNTFLD CF E
WORKSTN
C
EVAL
FLD001 = 'KEANE INDIA LIMITED HYD'
C
EVAL
FLD001 = %TRIM(FLD001) +
C
'KEANE INDIA LIMITED HYD'
C
EVAL
FLD001 = %TRIM(FLD001) +
C
'KEANE INDIA LIMITED HYD'
C
EVAL
FLD001 = %TRIM(FLD001) +
C
'KEANE INDIA LIMITED HYD'
C
DO
C
EXFMT CNTFLDA
C
IF
*IN03 = *ON
C
LEAVE
C
ENDIF
C
ENDDO
C
SETON
LR
As the CNTFLD is not supported for output fields, make use of DSPATR(UL) & DSPATR(PR)
to display the both field as output field.
6. iSeries (AS/400) FTP Tips and Techniques
1.
2.
3.
4.
5.
6.
7.

Automate the FTP transfer on the AS/400


Automated Batch Data Transfers from AS/400 to PC
Batch File Transfer via FTP
Batch FTP Between AS/400s
Copy source from the AS/400 to a PC
File PC to a AS/400 spool file?
FTP Problem

8. FTP Return Codes in Numeric Order


1. Automate the FTP transfer on the AS/400
To answer your implied future question, yes, you can automate the FTP transfer
on the AS/400. Place the FTP commands in a source member, then use:
OVRDBF FILE(INPUT) TOFILE(srclib/srcfile) MBR(ftpcmdmbr)
OVRDBF FILE(OUTPUT) TOFILE(srclib/srcfile) MBR(ftplogmbr)
and either
FTP RMTSYS(url)
or
FTP RMTSYS(*INTNETADR) INTNETADR(ipaddr)
and as always, clean up the overrides
DLTOVR FILE(INPUT)
DLTOVR FILE(OUTPUT)
You can use an RPG program (just to keep slightly on topic) to generate and
write the FTP commands to the source member. This gives you a lot of flexibility
in naming the files to be sent or received.
2. Automated Batch Data Transfers from AS/400 to PC
In a CL program, CPYTOIMPF to create a CSV file on the AS/400, and FTP the
resulting file to the PC. In my experience, the only way to get a truly useful
CSV from CPYTOIMPF is to create a stream file on the IFS, and use the *CRLF
record delimiter option.
For example:
CPYTOIMPF FROMFILE(MYLIB/MYFILE)
TOSTMF('/home/paul/myfile.csv')
MBROPT(*REPLACE)
RCDDLM(*CRLF)
Then, in the FTP session, use the command NAMEFMT 1 before doing a PUT to the
FTP server on the PC.
3. Batch File Transfer via FTP
http://www.as400network.com/nwn/story.cfm?ID=7719 Q. I'm trying to automate the
transfer of a PC .txt file to our AS/400 and then automatically trigger a
conversion program to integrate the data into our data files. I wrote a .bat
file that uses Rumba AS/400 file transfer to upload the file to the AS/400. I
now must call a CL program from within the .bat file. Can I do this and, if so,

how?
A. Although you can't do this with Rumba's file transfer, you can easily do it
with FTP. Although FTP's primary function is to perform file transfers, you can
use its RCMD subcommand to execute commands and programs on the AS/400. RCMD is
handy for launching AS/400 jobs that process the transferred files. The
following sample FTP command line shows how you can execute under Windows NT a
batch FTP job that performs a file transfer and calls an AS/400 program.
ftp -n -i -s:ftp400cmd.txt S101AA0A
The ftp command starts the Windows FTP application, and the -n and -i switches
indicate that the program will run in batch mode and won't perform any
interactive prompting. At the end of the line, S101AA0A specifies the name of
the AS/400 host system. The -s: switch specifies a file that contains the FTP
subcommands to be executed.
The contents of the ftp400cmd.txt file are as follows:
USER myID
myPWD
cd QGPL
put myfile.txt
quote rcmd call pgm(mylib/mypgm)
quit
The first line supplies the user ID used to connect to the AS/400, and the
second line supplies the password. Note that by default these values are sent
across the network in clear text. Although this is probably fine for most
internal networks, you shouldn't do this for public Internet access. The cd
subcommand changes the AS/400's current library to QGPL. The put subcommand
sends the file myfile.txt from the Windows NT system to the AS/400's QGPL
library. Next, the quote rcmd subcommands execute AS/400 program mypgm in mylib.
Finally, the quit subcommand terminates the FTP session. -- Michael Otey,
NEWS/400 Senior Technical Editor
4. Batch FTP Between AS/400s
To initiate an automatic batch FTP transfer from an AS/400, first create a
script in a source physical file containing valid FTP commands. To get it to
work in batch (that is, without user input) when you run the FTP session, you
must create a file override on a file called INPUT that tells the AS/400's FTP
client where to retrieve the commands from (instead of from the keyboard, as it
normally would). Thus, you override INPUT to point to your FTP script. If you
want to capture the FTP session's results, you also must override a file called
OUTPUT to a member where the session will be logged.
For example, to transfer member HISMBR in file HISFILE in HISLIB from remote
AS/400 HISAS400 to member MYMBR in file MYFILE in library MYLIB on MYAS400, use

the following script, which I've named FTPCMDS in the source file FTPSRC on the
AS/400 originating the FTP session (MYAS400):
MYUSER PASSIT
GET HISLIB/HISFILE.HISMBR MYLIB/MYFILE.MYMBR
QUIT
This script works for source file members. To use the script, start the FTP
server on the remote system (HISAS400) with the command STRTCPSVR *FTP. Then,
execute the following CL program on the source system (MYAS400):
PGM
OVRDBF FILE(INPUT) TOFILE(FTPSRC) MBR(FTPCMDS)
CLRPFM FTPSRC/OUT
OVRDBF FILE(OUTPUT) TOFILE(FTPSRC) MBR(OUT)
FTP HISAS400
ENDPGM
For this CL program to work, you must create a member called OUT in the FTPSRC
file, which will contain the responses from the remote AS/400. Look in this
member for any messages for debugging/error checking.
Note that the user ID and password must be stored in the FTP command source
member, so be sure to secure that member appropriately.
The above NEWS/400 tip is from Terry Silva.
5. Copy sources from the AS/400 to a PC
You can use the MGET FTP command.
From a DOS prompt on your PC:
ftp as400name
userid
password
prompt
quote site namefmt 1
mget QSYS.LIB/library.LIB/sourcefile.FILE/*.MBR
quit
The "prompt" command keeps FTP from asking you to confirm each transfer. You
could leave out the "quote site namefmt 1" command and use "mget
library/sourcefile.*" instead. Doing it that way will save the members on
the PC as "sourcefile.member". Switching to namefmt 1 as shown above will
save the members on the PC as "member.MBR".
6. File PC to a AS/400 spool file?
This will work for printing a file from a PC via FTP:
ftp as400
Name (as400:klemscot): klemscot

331 Enter password.


Password:
230 KLEMSCOT logged on.
ftp> cd qsys
250 Current library changed to QSYS.
ftp> ascii
200 Representation type is ASCII nonprint.
ftp> put myfile.txt qsysprt
local: myfile.txt remote: qsysprt
200 PORT subcommand request successful.
150 Sending file to member QSYSPRT in library QSYS.
250 File transfer completed successfully.
4240 bytes sent in 0.49 seconds (8.49 KB/s)
ftp> quit
221 QUIT subcommand received.
7. FTP Problem
http://www.as400network.com/nwn/story.cfm?ID=9480 Q. When I FTP a database file
from one AS/400 to another, records and some data are often missing. Is there a
bug in FTP?
A. There's no support in FTP for special numeric formats such as packed decimal
and zoned decimal. To send a file that contains these formats, you must use
either a transfer type of TYPE I (BINARY) or TYPE E (EBCDIC) with a transmission
mode of BLOCK; these transfer types send the data "as is" without requiring
conversion. Other transfer type results are unpredictable. In addition, you must
create the file on the target AS/400 (using DDS source) before transferring the
data.
You can also save the file in a save file, FTP (in binary mode) the save file to
a save file on the target AS/400, and then restore the file on the target
system.
To transfer an AS/400 externally described file with special numeric formats to
a non-AS/400 system, you must first copy the file to a file without these
formats (printable form) and then FTP this temporary file to the non-AS/400
system.
8. FTP Return Codes in Numeric Order
110 Restart marker reply. In this case, the text is exact and not left to the
particular implementation; it must read: MARK yyyy = mmmm where yyyy is
User-process data stream marker, and mmmm server's equivalent marker (note the
spaces between markers and "=").
120 Service ready in nnn minutes.
125 Data connection already open; transfer starting.
150 File status okay; about to open data connection.

200 Command okay.


202 Command not implemented, superfluous at this site.
211 System status, or system help reply.
212 Directory status.
213 File status.
214. Help message. On how to use the server or the meaning of a particular
non-standard command. This reply is useful only to the human user.
215. NAME system type. Where NAME is an official system name from the list in
the Assigned Numbers document.
220. Service ready for new user.
221 Service closing control connection.
225. Data connection open; no transfer in progress.
226 Closing data connection. Requested file action successful (for example,
File transfer or file abort).
227. Entering Passive Mode (h1, h2, h3, h4, p1, p2).
230. User logged in, proceed. Logged out if appropriate.
250 Requested file action okay, completed.
257 "PATHNAME" created.
331 User name okay, need password.
332 Need account for login.
350 Requested file action pending further information
421 Service not available, closing control connection.This may be a reply to
any command if the service knows it must shut down.
425 Can't open data connection.
426 Connection closed; transfer aborted.
450 Requested file action not taken.
451 Requested action aborted. Local error in processing.
452 Requested action not taken. Insufficient storage space in system.File
unavailable (e.g., file busy).
500 Syntax error, command unrecognized. This may include errors such as
command line too long.
501 Syntax error in parameters or arguments.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
530 Not logged in.
532 Need account for storing files.
550 Requested action not taken. File unavailable (e.g., file not found, no
access).
551 Requested action aborted. Page type unknown.
552 Requested file action aborted. Exceeded storage allocation (for current
directory or dataset).
553 Requested actions not taken. File name not allowed.

NARRATIVE - This program FTP function transfers ATB summary data (comma
delimited) to the finance shared corporate drive. FTP script instruction used to deliver
data are defined in file ARPFTPS.
PGM
PARM(&RMTSYSNAM)
DCL
VAR(&RMTSYSNAM) TYPE(*CHAR) LEN(30)
CLRPFM FILE(*LIBL/ARPFTPL)
OVRDBF FILE(INPUT) TOFILE(*LIBL/ARPFTPS)
OVRDBF FILE(OUTPUT) TOFILE(*LIBL/ARPFTPL)
FTP
RMTSYS(&RMTSYSNAM)
DLTOVR FILE(ARPFTPS)
MONMSG MSGID(CPF0000)
DLTOVR FILE(ARPFTPL)
MONMSG MSGID(CPF0000)
ENDPGM
Info:- For &RMTSYSNAM we need to pass the IP address or system name.
File ARPFTPS is used for logging the FTP commands to be executed. One such example is
listed below,
FINFTP FINFTP
CD /
CD /SYS2/SHARED/ATBREPT
PUT TARCUST/ARPATBWK HSDATB.XLS
QUIT
Where FINFTP is the Remote User ID and FINFTP is Password.
File ARPFTPL is used for logging the FTP messages. System will take care of logging the
messages in to the file. File is a flat file with 120A length field.
7. How are the
Ans) *IN
*IN(XX)
*INXX

indicators accessed in the program?


To access all the indicators(o to 99)
To access indicator starting from XX to 99
To access the particular indicator XX.

8. File exception (INFDS) codes for database file.


FMYFILE IF E DISK INFDS(FILEFBK)
*
DFILEFBK DS
D FILE
*FILE
* File name
D OPEN_IND 9 9N
* File open?
D EOF_IND 10 10N
* File at eof?
D STATUS
*STATUS
* Status code
D OPCODE
*OPCODE
* Last opcode
D ROUTINE *ROUTINE
* RPG Routine
D LIST_NUM 30 37
* Listing line

D SPCL_STAT 38 42S 0
* SPECIAL status
D RECORD
*RECORD
* Record name
D MSGID
46 52
* Error MSGID
D SCREEN
*SIZE
* Screen size
D NLS_IN
*INP
* NLS Input?
D NLS_OUT *OUT
* NLS Output?
D NLS_MODE *MODE
* NLS Mode?
Example of Coding an INFDS with File Feedback Information
9. How to look for OUTQ & Printer device for your AS/400 interactive job.
Look for the value in the PRTDEV parameter of the job description is *USRPRF, which tells
the system to look at the PRTDEV parameter in user profile. If the value in the parameter
is *WRKSTN, which tells the system to look at the PRTDEV parameter in the work station
description.
Commands to use,
DSPJOBD, WRKUSRPRF, DSPDEVD DEVD(QPADEV0007)
Ref os/400 Printer device programming V5R1
10. How to Debug a Batch Job
Ans)

Open two sessions :


S No

1
2

Session 1

Submit a batch job for the program,


press F10 for additional parameters
and say HOLD = *Yes
Work with Submit Job
(WRKSBMJOB)

3
4

Session 2

Release the job by taking 6 option


for the job on hold.

Start Service Job (STRSRVJOB) with the


job details (name, user and number)
Start Debug (Note: it will not allow to
add any breakpoint as the job is being
serviced in this session, Press F12 to
come out of Debug Source
It will display a message Press Enter to
Start the Job and F10 to enter debug
Press F10, say DSPMODSRC on
command Line and add the breakpoints.
Press F12 two times to come back to the
message screen
Press enter to start the job ( it will debug
the program now)

To End the Debug .


S No

Session 1

Kill the job by taking option 4

Session 2

2
3

End Debug (ENDDBG)


End Service Job (ENDSRVJOB)

11. How to access user ID in RPG.


Ans) We can use following code to access the user ID,
Duser
S
10 INZ(*USER)
C USER
DSPLY
C
SETON
LR
OR
Use the positions 358 367 or 254 263 in the program status data structure to trap the
User ID
12. Can we dynamically use the dataarea in RPG?
Ans) If I have DtaAraNameIn defined as an *entry parm, then declare and use as follows.
D DtaAreaNameWrk UDS
DTAARA(*VAR : DtaAraNameIn)
D DtaAraFld1
1 30
D DtaAraFld2
31 33
And from now on make all program references to DtaAreaNameWrk (and its
subfields)
13. How to know the caller of the calling program.
In Parameter P$CALLED you pass your actual program. (Position 1 - 10 from Program
Status Datastructure)
In Parameter P$CALLER the caller program is returned.
CL-Program:
PGM
PARM(&P$CALLER &P$CALLED)
DCL
VAR(&P$CALLER) TYPE(*CHAR) LEN(10)
DCL
VAR(&P$CALLED) TYPE(*CHAR) LEN(10)
DCL
VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
DCL
VAR(&SENDER) TYPE(*CHAR) LEN(80)
SNDPGMMSG MSG('TEST') TOPGMQ(*PRV (&P$CALLED)) +
MSGTYPE(*RQS) KEYVAR(&MSGKEY)
RCVMSG PGMQ(*PRV (&P$CALLED)) MSGKEY(&MSGKEY) +
SENDER(&SENDER)
CHGVAR VAR(&P$CALLER) VALUE(%SST(&SENDER 56 10))
ENDE: ENDPGM
Link for REDBOOKS
http://publib-b.boulder.ibm.com/Redbooks.nsf/redbooks/
14. How to downloading reports to pdf (Acrobat reader)
Ans) The command, which copies from a spool file to a .pdf document on the IFS is,

CVTSPLSTMF FROMFILE(PRTFLNAME) TOSTMF(NAME.PDF) TODIR('/qdls/foldername/')


SPLNBR(99) TOFMT(*PDF) STMFOPT(*REPLACE) PAGESIZE(*LETTER
*PORTRAIT)
15. INFDS for Printer files.
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++
+Comments++
FMYFILE O F 132 PRINTER INFDS(OPNFBK)
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++
+Comments
DOPNFBK DS
D ODP_TYPE
81 82
* ODP Type
D FILE_NAME
83 92
* File name
D LIBRARY
93 102
* Library name
D SPOOL_FILE
103 112
* Spool file name
D SPOOL_LIB
113 122
* Spool file lib
D SPOOL_NUM
123 124I 0
* Spool file num
D RCD_LEN
125 126I 0
* Max record len
D KEY_LEN
127 128I 0
* Max key len
D MEMBER
129 138
* Member name
D TYPE
147 148I 0
* File type
D ROWS
152 153I 0
* Num PRT/DSP rows
D COLUMNS
154 155I 0
* Num PRT/DSP cols
D NUM_RCDS
156 159I 0
* Num of records
D ACC_TYPE
160 161
* Access type
D DUP_KEY
162 162
* Duplicate key?
D SRC_FILE
163 163
* Source file?
D VOL_OFF
184 185I 0
* Vol label offset
D BLK_RCDS
186 187I 0
* Max rcds in blk
D OVERFLOW
188 189I 0
* Overflow line
D BLK_INCR
190 191I 0
* Blk increment
D FLAGS1
196 196
* Misc flags
D REQUESTER
197 206
* Requester name
D OPEN_COUNT
207 208I 0
* Open count
D BASED_MBRS
211 212I 0
* Num based mbrs
D FLAGS2
213 213
* Misc flags
D OPEN_ID
214 215
* Open identifier
D RCDFMT_LEN
216 217I 0
* Max rcd fmt len
D CCSID
218 219I 0
* Database CCSID
D FLAGS3
220 220
* Misc flags
D NUM_DEVS
227 228I 0
* Num devs defined
Example of Coding an INFDS with Open Feedback Information File Exception/Errors
16. Information available is Program status data structure.(PSDS)
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++Comments++++++++++
DMYPSDS SDS
D PROC_NAME *PROC
* Procedure name
D PGM_STATUS *STATUS
* Status code
D PRV_STATUS 16 20S 0
* Previous status
D LINE_NUM
21 28
* Src list line num
D ROUTINE
*ROUTINE
* Routine name
D PARMS
*PARMS
* Num passed parms
D EXCP_TYPE 40 42
* Exception type
D EXCP_NUM 43 46
* Exception number
D PGM_LIB
81 90
* Program library
D EXCP_DATA 91 170
* Exception data
D EXCP_ID
171 174
* Exception Id
D DATE
191 198
* Date (*DATE fmt)
D YEAR 199 200S 0
* Year (*YEAR fmt)
D LAST_FILE
201 208
* Last file used
D FILE_INFO
209 243
* File error info
D JOB_NAME
244 253
* Job name

D USER
254 263
* User name
D JOB_NUM
264 269S 0
* Job number
D JOB_DATE
270 275S 0
* Date (UDATE fmt)
D RUN_DATE
276 281S 0
* Run date (UDATE)
D RUN_TIME
282 287S 0
* Run time (UDATE)
D CRT_DATE
288 293
* Create date
D CRT_TIME
294 299
* Create time
D CPL_LEVEL 300 303
* Compiler level
D SRC_FILE
304 313
* Source file
D SRC_LIB
314 323
* Source file lib
D SRC_MBR
324 333
* Source file mbr
D PROC_PGM 334 343
* Pgm Proc is in
D PROC_MOD 344 353
* Mod Proc is in
Example of Coding a PSDS Program Exception/Errors
17. To convert the contents of the database field from Lower case to Upper case.

In a logical you can use the file-level keyword ALTSEQ(QSYSRTNTBL) to convert the key fields
of the file to all upper case.
To do that to an individual field, you have to map the entire file (that is list all the fields you want in
the logical) and specify the TRNTBL(QSYSTRNTBL) keyword at the field-level

18) How to conditionally prompt a parameter in a command in CL?


Value
Passed
to CPP if
Value
You Enter
??KEYWORD()
??KEYWORD(VA
?*KEYWORD()
?*KEYWORD(VA
?<KEYWORD()
?<KEYWORD(VA
?/KEYWORD()
?/KEYWORD(VA
?-KEYWORD()
?-KEYWORD(VA
?&KEYWORD()
?&KEYWORD(VA
?%KEYWORD()
?%KEYWORD(VA

Displayed
Default
UValue
Default
UValue
Default
UValue
Default
UValue
None
UNone
Default
UValue
Default
UValue

Protected
No
No
Yes
Yes
No
No
Yes
Yes
N/A
N/A
No
No
Yes
Yes

Nothing

Marked with

Specified
Default
Value
Default
Value
Default
Default
Default
Default
Default
Value
Default
Default
Default
Default

> Symbol
No
Yes
No
Yes
No
No
No
No
N/A
N/A
No
No
No
No

Você também pode gostar