Having problem understanding an application

I have just been thrown into the fire to learn Natural and I would like to have an application explained to me so I can understand whats going on with it.

0010 DEFINE DATA LOCAL
0020 01 NLM-CASE-FILE VIEW OF NLM-CASE-FILE
0030 02 CF-FILE-TYPE-AND-NUMBER
0040 02 CF-REC1-STATUS-DESC
0050 02 CF-CASE-TYPE
0060 02 CF-REC1-CASE-STATUS
0070 02 CF-REC1-SPECIAL-CODE
0080 02 CF-CASE-SUPER-DESC-10
0090 *
0100 01 #KAARRAY (99)
0110 02 #SPECIAL-CODE (A4)
0120 02 #TYPE-COUNT (I2)
0130 *
0140 01 #KAARRAY-CNT (I2)
0150 01 #I (I2)
0160 *
0170 END-DEFINE
0180 **********************************************************
0190 READ (200) NLM-CASE-FILE BY CF-CASE-SUPER-DESC-10 = ‘571’
0200 IF #KAARRAY-CNT EQ 0
0210 MOVE 1 TO #KAARRAY-CNT
0220 MOVE CF-REC1-SPECIAL-CODE TO #SPECIAL-CODE (1)
0230 MOVE 1 TO #TYPE-COUNT (1)
0240 ELSE
0250 FOR #I = 1 TO #KAARRAY-CNT STEP 1
0260 DECIDE FOR FIRST CONDITION
0270 WHEN CF-REC1-SPECIAL-CODE EQ #SPECIAL-CODE (#I)
0280 ADD 1 TO #TYPE-COUNT (#I)
0290 ESCAPE BOTTOM
0300 WHEN #I = #KAARRAY-CNT
0310 ADD 1 TO #KAARRAY-CNT
0320 MOVE CF-REC1-SPECIAL-CODE TO #SPECIAL-CODE (#KAARRAY-CNT)
0330 MOVE 1 TO #TYPE-COUNT (#KAARRAY-CNT)
0340 ESCAPE BOTTOM
0350 WHEN NONE
0360 IGNORE
0370 END-DECIDE
0380 END-FOR
0390 END-IF
0400 *
0410 IF CF-CASE-TYPE NE ‘571’
0420 ESCAPE BOTTOM
0430 END-IF
0440 *
0450 IF CF-REC1-CASE-STATUS < ‘90’
0460 DISPLAY
0470 ‘STATUS DESC’ CF-REC1-STATUS-DESC 4X
0480 ‘CASE TYPE’ CF-CASE-TYPE 4X
0490 ‘CASE STATUS’ CF-REC1-CASE-STATUS 4X
0500 END-IF
0510 *
0520 AT BREAK OF CF-REC1-CASE-STATUS
0530 SKIP 1
0540 END-BREAK
0550 *
0560 AT BREAK OF CF-REC1-CASE-STATUS
0570 WRITE COUNT (CF-REC1-CASE-STATUS) ‘RECORDS FOUND’
0580 ‘IN CASE STATUS’ OLD(CF-REC1-CASE-STATUS) /
0590 END-BREAK
0600 *
0610 END-READ
0620 *
0630 FOR #I = 1 TO #KAARRAY-CNT STEP 1
0640 WRITE #I
0650 ‘SPECIAL CODE:’ #SPECIAL-CODE (#I) 7X
0660 ‘COUNT:’ #TYPE-COUNT (#I)
0670 END-FOR
0680 END

Basically I dont know what is really going on between line 0220 and 0390. Please shed some light on this program for me Thanx!

As each record is read, the value of CF-REC1-SPECIAL-CODE is interrogated. If the value exists in an internal table (#SPECIAL-CODE), the associated count (#TYPE-COUNT) is incremented. Otherwise, the value is added as the next entry in the table, with a count of 1.

The purpose of the code segment is to count the number of occurrences of the values in CF-REC1-SPECIAL-CODE.

ps I presume that the code was mistakenly left-justified as it was posted here, but if if the original has the same format, I suggest that you execute the STRUCT command within the program editor to make the code easier to read.

Ralph’s explanation is absolutely correct. I would like to add to his comment about making the code easier to read.

As evident from your question, Natural, like most programming languages, is not really self documenting. If the potential exists for other newbies in your organization to be faced with learning this program, a few comments would help enormously. For example:

0190 READ (200) NLM-CASE-FILE BY CF-CASE-SUPER-DESC-10 = ‘571’
0195 ** following if is to place first entry in table with count of one
0200 IF #KAARRAY-CNT EQ 0
0210 MOVE 1 TO #KAARRAY-CNT
0220 MOVE CF-REC1-SPECIAL-CODE TO #SPECIAL-CODE (1)
0230 MOVE 1 TO #TYPE-COUNT (1)
0235 ** end of first entry code, following code either adds one to the
0236 ** count for an existing table entry, or creates a new table entry
0240 ELSE
0250 FOR #I = 1 TO #KAARRAY-CNT STEP 1
0260 DECIDE FOR FIRST CONDITION
0270 WHEN CF-REC1-SPECIAL-CODE EQ #SPECIAL-CODE (#I)
0275 ** add one to count for existing entry then exit FOR loop
0280 ADD 1 TO #TYPE-COUNT (#I)
0290 ESCAPE BOTTOM
0300 WHEN #I = #KAARRAY-CNT
0305 ** value for cf-rec1-special-code does not yet exist in table
0306 ** create new entry with count of one
0310 ADD 1 TO #KAARRAY-CNT
0320 MOVE CF-REC1-SPECIAL-CODE TO #SPECIAL-CODE (#KAARRAY-CNT)
0330 MOVE 1 TO #TYPE-COUNT (#KAARRAY-CNT)
0340 ESCAPE BOTTOM /* not necessary, potentially confusing
0350 WHEN NONE
0360 IGNORE
0370 END-DECIDE
0380 END-FOR
0390 END-IF

Having commented about readability, the following may seem a bit contrary, however, I think it would be worth considering:

at start of data
MOVE 1 TO #KAARRAY-CNT
MOVE CF-REC1-SPECIAL-CODE TO #SPECIAL-CODE (1)
MOVE 1 TO #TYPE-COUNT (1)
end-start
*
at end of data
subtract 1 from #TYPE-COUNT (1)
end-enddata

Without the IF…ELSE, the first code will be “double counted”; once by the at start of data clause, and once by the “table loop”. The at end of data compensates for that. the need to comment the at end of data action, is, in my view, more than compensated for by the elimination of IF…ELSE; but that is clearly very subjective.

So, KJ, if you have the authority to do so, you might want to help out those who come later, by adding a few comments.

steve

Thanks a bunch. Like I said I have been thrown into this and have never even seen Natural before. I’m a ColdFusion programmer and my work took me out of that and decided they want me to learn Natural. Thanks for the explanations. I’m sure I’ll have more questions.

OK 1 other quick question. Could you give me a definition of #KAARRAY-CNT and describe how it works.

It’s an elementary field defined by the programmer. Its name has no significance. It is used as an index into an internal array, so, in Natural, it should be defined as a 4-byte integer.

KJ, earlier today I had occasion to write a response to someone that applies equally to you. Learning Natural on your own should not be an option. Management needs to know that unless they intend to dedicate a mentor to you, your knowledge of Natural will likely not meet their expectations.

steve

Thanx Steve, yea I’m not to confident right now and my supervisors think I should know this as of yesterday and I’m struggling very bad. I’m dealing with a supervisor who looks at my code and just tells me its wrong and then walks away. I’m actually trying to get out of the unit I’ve been put into so I can get back to ColdFusion buts its a wait and see deal right now. Until then I need to try and get through as best as possible. You’ve definately validated evrything that I have said already.

OK last question on this topic–my display is as such:

  535 RECORDS FOUND IN CASE STATUS 11       
                                            
    3 RECORDS FOUND IN CASE STATUS 20       
                                            
   15 RECORDS FOUND IN CASE STATUS 21       
                                            
 1167 RECORDS FOUND IN CASE STATUS 35       
                                            
    1 RECORDS FOUND IN CASE STATUS 4Z       
                                            
   15 RECORDS FOUND IN CASE STATUS 60       
                                            
   16 RECORDS FOUND IN CASE STATUS 64       
                                            
 3033 RECORDS FOUND IN CASE STATUS 80       
                                            
    1 RECORDS FOUND IN CASE STATUS 90       
                                            
  1 SPECIAL CODE: 7712       COUNT:    753  
  2 SPECIAL CODE: 7002       COUNT:    115  
  3 SPECIAL CODE: 7702       COUNT:   2594                                         
  4 SPECIAL CODE: 7004       COUNT:     28 
  5 SPECIAL CODE: 7708       COUNT:    424 
  6 SPECIAL CODE: 7703       COUNT:    184 
  7 SPECIAL CODE: 7701       COUNT:      8 
  8 SPECIAL CODE: 7000       COUNT:    168 
  9 SPECIAL CODE: 7710       COUNT:     57 
  10 SPECIAL CODE: LTFT       COUNT:     38 
  11 SPECIAL CODE: 7003       COUNT:      5 
  12 SPECIAL CODE: 7714       COUNT:    244 
  13 SPECIAL CODE: LTFU       COUNT:      5 
  14 SPECIAL CODE: 7715       COUNT:     64 
  15 SPECIAL CODE: 7713       COUNT:    109 
  16 SPECIAL CODE: 7001       COUNT:      3 
  17 SPECIAL CODE: 7707       COUNT:      3 

The display (lines 600-620) code has been commented out for this and escape bottom was inserted also line 580 was changed to > 80. This is close to what I want but I need it to also show like:
535 RECORDS FOUND IN CASE STATUS 11
1 SPECIAL CODE: 7712 COUNT: 200
2 SPECIAL CODE: 7002 COUNT: 200
3 SPECIAL CODE: 7702 COUNT: 135
3 RECORDS FOUND IN CASE STATUS 20
1 SPECIAL CODE: 7712 COUNT: 2
2 SPECIAL CODE: 7002 COUNT: 1
etc…etc. I’m not sure how to get this to work. Any help would be greatly appreciated as to get the super off my case for today. Thanks.

You write the Status field (CF-REC1-CASE-STATUS) when its value changes (AT BREAK). You write the Code values after all the data is read (following the END-READ).

Write the contents of the table immediately after writing the Status field. Then clear the Code table for the next Status value.

  AT BREAK OF CF-REC1-CASE-STATUS 
     WRITE COUNT (CF-REC1-CASE-STATUS) 'RECORDS FOUND' 
      'IN CASE STATUS' OLD(CF-REC1-CASE-STATUS) / 
     /* 
     FOR #I = 1 TO #KAARRAY-CNT STEP 1 
       WRITE #I 
         'SPECIAL CODE:' #SPECIAL-CODE (#I) 7X 
         'COUNT:' #TYPE-COUNT (#I) 
     END-FOR 
     RESET #KAARRAY (*)     /* Clear the table 
           #KAARRAY-CNT
  END-BREAK 
* 
END-READ 
END

Thanks I was missing the reset table portion. I am getting a small weird result in one of the cases it says there are only 3 but I’m getting a count of 5. Any idea what would be causing this?

Hi KJ;

What is the structure of the super descriptor? That is, what fields (and what positions of these fields) comprise the super?

Since you are reading by the super, it may not be straightforward to use the AT BREAK for status.

steve

The fields are CF-CASE-TYPE 1-3, CF-REC1-CASE-STATUS 1-2 and CF-FILE-TYPE-AND-NUMBER 1-17.

I don’t mean to scare you, kjharley, but have you considered the possibility that you are being set up to be fired i.e. your org would like to get rid of you ? This is the method used in many companies … more probable if a few people have been let go after being assigned to the unit you are in now … which has a hitman for a supervisor …

Oh yea, been down that road. The only plus side is that I’m a unioned employee so in all actuality I would have to quit. I kind of expected that about a week into this. The union is aware of whats going on so we’ll see. I’ve applied for a programming job in another division that is suited more to my qualifications.