‎2006 Feb 23 11:04 PM
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
‎2006 Feb 24 5:32 AM
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>
‎2006 Feb 23 11:14 PM
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.
‎2006 Feb 23 11:23 PM
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
‎2006 Feb 24 12:12 AM
‎2006 Feb 24 5:20 AM
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
‎2006 Feb 24 5:32 AM
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>
‎2006 Feb 24 5:49 AM
Srinivas and Hymavathi,
Select single NEVER needs an ENDSELECT.
‎2006 Feb 24 5:53 AM
‎2006 Feb 24 3:20 PM
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
‎2006 Feb 24 3:26 PM
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
‎2006 Feb 24 3:28 PM
‎2006 Feb 24 3:30 PM
Hi,
Put a break point in the FM,& see whether the data is populating from your select statement.
‎2006 Feb 24 3:36 PM
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
‎2006 Feb 24 3:39 PM
Hi,
Can you move the valur into a char variable & use FM 'CONVERSION_EXIT_ALPHA_INPUT' ,& then pass it to your select.
‎2006 Feb 24 3:42 PM
Hi ,
Please define Z_CLIENT_Id as Charcter type. Then your code will work.
Regards,
lanka
‎2006 Feb 24 3:45 PM
‎2006 Feb 24 3:50 PM
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
‎2006 Feb 24 3:51 PM
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!
‎2006 Feb 24 5:42 AM
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