# Automation in AS400



## vasuvv (Mar 23, 2012)

Hi,

I want to write an automation script for the below requirement for AS400.

1. *Automation for :*
SENDING REPORT TO DISTRIBUTED MAIL LIST OF WRKACTJOB ,WRKJOBSCDE,WRKJOBJS.

Dsplog job(Job_name) for this we need to send those log files with as an attachement to the distributed mail list.

2. *Description*

Jobs have high medium and low priority, we can send report to our DL every half an hour regarding the job status, start time, end time, description. This can be done for only medium and low priority jobs. High priority jobs need to be looked at that time 

3. *Purpose*

Manual effort will reduce. Suppose there are 100 jobs , only 20 jobs will be high priority. So our team need to check for the high priority jobs and can monitor mail box for the rest

Please look into this and guide me to write an automation script.

Thanks,
Vasu.


----------



## DrSheldonCooper (Mar 16, 2012)

What language do you wish to use, and what are you skilled in. I strongly suggest using C++ for the myfile functions.


----------



## vasuvv (Mar 23, 2012)

Hi,

I want to write the code using AS400 (RPG/CL) .

Thanks


----------



## DrSheldonCooper (Mar 16, 2012)

Hmm, I've never heard of that before, unfortunately many people probably wouldn't either. I would suggest you write several scripts. If there are 3 different levels, make 3, one mass-mails to the first group, the second to another, etc.


----------



## vasuvv (Mar 23, 2012)

Is it possible to write the code through Javascript/xml/HTML/C. If possible please provide me the code.


----------



## DrSheldonCooper (Mar 16, 2012)

HTML and XML are markup languages, so probably not. Javascript I cannot speak for, I have very little programming experience with Javascript. C/C++ would be better languages to use, as I can confirm they will work. Unfortunately, I am not trained in C, only C++, yes the syntax is similar, but my scripting would be incorrect.


----------



## Ninjaboi (Dec 27, 2010)

Hello vasuvv!

You have specified some program requirements here, but I was confused as to what you intended it to do. It sounds like you want a program that saves logs of job details and allows the user to select if that job is 'High', 'Medium', or 'Low' priority to be looked at by your staff. Whether or not that's what you meant will probably be answered in your next response.



> Hi,
> 
> I want to write the code using AS400 (RPG/CL) .
> 
> Thanks


I haven't heard or used AS400 until I saw your previous post requesting to post a thread of it in the Programming section of TSF. Not sure if it's only popular with developers for the AS400 machine or not, but I'm not sure we have developers here at TSF that use it enough to help you greatly with it.



> Is it possible to write the code through Javascript/xml/HTML/C. If possible please provide me the code.


For this particular task set that the program needs to accomplish ( based on what I _thought_ you intended, which might be different from what you intended, apologies for being a bit confused ) you could use any of those languages successfully. 

All those languages support in some way or another sending files and/or emails, which your program would require for the logs of jobs. They also could make basic GUI items that could be used to get the log data displayed cleanly in the program as well as set/show the priority level of the job.

Sheldon was right about HTML and XML not being able to do what you need alone though. Javascript can be integrated into an HTML web page file that could be used for the program you want, and it would do what you need it to do. I assume you chose to ask if it could be done in those languages because you saw them in Sheldon's signature ( though C and C++ are different languages, but I think you just made your typing quicker and ignored the '++' ). It's a smart idea to see if the people helping you know languages that you know for the task at hand, but I don't think it would help you if you're not proficient in those languages yourself. If the only language you know is AS400, the best options for you are:

*1*. Develop the program in AS400, posting questions and problems you have along the way here so we can do our best to answer them.

*2*. Assemble another person or even a small group of colleagues that you know develop applications and are willing to help you build it ( assuming they also know AS400 ).

*3*. Learn a new language that's more widely used so that you have an easier time seeking help.

*4*. Hire a developer to create the application for you.

I highly recommend the first one, as the other options are more extreme. Since you seem to know a language already ( AS400 ), it's probably not your desire to hire another programmer to do the job for you. If all you're wanting is to have this program created, not necessarily get to make it yourself, then hiring someone might not be a bad option at all. I couldn't quite tell if you were asking us to develop it for you and give you the code or not, so I'll leave that alone for now.

If you do decide to not use AS400 and try another language for the job, do tell us so that we understand that you made a change. We are more than willing to help you, but unfortunately it's hard to help when we don't know or use the language(s) you use or choose.


----------



## vasuvv (Mar 23, 2012)

Hi all at last have written the code... Please look into the following code and let me know is it possible to write it in Perl/Shell.Please find the below code.
<code>

PGM PARM(&SPLF &JOB &PSPLNBR &SPFSIZE +
&EMAIL &SUBJCT &MESSAG)

DCL VAR(&SPLF) TYPE(*CHAR) LEN(10)
DCL VAR(&JOB) TYPE(*CHAR) LEN(26)
DCL VAR(&JOBNAM) TYPE(*CHAR) LEN(10)
DCL VAR(&USRNAM) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&PSPLNBR) TYPE(*CHAR) LEN(4)
DCL VAR(&NSPLNBR) TYPE(*DEC) LEN(6)
DCL VAR(&SPLNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&SPFSIZE) TYPE(*CHAR) LEN(3)
DCL VAR(&EMAIL) TYPE(*CHAR) LEN(40)
DCL VAR(&SUBJCT) TYPE(*CHAR) LEN(44)
DCL VAR(&MESSAG) TYPE(*CHAR) LEN(255)
DCL VAR(&PFILE) TYPE(*CHAR) LEN(10)
DCL VAR(&PCFILE) TYPE(*CHAR) LEN(10)
DCL VAR(&INTADD) TYPE(*CHAR) LEN(56)

MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ABEND))

/* resolve the job parameter */
IF COND(%SST(&JOB 1 1) *EQ '*') THEN(DO)
RTVJOBA JOB(&JOBNAM) USER(&USRNAM) NBR(&JOBNBR)
ENDDO
ELSE CMD(DO)
CHGVAR VAR(&JOBNAM) VALUE(%SST(&JOB 1 10))
CHGVAR VAR(&USRNAM) VALUE(%SST(&JOB 11 10))
CHGVAR VAR(&JOBNBR) VALUE(%SST(&JOB 21 6))
ENDDO

/* resolve the spool file number parameter */
CHGVAR VAR(&NSPLNBR) VALUE(%BIN(&PSPLNBR))
IF COND(&NSPLNBR *EQ 0) THEN(DO)
CHGVAR VAR(&SPLNBR) VALUE(*ONLY)
ENDDO
ELSE CMD(IF COND(&NSPLNBR *EQ -1) THEN(DO))
CHGVAR VAR(&SPLNBR) VALUE(*LAST)
ENDDO
ELSE CMD(IF COND(&NSPLNBR *EQ -2) THEN(DO))
CHGVAR VAR(&SPLNBR) VALUE(*ANY)
ENDDO
ELSE CMD(DO)
CHGVAR VAR(&SPLNBR) VALUE(%BIN(&PSPLNBR))
ENDDO

CHGVAR VAR(&INTADD) VALUE(&EMAIL *TCAT '@yourcompany.com')
CHGVAR VAR(&PFILE) VALUE(%SST(&SPLF 1 6))
CHGVAR VAR(&PCFILE) VALUE(&PFILE *TCAT '.TXT')
CRTPF FILE(QTEMP/&PFILE) RCDLEN(&SPFSIZE)
CHGPF FILE(QTEMP/&PFILE) SIZE(100000 10000 9)
IF COND(&SPLNBR *NE ' ') THEN(DO)
CPYSPLF FILE(&SPLF) TOFILE(QTEMP/&PFILE) +
JOB(&JOBNBR/&USRNAM/&JOBNAM) SPLNBR(&SPLNBR)
MONMSG MSGID(CPF3303) EXEC(GOTO CMDLBL(ERR))
ENDDO
ELSE DO
CPYSPLF FILE(&SPLF) TOFILE(QTEMP/&PFILE) +
JOB(&JOBNBR/&USRNAM/&JOBNAM) SPLNBR(*LAST)
MONMSG MSGID(CPF3303) EXEC(GOTO CMDLBL(ERR))
ENDDO
CRTFLR FLR(SNDESPFF) TEXT('Temporary folder for +
SNDESPF Command usage')
MONMSG MSGID(CPF8A85) /* In case it exist */
CPYTOPCD FROMFILE(QTEMP/&PFILE) TOFLR(SNDESPFF) +
FROMMBR(&PFILE) TODOC(&PCFILE) +
REPLACE(*YES) TRNTBL(*DFT)
CHGDOCD DOC(&PCFILE) FLR(SNDESPFF) DOCD(&SUBJCT)
SNDDST TYPE(*DOC) TOINTNET((&INTADD)) DSTD(MAIL) MSG(&MESSAG) +
SNDFMT(*NOCHG) DOC(&PCFILE) FLR(SNDESPFF) ALWX400CNV(*YES)
SNDPGMMSG MSG('E-Mail was sent to ' *CAT &INTADD)
DLTDLO DLO(*ALL) FLR(SNDESPFF)
MONMSG MSGID(CPF8A77) /* In case it was deleted */
DLTF FILE(QTEMP/&PFILE)
GOTO CMDLBL(END)
ERR: SNDPGMMSG MSG('The specified spool file does not exist.')
END: RETURN
ABEND:
/* cancel the program */
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('SNDESPF +
ended abnormally; see job log.') +
MSGTYPE(*ESCAPE)
MONMSG MSGID(CPF0000)
ENDPGM
</code>

if it is possible to write the code please guide me to write it in Shell/Perl

Thanks.


----------



## Ninjaboi (Dec 27, 2010)

Hello vasuuv.

It is possible, but I don't think you need to write it in another language if the current language you used made the program you wanted. If you're having compatibility issues with the compiler and the OS you're targeting, you can tell us and we can do some research on it for you in order to get you a new compiler ( or setup the existing one to work ).


----------

