While moving a decimal value to Comp-5, you just need to consider these: it stores only the integer portion and ignores the decimal portion.

Suppose you have defined a field with PIC 9(07)V99 and you moved a value from this data type to COMP-5.

COBOL Example: How to use COMP-5.

01 My-data     PIC 9(07)v99 value 1234567.10.
01 Out-data    comp-5 or S9(07)v99 Comp-5.
   MOVE My-data   to  Out-data.

The result will be: 1234567

Resolution

The key point I want to share is that Comp-5 stores only integer parts and truncates decimal parts.

Note: So, you cannot use comp-5 as S9(07)v99, but you can use it as S9(09).

More details of COMP-5

  • Comp-5 stores the data in the form of Binary ( because binary doesn’t support decimals)
  • It has boundaries. It stores as 2/4/8 bytes internally
  • S9(1) to S9(4) => 2 bytes(half)
  • S9(5) to S9(9) ==> 4 bytes(full)
  • S9(10) to S9(18) ==> 8 bytes(double)
  • With or without ‘S’ you can define the Comp-5 data types

References

LATEST POSTS

AI Agents in Data Engineering: Everything You Need to Know

AI agents are revolutionizing data engineering by automating tasks such as monitoring pipelines, generating SQL queries, and ensuring data quality. They enhance productivity, speed up troubleshooting, and improve data accessibility for users. While offering significant advantages, AI agents also face challenges in security, accuracy, and integration with existing systems.

The End-to-End AI Stack – A Real Guide for Developers to Code, Create, and Execute

Artificial Intelligence tools are on the rise, from writing assistants to coding helpers and automation platforms. However, many professionals struggle to compare these tools effectively. This is where the AI Stack becomes important. Modern AI tools like ChatGPT, NotebookLM, and Antigravity serve different purposes, and understanding their roles helps in: Layer 1: Conversational AI (Thinking…

10 Workplace Communication Speaking Exercises to Improve Fluency at Work

Strong workplace communication is one of the most valuable professional skills today.Whether you’re giving project updates, speaking to clients, or collaborating with teams — the ability to speak clearly and confidently can set you apart. However, many professionals struggle with: One of the best ways to improve is through chunking and pausing. Chunking helps you:✔…

Step-by-Step: 4 Methods to Create RDS in AWS & Build Schemas

Setting up a Relational Database Service (RDS) database in Amazon Web Services (AWS) is an essential skill for developers and data engineers. This blog post outlines four different methods for creating an RDS database, providing step-by-step instructions that are easy for beginners to follow. Additionally, we will discuss how to create schemas after establishing the…

Something went wrong. Please refresh the page and/or try again.