Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Calucate the salary of each employee using SEARCH

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Calucate the salary of each employee using SEARCH
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Sat Jul 17, 2010 10:08 pm    Post subject:
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    Post subject: Reply to: SEARCH - Query
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 19, 2010 4:39 pm    Post subject: Reply to: SEARCH - Query
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    Post subject: Reply to: SEARCH - Query
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

Site Director


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

PostPosted: Mon Jul 19, 2010 8:17 pm    Post subject:
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    Post subject: Reply to: SEARCH - Query
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

Site Director


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

PostPosted: Tue Jul 20, 2010 8:13 am    Post subject:
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: 205
Location: Bangalore

PostPosted: Tue Jul 20, 2010 8:46 pm    Post subject:
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: 205
Location: Bangalore

PostPosted: Tue Jul 20, 2010 8:49 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Search a Load Module sreekanth1984 TSO/ISPF 8 Tue Jun 07, 2016 8:45 pm
No new posts Copy one PDS to another PDS based on ... alluri12 JCL & VSAM 10 Tue Sep 29, 2015 8:10 pm
No new posts Search and replace the key in the report V S Amarendra Reddy SYNCSORT 1 Thu Jul 09, 2015 7:41 pm
No new posts Search Member Name in Library (DSORG=... jackare JCL & VSAM 9 Thu Jun 25, 2015 8:15 pm
No new posts Suggestion on Search and Split using ... shiitiizz DFSORT/ICETOOL 14 Tue Jun 16, 2015 1:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us