Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:01:45+00:00 2026-05-27T14:01:45+00:00

I ran into a strange statement when working on a COBOL program from $WORK.

  • 0

I ran into a strange statement when working on a COBOL program from $WORK.

We have a paragraph that is opening a cursor (from DB2), and the looping over it until it hits an EOT (in pseudo code):

... working storage ...
01  I                       PIC S9(9) COMP VALUE ZEROS.
01  WS-SUB                  PIC S9(4) COMP VALUE 0.

... code area ...
PARA-ONE.                                                
    PERFORM OPEN-CURSOR
    PERFORM FETCH-CURSOR

    PERFORM VARYING I FROM 1 BY 1 UNTIL SQLCODE = DB2EOT                        
        do stuff here...
    END-PERFORM                                           

    COMPUTE WS-SUB = I + 0                            
    PERFORM CLOSE-CURSOR

    ... do another loop using WS-SUB ...

I’m wondering why that COMPUTE WS-SUB = I + 0 line is there. My understanding is that I will always at least be 1, because of the perform block above it (i.e., even if there is an EOT to start with, I will be set to one on that initial iteration).

Is that COMPUTE line even needed? Is it doing some implicit casting that I’m not aware of? Why would it be there? Why wouldn’t you just MOVE I TO WS-SUB?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:01:45+00:00Added an answer on May 27, 2026 at 2:01 pm

    Call it stupid, but with some compilers (with the correct options in effect), given

     01  SIGNED-NUMBER   PIC S99 COMP-5 VALUE -1.
     01  UNSIGNED-NUMBER PIC  99 COMP-5.
          ... 
          MOVE SIGNED-NUMBER TO UNSIGNED-NUMBER
          DISPLAY UNSIGNED-NUMBER
    

    results in: 255. But…

    COMPUTE UNSIGNED-NUMBER = SIGNED-NUMBER + ZERO
    

    results in: 1 (unsigned)

    So to answer your question, this could be classified as a technique used cast signed numbers into unsigned numbers. However, in the code example you gave it makes no sense at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a strange issue over the weekend while I was working on
I have ran into a very strange issue with Google Maps in Chrome 5.0.375.99:
Im learning C++ and I ran into something strange that I couldn't find any
I'm working with a nullable DateTime object and ran into some strange behavior. Here's
I ran into a strange bug in my PHP web app that I'm unable
I have recently ran into this strange issue, I was trying to reference parent
I was working on a method yesterday and ran into something strange, here is
I've ran into a strange situation. I'm writing some test cases for my program.
I'm experimenting with CUDA and I ran into a very strange bug. I have
I ran into a strange problem. In my unit test, I want to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.