Showing posts with label Interview Questions. Show all posts
Showing posts with label Interview Questions. Show all posts

Saturday, 10 June 2023

REST API Interviews for Solution Architects: Key Concepts. #apis

REST API Interview Questions

REST API's Interview Questions.

In today's digital landscape, RESTful APIs (Representational State Transfer Application Programming Interfaces) have become the backbone of modern application development. As the demand for seamless integration and interoperability rises, organizations are increasingly relying on solution architects to design robust and scalable RESTful architectures. However, excelling in REST API interviews for solution architect roles requires a deep understanding of the underlying principles, best practices, and industry trends. 

This blog post aims to guide aspiring solution architects through the crucial concepts and preparation strategies necessary to ace REST API interviews. Whether you're a seasoned professional or just starting your journey, read on to equip yourself with the knowledge and insights needed to showcase your expertise in RESTful API design and implementation.

What is REST, and what are its key principles?

The term REST stands for Representational State Transfer. It's an architectural style for designing and building loosely coupled applications. Its key principles include:
  1. Stateless: The server does not store any client state, and each request from the client must contain all the necessary information.
  2. Client-Server: The client and server function as independent components that interact over a network, enabling scalability and the division of responsibilities.
  3. Uniform Interface: A consistent set of well-defined methods and standard conventions are used for interacting with resources.
  4. Cacheable: Responses from the server can be cached to improve performance and reduce the load on the server.
  5. Layered System: The architecture can consist of multiple layers, wherein each layer delivers distinct functionality.

How does REST differ from other architectural styles, such as SOAP?

REST and SOAP (Simple Object Access Protocol) are both architectural styles for building distributed systems, but they have significant differences:
  • REST is based on stateless, lightweight protocols like HTTP, while SOAP relies on XML-based messaging protocols.
  • REST uses standard HTTP methods (GET, POST, PUT, DELETE) for operations, whereas SOAP uses a more rigid XML-based messaging format.
  • REST is more flexible and scalable, while SOAP provides more built-in functionality and protocol support.
  • REST is widely used for web-based APIs, while SOAP is often used in enterprise applications and web services.

Explain the components of a RESTful architecture.

A RESTful architecture typically consists of the following components:
  • Resources: These are the key entities that the API exposes. Resources can be anything that can be uniquely identified, such as objects, documents, or services.
  • URIs (Uniform Resource Identifiers): URIs identify and locate resources in the API. They follow a specific pattern and provide a unique address for each resource.
  • HTTP Methods: RESTful APIs use standard HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources.
  • Representations: Resources can have different representations (e.g., JSON, XML) based on client requirements or the API's design.
  • Hypermedia: Hypermedia, such as links or URLs embedded within responses, allows clients to discover and navigate related resources.
  • Request and Response: Clients send requests to the API, which processes the request and returns a response, typically in the form of a representation of the requested resource.

What are the advantages of using RESTful APIs over other approaches?

Some advantages of RESTful APIs include the following:
  • Simplicity: REST follows a straightforward design philosophy, leveraging existing standards like HTTP and URI.
  • Scalability: RESTful architectures can scale easily due to their stateless nature and separation of concerns between client and server.
  • Flexibility: REST allows clients to consume APIs using different representations and can be easily integrated into different platforms and technologies.
  • Caching: REST supports caching of responses, which improves performance and reduces the load on the server.
  • Wide adoption: RESTful APIs have gained widespread popularity and support, making them well-documented and supported by various tools and frameworks.

Which HTTP methods are commonly employed in RESTful APIs? Elucidate their respective purposes.

Here, are the primary HTTP methods utilized in RESTful APIs:
  • GET: Retrieves a representation of a resource without modifying it. Thus, It's used to read or get data from the resource.
  • POST: Post/send data to be processed by a resource. It is used to create new resources or trigger actions.
  • PUT: Updates a resource with new data or replaces it entirely. It's used to update/replace existing resources.
  • DELETE: Removes a specified resource. It is used to delete resources.
  • PATCH: Applies partial modifications to a resource. That means it would be used to update selected fields or information. 

How do you handle versioning in RESTful APIs?

Versioning in RESTful APIs can be handled in various ways:
  • URI Versioning: The version number is included in the URI, such as "/api/v1/resource". It allows clients to access a specific version of the API.
  • Query Parameter Versioning: The version number is included as a query parameter, such as "/api/resource?version=1". The client or user can indicate their preferred version of API. 
  • Header Versioning: The version number is included in the request header, such as "Accept-Version: 1". It allows clients to indicate the desired version in the title.

What is the purpose of HTTP status codes in RESTful APIs? Can you give some examples?

HTTP status codes provide information about the status of a request in RESTful APIs. Some examples include:
  • 200 OK: The status code 200 indicates that request was processed successfully, and the server returns the requested resource.
  • 201 Created: The request to create a new resource was successful, and the server has created it.
  • 400 Bad Request: The server cannot process the request due to invalid syntax or parameters.
  • 401 Unauthorized: The client needs to authenticate itself to access the requested resource.
  • 404 Not Found: It indicates that the requested resource is not found on the server. 
  • 500 Internal Server Error: The server encountered an unforeseen error.

How do you handle authentication and authorization in RESTful APIs?

Authentication is the process of verifying the identity of a client, while authorization determines what actions a client can perform. Some common approaches for handling authentication and authorization in RESTful APIs are:

Token-based Authentication: Clients include an authentication token (e.g., JWT) in the request header to authenticate themselves.

OAuth 2.0: OAuth 2.0 is a widely used protocol for authentication and authorization, allowing clients to obtain access tokens to access protected resources.

Role-based Access Control (RBAC): RBAC assigns roles to users, and based on their roles, they are granted specific permissions to access resources.

Describe the role of request and response headers in RESTful APIs.

Request and response headers carry additional information about the request or response in RESTful APIs. Some common headers include:
  • Content-Type: Specifies the media type of the request or response payload (e.g., application/json).
  • Accept: Indicates the desired media types that the client can handle for the response.
  • Authorization: Contains authentication credentials for the request.
  • Cache-Control: Specifies caching directives for both client and server to control caching behavior.
  • Location: In the response, it specifies the URI of the newly created resource.

How do you handle error responses in RESTful APIs?

Error responses in RESTful APIs typically include an appropriate HTTP status code, along with an error message or error details in the response payload. The response might follow a specific error format, such as JSON or XML, providing information about the encountered error. Additionally, error handling can include standardized error codes, error descriptions, and suggestions for resolving the issue.

What are the best practices for designing resource URIs in RESTful APIs?

Some best practices for designing resource URIs in RESTful APIs are:
  • When representing resources, it is recommended to use nouns instead of verbs.
  • Keep URIs simple, meaningful, and easy to understand.
  • Use a hierarchical structure for related resources (e.g., /users/{userId}/orders).
  • Avoid exposing implementation details in URIs.
  • Use plural nouns for collections (e.g., /users) and singular nouns for individual resources (e.g., /users/{userId}).

What is HATEOAS (Hypermedia as the Engine of Application State), and how does it relate to REST?

HATEOAS is a constraint of REST that enables a client to navigate a RESTful API by discovering and following hyperlinks provided in the response. In other words, the API provides hypermedia links that guide the client's next actions and available resources. HATEOAS promotes loose coupling between the client and server, as the client doesn't need to have prior knowledge of the API structure and can dynamically discover and interact with resources based on the available links.

How do you handle pagination and sorting in RESTful APIs?

Pagination and sorting can be handled by incorporating query parameters in the API requests. For pagination, parameters like page and limit can be used to specify the page number and the number of results per page. Sorting can be achieved by using a sort parameter with the desired sorting criteria.

Explain the concept of content negotiation in RESTful APIs.

Content negotiation allows clients and servers to agree on the most suitable representation format for exchanging data. The negotiation process is typically based on the Accept header in the request, where the client specifies the preferred media types it can handle. The server examines the Accept header and responds with the appropriate representation format (e.g., JSON, XML) based on the available options. Content negotiation promotes interoperability and flexibility in RESTful APIs by allowing clients and servers to communicate using the most compatible format.

What are the considerations for handling concurrency and caching in RESTful APIs?

Handling concurrency and caching in RESTful APIs involves the following considerations:
  • Concurrency: APIs should handle concurrent requests by ensuring data integrity and consistency. Techniques like optimistic locking or conditional requests (using ETags) can be employed to manage concurrent modifications.
  • Caching: APIs can utilize caching to improve performance and reduce server load. Cache-control headers (e.g., Cache-Control, Expires) can be set to specify caching directives for both clients and intermediary servers. Additionally, ETags can be used to support conditional requests and cache validation.

Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 

Mainframe Forum™


Saturday, 6 April 2019

Top 20 Interview Questions for VSAM (Virtual Storage Access Method)


Top 20 Interview Questions.
Top 20 Interview Questions for VSAM.



Interview Questions



Q.
What are the types of VSAM DataSets?
A. Entry sequenced DataSets (ESDS), Key sequenced DataSets (KSDS) and relative record (RRDS), LDS (linear Data Set).
Q. Why do VSAM take more disk space than other utilities?
A. VSAM increases the disk space requirements of systems. This is because VSAM offers certain capabilities like partial self-reorganization to make things more efficient in data sets that can be modified.
Q. What are the distinctive features of a KSDS, Key sequenced DataSet?
A. The index and the distributed free space. CI and CA split upon updates. Record length may be changed during the update. The records are accessed by a particular Key.
Q. How are records stored in an ESDS, entry sequenced DataSet?
A. They are stored without respect to the contents of the records and in the order in which they are included in the file.
Q. What's an LDS (Linear Data Set) and what's it used for?
A. LDS is a VSAM DataSet in name only. It has unstructured 4k (4096 bytes) fixed size CIs which do not contain control fields. There is no free space, and no access from Cobol. LDS is essentially a table of data maintained on disk. The 'table entries' must be created via a user program and can only be logically accessed via a user program. When passed, the entire LDS must be mapped into storage, then data is accessed via base and displacement type processing.
Q. In ESDS, do we have the facility of accessing the records randomly?
A. YES, Random access to records is possible. Records, however, cannot be deleted. We can do it by referring to the RBA (relative byte address).
Q. Why is space is kept in the data component of the KSDS DataSet?
A. Free space specified during the allocation of the KSDS is left at regular intervals during the initial load of the data set. This space helps keep the data component in physical sequence in spite of random insertions.
Q. What is the difference b/w the ESDS and KSDS?
A. ESDS doesn’t have embedded free space.
The KEYS parameter has no meaning in the context of ESDS ESDS has no index component. An additional parameter, NONINDEXED is used to tell AMS that an ESDS is being allocated.
Q. How is LDS different from ESDS?
A. An LDS is a data set, very similar to an ESDS without the control information.It has no records and used for fast random access. It takes advantages of the computer’s very fast paging hardware for retrieval and storage and the bytes are implicitly divided into 4K blocks or pages, and the paging hardware reads and writes blocks from disk. There is no free space, unused space, control field in LDS.
Q. What is a CI, Control Interval?
A. A Control Interval is the unit of information that VSAM transfers between virtual and auxiliary storage.
Q. What is Control Interval Split?
A. A new record stored in the same CI, only if there is enough space. If not VSAM locates the free CI within the same CA, moves approximately half of the records to next CI and stores the new record at the correct position. This is called Control Interval Split. Whenever CI split occurs the sequence set is updated.
Q. What is a CA, control area?
A. A group of Control Intervals makes up a control area.
Q. If the records are larger than the CI size, for ex. if a record extends CI boundary and extends unto 3 CI, and there is still some space left in last i.e. third CI, will that be used by other CI DataSets?
A. NO. Some records are larger than the CI size, the records extend across CI boundaries (only for ESDS and KSDS). A spanned record begins on a CI boundary and it occupies two or more CIs in a CA. The unused space in the last CI can only be used to extend the record, it cannot contain any other record i.e. a new record has to be added in a new CI.
Q. What is a sequence set?
A. This is the part of the index that points to the CA and CI of the record being accessed.
Q. What is a cluster?
A. A cluster is the combination of the index, sequence set and data portions of the DataSet. The operating system gives program access to the cluster, i.e. to all parts of the DataSet simultaneously.
Q. What is the index set?
A. This is the other part of the index. It has multiple levels with pointers that ultimately reach to the sequence set.
Q. What is a Catalog?
A. The catalogue contains the names of all DataSets, VSAM and non-VSAM. It is used to access these datasets.
Q. What is an alternate index?
A. An AIX is a file that allows access to a VSAM DataSet by a Key other than the primary one. The alternate Key-pointer pair records are stored in an index cluster. This index cluster is known as the alternate index. The alternate Key-pointer pair records are loaded into the alternate index cluster
by the command BLDINDEX.AIX can be built over a KSDS and ESDS, but not over an RRDS.
Q. What could be the maximum number of the AIXs per base cluster?
A. There can be a maximum of 253 AIXs per base cluster. It is not advisable to have more than 5 AIXs per base cluster because of additional overhead during updates and retrievals.
Q. Can AIX be defined over an ESDS, which does not have any Key?
A. Although an ESDS does not have a primary Key, an AIX can be defined over an ESDS. In the case of an ESDS it is the relative byte address of the corresponding record in the base cluster that is stored.
Q. Can we access records in VSAM only by a single Key, i.e. primary Key?
A. It is also possible to access the records in a sequence other than that of the primary Key. Such Keys are called alternate Keys and they can be non-unique. For Example, in a pay-roll system where employee number is the unique primary Key and the employee name as alternate Key.
Q. What is the 'verify' command in the VSAM files ?
A. This command is used to close those files that are kept open after the abnormal termination of the file. It also brings the index component in sync with the data components and updates the catalog.
Q. What is a path?
A. A path is a file that allows you to access a file by alternate index - the path provides an association between the AIX and the base cluster.
Q. What is the upgrade set?
A. The upgrade set is the list of all AIXs that VSAM must maintain for a specific base cluster, so that when data in the base cluster is updated, the AIX files are also updated.
Q. What is free space?
A. Free space is reserved within the data component of a KSDS to accommodate inserting new records.
Q. What is IDCAMS? and what is the purpose of it?.
A. IDCAMS, also known as Access Method Services, is used to perform the following tasks:
  * Create a VSAM data set, VSAM alternate index, or catalog.
  * List a catalog entry for a data set, DataSet/catalog contents.
  * Copy a DataSet or catalog .
  * Convert non-VSAM to VSAM data set .
  * Load a VSAM DataSet from VSAM records
  * Rename VSAM data sets.
Q. What is a VSAM split?
A. If there isn't enough space in the Control Interval VSAM performs a Control Interval split by moving some records to the free Control Intervals. If there isn't a free Control Interval VSAM performs a control area split by allocating a new control area and moving half of the Control Intervals to it.
Q. What is the base cluster?
A. The base cluster consists of the data component and the index component for the primary index of a KSDS.
Q. What will happen if there is no secondary allocation made for DataSets?
A. VSAM will inform COBOL program of the problem and terminate the processing of the program.
Q. Why CI and CA splits are not possible in ESDS and RRDS?
A. In ESDS the new record is added at the end of last record. And no imbedded free space is allocated at the time of DataSet definition. In the case of RRDS the slots for the records are preallocated and so the CI and CA split is not possible.
Q. Do primary Key values have to be unique? Do alternate Key values have to be unique?
A. Primary Key values must be unique; alternate Key values need not be.
Q. In the COBOL SELECT statement what is the ORGANIZATION for a KSDS?
A. The ORGANIZATION is INDEXED.
Q. In the COBOL SELECT statement for a KSDS what are the three possibilities for ACCESS? 
A. ACCESS can be SEQUENTIAL, RANDOM or DYNAMIC.
Q. What is the COBOL RECORD KEY clause?
A. The RECORD KEY in the SELECT clause identifies the files primary Key as it will be known to the program.
Q. What is the purpose of the FILE STATUS clause in the SELECT statement?
A. The FILE STATUS field identifies the field that VSAM uses to provide information about each I/O operation for the file.
Q. If you wish to use the REWRITE command how must the VSAM file be opened?
A. It must be opened I/O mode.
Q. Explain the meaning and syntax for the START command?
A. The START command is used to read other than the next VSAM record. A value must be moved into the RECORD KEY. The KEY clause is optional, but it can be used to specify  relational (equal, less than, etc.) operator.
Q. What is the meaning of dynamic processing?
A. It means one program uses both sequential and random processing for a VSAM KSDS file. It's rarely used.
Q. Name some common VSAM error conditions and codes?
A. They are end of file (10), duplicate Key (22), record not found (23), Out of space condition is raised (28) ,VSAM logic error (90), open problem (92) and space problem (93).
Q. What is the VSAM-code field?
A. It is a COBOL II enhancement to VSAM batch processing expanding the FILE STATUS field. It is defined in WORKING - STORAGE as a six byte group item with three two byte elements, the normal return code, the function code and the feedback code.
Q. What is a VSAM slot?
A. A relative record DataSet (RRDS) consists of a specified number of areas called slots. Each slot is identified by a relative record number (RRN) which indicates its relative position in the file.
Q. What is the utility program closely associated with VSAM?
A. IDCAMS, the access method services utility.
Q. There are at least seven IDCAMS commands; name and explain each of them?
A. ALTER modifies information for a catalog, alternate index, cluster or path.
BLDINDEX builds the alternate index, of course.
DEFINE is used for ALTERNATEINDEX, CLUSTER or PATH.
DELETE removes the catalog entry for a catalog, cluster, alternate index or path.
LISTCAT lists information about the DataSet.
PRINT prints the DataSet contents.
REPRO copies records from one file to another.
Q. What are the three levels of definition for the VSAM DEFINE?
A. They are DEFINE CLUSTER, DATA and INDEX.
Q. What is the significance of the SHAREOPTIONS parameter?
A. It specifies how the file may be shared between jobs and between batch and CICS environments.
Q. What is the meaning of the DEFINE MODEL parameter?
A. It specifies whether the MODEL parameter allows you to model your cluster by modelling it after an existing cluster.
Q. How do you fix the problem associated with VSAM out of space condition?
A. 1. Define new VSAM DataSet allocated with more space.
2. Use IDCAMS to REPRO the old VSAM file to new VSAM DataSet.
3. Use IDCAMS to ALTER / rename the old VSAM DataSet or set IDCAMS to DELETE the
old VSAM DataSet.
4. Use IDCAMS to ALTER / rename the new VSAM DataSet to the name of the original
VSAM DataSet.
Q. In how many ways can you load the data in a VSAM cluster?
A. 1. Using the REPRO command.
2. Using COBOL program
Q. What is the REPRO command?
A. While a new cluster is created using IDCAMS, cluster will be empty. By using the REPRO command, we can load records into the cluster.

REPRO is Used to :
• Copy DataSets (VSAM or NON-VSAM), copy catalogs.
• Convert sequential and index sequential DataSets to VSAM format
• Convert VSAM and Index sequential DataSets to sequential format
• Backup VSAM catalog
• Read a backup copy of VSAM catalog
Q. Is it slower if you access a record through ALTERNATIVE INDEX as compared to Primary INDEX?
A. YES. Because the alternate Key would first locate the primary Key, which in turn locates the actual record. Needs twice the number of I/Os.
Q. What is RECOVERY and SPEED parameters in DEFINE CLUSTER command?
A. RECOVERY (default) and SPEED are mutually exclusive. Recovery pre-formats the control areas during the initial DataSet load, if the job fails, you can restart but you must have a recovery routine already written to restart the job. SPEED does not pre-format the CAs. It is recommended that you specify SPEED to speed up your initial data load.
Q. What is a SHAREOPTIONS parameter (SHR) in Define Cluster command.
A. It defines the cross-region and cross-system sharing capabilities of the DataSet. Syntax is SHR
(CRvalue CSvalue)
1 means multiple read OR single write (read integrity)
2 means multiple read AND single write (Write integrity)
3 means Multiple read AND multiple write
4 is same as 3, which refreshes the buffer with every random access. Default is SHR (1 3).
Q. What are the optional parameters to the input DataSet While loading the empty cluster with the data records?
A. i)  Skip and Count

Syntax:
SKIP(2)
COUNT(4)
In this case, the first two records are skipped and the next four records are printed. The default for SKIP is 0, and for COUNT will be printing records from beginning to end.

ii) FromKey and ToKey

PRINT -
INDATASET (CUSTOMER.KSDS.CLUSTER) -
FROMKEY (111111) -
TOKEY (444444)
Will print all records with Key value ranging from 111111 to 444444.

iii) FROMADDRESS and TOADDRESS

iv) FROMNUMBER and TONUMBER
Q. What does GDG mean in VSAM?
A. Generation Data Group
Q. Is a delete operation possible in an ESDS? Is rewrite operation possible in ESDS ?
A. No. Delete operation is not possible in VSAM ESDS. Yes, rewrite operation is possible in an ESDS
Q. Can VSAM files be deleted with the DELETE option of the DISPOSITION parameter of JCL?
A. No, you have to give a separate DELETE command in the VSAM cluster.
Q. How many buffers are allocated to VSAM KSDS and ESDS?
A. 2 data buffers by default for ESDS. For KSDS it allots 2 data buffers and 1 index buffers. Each buffer is about 4k.
Q. What are the codes returned by the AMS (Access Method Services) command during the execution?
A. Every AMS command issues a condition code. If multiple commands are being executed successively, there might be a requirement to execute or bypass certain commands on the success or failure of a previous command.

0 - The function was executed successfully
4 - A problem was encountered while executing the function, WARNING
8 - The requested function was executed, but major specifies were unavoidably bypassed,
ERROR
12 - The requested command could not be performed because of a logical error, SEVERE
16 - A severe error occurred causing the remainder of the command stream to be
bypassed., FATAL.



Top 20 Interview Questions for VSAM Share
Share VSAM Interview Questions.


Thursday, 14 August 2014

COBOL Subtract Statement | SUBTRACT STATEMENT Example.


Numerical calculation is one of the most critical part of programming language. In-fact most of the programming language provide various functions that can be used to implement business calculation logic. 

Similarly, COBOL also provide various clause such as SUBTRACT, MULTIPLY, ADD, DIVIDE, COMPUTE etc to perform various calculation

In this tutorial, I would focus on various format of SUBTRACT clause available in COBOL. I would try to explain syntax with few examples.

The SUBTRACT statement subtracts one numeric item, or the sum of two or more numeric items, from one or more numeric items and stores the result. Subtract has three different format which is applicable in various situation. 

Format : 1
Subtract
COBOL Subtract From.
Example: 

Add a note hereAdd a note hereSUBTRACT 1 FROM WS-COUNTER.

Here, all identifiers or literals preceding the key word FROM are added together and this sum is subtracted from and stored immediately in identifier-2. This process is repeated for each successive occurrence of identifier-2, in the left -to-right order in which identifier-2 is specified.
Format : 2
Subtract in COBOL
COBOL Subtract From Giving
Example:
SUBTRACT WS-HOURS FROM TOT-HOURS GIVING OVERTIME-HRS. 
Here, all identifiers or literals preceding the key word FROM are added together and this sum is subtracted from identifier-2 or literal-2. The result of the subtraction is stored as the new value of each data item referenced by identifier-3.
Format : 3
COBOL Tutorial
Subtract From in COBOL
Example:

SUBTRACT WS-AMT1 WS-AMT2 WS-AMT3 FROM GRS-PAY GIVING NET-PAY.
Here, the elementary data items within identifier-1 are subtracted and stored in the corresponding elementary items within identifier-2.

COBOL TUTORIAL

Check-out my tutorial on COBOL BLANK WHEN ZERO Clause.

COBOL REDEFINE Clause | REDEFINE in COBOL Example and rules.

COBOL
COBOL REDEFINE Tutorial
Another important statement/feature of COBOL in REDEFINES clause. The Redefines clause lets you define a field in storage in two or more ways. 

When used, this clause must have the same level number as the data item it is redefining and it must come right after that item.

The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.   

Always remember, the definition and the redefinition both refer to the same bytes of storage, you can code a Value clause only on the original definition. 
Syntax : 
01-49  data-name-1 REDEFINES data-name-2

Example 1: A Redefines clause that redefines a date field

Add a note hereAdd a note here05  WS-TDY-DTE       PIC 9(08).
05  WS-TDY-DTE-X     REDEFINES WS-TDY-DTE.
    10  TDY-YR       PIC 9(04).
    10  TDY-MNTH     PIC 9(02).
    10  TDY-DAY      PIC 9(02).

Example 2 : A Redefines clause that redefines a print field

Add a note hereAdd a note here05  WS-CHG-PERNT     PIC ZZ9.9-.
05  WS-CHG-PERNT-X   REDEFINES WS-CHG-PERNT
                     PIC X(6).

Example 3 : A Redefines clause that redefines alphanumeric with numeric.

     05  WS-EMP-REC       PIC X(20).
  05  WS-SAL-AMT       REDEFINES     WS-EMP-REC.
      10 WS-EMP-SALE   PIC 9(05)v99. 
      10 WS-EMP-TAX    PIC 9(02)v99. 

Rule : 
  1. Level number, data-name-1, and FILLER are not part of the REDEFINES clause itself and are included in the format only for clarity.
  2. Level-numbers of data-name-1 and data-name-2 must be identical and must not be level 66 or level 88.
  3. Data-name-1, FILLER identifies an alternate description for the same area and is the redefining item or the REDEFINES subject.
  4. Data description entry for the redefined item cannot contain an OCCURS clause.
  5. More than one redefinition of the same storage area is permitted. The entries giving the new descriptions of the storage area must immediately follow the description of the redefined area without intervening entries that define new character positions.
  6. Multiple redefinitions must all use the data-name of the original entry that defined this storage area.
  7. Redefining entry (identified by data-name-1) and any subordinate entries, must not contain any VALUE clauses.

START CLAUSE EXAMPLE

Have a look of COBOL Start Statement?



COBOL Rounded Clause | ROUNDED in COBOL Example [COBOL ROUNDED Statement].

COBOL ROUNDED Phrase, COBOL Rounding

COBOL ROUNDED Phrase

Welcome back to today's session on "COBOL Rounded Clause" or "COBOL Rounding". In this session, you'll learn the basics of the COBOL ROUNDED statement and why you use COBOL rounding in your application programs.  You'll go through the COBOL rounding up an example for better understanding. Let's get started with the COBOL Rounded Phrase introduction.  
Agenda. 
  • Introduction. 
  • What is COBOL ROUNDED Clause (i.e. COBOL ROUNDED Statement)?
  • COBOL ROUNDED Syntax. 
  • COBOL ROUNDED Example. 
    • ROUNDING in COBOL Example.
  • ROUNDED in COBOL Rules.
  • Conclusion.

Introduction. 

The capability of rounding up or rounding down is another important feature of any programming language. There are many business scenarios where monetary transaction value is either round-up or rounded down based on the requirement. COBOL ROUNDED Phrase (i.e. COBOL ROUNDED statement) is used to implement rounding in COBOL programs. In COBOL, you do not have any default rounding. You've to specify the rounding in your program. 
 

COBOL Rounding Rule of Thumb. 

  • If the ending value is 5 or more then round Up (i.e. COBOL round up).
  • If the ending value is 4 or less then round Down (i.e. COBOL round down).

What is COBOL ROUNDED Clause (i.e. COBOL ROUNDED Statement)?


COBOL ROUNDED Clause, ROUNDED in COBOL

COBOL ROUNDED CLAUSE
Once the decimal point is aligned, the number of places given for the fraction of the resultant identifier is compared to the number of places in the fraction of the product of an arithmetic operation. 

Unless the COBOL ROUNDED phrase is known, truncation occurs when the size of the fractional result exceeds the number of places given for its storage.

When the COBOL ROUNDED verb is used, the resulting identifier's least significant digit is increased by 1 if the excess's most significant digit is greater than or equal to 5.

COBOL Rounding or truncation occurs relative to the rightmost integer position for which storage is allocated when the resultant identifier is defined by a PICTURE clause containing the rightmost Ps and the number of places in the measured result exceeds the number of integer positions stated.

Important: The COBOL ROUNDED phrase has no effect in a floating-point arithmetic operation; the output of a floating-point operation is always rounded.

COBOL ROUNDED Syntax. 

The syntax of ROUNDED in COBOL is pretty simple and straightforward. You need to specify the ROUNDED keyword as illustrated in the following figure.  
COBOL ROUNDED, ROUNDED in COBOL
ROUNDED  in COBOL Example.

When the result is truncated on either the left or right side after decimal point alignment, this is known as a size error message. Let's look at the following COBOL round down and COBOL rounds up examples.

ROUNDED in COBOL Example. 

Destination Field   |  Actual Result   | Truncated Result | Rounded Result
PIC 9(03)v9.     123.26         123.2          123.3
PIC 9(03)v9.     234.54         234.5          234.5 
PIC 9(03).       456.25         456            456 

Important Point: Division by 0 always leads to SIZE ERROR. 

ROUNDED in COBOL Example: 

COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT * .0785


Rounded in COBOL Rules:

  1. ROUNDED in COBOL can be used with any arithmetic operation. 
  2. Data will be truncated if you did not specify COBOL Rounded Clause and the resultant fields is not sufficient to store the decimal data. 
  3. When the COBOL ROUNDED phrase is used, the output will be rounded to the PICTURE specification of the destination field.
  4. When ROUNDED in COBOL and REMAINDER are used in the same operation then DIVIDE, ROUNDED must be defined first.
You can code the Rounded clause whenever the result of a calculation can have more decimal places than is specified in the picture of the result field. If you don’t use the Rounded clause, the extra decimal places are truncated

Conclusion.

Finally, this marks an end to our today's COBOL ROUNDED clause. In this session, you learn what is COBOL rounding or COBOL ROUNDING Function. You learned COBOL ROUNDED Statement syntax along with COBOL round-up and COBOL round-down examples for better understanding.  


COBOL Tutorial

Have a look at CICS Top 100 Interview Questions Part II.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™


New In-feed ads