John,

The S0C1 is because SYS1.SCEELKED isn’t available for the dynamic call.  When I 
put SCEELKED in a STEPLIB I can dynamically call cuserid() using your code 
sample without any problem except that the RETURN-CODE value gets corrupted by 
the return pointer, so you also have to zero the RETURN-CODE special register 
if you don’t want weird return codes from you batch run.

My version of your code sample:

       IDENTIFICATION DIVISION.                                        
       PROGRAM-ID.    TESTPGM.                                         
       ENVIRONMENT DIVISION.                                           
       DATA DIVISION.                                                 
       WORKING-STORAGE SECTION.                                       
       01  USERID-PLUS-1.                                             
           05   USERID     PIC X(8).                                  
           05   FILLER     PIC X.                                     
       01  CUSERID-POINTER POINTER.                                   
       01  CUSERID-PGM     PIC X(8) VALUE 'CUSERID'.                  
       PROCEDURE DIVISION.                                            
       MAIN-PARA.                                                     
      *    STATIC CALL                                                
           MOVE SPACES TO USERID                                      
           CALL "CUSERID" USING USERID-PLUS-1                         
           INSPECT USERID REPLACING ALL LOW-VALUE BY SPACE            
           DISPLAY 'TESTPGM'                                         
               ': STATIC CUSERID() RETURNED "' USERID '"'             
      *    DYNAMIC CALL, NEEDS HLQ.SCEELKED IN STEPLIB/JOBLIB/LINKLIST
           MOVE SPACES TO USERID                                      
           CALL CUSERID-PGM USING USERID-PLUS-1                       
           INSPECT USERID REPLACING ALL LOW-VALUE BY SPACE            
           DISPLAY 'TESTPGM'                                         
               ': DYNAMIC CUSERID() RETURNED "' USERID '"'            
      *    RESET RETURN-CODE                                          
           MOVE ZERO TO RETURN-CODE                                   
           STOP RUN.                                                  

HTH and many thanks for all the new ideas you have put into my head!

Peter

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf 
Of John McKown
Sent: Thursday, April 06, 2017 5:05 PM
To: [email protected]
Subject: Re: Opinion: Using C "standard library" routines in COBOL.

On Thu, Apr 6, 2017 at 3:53 PM, Farley, Peter x23353 < 
[email protected]> wrote:

> John,
>
> Not "nutso" at all, just very cool.
>
> I notice you are using "static" calls (quoted literal program names) 
> in upper case.  Does that mean that you statically link the C 
> subroutines with your program?  Does it require using any non-default 
> compiler options?
> Assuming you are using COBOL V4.2 or earlier, do you have to use 
> PDSE's for the load modules because of the C subroutines?
>

​Well, I originally used a DYNAM compile parm. But when I did the cuserid() 
CALL, I got an S0C1. When I did a static link, I got what I was looking for. I 
haven't tried to track down the cause of the S0C1 yet.​

​Good question about the PDS/E. I'm using COBOL 4.2 on z/OS 1.12 for my 
testing. My testing is done using a UNIX shell. I use the "cob2" command to 
compile my programs, then test them right there. ​ ​I did a quickie test 
copying my UNIX resident program to a standard PDS data set using "cp -X". It 
ran fine, so I don't think that a PDSE is required. It may be for C++, but 
doesn't appear to be​



>
> I am quite excited if this is all I have to do to use C library 
> routines, but static links make me uneasy, especially for system-level 
> runtime code like the C library functions.
>
> Peter
>
>

--


This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to