SKIP The Record

Rajshri

New Member
Consider a table named "pmac" in the data base.

Fields: (1) Project Code
(2) PNO
(3) Status
A project may have many PNOs.

Consider Project A has two PNOs 1 & 2.

we have to validate project through procedure library VALIDATE-PROJECT-MASTER.
run​
VALIDATE-PROJECT-MASTER in THIS-PROCEDURE

(​
input fb_pmac.pmkey,
input fb_pmac.pm-code,
input "pm-status":U,
input true,
output vl_Error,
output vl_ErrMsg,
output vl_ErrType,
output vl_Return).


if vl_Error
or entry(1, vl_Return) lt "7":U

or entry(1, vl_Return) gt "k":U then

next.
In this code if the status of Project A(for PNO 1) is wrong then it reads next pmac record, which is again Project A for PNO 2.

Is there any statement or function to skip record at this point?

Because again it reads Project A & validates.

We don't want to validate Project A if it has many PNOs.


 

Rajshri

New Member
for​
each fb_pmac no-lock

where fb_pmac.pmkey eq vl_sc-proj-key
and fb_pmac.pm-code ge vl_StartProject
and fb_pmac.pm-code le vl_EndProject

break by fb_pmac.pm-code:


run​
VALIDATE-PROJECT-MASTER in THIS-PROCEDURE

(​
input fb_pmac.pmkey,
input fb_pmac.pm-code,
input "pm-status":U,
input true,
output vl_Error,
output vl_ErrMsg,
output vl_ErrType,
output vl_Return).


if vl_Error
or entry(1, vl_Return) lt "7":U

or entry(1, vl_Return) gt "k":U then

next.

end.
 
1. once per project:
If first-of (fb_pmac.pm-code) then
do:
run validate ().
end.

2. dont validate if 2 records:

find PNO of fb_pmac NO-ERROR.
if ambiguos PNO then NEXT.
 

Rajshri

New Member
1. once per project:
If first-of (fb_pmac.pm-code) then
do:
run validate ().
end.

2. dont validate if 2 records:

find PNO of fb_pmac NO-ERROR.
if ambiguos PNO then NEXT.

But if we validate Project-Master in first-of(fb_pmac.pm-code) then
Now the way you have the program it doesn't check the project and includes the PNO on the report (it shouldn't).
 

LarryD

Active Member
You're not clear on the behavior you want.

If you just want to validate once per project:

Code:
for [SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]each[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]no-lock[/COLOR][/SIZE][/COLOR][/SIZE]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]    where[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pmkey [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]eq[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_sc-proj-key
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]      and[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pm-code [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]ge[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_StartProject
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]      and[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pm-code [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]le[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_EndProject[/SIZE][/LEFT]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]            break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]by[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pm-code:[/SIZE]
 
[SIZE=2]     [SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if first-of(fb_pmac.pm-code) then do:
[LEFT]      run[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2] VALIDATE-PROJECT-MASTER [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]in[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]THIS-PROCEDURE[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]           ([/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pmkey,
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fb_pmac.pm-code,
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pm-status"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE][SIZE=2][COLOR=#ff8000][SIZE=2][COLOR=#ff8000]U[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#cd3a3a][SIZE=2][COLOR=#cd3a3a]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             output[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_Error,
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             output[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_ErrMsg,
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             output[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_ErrType,
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             output[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_Return).

[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]           if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vl_Error
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             or[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]entry[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], vl_Return) [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]lt[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"7"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE][SIZE=2][COLOR=#ff8000][SIZE=2][COLOR=#ff8000]U[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#ff8000][SIZE=2][COLOR=#ff8000]
[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]             or[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]entry[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], vl_Return) [/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]gt[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"k"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:[/SIZE][SIZE=2][COLOR=#ff8000][SIZE=2][COLOR=#ff8000]U[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]then[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]                  next[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][/LEFT]
[SIZE=2]end.
else next.

... report stuff...  (I'm guessing)

end.
[/SIZE][/SIZE]


EDIT: the editor is "too helpful" ... extra code statements shouldn't be there.


 

Rajshri

New Member
Please have a look into the given example:

Project A has two Pno's B and C

for each pmac finds both PNO B and C

the first-of pm-code (which is PNO B) checks status of the project and if not correct then does a next.

the program then reads the next one (which is PNO C and belongs to the same project). We have to stop this re-read because PNO C belongs to the same project A.

if we have the validation in first-of(fb_pmac.pm-code) then the first-of(fb_pmac.pm-code) which is PNO B checks status of the project and but it doesn't check the status for PNO C and includes the PNO on the report (it shouldnt).
 

Rajshri

New Member
Did you mean by this?

if​
first-of(fb_pmac.pm-code) then

do:
run VALIDATE-PROJECT-MASTER in THIS-PROCEDURE

(​
input fb_pmac.pmkey,
input fb_pmac.pm-code,
input "pm-status":U,
input true,
output vl_Error,
output vl_ErrMsg,
output vl_ErrType,
output vl_Return).

if vl_Error
or entry(1, vl_Return) lt "7":U

or entry(1, vl_Return) gt "k":U then

next.
end.
else

next.

If I code like this it doesn't give me the complete data on the report.

It gives me the data for project which has many PNOs first time only.
 
just add some logical variable then

for each:
if first-of () then
do:
badproject = false.
validate ()
if doesntvalid then
badproject = true.
end.
if badproject then next.

print datareport.
end.
 

Rajshri

New Member
just add some logical variable then

for each:
if first-of () then
do:
badproject = false.
validate ()
if doesntvalid then
badproject = true.
end.
if badproject then next.

print datareport.
end.

it means

if first-of (fb_pmac.pm-code) (PNO is B) then
do:
badproject = false.

validate PROJECT-MASTER

if vl_Error(i.e status is wrong for Project A - PNO B) then
badproject = true.
end.

if badproject then
next. (it means it reads the next record which is again Project A - PNO C)
The question is when we have done vaidation for Project A for PNO B then why to validate same project A for PNO C?
Once it has found that the status of Project A is wrong we have to skip this Record at this point itself if it has many PNOs.
Say Project A has 10 PNOs 1,2,3........10.
We have found that the status of Project A for PNO 1 is wrong then why do we need to validate project A further for PNOs 2,3,4,.......10.
validate Project-master in first-of(fb_pmac.pm-code) is not the correct way because if we use first-of(fb_pmac.pm-code) then it means we are including PNO C in the report without validating Project for PNO C.
isn't it?
 
first-of restricts that validation will be applied once per project. And it initialize logical variable once only.
for PNO C,D etc it skips validation and go to

if badproject then next.
 

Rajshri

New Member
does it make sense?


run
VALIDATE-PROJECT-MASTER inTHIS-PROCEDURE

(


input fb_pmac.pmkey,

input fb_pmac.pm-code,
input"pm-status":U,
inputtrue,
output vl_Error,
output vl_ErrMsg,
output vl_ErrType,
output vl_Return).



if vl_Error
or entry(1, vl_Return) lt"7":U
or entry(1, vl_Return) gt"k":Uthen
if last-of(fb_pmac.pm-code) then


next.

Because the question was why to validate Project A for PNO C if status is wrong.
now we have next pmac record on last-of(fb_pmac.pm-code).
it means, it validates Project for both PNO B & PNO C but reads next record only after PNO C.
isn't it?
 

Rajshri

New Member
just add some logical variable then

for each:
if first-of () then
do:
badproject = false.
validate ()
if doesntvalid then
badproject = true.
end.
if badproject then next.

print datareport.
end.

Thank you very much...
Yes this code is working fine.
 

skunal

Member
is it the correct way to handle this one?
v-pmkey = "";
v-pmcode = "";
for
each fb_pmac no-lock


where fb_pmac.pmkey eq vl_sc-proj-key
and fb_pmac.pm-code ge vl_StartProject
and fb_pmac.pm-code le vl_EndProject

breakby fb_pmac.pm-code:

you can use the variables here and then check if it has been already used for that project then run the project else go to next record
if v-pmkey = fb_pmac.pmkey and v-pmcode = fb_pmac.pm-code then
Next;
else
do:
v-pmkey = fb_pmac.pmkey ;
v-pmcode = fb_pmac.pm-code;




run​
VALIDATE-PROJECT-MASTER inTHIS-PROCEDURE

end.
hope this resolves the issue
 
Top