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

Need COBOL logic for creating diff. question paper patterns


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

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Tue Dec 19, 2006 1:17 pm
Reply with quote

I have around 10 quesions in a sequential file.Now i would like to write a cobol program which will read this file and produce 10 diffrent sets of question papers in which the question order should differ from one question paper to another.

Code:
Note: Each question papers should contain all the 10 questions but the order must be different from one question paper to the other.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 3:35 pm
Reply with quote

Load all 10 into a table.
Generate random numbers into another 10 element array.
Search this array for the random numbers from lowest to highest.
Each time you find the next sequential number, use the equivalent question.
When you have done all ten, go back to the generate and repeat.

No real guarantee, but all should be somewhat different.
Back to top
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Tue Dec 19, 2006 4:20 pm
Reply with quote

thanks for the reply Williams...can you please expand your explanition some more as i am finding it difficult to understand
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 4:31 pm
Reply with quote

What part are you finding difficult to understand?
Back to top
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Tue Dec 19, 2006 5:49 pm
Reply with quote

Generate random numbers into another 10 element array.it is this part.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 5:56 pm
Reply with quote

If you can't find a integrated way to produce random numbers, there are simple ways to get them that are good enough for this application.
Back to top
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Wed Dec 20, 2006 11:25 am
Reply with quote

Hi williams...Can you please help me by expanding the pseudocode what you have allready provided...i am finding it difficult to understand.THnx in advance.....
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Wed Dec 20, 2006 1:58 pm
Reply with quote

Please check the following logic.


working-storage section.
01 a.
02 b occurs 10 times.
05 c pic x.
01 i pic 99 value 1.
01 temp pic x.
procedure division.
p0.
move "ABCDEFGHIJ" to a.
perform p1 10 times.
stop run.

p1.
perform p2 10 times.

move c(1) to temp.
move 1 to i.
perform p3 9 times.
move temp to c(10).
move 1 to i.
p2.
display c(i).
add 1 to i.

p3.
move c( i + 1 ) to c(i).
add 1 to i.

Aji
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Thu Dec 21, 2006 5:07 am
Reply with quote

Hello vin12pr,

The problem you present, on the surface may seem a simple task, but in implementation is not quit so simple. What you want is a series of random numbers 1 through 10, that do not repeat themselves in any given sequence, and that the sequence itself does not repeat for the duration of the run.

Given this, most of the processing done is checking if there is a repeat.

The code below is most of the way to where you need to be. The logic to ensure that the sequence itself does not repeat itself I leave up to you. It just wouldn?t be fun if someone gave you the whole logic. icon_smile.gif

Code:

WORKING-STORAGE SECTION.                                   
                                                           
01  WS-D-NUMBER               PIC S9(11) COMP-3           
                                         VALUE +0.         
01  WS-R-NUMBER               PIC S9(3)  COMP-3           
                                         VALUE +0.         
01  SUB                       PIC S9(3)  COMP-3           
                                         VALUE +0.   
01  WS-TABLES.                                                     
    05  WS-QUESTIONS.                                               
        10  FILLER            PIC X(100) VALUE 'QUESTION 01'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 02'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 03'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 04'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 05'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 06'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 07'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 08'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 09'.       
        10  FILLER            PIC X(100) VALUE 'QUESTION 10'.       
    05  TBL-QUESTIONS REDEFINES WS-QUESTIONS                       
                              PIC X(100) OCCURS 10 TIMES.           
    05  TBL-RAND-ORDER        PIC S9(3)  COMP-3                     
                                         OCCURS 10 TIMES.           
    05  TBL-Q-NUMBER          PIC S9(3)  COMP-3                     
                                         OCCURS 10 TIMES.           
                                                                   
PROCEDURE DIVISION.                                         
PROGRAM-START.                                               
                                                             
                                                             
*   LOAD THE QUESTION TABLE WITH QUESTIONS FROM FILE         
                                                             
                                                             
    PERFORM                                                 
      10 TIMES                                               
        PERFORM P2000-POPULATE-TBL-RAND-ORDER               
            THRU P2000-EXIT                                 
        PERFORM P3000-PRINT-RAND-QUESTIONS                   
            THRU P3000-EXIT                                 
    END-PERFORM.                                             
                                                             
    GOBACK.                                                 
                                                             
                                                               
P2000-POPULATE-TBL-RAND-ORDER.                                 
                                                               
    PERFORM                                                     
      VARYING SUB FROM 1 BY 1                                   
      UNTIL SUB > 10                                           
        MOVE 0                  TO TBL-RAND-ORDER (SUB)         
                                   TBL-Q-NUMBER (SUB)           
    END-PERFORM.                                               
                                                               
    PERFORM                                                     
      VARYING SUB FROM 1 BY 1                                   
      UNTIL SUB > 10                                           
        PERFORM                                                 
          WITH TEST AFTER                                       
          UNTIL TBL-Q-NUMBER ( WS-R-NUMBER ) = 0               
            COMPUTE WS-D-NUMBER                                 
                = FUNCTION RANDOM * 100000000000               
            DIVIDE WS-D-NUMBER BY 10 GIVING WS-D-NUMBER         
                                  REMAINDER WS-R-NUMBER         
            ADD 1               TO WS-R-NUMBER                   
        END-PERFORM                                             
        MOVE WS-R-NUMBER        TO TBL-RAND-ORDER (SUB)         
                                   TBL-Q-NUMBER (WS-R-NUMBER)   
    END-PERFORM.                                                 
                                                                 
P2000-EXIT.                                                     
    EXIT.                                                       
                                                                 
P3000-PRINT-RAND-QUESTIONS.                                     
    DISPLAY ' '                                                 
    PERFORM                                                     
      VARYING SUB FROM 1 BY 1                                   
      UNTIL SUB > 10                                             
        MOVE TBL-RAND-ORDER (SUB) TO WS-R-NUMBER                 
        DISPLAY TBL-QUESTIONS (WS-R-NUMBER)                     
    END-PERFORM.                                                 
P3000-EXIT.                                                     
    EXIT.                                                       


Dave
Back to top
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Fri Dec 22, 2006 11:14 am
Reply with quote

Thanks David...Can you please explain that RANDOM function which u have used..I am not understanding as to how it works...Thanks in advance.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Fri Dec 22, 2006 11:32 am
Reply with quote

Hi there,

Please refer to below link

www.uni.edu/coboldoc/cobrm_040.htm
Back to top
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Thu Dec 28, 2006 1:33 pm
Reply with quote

When I use the Function Random statement in the program,its throwing the error as ""FUNCTION" was not defined as a data-name".

Can anybody please advise as to why it is happening like this.

Can anybody place the proper syntax for using the cobol functions in an application program.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Thu Dec 28, 2006 2:27 pm
Reply with quote

Hi !

That depends on your installed cobol-version in your company.
Not all commands are allowed under standard IBm COBOL-II.
Depends on version & level of installation.

Other solution, if DB2 is installed:

Write those ten questions into a dataset, prefixed with a timestamp.
Then you can sort them in several ways to printer. Ten minutes work.

Regards & happy new year
UmeySan
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top