Question

I need to move the two bytes of a four byte field into a new field that is two bytes.

Code I want to use:

MOVE C-SERVICE-CYE TO S-CYE.   

I need the last two digits of the year. Ex: 2014 would be 14

Data Structure:

02  S-DATE.                            
     10  S-MME   PIC X(02).             
     10  FILLER  PIC X(01) VALUE '/'.   
     10  S-DDE   PIC X(02).             
     10  FILLER  PIC X(01) VALUE '/'.   
     10  S-CYE   PIC X(02).             

Second Data Structure:

02  C-SERVICE-DATE-E.             
    10  C-SERVICE-CYE   PIC X(04).
    10  C-SERVICE-MME   PIC X(02).
    10  C-SERVICE-DDE   PIC X(02).
Was it helpful?

Solution

There are two fairly straight forward ways of doing this.

One is to subdivide the source variable declaration:

02  C-SERVICE-DATE-E.             
    10  C-SERVICE-CYE.
        15 C-SERVICE-CYE-CC PIC X(02).
        15 C-SERVICE-CYE-YY PIC X(02).
    10  C-SERVICE-MME   PIC X(02).
    10  C-SERVICE-DDE   PIC X(02).

Then modify the MOVE statement to: MOVE C-SERVICE-CYE-YY TO S-CYE

The other way is to use reference modification: MOVE C-SERVICE-CYE (3:2) TO S-CYE

This all works because the data items you are referencing here are DISPLAY types. Had they been numeric (eg. COMP something) this technique would not work.

OTHER TIPS

Whilst I would use NealB's first method for your actual example, and avoid the reference-modification (I think it obscures code, so the next person along has to find out what (3:2) is before they can "read" the code - and the next person may be you in a couple of months), there are other ways.

    10  S-CYE   PIC 9(02).

Now when you do the MOVE, the compiler will generate code to right-justify and left-truncate. With alphanumeric to alphanumeric you get left-justified right-truncated.

If your source field is "computational" (binary or packed decimal), you can get the "14" from the current year that way.

If the source field happens to be in the order that you require to be shown, and contains the same data (not your example), the whole thing can be done in one shot.

01  EDITED-DATE-1 PIC XX/XX/XXXX.
01  EDITED-DATE-2 PIC XXXX/XX/XX.

Now when you MOVE a PIC X(8) date to either of the above (depending on where the year is) you'll get the slashes. The Xs in the PIC can be changed to 9 if the source is "computational".

you can use: MOVE C-SERVICE-CYE(3:2) TO S-CYE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top