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

Code Problem

Former Member
0 Likes
796

Hello eveyone

I have a really strange problem and I am not sure what I am doing wrong. I have created an include with the following code.

I am calling this include in MV45AFZB under userexit userexit_get_field_from_sdcom USING sdcom STRUCTURE sdcom.

When I try to activate it in the main include, it comes up with an error at the "else" statement saying, no open "if" statement.

Can you please analyze the code and tell me what I am doing wrong?

DATA: lv_wrk02 LIKE vbap-werks,

lv_inst LIKE VBAP-cuobj,

lt_config LIKE conf_out OCCURS 0 WITh HEADER LINE.

TABLES: t460A.

DO 1 TIMES.

CHECK VBAP-SPART EQ '8'.

SELECT * FROM MARC WHERE matnr = vbap-matnr AND

werks = vbap-werks.

IF sy-subrc = 0.

CHECK marc-strgr = 'Z1'.

ENDIF.

IF marc-sobsl IS NOT INITIAL.

SELECT wrk02 FROM t460A INTO lv_wrk02 WHERE werks = vbap-werks AND

sobsl = marc-sobsl.

CHECK sy-subrc = 0.

SELECT cuobj FROM MARC INTO lv_inst WHERE matnr = vbap-matnr AND

werks = lv_wrk02.

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

INSTANCE = lv_inst

TABLES

CONFIGURATION = lt_config

EXCEPTIONS

INSTANCE_NOT_FOUND = 1

INTERNAL_ERROR = 2

NO_CLASS_ALLOCATION = 3

INSTANCE_NOT_VALID = 4

OTHERS = 5.

CHECK SY-SUBRC = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

vbap-zkalk_menge = lt_config-atwrt.

ENDLOOP.

ELSE.

SELECT cuobj FROM MARC INTO lv_inst WHERE matnr = vbap-matnr AND

werks = vbap-werks.

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

INSTANCE = lv_inst

TABLES

CONFIGURATION = lt_config

EXCEPTIONS

INSTANCE_NOT_FOUND = 1

INTERNAL_ERROR = 2

NO_CLASS_ALLOCATION = 3

INSTANCE_NOT_VALID = 4

OTHERS = 5.

CHECK SY-SUBRC = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

vbap-zkalk_menge = lt_config-atwrt.

ENDLOOP.

ENDIF.

ENDDO.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
714

The problem is you did not put END SELECT statement. Its because you are using SELECT...INTO.

Each SELECT must be concluded by END SELECT. Put it in appropriate place then surely u wont get that error.

Otherwise you can use SELECT SINGLE if you don't want SELECT...END SELECT .....

Reward if its useful.

Thanks,

Sail

DATA: lv_wrk02 LIKE vbap-werks,

lv_inst LIKE vbap-cuobj,

lt_config LIKE conf_out OCCURS 0 WITH HEADER LINE.

TABLES : marc, vbap.

TABLES: t460a.

DO 1 TIMES.

CHECK vbap-spart EQ '8'.

<b>SELECT single * FROM marc WHERE matnr = vbap-matnr AND

werks = vbap-werks.</b>

.

IF sy-subrc = 0.

CHECK marc-strgr = 'Z1'.

ENDIF.

IF marc-sobsl IS NOT INITIAL.

<b> SELECT single wrk02 FROM t460a INTO lv_wrk02 WHERE werks = vbap-werks AND sobsl = marc-sobsl.</b>

CHECK sy-subrc = 0.

<b>SELECT single cuobj FROM marc INTO lv_inst WHERE matnr = vbap-matnr AND werks = lv_wrk02.</b>

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

instance = lv_inst

TABLES

configuration = lt_config

EXCEPTIONS

instance_not_found = 1

internal_error = 2

no_class_allocation = 3

instance_not_valid = 4

OTHERS = 5.

CHECK sy-subrc = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

ENDLOOP.

ELSE.

<b>SELECT single cuobj FROM marc INTO lv_inst WHERE matnr = vbap-matnr AND werks = vbap-werks.</b>

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

instance = lv_inst

TABLES

configuration = lt_config

EXCEPTIONS

instance_not_found = 1

internal_error = 2

no_class_allocation = 3

instance_not_valid = 4

OTHERS = 5.

CHECK sy-subrc = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

ENDLOOP.

ENDIF.

ENDDO.

5 REPLIES 5
Read only

Former Member
0 Likes
714

Hi Suparana,

the piece of code you written here is syntatically correct. there is no mismatch in any statement. can you just try to activate the whole program using SE80.

Reward points if useful.

Regards,

Atish

Read only

Former Member
0 Likes
715

The problem is you did not put END SELECT statement. Its because you are using SELECT...INTO.

Each SELECT must be concluded by END SELECT. Put it in appropriate place then surely u wont get that error.

Otherwise you can use SELECT SINGLE if you don't want SELECT...END SELECT .....

Reward if its useful.

Thanks,

Sail

DATA: lv_wrk02 LIKE vbap-werks,

lv_inst LIKE vbap-cuobj,

lt_config LIKE conf_out OCCURS 0 WITH HEADER LINE.

TABLES : marc, vbap.

TABLES: t460a.

DO 1 TIMES.

CHECK vbap-spart EQ '8'.

<b>SELECT single * FROM marc WHERE matnr = vbap-matnr AND

werks = vbap-werks.</b>

.

IF sy-subrc = 0.

CHECK marc-strgr = 'Z1'.

ENDIF.

IF marc-sobsl IS NOT INITIAL.

<b> SELECT single wrk02 FROM t460a INTO lv_wrk02 WHERE werks = vbap-werks AND sobsl = marc-sobsl.</b>

CHECK sy-subrc = 0.

<b>SELECT single cuobj FROM marc INTO lv_inst WHERE matnr = vbap-matnr AND werks = lv_wrk02.</b>

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

instance = lv_inst

TABLES

configuration = lt_config

EXCEPTIONS

instance_not_found = 1

internal_error = 2

no_class_allocation = 3

instance_not_valid = 4

OTHERS = 5.

CHECK sy-subrc = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

ENDLOOP.

ELSE.

<b>SELECT single cuobj FROM marc INTO lv_inst WHERE matnr = vbap-matnr AND werks = vbap-werks.</b>

CHECK sy-subrc = 0.

CALL FUNCTION 'VC_I_GET_CONFIGURATION'

EXPORTING

instance = lv_inst

TABLES

configuration = lt_config

EXCEPTIONS

instance_not_found = 1

internal_error = 2

no_class_allocation = 3

instance_not_valid = 4

OTHERS = 5.

CHECK sy-subrc = 0.

LOOP AT lt_config WHERE atnam = 'ZZKALK_MENGE' .

ENDLOOP.

ENDIF.

ENDDO.

Read only

Former Member
0 Likes
714

SELECT * FROM marc into <b>it_tab</b> WHERE matnr = vbap-matnr AND

werks = vbap-werks.

I think you have to use an internal table for the selected rows. Please check that.

since there is going to be only one row selected you should say

SELECT single * FROM marc WHERE matnr = vbap-matnr AND

werks = vbap-werks.

Thanks.

Message was edited by:

mg s

Read only

Former Member
0 Likes
714

Hi Suparna,

Just make the change below,

SELECT <b>SINGLE</b> * FROM MARC WHERE matnr = vbap-matnr AND

werks = vbap-werks.

Reward points if useful.

Regards,

Atish

Read only

Former Member
0 Likes
714

Thanks everyone for the solutions. Also, can you tell me how to optimize the code? I have written a basic code to test the logic. How can I optimize it?