2007 Jul 09 9:56 AM
Hi Guys/Dolls
I have the following piece of code - not very elegant but it works.
* Select data for monthly staff.
SELECT * FROM ztcdata INTO irec
WHERE mnthf EQ p_month
AND procf EQ '2'
AND abkrs EQ 'M1'.
APPEND irec.
ENDSELECT.
* Select data for weekly staff.
SELECT * FROM ztcdata INTO irec
WHERE procf EQ '2'
AND abkrs EQ 'W1'.
APPEND irec.
ENDSELECT.
The problem is if there is no weekly data the value of sy-subrc is set to "0" and all other processing (i.e. rest of the program) does not proceed.
I can explicitly set the value of sy-subrc to 0 after the 2nd select but was wondering if there was a more elegant way of doing this.
Many thanks in advance.
Raj
2007 Jul 09 10:30 AM
hi,
try like this,
Select data for monthly staff.
SELECT * FROM ztcdata INTO TABLE irec
WHERE mnthf EQ p_month
AND procf EQ '2'
AND abkrs EQ 'M1'.
if sy-subrc eq 0.
Select data for weekly staff.
SELECT * FROM ztcdata INTO TABLE irec
WHERE procf EQ '2'
AND abkrs EQ 'W1'.
if sy-subrc eq 0.
conditions.
endif.
endif.
if helpful reward some points.
with regards,
Suresh.A
2007 Jul 09 10:04 AM
Hi,
Add your other condition to if sy-subrc = 0 or (Your conditio here).
But if you want to proceede even if sy-subrc is not 0 then why are you checking the condition in the first place you need not check and procede as nothing has happened.
I am sorry if I understood it wrongly
Regards,
Sesh
2007 Jul 09 10:30 AM
hi,
try like this,
Select data for monthly staff.
SELECT * FROM ztcdata INTO TABLE irec
WHERE mnthf EQ p_month
AND procf EQ '2'
AND abkrs EQ 'M1'.
if sy-subrc eq 0.
Select data for weekly staff.
SELECT * FROM ztcdata INTO TABLE irec
WHERE procf EQ '2'
AND abkrs EQ 'W1'.
if sy-subrc eq 0.
conditions.
endif.
endif.
if helpful reward some points.
with regards,
Suresh.A
2007 Jul 09 11:03 AM
Ok managed to solve it like this but still not sure if its the right route to take.
Any comments appreciated.
Many thanks to all you guru's who took the time out to look at my question.
DATA: irec_counter TYPE i VALUE 0. " irec counter.
* Select data for monthly staff.
SELECT * FROM ztcdata INTO irec
WHERE mnthf EQ p_month
AND procf EQ '2'
AND abkrs EQ 'M1'.
APPEND irec.
ENDSELECT.
* Select data for weekly staff.
SELECT * FROM ztcdata INTO irec
WHERE procf EQ '2'
AND abkrs EQ 'W1'.
APPEND irec.
ENDSELECT.
DESCRIBE TABLE irec LINES irec_counter.
IF irec_counter > 0.
sy-subrc = 0.
ENDIF.
Raj
2007 Jul 09 11:30 AM
Hi,
Try this also
if sy-subrc = 0 or LINES(irec) > 0.
endif.
Regards,
Sesh
2007 Jul 09 11:20 AM