• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1104
  • Last Modified:

writing a simple program

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
SinSual
Asked:
SinSual
  • 2
1 Solution
 
blklineCommented:
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
 
theo kouwenhovenCommented:
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
 
tliottaCommented:
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
 
tliottaCommented:
...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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now