Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CL to Cobol parameter

Status
Not open for further replies.

confusedlady

Programmer
Apr 26, 2001
163
US
I am trying to pass a negative value to a Cobol program. I am not able to alter the existing Cobol program, only the CL I am writing. In the Cobol program, the field is defined as S9(6), so my question is, how do I need to define the value in the CL?

For example, how would I pass say -145? This is a value entered by the user, so it first is a parameter for the CL. As it is, if the user wished to pass positive 145, I just have it defined as CHAR (6), and alls fine, but can't get that - to go! I hope this makes sense........
 
Please suply the exact COBOL definition, including any COMP-XXX used. This will affect the solution.

Depending on this you will need to define the CL variable differently, and eventually you will need to mess with the %DEC %BIN functions, or even do some string manipulation.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Oh, sorry. The Cobol definition is just PIC S9(6) (no compXXX).
 
I suspect you need to pass it in with a sign overpunch. That is, the last of the 6 digits needs to indicate the sign as follows:

0 = }
1 = J
2 = K
...
9 = R

so -145 would be 00014N

Regards.

Glenn
 
3GM,
Could you elaborate on what you're saying? Is this in conjunction with using the %BIN function, as suggested in previous post?

Sorry for all the questions. I haven't used that function before....
 
Ok. With that information it is clear what you have.

So

COBOL (PGM1)
Linkage Section
01 var1 pic S9(6).
procedure using var1.
m1.
display var1.

CL
DCL VAR(&V1) *DEC LEN(6) value(-10)

doing a straight
call pgm1 parm(&v1)
will not work as decimal fields are sent as packed fields (e.g. COMP-3 or COMP-4). not sure now.

doing
DCL VAR(&V2) *CHAR LEN(11)
chgvar &V2 &V1
call pgm1 parm(&v2)
will not work either as
&V2 will contain a numeric field with leading sign
(e.g. 01 VX PIC -9(6) SIGN LEADING SEPARATE.)

So solution is to perform some string manipulation.

CL
DCL VAR(&V1) *DEC LEN(6) value(-10)
DCL VAR(&V2) *CHAR LEN(7)
DCL VAR(&V3) *CHAR LEN(6)
DCL VAR(&V4) *CHAR LEN(1)
chgvar &V2 &V1
if cond(&v1 *GE 0) then(DO)
GOTO CMDLBL(POSITIVE)
if cond(%sst(&v2 7 1) *eq 0) THEN(DO)
chgvar &v4 '}'
ELSE
if cond(%sst(&v2 7 1) *eq 1) THEN(DO)
chgvar &v4 'J'
ELSE
if cond(%sst(&v2 7 1) *eq 2) THEN(DO)
chgvar &v4 'K'
ELSE
if cond(%sst(&v2 7 1) *eq 3) THEN(DO)
chgvar &v4 'L'
Do for all the below cases.
Case "}": i = 0
Case "J": i = 1
Case "K": i = 2
Case "L": i = 3
Case "M": i = 4
Case "N": i = 5
Case "O": i = 6
Case "P": i = 7
Case "Q": i = 8
Case "R": i = 9
chgvar &v3 %sst(&v2 2 5) *TCAT %sst(&v4)
GOTO CMDLBL(CALLPGM)
POSITIVE:
chgvar &v3 %sst(&v2 2 6)
CALLPGM:
CALL PGM1 PARM(&V3)


The above should enable you to do the program.

Another option would be to create a cobol program that accepts a numeric field and returns a char field on the correct format.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
If the COBOL picture is S9(6), is a zoned format. Example values:

-000001 = X'F0F0F0F0F0D1'
+000001 = X'F0F0F0F0F0C1'
000001 = X'F0F0F0F0F0F1'

The last format is in fact not 100% guaranteed valid, because the cobol picture has a sign and the data not. It can even depend on the compiler options if a numeric test is positive.

The length of the cobol picture is fixed.

The first nibble of the last byte contains the sign. The D is negative, the C positive and F is neutral.

I hope this helps you.

Regards,

Crox
 
Crox -

The poster appears to be running under VMS (note the references to CL) and therefore (I assume) using ASCII, not EBCDIC. Zone overpunches really only make sense in EBCDIC (and only on Hollerith punched cards if you want to go back that far). Implementors using ASCII machines recognized that data keyed with a zone overpunch had to be interpreted using the ASCII equivalent of the zone overpunched EBCDIC character hence "}JKLMN..." are used for negative signed least significant digits in both ASCII and EBCDIC zoned numbers.

Your point regarding unsigned input to a field defined as signed is a good one although I believe in most situations it will work as expected. It's the other small percentage that will drive you crazy.

Regards.

Glenn
 
Just to let you know, I'm still playing around with my final coding, but the solutions from 3GM and fredericofonseca worked, and now I'm passing the value as negative when it should be.

Thanks all!
 
Glenn,

a test program using such a picture, gives exactly the same result using the mvs mainframe with ebcdic but also on the pc with ca-realia which works with ascii...

Regards,

Crox
 
Crox -

My point primarily was your examples and statement "D is negative" all apply solely to EBCDIC-based machines, not ASCII-based ones and perhaps not too enlightening for someone running on VMS.

Replicating your example in ASCII:

-000001 = X'30303030304A' = "00000J"
+000001 = X'303030303041' = "00000A"
000001 = X'303030303031' = "000001"

You'll note that the character representation I've added as the last value for each example is the same for EBCDIC and ASCII machines.

Regards.

Glenn
 
Yeah Glenn, you are right. But it is clear to me that the system is copied from the EBCDIC-mainframe way of life. Else no one would have chosen this because in ASCII it does not make sense to do the things this way.


DEMONSTRATION SOURCE

Code:
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. SIGNS.
000300 ENVIRONMENT DIVISION.
000400 CONFIGURATION SECTION.
000500 SOURCE-COMPUTER. CROX.
000600*                                     **********************
000700*                                     * CROX COPYRIGHT (C).*
000800*                                     **********************
000900 OBJECT-COMPUTER. CROX.
001000 SPECIAL-NAMES.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300 DATA DIVISION.
001400 FILE SECTION.
001500 WORKING-STORAGE SECTION.
001600 01  NUM-LEADING PIC S9(2) SIGN LEADING SEPARATE.
001700 01  NUM         PIC S9(2).
001800 PROCEDURE DIVISION.
001900 MAIN SECTION.
002000 MAIN-000.
002100     DISPLAY 'POSITIVE LOOP'
002200     PERFORM VARYING NUM-LEADING FROM 0 BY 1
002300       UNTIL NUM-LEADING > 10
002400        DISPLAY 'NUM-LEADING = ' NUM-LEADING
002500     END-PERFORM
002600     DISPLAY 'NEGATIVE LOOP'
002700     PERFORM VARYING NUM-LEADING FROM 0 BY -1
002800       UNTIL NUM-LEADING < -10
002900        DISPLAY 'NUM-LEADING = ' NUM-LEADING
003000     END-PERFORM
003100     DISPLAY 'POSITIVE LOOP'
003200     PERFORM VARYING NUM FROM 0 BY 1
003300       UNTIL NUM > 10
003400        DISPLAY 'NUM         = ' NUM
003500     END-PERFORM
003600     DISPLAY 'NEGATIVE LOOP'
003700     PERFORM VARYING NUM FROM 0 BY -1
003800       UNTIL NUM < -10
003900        DISPLAY 'NUM         = ' NUM
004000     END-PERFORM
004100     .
004200 MAIN-999.
004300     GOBACK.
004400 END PROGRAM SIGNS.

COMPACT OUTPUT:

Code:
POSITIVE LOOP        POSITIVE LOOP    
NUM-LEADING = +00    NUM         = 0{ 
NUM-LEADING = +01    NUM         = 0A 
NUM-LEADING = +02    NUM         = 0B 
NUM-LEADING = +03    NUM         = 0C 
NUM-LEADING = +04    NUM         = 0D 
NUM-LEADING = +05    NUM         = 0E 
NUM-LEADING = +06    NUM         = 0F 
NUM-LEADING = +07    NUM         = 0G 
NUM-LEADING = +08    NUM         = 0H 
NUM-LEADING = +09    NUM         = 0I 
NUM-LEADING = +10    NUM         = 1{ 
 
NEGATIVE LOOP        NEGATIVE LOOP     
NUM-LEADING = +00    NUM         = 0{  
NUM-LEADING = -01    NUM         = 0J  
NUM-LEADING = -02    NUM         = 0K  
NUM-LEADING = -03    NUM         = 0L  
NUM-LEADING = -04    NUM         = 0M  
NUM-LEADING = -05    NUM         = 0N  
NUM-LEADING = -06    NUM         = 0O  
NUM-LEADING = -07    NUM         = 0P  
NUM-LEADING = -08    NUM         = 0Q  
NUM-LEADING = -09    NUM         = 0R  
NUM-LEADING = -10    NUM         = 1}
 
The reason for having ASCII mimic the EBCDIC overpunch mechanism is simple to understand. It is so that records that are entirely USAGE DISPLAY could be translated directly from the EBCDIC alphabet to the ASCII alphabet, and so that cards punched in the standard manner could still be processed.

Tom Morrison
 
Tom,

Still there are a lot of troubles when transferring from one platform to the other. Also IBM is giving the advice to use the definition SIGN LEADING SEPERATE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top