IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Calucate the salary of each employee using SEARCH


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nareshdacha

New User


Joined: 12 Jan 2010
Posts: 66
Location: US

PostPosted: Sat Jul 17, 2010 12:04 pm
Reply with quote

I have a input file which contains the values as emp_no,emp-name,emp-sal. Each employee can contain more than once but emp_no is unique.
My requirement is to calucate the salary of each employee using SEARCH only.
For example:
emp-no e-name emp-sal
100 xxx 1000
200 abc 2000
300 pqr 3000
100 xxx 4000
300 pqr 1000

Now result should be like this
Emp-no emp-sal
100 5000
200 2000
300 4000
If emo_no exists more than once then the salary should be added togetherand display.

Can anyone explain how better way we can code this.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Sat Jul 17, 2010 12:15 pm
Reply with quote

Hi Naresh,
Quote:
Can anyone explain how better way we can code this
Shouldn't you be tellling us what your design is ... so that we can suggest a "better" way (if any)...
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Sat Jul 17, 2010 12:20 pm
Reply with quote

you can do it with sort i guess....you can search in the forum, you'll find many.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jul 17, 2010 10:08 pm
Reply with quote

Hello,

When help is asked for a programming solution, it is rarely appropriate to propose a utility solution.

Most often there is more to the requirement than is posted and adding additional processes (the cobol code will most likely still be needed to do the complete process) just wastes resources and is additional maintenance. . .

@Naresh - you can accomplish what you want by using an internal sort and summarizing by emp-no. If you get stuck, post what you have done and where you want help - as Binop suggested.
Back to top
View user's profile Send private message
nareshdacha

New User


Joined: 12 Jan 2010
Posts: 66
Location: US

PostPosted: Mon Jul 19, 2010 4:31 pm
Reply with quote

Actually this question was asked in interview.. She asked to me to explain with the code by using COBOL only.. i have pasted the code for your ref...
I just pasted a rough code below.... Please suggest me whether this process is correct or not..... Or any other way ????

First i loaded the input values to a table EMP-TABLE
05 EMP-TABLE OCCURS 10 TIMES INDEXED BY I
10 EMP-NO PIC 9(5)
10 EMP-NAME PIC X(10
10 EMP-SAL PIC 9(4)

05 WS-TABLE OCCURS 10 TIMES INDEXED BY J
10 WS-NO PIC 9(5)
10 WS-NAME PIC X(10
10 WS-SAL PIC 9(4)
10 WS-SUM PIC 9(8)

READ INPUT FILE (INP-NO,INP-NAME,INP-SAL) AT END GO TO END-PARA

LOAD THE INPUT VALUES TO EMP-TABLE,WS-TABLE..........

SET I TO 1
SET J TO 1

PERFORM PARA1 10 TIMES
ADD 1 TO J

PARA1.

SEARCH ACCT-TABLE
NOT FOUND DISPLAY 'ERROR'
WHEN WS-NO(J) = EMP-NO (I)
WS-SUM(I) = WS-SUM(I) + EMP-SAL(I)
ADD 1 TO I
IF I = 10 THEN
MOVE 1 TO I

END-SEARCH
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 19, 2010 4:39 pm
Reply with quote

You are inconsistent. ADD, MOVE, SUBTRACT, etc, cannot be used against an INDEX. Only SET is allowed.

Bill
Back to top
View user's profile Send private message
nareshdacha

New User


Joined: 12 Jan 2010
Posts: 66
Location: US

PostPosted: Mon Jul 19, 2010 5:09 pm
Reply with quote

Ya you are correct.....its my mistake....
Then how to loop thru the file to check the current record and prev record to add the salary...........
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 19, 2010 8:17 pm
Reply with quote

Hello,

This would be better done using the COBOL "internal sort" (especially if the file has more than just a few records).

Read about the COBOL SORT in the Language Reference manual available via the "IBM Manuals" link at the top of the page. If you find something in the manual that is not clear, post what you found and your doubt and someone will be able to clarify.
Back to top
View user's profile Send private message
nareshdacha

New User


Joined: 12 Jan 2010
Posts: 66
Location: US

PostPosted: Tue Jul 20, 2010 8:03 am
Reply with quote

Yes dick ... I replied the same to the interviewer but she said ' I want in COBOL itself' hence i tried as above.............
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jul 20, 2010 8:13 am
Reply with quote

Hello,

Yes, you can use arrays and increment the values according to when the "key" value is found.

Suggest you actually convert your pseudo-code to real code and run the process with a bit of made-up inpt data.
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Tue Jul 20, 2010 8:46 pm
Reply with quote

First you can sort the input file data by empno using sort statement. Populate the table. Now use the below code

Search-para.
SAL-TOTAL = 0
SET NDX TO 1
HOLD-EMP = emp(1)
Perform proces-para

process-para.
search table at end
DISPLAY HOLD-EMP, SAL-TOTAL
NEXT SENTENCE
when emp(NDX) = HOLD-EMP
compute sal-total = sal-total + sal(NDX)
set ndx up by 1
go to process-para

when emp(NDX) not equal HOLD-EMP
DISPLAY HOLD-EMP, SAL-TOTAL
MOVE ZERO TO SAL-TOTAL
SET HOLD-EMP TO EMP(NDX)
compute sal-total = sal-total + sal(NDX)
set ndx up by 1
go to process-para
END-SEARCH


Thanks
Ajay
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Tue Jul 20, 2010 8:49 pm
Reply with quote

Code:
Search-para.
  Move zero to SAL-TOTAL .
  SET NDX TO 1.
  Move emp(1) to HOLD-EMP.
  Perform proces-para.

process-para.
  search table at end
       DISPLAY HOLD-EMP, SAL-TOTAL
       NEXT SENTENCE
    when emp(NDX) = HOLD-EMP
        compute sal-total = sal-total + sal(NDX)
        set ndx up by 1
        go to process-para

    when emp(NDX) not equal HOLD-EMP
        DISPLAY HOLD-EMP, SAL-TOTAL 
        MOVE ZERO TO SAL-TOTAL
        SET HOLD-EMP TO EMP(NDX)
        compute sal-total = sal-total + sal(NDX)
        set ndx up by 1
        go to process-para
END-SEARCH
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts first column truncated in search result IBM Tools 13
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top