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: 

How to write a FM...?

Former Member
0 Kudos

Gurus,

I have to write a RFC enabled FM that will take date parameter and then find out documents whose status has changed from parked to post...and then return the list of such GL documents....I was able to figure out the logic that i can use....and wrote a test program for that....attaching the code here....

if u guys can review the same and tell me how to make it in a FM i will appreciate....

Its a beginning for me in ABAP so.....

Test Code:

REPORT ZTEST_PARK_TO_POST.

Tables: BKPF.

PARAMETERS: p_cpudt LIKE BKPF-CPUDT.

DATA: Begin of i_vbkpf occurs 0,

v_bukrs LIKE BKPF-BUKRS,

v_BELNR LIKE BKPF-BELNR,

v_GJAHR LIKE BKPF-GJAHR.

DATA: End of i_vbkpf.

DATA: Begin of i_bkpf occurs 0,

v_bukrs LIKE BKPF-BUKRS,

v_BELNR LIKE BKPF-BELNR,

v_GJAHR LIKE BKPF-GJAHR,

v_BSTAT LIKE BKPF-BSTAT.

DATA: End of i_bkpf.

if p_cpudt is not initial.

select BUKRS BELNR GJAHR from BKPF into TABLE i_vbkpf where BLART = 'SY'

AND CPUDT eq p_cpudt

AND PPNAM IS NOT NULL.

if sy-subrc = 0.

select BUKRS BELNR GJAHR BSTAT from BKPF into table i_bkpf

for all entries in i_vbkpf

where BUKRS = i_vbkpf-v_BUKRS AND

BELNR = i_vbkpf-v_BELNR AND

GJAHR = i_vbkpf-v_GJAHR AND

BSTAT = ''.

endif.

endif.

if sy-subrc eq 0.

Write: 'Success'.

endif.

Thanks

Cheers:

Sam

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

It ll be similar to ur program.

The Import Parameter for ur FM will be DATE

In Export Parameters or in Tables define your TABLES.

U can use the same code for retrieving data in u r FM as well.

Since its a RFC, u call it using

CALL FUNCTION 'xxx' DESTINATION p_dest.

Sri

Message was edited by:

Sri Tayi

9 REPLIES 9

Former Member
0 Kudos

hi,

It ll be similar to ur program.

The Import Parameter for ur FM will be DATE

In Export Parameters or in Tables define your TABLES.

U can use the same code for retrieving data in u r FM as well.

Since its a RFC, u call it using

CALL FUNCTION 'xxx' DESTINATION p_dest.

Sri

Message was edited by:

Sri Tayi

0 Kudos

Thanks for the reply Sri....how can i include ALV functionality in this also...becoz i will have to display as a list....

Also it is RFC enabled FM that has to be written so will it have import and export parameters...or just tables...please explain...

0 Kudos

You will have a report, in which you will call this FM.

So, u r input to the FM will be the date and the output will be your tables.

Now u can use standard ALV FM and pass in those tables in your report to display in ALV.

Sri

0 Kudos

Sri, it will be a RFC enabled FM that will be called from outside SAP...

Message was edited by:

Sam williams

0 Kudos

gurus,

i just want to know what will be the import export and tables parameters for this FM and how shud i change my current code to make it part of the FM....

Please suggest.....any inputs will be appreciated....

0 Kudos

Hi Sam,

As i told..

The Import Parameter for ur FM will be DATE

In Export Parameters or in Tables define your TABLES.

U can use the same code for retrieving data in u r FM as well.

Sri

0 Kudos

Thanks for the rply Sri...ok IMPORT parameter will be date ...as in my code i am using 2 internal tables: i_vbkpf and i_bkpf....

how shud i pass these in tables parameter...i mean how shud i define the table....can u provide me the steps...shud i just pass my internal tables....

Thanks

0 Kudos

why would you need two SELECTS on the same TABLE BKPF.

Cant you do it in one select???

0 Kudos

Sri, I have to write a FM that returns a list of parked documents and then also returns a list of posted documents that were parked...so out of the parked documents i have to find documents that got posted....thats the reason i have two selects...first select gets the parked document into the internal table and second select gets the posted documenst out of the parked documents.....

So how shud i return these two tables....

Thanks Sri