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

Getting error in the singnle select program (​Error :Local SELECT-OPTIONS are not allowed)

former_member584050
Participant
0 Likes
2,321

Dear experts:
i am getting following error for the below program could you please suggest what i have to rectify.
Error :Local SELECT-OPTIONS are not allowed (FORM routine or GET event is active). active).

REPORT Y_MESSAGE_SELECT_SINGLE.
tables kna1.
select-options s_kunnr for kna1-kunnr.
data vi type kna1-kunnr.
at selection-screen.
select single kunnr from kna1 into vi where kunnr in s_kunnr.
if sy-subrc <> 0.
message A000(ZSPT_8AM_MSG) with 'Invalid length'.
endif.

tables vbak.
select-options s_vbeln for vbak-vbeln.
data vi type vbak-vbeln.
at selection-screen.
select single vbeln from vbak into vi where vbeln in s_vbeln.
if s-subrc <> 0.
message a000(ZSPT_8AM_MSG) with 'Invalid customer'.
endif.

tables lfa1.
select-options s_lifnr for lfa1-lifnr.
data vi type lfa1-lifnr.
at selection-screen on s_lifnr.
select single lifnr from lfa1 into vi where lifnr in s_lifnr.
if sy-subrc <> 0.
message a000(ZSPT_8AM_MSG) with 'invalid vendor'.
endif.

start-of-selection.
select kunnr name1 ort01 from kna1 into table it_kna1 where kunnr in s_kunnr.
end-of-selection.
if p_dis = 'X'.
loop at it_kna1 into wa_kna1.
write:/ wa_kna1-kunnr,wa_kna1-name1,wa_kna1-ort01.
endloop.
else if p_nodis = 'X'.
write: 'please select check box'.
endif.
top-of-page.
write ' sy tech'.
end-of-page.
write: 'hs 30 , above deb'.

1 ACCEPTED SOLUTION
Read only

former_member1716
Active Contributor
1,677

Hello kumar kumar,

Next time when you post the code please ensure you use the CODE option as i did below so that your code is well aligned and easy to read.

Now coming back to the error that you are facing:

The reason is you have declared Selection Screen parameters in AT SELECTION SCREEN EVENT. That's why you got the error as local select options are not allowed.

Few important Points to know:

1) Declarations and Selection screen parameters must be the initial part of the program. Selection screen parameter in specific should not be declared after the start of any explicit events declared in program.

2) It would be the best practice if you have Separate Includes for Data Declaration, Selection Screen Parameters and remaining Sub routines.

3) You have declared Multiple at selection screen event which is not required.

4) You have used Parameters in the program which was never declared.

Recommend you to understand the flow of Events in report programming before proceeding further. Based on my understanding on your requirement i have corrected your code, recommend you to understand the code before proceeding further.

TABLES: vbak, kna1, lfa1.

DATA: v1 TYPE kna1-kunnr,
      v2 TYPE vbak-vbeln,
      v3 TYPE lfa1-lifnr.


SELECT-OPTIONS: s_kunnr FOR kna1-kunnr,
                s_vbeln FOR vbak-vbeln,
                s_lifnr FOR lfa1-lifnr.

PARAMETERS: p_dis TYPE c AS CHECKBOX.

AT SELECTION-SCREEN.

  SELECT SINGLE kunnr FROM kna1 INTO v1 WHERE kunnr IN s_kunnr.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'Invalid length'.
  ENDIF.

  SELECT SINGLE vbeln FROM vbak INTO v2 WHERE vbeln IN s_vbeln.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'Invalid customer'.
  ENDIF.

AT SELECTION-SCREEN ON s_lifnr.

  SELECT SINGLE lifnr FROM lfa1 INTO v3 WHERE lifnr IN s_lifnr.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'invalid vendor'.
  ENDIF.

START-OF-SELECTION.

  SELECT kunnr,
         name1,
         ort01
  FROM kna1
  INTO TABLE @DATA(it_kna1)
  WHERE kunnr IN @s_kunnr.
  
  IF Sy-subrc EQ 0.
   SORT IT_KNA1 by KUNNR.
  endif.

END-OF-SELECTION.

  IF p_dis = 'X'.
    LOOP AT it_kna1 INTO DATA(wa_kna1).
      WRITE:/ wa_kna1-kunnr,wa_kna1-name1,wa_kna1-ort01.
    ENDLOOP.
  ELSE.
    WRITE: 'please select check box'.
  ENDIF.

TOP-OF-PAGE.
  WRITE ' sy tech'.

END-OF-PAGE.
  WRITE: 'hs 30 , above deb'.

Regards!

4 REPLIES 4
Read only

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Likes
1,677

Changed tag since question is not related to sap cloud platform abap environment

ceterum censeo RAP esse utendam
Read only

former_member1716
Active Contributor
1,679

Hello kumar kumar,

Next time when you post the code please ensure you use the CODE option as i did below so that your code is well aligned and easy to read.

Now coming back to the error that you are facing:

The reason is you have declared Selection Screen parameters in AT SELECTION SCREEN EVENT. That's why you got the error as local select options are not allowed.

Few important Points to know:

1) Declarations and Selection screen parameters must be the initial part of the program. Selection screen parameter in specific should not be declared after the start of any explicit events declared in program.

2) It would be the best practice if you have Separate Includes for Data Declaration, Selection Screen Parameters and remaining Sub routines.

3) You have declared Multiple at selection screen event which is not required.

4) You have used Parameters in the program which was never declared.

Recommend you to understand the flow of Events in report programming before proceeding further. Based on my understanding on your requirement i have corrected your code, recommend you to understand the code before proceeding further.

TABLES: vbak, kna1, lfa1.

DATA: v1 TYPE kna1-kunnr,
      v2 TYPE vbak-vbeln,
      v3 TYPE lfa1-lifnr.


SELECT-OPTIONS: s_kunnr FOR kna1-kunnr,
                s_vbeln FOR vbak-vbeln,
                s_lifnr FOR lfa1-lifnr.

PARAMETERS: p_dis TYPE c AS CHECKBOX.

AT SELECTION-SCREEN.

  SELECT SINGLE kunnr FROM kna1 INTO v1 WHERE kunnr IN s_kunnr.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'Invalid length'.
  ENDIF.

  SELECT SINGLE vbeln FROM vbak INTO v2 WHERE vbeln IN s_vbeln.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'Invalid customer'.
  ENDIF.

AT SELECTION-SCREEN ON s_lifnr.

  SELECT SINGLE lifnr FROM lfa1 INTO v3 WHERE lifnr IN s_lifnr.
  IF sy-subrc <> 0.
    MESSAGE a000(zspt_8am_msg) WITH 'invalid vendor'.
  ENDIF.

START-OF-SELECTION.

  SELECT kunnr,
         name1,
         ort01
  FROM kna1
  INTO TABLE @DATA(it_kna1)
  WHERE kunnr IN @s_kunnr.
  
  IF Sy-subrc EQ 0.
   SORT IT_KNA1 by KUNNR.
  endif.

END-OF-SELECTION.

  IF p_dis = 'X'.
    LOOP AT it_kna1 INTO DATA(wa_kna1).
      WRITE:/ wa_kna1-kunnr,wa_kna1-name1,wa_kna1-ort01.
    ENDLOOP.
  ELSE.
    WRITE: 'please select check box'.
  ENDIF.

TOP-OF-PAGE.
  WRITE ' sy tech'.

END-OF-PAGE.
  WRITE: 'hs 30 , above deb'.

Regards!

Read only

0 Likes
1,677
Dear satish, 

i understood your suggestion and rectified code even after maintaining endif. before top-of-the page getting and eeror "Incorrect nesting: Before the statement "TOP-OF-PAGE", the control structure introduced by "IF" must be concluded with "ENDIF". Could you please suggest REPORT Y_MESSAGE_SELECT_SINGLE. TABLES: vbak, kna1, lfa1. data : v1 type kna1-kunnr, v2 TYPE vbak-vbeln, v3 TYPE lfa1-lifnr. SELECT-OPTIONS: s_kunnr FOR kna1-kunnr, s_vbeln FOR vbak-vbeln,
s_lifnr FOR lfa1-lifnr. types: begin of ty_kna1,
kunnr type kna1-kunnr,
name1 type kna1-name1,
ort01 type kna1-ort01, end of ty_kna1.
data wa_kna1 type ty_kna1. data it_kna1 type table of ty_kna1. PARAMETERS: p_dis TYPE c AS CHECKBOX. PARAMETERS: p_nodis TYPE c AS CHECKBOX.
at selection-screen. select single kunnr from kna1 into v1 where kunnr in s_kunnr. if sy-subrc <> 0. message A000(ZSPT_8AM_MSG) with 'Invalid length'. endif. select single vbeln from vbak into v2 where vbeln in s_vbeln. if sy-subrc <> 0. message a000(ZSPT_8AM_MSG) with 'Invalid customer'. endif. at selection-screen on s_lifnr. select single lifnr from lfa1 into v3 where lifnr in s_lifnr. if sy-subrc <> 0. message a000(ZSPT_8AM_MSG) with 'invalid vendor'. endif. start-of-selection. select kunnr name1 ort01 from kna1 into table it_kna1 where kunnr in s_kunnr. end-of-selection. if p_dis = 'X'. loop at it_kna1 into wa_kna1. write:/ wa_kna1-kunnr,wa_kna1-name1,wa_kna1-ort01. endloop. else. if p_nodis = 'X'. write: 'please select check box'. endif. top-of-page.
write ' sy tech'. end-of-page. write: 'hs 30 , above deb'.
Read only

1,677
kumar kumar Check twice, I can see immediately that you have 2 "IF" but only 1 "ENDIF" -> so, 1 "ENDIF" is missing in your code.