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

parameters and if

sandeepkarnati
Participant
0 Likes
1,697

here i am trying to bring data on to screen from internal table base on input given at parameters.....

there is a problem with the IF stmt........could any one correct the code.....

selection-screen : begin of block b1 with frame title text-123 no

intervals.

parameters : s_vbeln type vbak-vbeln.

selection-screen end of block b1.

at selection-screen on s_vbeln.

if s_vbeln in vbak-vbeln.

loop at it3 into wa3..

write : / wa3-vbeln,

         wa3-werks,

          wa3-matnr.

endloop.

else.

message 'no data' type 'E'.

endif.

(or)

loop at it3 into wa3 where s_vbeln in vbak-vbeln.

write : / wa3-vbeln,

          wa3-werks,

          wa3-matnr.

endloop.

10 REPLIES 10
Read only

Former Member
0 Likes
1,557

Hi Sandeep,

what error are you getting? Have u populated it3? VBAK-VBELN can not be used like the way u have used in the code. it cant be compared like that

Regards,

Shahir Mirza

Read only

sandeep_ramesh88
Explorer
0 Likes
1,557

Helo Sandeep,

Are you populating the IT3 internal table? The check you have done for the VBELN select option is wrong. Fill the internal table with the required data and check the same with your select option. There is no need of an IF statement check. Select the data from the database based on your input only.

Again if the field in the selection screen is a free flow field, for the validation purpose do the below:

SORT IT3 BY VBELN ASCENDING.

IF SO_VBELN-LOW IS NOT INITIAL.

READ TABLE IT3 INTO WA3 WITH KEY VBELN = SO_VBELN-LOW BINARY SEARCH.

ELSE

MESSAGE 'No Data found' TYPE 'E'.

ENDIF.

IF SO_VBELN-HIGH IS NOT INITIAL.

READ TABLE IT3 INTO WA3 WITH KEY VBELN = SO_VBELN-HIGH  BINARY SEARCH.

ELSE

MESSAGE 'No Data found' TYPE 'E'.

ENDIF.

This is the simplest validation.


Read only

Former Member
0 Likes
1,557

Hi Sandeep, You are not using any select statement for populating data on screen, or you forget to paste it here.

SELECT SINGLE *

   from vbak

   INTO wa3

   where vbeln = p_vbeln.

  write : / wa3-vbeln.

will work fine.

Regards,

Nivedita

Read only

Former Member
0 Likes
1,557

Hi,

If you are trying to take data form VBAK table and print it on scrren based on value passed on selection screen table code will be like this .

   REPORT  ztestmessage.
tables : vbak.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-123 NO

INTERVALS.

SELECT-OPTIONS : s_vbeln for vbak-vbeln.
SELECTION-SCREEN END OF BLOCK b1.
data : it3 type STANDARD TABLE OF vbak,
       wa3 type vbak.



START-OF-SELECTION.
select * from vbak into table it3 where vbeln in s_vbeln.
if sy-subrc EQ 0.
    LOOP AT it3 INTO wa3.
      WRITE : / wa3-vbeln.
*                wa3-waerk,
*                wa3-matnr.
    ENDLOOP.
  ELSE.
    MESSAGE 'no data' TYPE 'E'.
  ENDIF.

Regards,

Priyaranjan

Read only

Former Member
0 Likes
1,557

hi kranthi,

               before loop statement you can write the code of start-of-selection. you can this code

data : it3 TYPE STANDARD TABLE OF vbak,

        wa3 TYPE vbak.

selection-screen : begin of block b1 with frame title text-123.

parameters : s_vbeln type vbak-vbeln.

selection-screen end of block b1.

at selection-screen on s_vbeln.

SELECT * from vbak into TABLE it3.

START-OF-SELECTION.

loop at it3 into wa3 where vbeln eq s_vbeln.

write : / wa3-vbeln,

           WA3-WAERK.

*          wa3-matnr.

endloop.

Read only

VijayaKrishnaG
Active Contributor
0 Likes
1,557

Hi Sandeep,

You cannot check whether the entered VBELN exist in VBAK or not. You should fetch atleast one record from VBAK related to entered VBELN. And this issue is not with combination of Parameter and IF conditions. The problem is with your comparison in IF condition.

So, you can try like as follows,

AT SELECTION SCREEN.


SELECT SINGLE * FROM VBAK WHERE VBELN EQ S_VBELN.

IF SY-SUBRC NE 0.

  MESSAGE E000(<msg_class>) WITH 'text'.

ELSE.

  <you can handle your own code.

ENDIF.

Thanks & Regard,

-Vijay

Read only

mayur_priyan
Active Participant
0 Likes
1,557

Hi,

I am unable to understand the IF logic which u have stated in the code snippet.

if s_vbeln in vbak-vbeln.

Are you trying to check whether the value entered in the selection screen is present in the database table ?

If yes then you have to check it using a SELECT SINGLE * statement in the program and then code the WRITE statement if the sy-subrc of the Select statement is zero.

Select single * from vbak into ls_vbak where vbeln IN s_vbeln.

If sy-subrc = 0.

Add your WRITE statements.

Endif.

Read only

Former Member
0 Likes
1,557

Hi Sandeep,

Here you are using parameter and not select option.

Parameter acts like a variable while select option act like an internal table with 4 fields(sign, option,low,high).

"

if s_vbeln in vbak-vbeln.

loop at it3 into wa3..

write : / wa3-vbeln,

         wa3-werks,

          wa3-matnr.

endloop.

else.

message 'no data' type 'E'.

endif.

"

In the above code, "vbak-vbeln" need to be a variable whose value is already populated before you check the 'if statement'. Also the condition should be:

" if s_vbeln eq vbak-vbeln. "

Also , the internal table " it3 " also needed to be populated before the loop statement .

Hope you got the point.

Regards,

Alex

Read only

sandeepkarnati
Participant
0 Likes
1,557

This message was moderated.

Read only

Former Member
0 Likes
1,557

Hi sandeep,

As per my understanding you can not directly check the database table value with selection screen value. For yours you have to fetch the data from database to internal table then you can check the data it will work.

Regards,

John.