?
Solved

writing a simple program

Posted on 2004-10-13
7
Medium Priority
?
1,086 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
blkline earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

764 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