Troubleshooting
Problem
This document demonstrates the use of an IBM ILE RPG IV Procedure and Subprocedure. When this program is run, the user is asked to type a date. The program then calculates the day of the week that the date falls on and displays this information.
Resolving The Problem
The following demonstrates the use of an IBM ILE RPG IV Procedure and Subprocedure.
When this program is run, the user is asked to type a date.
The program then calculates the day of the week that the date falls on and displays this information.
Display File (DAYDSPF):
Display File (DAYDSPF):
A DSPSIZ(*DS3 *DS4)
A CA03(03 'EXIT')
A R DAYFMT
A OVERLAY
A 2 3'ENTER A DATE IN MDY:'
A DATE 6Y 0B 2 25EDTCDE(Y)
A EDTMSK(' & & ')
A R DAYFMT2
A OVERLAY
A 4 3'THIS DATE FALLS ON A '
A DAY 15A O 4 25
A R FOOTER
A OVERLAY
A 22 3'F3 = Exit'
Use the following command to compile the display file:
CRTDSPF FILE(libraryname/DAYDSPF) SRCFILE(libraryname/QDDSSRC) SRCMBR(*FILE)
RPG program with Subprocedure (DAYOFWKP):
Use the following command to compile the ILE RPG IV module:
CRTRPGMOD MODULE(libraryname/DAYOFWKP)
CRTDSPF FILE(libraryname/DAYDSPF) SRCFILE(libraryname/QDDSSRC) SRCMBR(*FILE)
RPG program with Subprocedure (DAYOFWKP):
Use the following command to compile the ILE RPG IV module:
CRTRPGMOD MODULE(libraryname/DAYOFWKP)
**FREE
Dcl-F DAYDSPF WORKSTN;
Dcl-Pr DayOfWeek Packed(1:0);
DateIn Date;
End-Pr;
//
Dcl-S Week_Date Date INZ;
Dcl-S WeekDay Packed(1:0);
//
//
DoW *in03 = '0';
Write footer;
Exfmt dayfmt;
If *in03 = '0';
Week_Date = %Date(date:*MDY);
WeekDay = DayOfWeek(Week_Date);
If WeekDay = 7;
%Subst(day:1:6) = 'Sunday';
Else;
If WeekDay = 6;
%Subst(day:1:8) = 'Saturday';
Else;
If WeekDay = 5;
%Subst(day:1:9) = 'Friday ';
Else;
If WeekDay = 4;
%Subst(day:1:9) = 'Thursday ';
Else;
If WeekDay = 3;
%Subst(day:1:9) = 'Wednesday';
Else;
If WeekDay = 2;
%Subst(day:1:8) = 'Tuesday ';
Else;
If WeekDay = 1;
%Subst(day:1:8) = 'Monday ';
EndIf;
EndIf;
EndIf;
EndIf;
EndIf;
EndIf;
EndIf;
Exfmt dayfmt2;
day = *Blanks;
EndIf;
EndDo;
*INLR = *ON;
//
ILE RPG IV Procedure (DAYOFWK1):
Use the following command to compile the ILE RPG IV module:
CRTRPGMOD MODULE(libraryname/DAYOFWK1)
CRTRPGMOD MODULE(libraryname/DAYOFWK1)
**FREE
Ctl-Opt NoMain;
Dcl-Pr DayOfWeek Packed(1:0);
DateIn Date;
End-Pr;
Dcl-Proc DayOfWeek EXPORT;
Dcl-Pi *n Packed(1:0);
DateIn Date;
End-Pi;
//
Dcl-S Weeks Packed(7:0);
Dcl-S DayNbr Packed(1:0);
Dcl-S AnySunday Date inz(d'1997-04-27');
Weeks = %Diff(DateIn:AnySunday:*D);
// Weeks = Weeks / 7;
DayNbr = %Rem(Weeks : 7);
Weeks = Weeks / 7;
If DayNbr < 1;
DayNbr = DayNbr + 7;
EndIf;
Return DayNbr;
End-Proc DayOfWeek;
Use CRTPGM to bind the two modules together so you can run the program:
CRTPGM PGM(libraryname/DAYOFWKP) MODULE(libraryname/DAYOFWKP libraryname/DAYOFWK1)
Call DAYOFWKP from command line.


[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
8492017
Was this topic helpful?
Document Information
Modified date:
19 November 2024
UID
nas8N1010153