Solved

writing a simple program

Posted on 2004-10-13
7
1,072 Views
Last Modified: 2007-12-19
I am creating a program that retrieves the current date and job name using the RTVJOBA Command,retrieves the current time
using the RTVSYSVAL command, and send a message that says "clpgm was run on DATE and TIME with job name JN"

This is my first program and I am having a little trouble setting it up.  I would appreciate some insight on how I might be going about this wrong.  Here is what I have so far.

clpgm:        PGM

/* defines the variables used in the program   */

                  DCL VAR(&DATE)  TYPE(*CHAR)  LEN(6)
                  DCL VAR(&TIME)  TYPE(*CHAR)  LEN(6)
                  DCL VAR(&JN)      TYPE(*CHAR)  LEN(2)
/*  RETRIEVES THE CURRENT DATE AND JOB NAME   */

                  RTVJOBA          DATE(&DATE)
                  RTVJOBA          JOB(&JN)

/* RETRIEVES THE CURRENT TIME
     
                  RTVSYSVAL SYSVAL(QTIME) TRNVAR(&TIME)

/* SENDS MESSAGE CONTAINING THE TIME, DATEM AND JOB NAME  */

                 SNDUSRMSG MSG('CLPGM WAS RUN ON ' *CAT &DATE  +
                       ' AT ' *CAT &TIME ' WITH JOB NAME. ' *CAT &JN)

END;           ENDPGM

I know this isnt correct, I appreciate your help!
0
Comment
Question by:SinSual
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
blkline earned 500 total points
ID: 12304523
Type things:

1) JobName must be *CHAR (10) .   If you use prompting for the command RTVJOBA (use F4) you'll see the recommended field lengths in parenthesis.  

2) Save yourself some serious headaches trying to do that concatenation within the SNDUSRMSG command.  It'll drive you nuts.  Instead, do this:

DCL VAR(&MSG)  TYPE(*CHAR) LEN(80)

CHGVAR &MSG ('CLPGM WAS RUN ON ' *CAT &DATE *CAT ' AT ' *CAT &TIME *CAT ' WITH JOB NAME ' +
                                         *CAT &JN)
SNDUSRMSG (&MSG)

I hope you typed this program instead of cut-and-pasting because if you didn't, you missed the closing comment */ and you shouldn't use a semi-colon (;) between the tag END and ENDPGM.  It's:    END:    ENDPGM
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 12317253
Hi SinSual,

Just my opinion about the *CAT opcodes (you dont have to agree)

Never use the *CAT, *BCAT or *TCAT commands it makes it unreadable (my own opinion).
I use the availble replacements for the CAT commands, it makes the total string more readable
and 3 positions shorter per CAT. Wauw big deal 3 whole positions ???
Yes and that is a lot 4 opcodes is saving 12 positions this is 15% of your CL-source line

Just use :

*CAT = ||
*BCAT = |>
*TCAT = |<

Now your command will look like this (BTW you forget 1 *CAT between &DATE and ' AT '):

     SNDUSRMSG MSG('CLPGM WAS RUN ON ' || &DATE || ' AT ' || &TIME ||' WITH JOB NAME. ' || &JN)

or (look to the trailing spaces in the text)

     SNDUSRMSG MSG('CLPGM WAS RUN ON' |> &DATE |> 'AT' |> &TIME |> 'WITH JOB NAME.' |> &JN)

This is even works beter, because you will get rid of trailing spaces in variables.

e.g.  

             DCL        VAR(&MYNAME) TYPE(*CHAR) LEN(25)        
             DCL        VAR(&MSGTXT) TYPE(*CHAR) LEN(100)      
                                                               
             CHGVAR     VAR(&MYNAME) VALUE('SinSual')            
             CHGVAR     VAR(&MSGTXT) VALUE('Hi ' || &MYNAME || ' how are you')

the contents of &MSGTXT:
     Hi SinSual                  how are you

replacing the || with |> the contents of &MSGTXT:
     Hi SinSual how are you

replacing the || with |< the contents of &MSGTXT:
     Hi SinSualhow are you
0
 
LVL 27

Expert Comment

by:tliotta
ID: 12322344
Comment on *CAT, etc...

_ALWAYS_ use *CAT, *TCAT, etc., rather than the special characters. Some of the special characters belong to the variant set of characters and are interpreted by displays and printers differently depending on specific device settings. This really tends to mess programs up as years go by, new devices are added, new programmers come and go, etc. It can cause major headaches when program code gets posted to international websites or is shared between company branches that cross national boundaries.

As for the program problem, some errors in the posted code have been pointed out. But the original question doesn't mention what the problem is. Is there an error message? Is the displayed message showing incorrect data? Does the program fail? Does it not compile?

If the code was copy/pasted, that's one thing. If typed, that's another.

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 12322390
...Also, the program retrieves Job Date but also retrieves Current Time. It's a minor point, but those two values can be inconsistent. Perhaps instead of Job Date, the program could retrieve Current Date. Or instead of Current Time, the program could retrieve Job Start Time which would be more consistent with the message "...was run on..."

It doesn't matter much in this simple program, but a more complex and important program should be more accurate.

Tom
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question