user3311539
user3311539

Reputation:

Convert Fixed format Rpg code to free format

Hi I need to convert fixed format code to Free format as per my companies coding standard instructions. I dont even understand what the below means except that some date movement and conversions are happening..

C     *ISO          MOVE      BCEXDT        MDYDATE
C                   MOVE      MDYDATE       PEXPDATT
C     *ISO          MOVE      BCSTDT        MDYDATE  
C                   MOVE      MDYDATE       PSTRDAT  

Field definitions below:

BCEXDT         8S 0  
BCSTDT         8S 0
D  MDYDATE        S               D   DATFMT(*MDY)

Upvotes: 1

Views: 893

Answers (2)

jmarkmurphy
jmarkmurphy

Reputation: 11473

The two move operations for which you have shown the definitions can be converted like this:

C     *ISO          MOVE      BCEXDT        MDYDATE
C     *ISO          MOVE      BCSTDT        MDYDATE  

to

MDYDate = %date(bcexdt: *ISO);
MDYDate = %date(bcstdt: *ISO);

Note that MDYDate is a date field, and has the same internal format as every other date field. The DATFMT(*MDY) keyword only defines how the field is represented externally by default when loaded into (or from) a character or numeric field. It also sets limits on allowable values. In the case of *MDY, those limits are 01-01-1940 to 12-31-2039. Notice that the values in BCEXDT and BCSTDT are *ISO format, and the values limits are different for those fields. Specifically 0001-01-01 to 9999-12-31. So you could get errors when attempting to assign the *ISO date to a *MDY date field.

The two moves I haven't converted for you would be done in one of the following ways.

  1. If the targets are date fields:
pexpdatt = MDYDate;
pstrdat = MDYDate;
  1. If the targets are numeric fields:
pexpdatt = %dec(MDYDate);
pstrdat = %dec(MDYDate);
  1. If the targets are character fields:
pexpdatt = %char(MDYDate);
pstrdat = %char(MDYDate);

%dec() and %char() will assign the date fields in *MDY format since it was not explicitly specified in the assignment, and the date fields have DATFMT(*MDY).

Upvotes: 5

Charles
Charles

Reputation: 23783

Nobody else is going to be able to tell you what is going on either; without the definitions of the source and target fields.

That's why IBM depreciated the MOVE op-code from free-form.

Upvotes: 0

Related Questions