11-19-2008 9:12 AM
Hi,
this is going to be a simple answer and I am sure there are lots of links out there but I cant find them.
I have been asked to create an RFC that takes in data runs a query and then returns the records. In this example I have been asked to pass in a WERKS(Plant) field and then return all the associated LGORT(Stor Loc).
I have done some resaech and found that the table I need is T001L but I am having trouble getting the RFC to work correctly.
I have created an import field of WERKS and created a RETURN_VALUES (new structure). I have attached the simple code below.
However when I run this code only the last record is returned in the results. When I debug this it adds all the records to the structure but seems to be overwriting the value each time. Sure this is something to do with loops. Maybe I shouldn't be using a structure - perhaps an internal table?
One more note is that this will be executed from a remote system.
FUNCTION Z_MDM_LU_STOR_LOCS.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(PLANT) TYPE WERKS
*" EXPORTING
*" VALUE(RETURN_VALUES) LIKE ZMDM_STORLOC STRUCTURE ZMDM_STORLOC
*"----------------------------------------------------------------------
SELECT LGORT FROM T001L
INTO RETURN_VALUES-LGORT
WHERE WERKS LIKE PLANT.
ENDSELECT.
ENDFUNCTION.
11-19-2008 9:23 AM
>
>
> FUNCTION Z_MDM_LU_STOR_LOCS. > *"---------------------------------------------------------------------- > *"*"Local interface: > *" IMPORTING > *" VALUE(PLANT) TYPE WERKS > *" EXPORTING > *" VALUE(RETURN_VALUES) LIKE ZMDM_STORLOC STRUCTURE ZMDM_STORLOC > *"---------------------------------------------------------------------- > > SELECT LGORT FROM T001L > INTO RETURN_VALUES-LGORT > WHERE WERKS LIKE PLANT. > ENDSELECT. > > ENDFUNCTION. >
Not an RFC problem; an ABAP understanding problem.
SELECT... ENDSELECT is a loop. So first time through the loop, return_values-lgort will be given the first value from the db. Second time through, that's be overwritten by the second value retrieved from the db.
As you've defined the exporting parameter "return_values" it is a structure, not a table. So it will, and can, only have one value.
You want SELECT INTO TABLE. And, IIRC, for an RFC fm, you need to use the TABLES FM parameter. Read the ABAP help for these for more details.
matt
11-19-2008 9:21 AM
Hi,
SELECT LGORT FROM T001L
INTO RETURN_VALUES-LGORT
WHERE WERKS LIKE PLANT.
ENDSELECT.
You are correct .. you have to use internal table to get multiple records..
Try this code..
select LGORT from T001L into table RETURN_VALUES where WERKS = PLANT.
11-19-2008 9:23 AM
>
>
> FUNCTION Z_MDM_LU_STOR_LOCS. > *"---------------------------------------------------------------------- > *"*"Local interface: > *" IMPORTING > *" VALUE(PLANT) TYPE WERKS > *" EXPORTING > *" VALUE(RETURN_VALUES) LIKE ZMDM_STORLOC STRUCTURE ZMDM_STORLOC > *"---------------------------------------------------------------------- > > SELECT LGORT FROM T001L > INTO RETURN_VALUES-LGORT > WHERE WERKS LIKE PLANT. > ENDSELECT. > > ENDFUNCTION. >
Not an RFC problem; an ABAP understanding problem.
SELECT... ENDSELECT is a loop. So first time through the loop, return_values-lgort will be given the first value from the db. Second time through, that's be overwritten by the second value retrieved from the db.
As you've defined the exporting parameter "return_values" it is a structure, not a table. So it will, and can, only have one value.
You want SELECT INTO TABLE. And, IIRC, for an RFC fm, you need to use the TABLES FM parameter. Read the ABAP help for these for more details.
matt
11-19-2008 9:24 AM
You are using a workarea , workarea can hold only one record thats why you have the last record.Use an internal table.
SELECT LGORT FROM T001L
INTO TABLE RETURN_VALUES-LGORT
WHERE WERKS LIKE PLANT.
11-19-2008 9:24 AM
Use Table option in FM insted of Export.
and append the data to table inbetween Select...Endselect to the table which you want to Export.
To make the Fm as RFC.... you need to check the option Remote-Eanbled Module in FM attributes.
11-19-2008 9:32 AM
Hi
Please change PLANT TYPE WERKS to WERKS_D.
and try this option
FUNCTION Z_MDM_LU_STOR_LOCS.
*"----
""Local interface:
*" IMPORTING
*" VALUE(PLANT) TYPE WERKS_D
*" EXPORTING
*" VALUE(RETURN_VALUES) LIKE ZMDM_STORLOC STRUCTURE ZMDM_STORLOC
*"----
DATA : IT_RETURN_VALUES TYPE TABLE OF ZMDM_STORLOC STRUCTURE .
REFRESH : IT_RETURN_VALUES.
SELECT LGORT INTO TABLE IT_RETURN_VALUES FROM T001L WHERE WERKS = PLANT.
RETURN_VALUES[] = IT_RETURN_VALUES[].
ENDFUNCTION.
Regards
Madhan D
11-19-2008 9:57 AM
Final code was
FUNCTION Z_MDM_LU_STOR_LOCS.
*"----
""Local interface:
*" IMPORTING
*" VALUE(PLANT) TYPE WERKS_D
*" TABLES
*" RETURN_VALUES STRUCTURE ZMDM_STORLOC
*"----
SELECT LGORT LGOBE FROM T001L
INTO TABLE RETURN_VALUES
WHERE WERKS = PLANT.
ENDFUNCTION.
Thanks people