Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sy-subrc

Former Member
0 Likes
897

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
850

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

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

5 REPLIES 5
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
850

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

Read only

Former Member
0 Likes
851

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

Read only

Former Member
0 Likes
850

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

Read only

0 Likes
850

Hi,

Try this also

if sy-subrc = 0 or LINES(irec) > 0.

endif.

Regards,

Sesh

Read only

Former Member
0 Likes
850

See my own hack.