You are here: Home > Knowledge Refreshers

KR editions 125 to 127

KR-125 : Zero or spaces- which is greater???

Consider a code snippet which checks 

IF CUR_DATE > 0 where CUR_DATE is X(8).

If CUR_DATE is spaces then is the above condition true or false??

It all comes down to the issue of is character SPACE greater than the character 0?

This can be solved easily if one knew the EBCDIC mapping between characters and their numeric equivalent codes.

So, a simple way to solve this doubt is:

  • Open a flat file in view/edit mode (an empty file is preferable).

  • Type the letters A, 'space', 5 within the file.

  • Type the command HEX ON and voila!

Snapshot will reveal something like this:


From above picture:

Character A = C1; Character space = 40 ; Character 5 = F5 ; Similarly character 0 = F0

So our question "Is CUR_DATE > 0 when CUR_DATE is spaces" is equivalent to the question: 

                          "Is hex 40 > hex F0? " - Answer've got it!

KR-126 : Undeleting/recovering datasets...Contributed by Elan

On some systems you may find some SMS utility (which provides a good user interface for recovering deleted

datasets which were backed up by the system). But in many places such an option may not exist. Here the HRECOVER command might work (and most of those tools in fact might use HLIST and HRECOVER  commands in the backend).

  • MVS (actually SMS) takes backup of most of the files/datasets (depending on the management class of the dataset). Also it keeps backup of many previous versions at any point of time. We can recover any deleted dataset as well as previous versions if the system has taken a backup of that.

  • To find out how many versions of a dataset are available in backup write the following command in the option 6 panel and hit enter:
    HLIST BCDS DSN ('Dataset Name').

  • This will tell you the list of backups. You will see that with every back up it has a backup date and a GEN no associated. 

  • Based on the version you want (using the date of backup), note down the GEN number for that backup.

  • Now to recover that file or PDS, write the following command on =6 panel and hit enter (let's say we want to retrieve GEN 005) 
    HRECOVER 'Original Dataset Name' GEN(005) NEWNAME. 
    Note: NEWNAME is a keyword.

  • Write the name there (within quotes) and hit enter. The system will recover that version with this name.
    Note: In case you just want to recover a deleted dataset simply write 
    HRECOVER 'Original Dataset Name' 
    If the system has that backup it will recover that with same name, i.e. the latest version.

Note: Backup frequency depends on the management class (our earlier KRs covered this topic).

KR-127 : SYNCSORT -line count...Idea triggered by Divya

Sometimes we might want to sort a file, get the count of records in a file and append a trailer record at the end of

 the file containing the count value. One method to achieve this is using SYNCSORT:

//              DISP=SHR 
//              DISP=(OLD,CATLG,CATLG) 
  SORT FIELDS=(1,1,CH,D) - 

The syntax within the SYSIN is fairly simple:


This will sort the file SORTIN (order the file based on the first character -i.e. starting from 1st column for a length  on 1 byte; in descending order).


This will add a trailer to the end of the file which will have the words LINES IN FILE: starting in column 1, the count value (i.e. number of records) in column 15 and then "n" number of spaces starting from column 23 (the value of "n" depends on the LRECL of the file and X denotes spaces).


In this method, SYNCSORT treats the TRAILER1 clause as a report writing clause; and it will expect the output file (SORTOUT) to be of format FBA (in FBA files the first byte is used to store a control character). So if one needs to have the output in FB and not FBA then you would need to convert the FBA into a FB. 

How? You can again use SYNCSORT!

Go back to the main contents page