Application Development 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: 

creating a simple RFC - basic help guidance required

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

matt
Active Contributor
0 Kudos

>

>


> 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

6 REPLIES 6

Former Member
0 Kudos

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.

matt
Active Contributor
0 Kudos

>

>


> 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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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