Solved

writing a simple program

Posted on 2004-10-13
7
1,058 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now