View previous topic :: View next topic
|
Author |
Message |
vabond
New User
Joined: 15 Oct 2008 Posts: 3 Location: Oregon
|
|
|
|
Hello folks,
I have an Assembler CICS program that is called by multiple COBOL programs. I am trying to rewrite it in COBOL. The problem is that the various programs that call it pass a variable number of parms in the call.
I need to figure out how many parms were used to call this program.
I tried the ADDRESS OF with a comparison to nulls but it did not work.
Any suggestions?
Thanks in advance,
Victor |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Victor and welcome to the forum,
How does the assembler code detect the number of parms? |
|
Back to top |
|
|
vabond
New User
Joined: 15 Oct 2008 Posts: 3 Location: Oregon
|
|
|
|
The assembler program just counts the parms in the parm list until it finds the x'80' in the high order byte of the address.
Thanks |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Victor,
You could set a WS POINTER to the ADDRESS OF each parm, redefining the POINTER as PIC X(04) and then test the high-order byte of the redefined POINTER for a value not less than X'80'.
I never tried this so this is a SWAG on my part....
Bill |
|
Back to top |
|
|
vabond
New User
Joined: 15 Oct 2008 Posts: 3 Location: Oregon
|
|
|
|
Bill,
Tried your suggestion. No go. In fact, I displayed the addresses for each and they all appeared to have addresses. Not sure what COBOL is doing. Here is what it looks like:
Program A:
CALL PROGRAM-C USING PARM-1, PARM-2, PARM-3.
Program B:
CALL PROGRAM-C USING PARM-1, PARM-2, PARM-3, PARM-4.
Program C:
PROCEDURE DIVISION USING PARM-1, PARM-2, PARM-3, PARM-4.
Program C needs to be able to determine if it was called with 3 or 4 parms.
Thanks again. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Maybe this would be a stop-gap until a better solution presents itself.
Write a new little "filter" in assembler that always calls the cobol replacement module with 4 parameters. Keep the current logic to check for "last parm" and when this filter calls the replacement code, it would place a constant value in the unused parm(s) (i.e. "NONE", or x'FF', or whatever).
This would allow the cobol replacement of the business functionality quickly.
FWIW. . . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL Application Programming Guide says this:
Quote: |
4.2.1.3 Testing for OMITTED arguments
You can specify that one or more BY REFERENCE arguments are not to be passed to a called program by coding the OMITTED keyword in place of those arguments in the CALL statement. For example, to omit the second argument when calling program sub1, code this statement:
Call 'sub1' Using PARM1, OMITTED, PARM3
The arguments in the USING phrase of the CALL statement must match the parameters of the called program in number and position.
In a called program, you can test whether an argument was passed as OMITTED by comparing the address of the corresponding parameter to NULL. For example:
Program-ID. sub1.
. . .
Procedure Division Using RPARM1, RPARM2, RPARM3.
If Address Of RPARM2 = Null Then
Display 'No 2nd argument was passed this time'
Else
Perform Process-Parm-2
End-If
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
1. Program-C can not be a CICS module
(i.e. a module that invokes CICS APIs),
since Program-C is invoked via a COBOL CALL.
2. The COBOL compiler generates the necessary register population (the CALL)
and the code to provide addressability for linkage section entries (USING ).
3. Program-C's compiler generated code will always provide addressability to all four parms.
4. Program-C's address for parm-4 will be radically different for that of parm-3,
depending on if Program-C is CALLed from Program-A (3 parm CALL) or Program-B (4 parm CALL).
5. I don't think the OP wants to modify any Program-As or Program-Bs, so the OMIT is not to helpful.
don't have access to a mainframe until Monday, so I can not check anything out,
but, I believe what Bill suggested to do should have worked,
had his suggestion been implemented properly.
May not be the hex80,
as I can not remember if it is a simple 'move address'
or set register, move address that is generated by the compiler for the USING phrase.
But there should be an easy way to determine number of parms passed.
====================
If there are 3 or 4 parms, is there no code in parm-1,2,or 3 to indicate what is going on?
what actually does Program-C do?
I don't think the OP has a lot of experience.
OP mentioned that he had no idea what the COBOL code did for addressability.
That's not to tough since one only has to look at the object generated. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The last part of the manual I quoted said
Quote: |
Program-ID. sub1.
. . .
Procedure Division Using RPARM1, RPARM2, RPARM3.
If Address Of RPARM2 = Null Then
Display 'No 2nd argument was passed this time'
Else
Perform Process-Parm-2
End-If |
I have tested this using a batch program and a COBOL program can distinguish between being passed 3 and 4 parameters by testing the address of the 4th parameter to be NULL. I haven't done a lot of testing so I'm not sure if there are conditions that could affect the results, but the called program displayed different messages based on getting 3 or 4 parameters. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the fastest approach would be to have an assembler stub
to analyze the number of parameters passed
and call the cobol subroutine ( which has to be written yet , if I understand correctly)
with an augmented parameter list where the first parm is the number of the parms that follow |
|
Back to top |
|
|
|