Thread: Convert COBOL to C

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    84

    Convert COBOL to C

    Hi,

    I want to convert a COBOL copybook into C to call a COBOL-API through C. Is that correct what I have done?

    Code:
    struct TestParms {
      // Filler PIC X(8) VALUE 'HYQCMQPR'.
      char m_eyeCatcher[8];
    
      // Filler PIC X(4) VALUE '0100'.
      char m_version[4];
    
      // MQPR-QueueMgr PIC X(48) VALUE spaces. 
      char m_mqprQueueMgr[48];
    
      // MQPR-Queue PIC X(48) VALUE spaces. 
      char m_mqprQueue[48];
    
      // MQPR-ReplyQueue PIC X(48) VALUE spaces . 
      char m_mqprReplyQueue[48];
    
      // MQPR-Message-p POINTER VALUE NULL.
      char m_mqprMessageP[sizeof(void *)];
    
      // MQPR-Message-l PIC S9(8) COMP-5 VALUE 0.
      char m_mqprMessageL[sizeof(int)];
    
      // MQPR-Messageld PIC X(24) VALUE LOW-VALUES.
      char m_mqprMessageld[24];
    
      // MQPR-Correlld PIC X(24) VALUE LOW-VALUES.
      char m_mqprCorrelId[24];
    
      // MQPR-CommitScope PIC S9(4) COMP-5 VALUE 0.
      char m_mqprCommitScope[sizeof(int)];
    
      // MQPR-Format PIC S9(4) COMP-5 VALUE 0.
      char m_mqprFormat[sizeof(int)];
    
      // MQPR-Persistency PIC S9(4) COMP-5 VALUE 0.
      char m_mqprPersistency[sizeof(int)];
    
      // MQPR- Priority PIC S9(4) COMP-5 VALUE 0.
      char m_mqprPriority[sizeof(int)];
    
      //  MQPR- Expiry PIC S9(4) COMP-5 VALUE 0.
      char m_mqprExpiry[sizeof(int)];
    
      //  MQPR-TargetEntity PIC X(3) VALUE' '. 
      char m_mqprTargetEntity[3];
    
      // MQPR-FILLER          PIC X(80) VALUE LOW-VALUES.
      char m_reserved1[80];
    
    };
    Thanks in Advance.
    Last edited by Salem; 11-02-2019 at 11:56 PM. Reason: Remove crayola

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > // MQPR-Message-l PIC S9(8) COMP-5 VALUE 0.
    > char m_mqprMessageL[sizeof(int)];
    ...
    > // MQPR-CommitScope PIC S9(4) COMP-5 VALUE 0.
    > char m_mqprCommitScope[sizeof(int)];
    Reading COBOL Layouts, Part 4: Numeric Fields
    If S9(8) is 00000000 decimal digits, and S9(4) is 0000 decimal digits, then neither has anything to do with the actual size of an integer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2016
    Posts
    84
    Can that be done hardcoded as well?Like char m_mqprMessageL[8] or char m_mqprFormat[4]?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Sure.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2016
    Posts
    84
    Thanks.I have at least 2 questions:

    1.) I've read that S9(4) COMP-5 is a "half-word" and S9(8) COMP-5 is a "double-word".As I know half-word has 2 BYTE and double-word has 8 BYTE. What does it mean?

    2.) I want to copy parameter values from MQ Message Descriptor into this struct.But the data type is MQLONG (32-bit integer).Would that work:
    memcpy(TestParms.m_mqprCommitScope, &msgDescriptor.CommitScope, sizeof(TestParms.m_mqprCommitScope);

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How much COBOL do you know?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2016
    Posts
    84
    Quote Originally Posted by Salem View Post
    How much COBOL do you know?
    Not that much, I am a newbie in Cobol.
    Or let's say,I never implemented in Cobol, now I am trying to get some basics which I need for my C Implementation.
    Last edited by Joe1903; 11-03-2019 at 02:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cobol?!
    By cyberCLoWn in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-23-2003, 06:23 PM
  2. Cobol!? Why!?
    By carrja99 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-08-2003, 02:44 PM
  3. Cobol
    By ammar in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 02-20-2003, 12:23 PM
  4. cobol
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-03-2002, 12:02 AM
  5. Cobol
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-19-2001, 10:50 AM

Tags for this Thread