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

Incorrect Nesting, before the statement ENDFUNCTION

Former Member
0 Likes
8,603

Hello:

I have this simple ABAP program, but I don't seem to make it work:

FUNCTION Z_SAP_GET_CREDIT.

*"----


""Interfase local

*" IMPORTING

*" VALUE(CLIENT_ID) TYPE Z_CLIENT_ID OPTIONAL

*" EXPORTING

*" VALUE(CREDIT_LIMIT) TYPE STRING

*" VALUE(CONDITIONS) TYPE STRING

*" EXCEPTIONS

*" USER_DOES_NOT_EXIST

*"----


TYPES: BEGIN OF credit_eq_type,

WEBTR TYPE string,

ZTERM TYPE int4,

END OF credit_eq_type .

DATA: credit_eq TYPE credit_eq_type.

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS OF credit_eq

WHERE KUNNR = CLIENT_ID.

*CREDIT_LIMIT = credit_eq-WEBTR.

ENDFUNCTION

I get this error:

Incorrect Nesting, before the statement "ENDFUNCTION", the structure introduced by SELECT must conclude with "END SELECT"

I've done selects before and it wasn't needed.... what is this?

Thanks

Alex

1 ACCEPTED SOLUTION
Read only

hymavathi_oruganti
Active Contributor
0 Likes
4,269

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS <b>OF credit_eq</b>WHERE KUNNR = CLIENT_ID.

IN THE ABOVE STATEMENT, <b>IF CREDIT_EQ IS A TABLE</b>, U NEED TO GIVE OF TABLE

LIKE BELOW

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS <b>OF TABLE credit_eq</b>

WHERE KUNNR = CLIENT_ID.

<b>IF ITS IS WORK AREA, U NEED TO GIVE END SELECT.</b> LIKE BELOW

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS OF credit_eq

WHERE KUNNR = CLIENT_ID.

<b>END SELECT.</b>

18 REPLIES 18
Read only

former_member186741
Active Contributor
0 Likes
4,269

THIS LOOKS OK, THE ONLY THING i CAN THINK OF IS THAT YOU HAVE ANOTHER FUNCTION MODULE IN THE SAME FUNCTION GROUP WHCIH HAS THE ERROR.

Read only

0 Likes
4,269

Actually, I don't know why, but I placed two definitions on the DATA section and it did compile and activated... however it won't work, it shows an error:

"One of the statements could no be executed. Following a SELECT statement, the data READ could not be placed in AN output area"

I know it's a matter of a conversion. probably due to incompatibility from the WEBTR field on KBN1 (seems to be on currency) into String... which datatype should be suitable?

Thanks Alex

Read only

0 Likes
4,269

use:

WEBTR TYPE webtr,

ZTERM TYPE dzterm,

Read only

0 Likes
4,269

Even though you are specifying SELECT SINGLE * in your code, you are not providing the full key of KNB1 which also includes company code BUKRS. So system expects either a ENDSELECT or your INTO statement to be followed by TABLE itab instead of just INTO strcuture. That is why you got this error. So either do option 1 or 2 as follows.

<u>Option 1</u>


TYPES: BEGIN OF credit_eq_type,
         WEBTR LIKE KNB1-WEBTR,
         ZTERM LIKE KNB1-ZTERM,
       END OF credit_eq_type .

DATA: credit_eq TYPE TABLE OF credit_eq_type with header line.

SELECT SINGLE webtr zterm FROM KNB1
                          INTO TABLE credit_eq
                         WHERE KUNNR = CLIENT_ID.

*CREDIT_LIMIT = credit_eq-WEBTR.

<u>Option 2</u>


TYPES: BEGIN OF credit_eq_type,
         WEBTR LIKE KNB1-WEBTR,
         ZTERM LIKE KNB1-ZTERM,
       END OF credit_eq_type .

DATA: credit_eq TYPE credit_eq_type.

SELECT webtr zterm FROM KNB1 UP TO 1 ROWS
                   INTO credit_eq
                  WHERE KUNNR = CLIENT_ID.
ENDSELECT.
*CREDIT_LIMIT = credit_eq-WEBTR.

<u>Option 3</u>


TYPES: BEGIN OF credit_eq_type,
         WEBTR LIKE KNB1-WEBTR,
         ZTERM LIKE KNB1-ZTERM,
       END OF credit_eq_type .

DATA: credit_eq TYPE credit_eq_type.

SELECT SINGLE webtr zterm FROM KNB1
                          INTO Credit_eq
                         WHERE KUNNR = CLIENT_ID
                           AND BUKRS = <either constant 
or another import parameter from the function module>.

*CREDIT_LIMIT = credit_eq-WEBTR.

3rd option is the best one if you have BUKRS. In the case where you don't have BUKRS, use the option 1. Option 2 is least efficient. <b>But in any case, please do not use SELECT * with INTO CORRESPONDING FIELDS when you need only two fields. Instead specify the fields AND yes you cannot use INTO with incompatable fields. They have to be compatible.

Srinivas

Message was edited by: Srinivas Adavi

Read only

hymavathi_oruganti
Active Contributor
0 Likes
4,270

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS <b>OF credit_eq</b>WHERE KUNNR = CLIENT_ID.

IN THE ABOVE STATEMENT, <b>IF CREDIT_EQ IS A TABLE</b>, U NEED TO GIVE OF TABLE

LIKE BELOW

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS <b>OF TABLE credit_eq</b>

WHERE KUNNR = CLIENT_ID.

<b>IF ITS IS WORK AREA, U NEED TO GIVE END SELECT.</b> LIKE BELOW

SELECT SINGLE *

FROM KNB1

INTO CORRESPONDING FIELDS OF credit_eq

WHERE KUNNR = CLIENT_ID.

<b>END SELECT.</b>

Read only

0 Likes
4,269

Srinivas and Hymavathi,

Select single NEVER needs an ENDSELECT.

Read only

0 Likes
4,269

yes niel u r right, sorry i was little confused

Read only

0 Likes
4,269

Hello:

This is my final code, with no syntax errors:

FUNCTION Z_SAP_GET_CREDIT.

*"----


""Interfase local

*" IMPORTING

*" VALUE(CLIENT_ID) TYPE Z_CLIENT_ID OPTIONAL

*" EXPORTING

*" VALUE(CREDIT_LIMIT) TYPE KNB1-WEBTR

*" VALUE(CONDITIONS) TYPE KNB1-ZTERM

*" EXCEPTIONS

*" USER_DOES_NOT_EXIST

*"----


TYPES: BEGIN OF credit_eq_type,

WEBTR LIKE KNB1-WEBTR,

ZTERM LIKE KNB1-ZTERM,

END OF credit_eq_type .

DATA: credit_eq TYPE credit_eq_type.

CONSTANTS BU LIKE KNB1-BUKRS value 'FSMX'.

SELECT SINGLE WEBTR ZTERM

FROM KNB1

INTO credit_eq

WHERE KUNNR = CLIENT_ID.

CREDIT_LIMIT = credit_eq-WEBTR.

CONDITIONS = credit_eq-ZTERM.

ENDFUNCTION.

It does compile, however, when I execute it, it returns me 0.00 for CREDIT_LIMIT and Nothing for CONDITIONS. I check out the table and there is data for that client, any ideas?

Thanks

Read only

0 Likes
4,269

Are you sure that you are handling the internal format?

Make sure that CLIENT_ID contains data that is zero filled left. Like '0000012345'.

You can handle this in the function module if you want.

Add the following function module.



TYPES: BEGIN OF credit_eq_type,
WEBTR LIKE KNB1-WEBTR,
ZTERM LIKE KNB1-ZTERM,
END OF credit_eq_type .

DATA: credit_eq TYPE credit_eq_type.

CONSTANTS BU LIKE KNB1-BUKRS value 'FSMX'.

<b>call function 'CONVERSION_EXIT_ALPHA_INPUT'
  exporting
    input         = CLIENT_ID
 IMPORTING
   OUTPUT        = CLIENT_ID.</b>

SELECT SINGLE WEBTR ZTERM
FROM KNB1
INTO credit_eq
WHERE KUNNR = CLIENT_ID.

REgard,

Rich Heilman

Read only

0 Likes
4,269

How is Z_CLIENT_ID Typed? You may be able to handle this if Z_CLIENT_ID is typed correctly. I hope that it is at least a 10 character field. Otherwise, the funciton module will work for you.

Read only

0 Likes
4,269

Hi,

Put a break point in the FM,& see whether the data is populating from your select statement.

Read only

0 Likes
4,269

Z_CLIENT_ID is an INT4 with length 10. I placed the code you suggested:

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = CLIENT_ID

IMPORTING

OUTPUT = CLIENT_ID.

And I get this runtime error: OBJECTS NOT_CHAR_LIKE

Read only

0 Likes
4,269

Hi,

Can you move the valur into a char variable & use FM 'CONVERSION_EXIT_ALPHA_INPUT' ,& then pass it to your select.

Read only

0 Likes
4,269

Hi ,

Please define Z_CLIENT_Id as Charcter type. Then your code will work.

Regards,

lanka

Read only

0 Likes
4,269

Excelent.... working good.

Thanks

Read only

0 Likes
4,269

You have made client_id optional. I don't think it should be. Are you sure you passed a valid value to it? Are you getting an exception?

Rob

Read only

0 Likes
4,269

optional yes, however, I tried non-optional and it wouldn't work =(. Since it's working now, I believe I'll leave it that way, thaks Rob!

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
4,269

Hi,

For declaration,just try this.

TYPES: BEGIN OF credit_eq_type,

WEBTR TYPE knb1-webtr,

ZTERM TYPE knb1-zterm,

END OF credit_eq_type .

In export parameters also,change the type

credit_limit type knb1-webtr