Sunday, 4 September 2016

Delete record using CURSOR

Using below COBOL program you could fetch a particular record from database and delete it using a query;

IDENTIFICATION DIVISION.
PROGRAM-ID. DELCUR.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
                EXEC SQL
                    INCLUDE NMTAB
                END-EXEC.
                EXEC SQL
                    INCLUDE SQLCA
                END-EXEC.
PROCEDURE DIVISION.
                PERFORM 100-MAIN-PARA.
100-MAIN-PARA.
                EXEC SQL
                     DECLARE CUR CURSOR FOR
                     SELECT ID,NAME FROM NMTAB
                    WHERE ID =”ID1022” FOR UPDATE OF NMTAB
                END-EXEC.
                EXEC SQL
                    OPEN CUR
                END-EXEC.
                PERFORM 200-UPD-PARA.
                EXEC SQL
                    CLOSE CUR
                END-EXEC.
                STOP RUN.
200-UPD-PARA.
                EXEC SQL
                     FETCH CUR INTO :MID, :MNAME
                END-EXEC.
                IF MID=”ID1022”
                EXEC SQL
                  DELETE FROM NMTAB
                 WHERE CURRENT OF CUR
                END-EXEC.
                ELSE
                DISPLAY “THE RECORD IS NOT FOUND”.

In the above program we have declared a cursor CUR to select a particular record from table NMTAB. Open the cursor perform the para where the record will be deleted using the query once the record has been fetched. Once done close the cursor and stop the program.

TABLE:

ID                     NAME                 JOB
M1011                  KARTI                SOFTWARE
M1022                  RAVI                 POLICE

AFTER PROGRAM:

ID                     NAME                 JOB
M1011                  KARTI                SOFTWARE




Question on COMP in COBOL program

1. Sign storage in COMP-3 field,

The sign indicator is always stored at the last bit.
If your number is +100, it stores hex 0C in the last byte.
If your number is -101, it stores hex 1D in the last byte.

2. Sign stored in COMP field.

The Sign is stored in the Most significant bit.
Bit is ON if -ve.
Bit is OFF if +ve.

3. difference between COMP & COMP-3.

COMP is a binary storage format.
COMP-3 is a Packed decimal format.

4. difference between COMP-1 & COMP-2.

COMP-1 - Represented as Single floating point. Uses 4 bytes.
COMP-2 - Represented as Double floating point. Uses 8 bytes.

5. S9(7) COMP-3 field occupy?

According to the formula  INT((n + 1)/2) 
n=7
INT((7+1)/2)) = 4.
This will take 4 bytes.

6. S9(8) COMP field occupy?

4 bytes. As the number of bytes are divided by 2.

7. S9(7) SIGN TRAILING SEPARATE field occupy?

8 bytes as the sign will remain as 1 byte due to trailing separate.


Saturday, 3 September 2016

Simple android program using onTouchEvent

This is the MainActivity which calls the TouchToView class,

package com.example.paintouch;

import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     //   setContentView(R.layout.activity_main);
        setContentView(new TouchToView(this));
    }

}

Here we have used onTouchEvent which will capture the motion of your finger when touching the screen and also we have defined the Paint and Path with its style, colour and width to get displayed.
The X and Y axis will be mapped with using the paint and path.

package com.example.paintouch;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;

public class TouchToView extends View{
private Paint alphanum = new Paint();
private Path trace = new Path();

public TouchToView(Context context) {
super(context);
// TODO Auto-generated constructor stub
alphanum.setAntiAlias(true);
alphanum.setStrokeWidth(6f);
alphanum.setColor(Color.RED);
alphanum.setStyle(Style.STROKE);
alphanum.setStrokeJoin(Join.ROUND);
}

protected void onDraw(Canvas canvas) {
canvas.drawPath(trace, alphanum);
}

@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
Float eventX = event.getX();
Float eventY = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
trace.moveTo(eventX, eventY);
break;
case MotionEvent.ACTION_MOVE:
trace.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
// trace.lineTo(eventX, eventY); do nothing
break;
case MotionEvent.ACTION_OUTSIDE:
// trace.lineTo(eventX, eventY); do nothing
break;
default:
return false;
}
invalidate();
return true;

}

}



Thursday, 1 September 2016

How to find special character in String using COBOL program

How to check special character in a string and replace with spaces using COBOL program.


01  TEMP-VAR                            PIC X(10) VALUE " INS#PECT ".
01  TEMP-VAR-LEN                   PIC 9(02) VALUE ZERO.
01  TEMP-VAR-COUNT             PIC 9(02) VALUE ZERO.
01  TEMP-CHAR-COUNT          PIC 9(02) VALUE ZERO.
01  TEMP-CHAR                         PIC X(10) VALUE SPACES.
01  TEMP-CHK-VAR                  PIC X(10) VALUE SPACES.


MOVE LENGTH OF TEMP-VAR TO TEMP-VAR-LEN.      

MOVE 0                   TO TEMP-VAR-COUNT.      
      
PERFORM VARYING TEMP-CHAR-COUNT FROM 1 BY 1                
            UNTIL TEMP-CHAR-COUNT > TEMP-VAR-LEN        

  MOVE  TEMP-VAR(TEMP-CHAR-COUNT:1) TO TEMP-CHAR  

  ADD 1                  TO TEMP-VAR-COUNT                

  EVALUATE TEMP-CHAR                                  
     WHEN ‘#’                                  
        MOVE SPACES TO TEMP-CHG-VAR(WS-VAR-COUNT:1)
     WHEN OTHER
        MOVE TEMP-CHAR TO TEMP-CHK-VAR(WS-VAR-COUNT:1)
  END-EVALUATE

END-PERFORM.


Here the logic is:
To get the length of the string and perform until the complete string has been checked, each word is checked using the EVALUATE and if the special character is found it will be replaced with spaces or the same character will be moved into the variable using reference modification. 

How to remove spaces in a String

How to remove front and back spaces in a variable and write it in middle of two variable,

01  VAR-SPACE            PIC X(10) VALUE '   DATA   '.
01  LEAD-SPACE         PIC 9(04)  COMP.
01  TRAIL-SPACE        PIC 9(04)  COMP.
01  LENG-SPACE         PIC 9(04)  COMP.
01  FIRST-VAR             PIC X(07) VALUE 'VALID -'.
01  TRAIL-VAR            PIC X(10) VALUE '- REQUIRED'.
01  FINAL-VAR            PIC X(21) VALUE SPACES.


INSPECT              VAR-SPACE
      TALLYING     LEAD-SPACE          
      FOR LEADING SPACES    
                 
INSPECT    FUNCTION REVERSE(VAR-SPACE)
     TALLYING    TRAIL-SPACE          
     FOR LEADING SPACES      
                
COMPUTE  SPACE-LENG =                        
                  LENGTH OF  VAR-SPACE - LEAD-SPACE - TRAIL-SPACE     
          
ADD    1                    TO   LEAD-SPACE    

STRING FIRST-VAR DELIMITED BY SIZE  
       VAR-SPACE (LEAD-SPACE:SPACE-LENG)
                                DELIMITED BY SIZE
       TRAIL-VAR   DELIMITED BY SIZE  
       INTO FINAL-VAR.    

DISPLAY "The result will be: " FINAL-VAR.


The result will be: VALID -DATA- REQUIRED.

Here the spaces which are present in front and back of 'VAR-SPACE' variable has to be removed.
So we have used INSPECT function to check for number of spaces in front and back using TALLYING function.
Then using reference modification only the DATA is moved after removing the leading and trailing spaces.

Expense Handler Application with advance technologies

Budget Planner  One of the application developed with Ionic 4 and Python-Flask.  Ionic 4 code:  https://github.com/logeshbuiltin/Expense...