Application Development 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: 

input check of report

Former Member
0 Kudos

I have selection option parameter to choose the date range called so_dt. this field gets data from the table ztbl_name.

Here is the common input check

IF NOT ztbl_name[] IS INITIAL.

SELECT dt

INTO wa

FROM ztbl_name

UP TO 1 ROWS

WHERE dt IN so_dt.

ENDSELECT.

IF NOT SY-SUBRC IS INITIAL.

MESSAGE E001(zmsg).

ENDIF.

ENDIF.

Can any body explain the code snippet above? and is it the best practice?

4 REPLIES 4

MarcinPciak
Active Contributor
0 Kudos

Hi Anthony,

Let me do couple remarks and explanations:

1) IF NOT ztbl_name[] IS INITIAL is wrong. I assume zttbl_name table is a custom DDIC (created via ABAP Dictionary) table, therefore you can't ask DB if table is empty with this statemnent. Instead you may use SELECT (count), but here it is not necessary at all

2) It is a bit more faster to use select single or select distinct instead of looping via table within select - endselect.

3) isntead of creating wa structure you use structure defined by TABLES ztbl_name. This will create a strucutre of line type ztbl_name.

4) If you require only certain fields (called projections) it is better and fater to move it only to specified destination i.e. INTO wa-dt, but anyhow this if ok too:)

5) Always check if sy-subrc = 0, not if not initial. In this case you can check also field sy-dbcnt which return no. of correctly read records

Providing above will apply lets do some coding below:


TABLES: ztbl_name.   "declare structure for the table first (this will be our work area)

SELECT SINGLE dt FROM ztbl_name "this will implicitly put data to ztbl_name structure
WHERE dt IN so_dt.


IF sy-subrc = 0.  "alternatively use sy-dbcnt <> 0.
    "do your processing here
    "you address dt field as ztbl_name-dt
ELSE.
      MESSAGE E001(zmsg).
ENDIF.

I hope it will give you some basic overview:)

Cheers

Marcin

0 Kudos

Thanks Marcin! The sy-subrc is initial means its value is 0 right?

0 Kudos

Probably yeah. But you were asking of best practices, that's why I wrote sy-subrc = 0, as this is the most common way of checking if statement was correct;)

KR

Marcin

0 Kudos

yes, thank you very much!