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

Display Error message if internal table is blan

Former Member
0 Likes
2,766

Hi,

I am making a report in which i am taking data from BSIK table, as per below code i have declare two internal tables

IT_BSIK_H

IT_BSIK_S without header line but i want to display error message if both those table are empty and user should be on selection screen

i want to display message as NO record Found.

How to do it.

****************************************************************************

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr zfbdt zterm zbd1t FROM bsik

INTO TABLE IT_BSIK_H where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'H'.

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr FROM bsik

INTO TABLE IT_BSIK_S where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

  • ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'S'.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,210

Hi,

If the internal table is blank the display error message

IF ITAB[] is initial.

message 'No records found' type 'E'.

leave screen.

endif

Regards

Nehruu

Hi,

I am making a report in which i am taking data from BSIK table, as per below code i have declare two internal tables

IT_BSIK_H

IT_BSIK_S without header line but i want to display error message if both those table are empty and user should be on selection screen

i want to display message as NO record Found.

How to do it.

****************************************************************************

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr zfbdt zterm zbd1t FROM bsik

INTO TABLE IT_BSIK_H where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'H'.

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr FROM bsik

INTO TABLE IT_BSIK_S where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

  • ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'S'.

12 REPLIES 12
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,210

Hello,

I think should be the way you should be doing this:

IF IT_BSIK_H IS INITIAL AND IT_BSIK_S IS INITIAL.
  MESSAGE 'No Records Found' TYPE 'I'.
  LEAVE LIST-PROCESSING.
ENDIF.

BR,

Suhas

Read only

Former Member
0 Likes
2,210

Hi,

As u said erro if both are empty :


SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr zfbdt zterm zbd1t FROM bsik
INTO TABLE IT_BSIK_H where BUKRS IN BUKRS AND
LIFNR IN LIFNR AND
ZTERM IN ZTERM AND
* ZFBDT IN ZFBDT AND
BLART IN BLART AND
SAKNR IN SAKNR AND
SHKZG eq 'H'.
*If data not selected
if not sy-subrc is initial.
p_err1 = 'X'.
endif.
SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr FROM bsik
INTO TABLE IT_BSIK_S where BUKRS IN BUKRS AND
LIFNR IN LIFNR AND
* ZTERM IN ZTERM AND
* ZFBDT IN ZFBDT AND
BLART IN BLART AND
SAKNR IN SAKNR AND
SHKZG eq 'S'.
*If data not selected
if not sy-subrc is initial.
p_err2 = 'x'.
endif.
start-of-selection.
if p_err1 eq 'X' and p_err2 eq 'X'.

*give error message

endif.

Regards,

Salil

Read only

Former Member
0 Likes
2,211

Hi,

If the internal table is blank the display error message

IF ITAB[] is initial.

message 'No records found' type 'E'.

leave screen.

endif

Regards

Nehruu

Read only

0 Likes
2,210

Hi,

Thaks for your reply, i have done changes as given but still if interval table is empty it is going for further operation

find below the code .

*******************************

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr zfbdt zterm zbd1t FROM bsik

INTO TABLE IT_BSIK_H where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'H'.

if not sy-subrc is initial.

Flag1 = 'x'.

endif.

SELECT bukrs lifnr zuonr gjahr belnr budat bldat waers xblnr blart SHKZG MWSKZ dmbtr WRBTR sgtxt saknr FROM bsik

INTO TABLE IT_BSIK_S where BUKRS IN BUKRS AND

LIFNR IN LIFNR AND

  • ZTERM IN ZTERM AND

  • ZFBDT IN ZFBDT AND

BLART IN BLART AND

SAKNR IN SAKNR AND

SHKZG eq 'S'.

if not sy-subrc is initial.

Flag2 = 'x'.

endif.

if flag1 eq 'X' and flag2 eq 'X'.

message E888 with 'No Data Found'.

LEAVE LIST-PROCESSING.

endif.

*******************************

regards,

zafar

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,210

Hello Zafar,

if flag1 eq 'X' and flag2 eq 'X'.
* message E888 with 'No Data Found'.
message I888 with 'No Data Found'.
LEAVE LIST-PROCESSING.
endif.

And what do you mean by "further operation" ?

BR,

Suhas

Edited by: Suhas Saha on Feb 26, 2010 12:13 PM

Read only

0 Likes
2,210

Hi,

After seleting data from table bsak further operation means it is selecting vendor name G/L account descripton all this think if first two internal tables are empty ti should not go for all this it should leave the program.

regards,

zafar

Read only

0 Likes
2,210

if flag1 eq 'X' and flag2 eq 'X'.

message I888 with 'No Data Found'.

LEAVE Program.

else.

selecr * from kna1...

select description

endif.

or

if itab1[] is initial and itab2[] is initial.

leave program.

else.

...process

endif

Read only

0 Likes
2,210

Hi,

I the problem is that even both the flag are set to X it is not executing the message part it is directly going to after end if of message and processing further.

regards,

zafar

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,210

Hello,

How have you defined the flags ?

I think your facing this because the flags are case-sensitive

Check this:

if not sy-subrc is initial.
Flag1 = 'x'. "Lower Case
endif.

But in the check you are checking the upper-case

if flag1 eq 'X' and flag2 eq 'X'. "Upper Case
message E888 with 'No Data Found'.
LEAVE LIST-PROCESSING.
endif.

I think this might be causing the problem.

BR,

SUhas

Read only

Former Member
0 Likes
2,210

Do like..

IF IT_BSIK_H IS INITIAL AND IT_BSIK_S IS INITIAL.

Message 'No Data Found' TYPE 'I' DISPLAY LIKE 'E'.

EXIT.

ELSE.

then your code to proceed if data found

ENDIF.

Edited by: Sachin Bidkar on Feb 26, 2010 8:13 AM

Read only

0 Likes
2,210

hi

If both flag is set 'X'. Further process

I think you dont want error message.

if flag1 eq 'X' and flag2 eq 'X'.

selecr * from kna1...

select description

endif.

Can you please tell me clear with you scenario...

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,210

Add the following lines to your report :

* TOP
TABLES : sscrfields.
* AT SELECTION-SCREEN ON selopt.
  PERFORM check_selopt.
* AT SELECTION-SCREEN
AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN 'ONLI' OR 'PRIN'.
      PERFORM read_main_tables.
      IF IT_BSIK_H[] IS INITIAL
      AND IT_BSIK_SH[] IS INITIAL
        MESSAGE e280(s1). " Message will be displayed on selection-screen.
      ENDIF.
  ENDCASE.
START-OF-SELECTION.
  PERFORM read_other_tables.
END-OF-SELECTION.
  PERFORM display_data.

Also check the behavior of program when message are sent at [Behavior of messages|http://help.sap.com/abapdocu_70/en/ABENABAP_MESSAGES_TYPES.htm] and [Messages in dialog processing |http://help.sap.com/abapdocu_70/en/ABENABAP_MESSAGE_DIALOG.htm]

Regards,

Raymond