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

function module

Former Member
0 Likes
359

I am crating a function module.

Input one filed , tables input 2 fields , output 3 fields.

So I declared first field as import parameter i_user.

Tables i_table type structure ztable.

Export i_export type structure zexport.

Ztable has fields name ,age.

Zexport has filelds name , age , sex.

And also zuser and zname are database tables.

Now in the coding part

{â—„FUNCTION zfunction.

*"----


""Local interface:

*" IMPORTING

*" VALUE(I_USER) TYPE CHAR30

*" EXPORTING

*" VALUE(I_EXPORT) LIKE ZEXPORT STRUCTURE ZEXPORT

*" TABLES

*" I_TABLE STRUCTURE ZTABLE

*"----


DATA

:Name_n(10) TYPE c,

v_user(30) TYPE c ,

age_n(3) type c

LOOP AT i_table.

IF i_table-NAME = 'Shiva'.

SELECT name INTO name_n FROM zname WHERE

age = i_table-age.

ENDSELECT.

ENDIF.

IF i_table-NAME = 'Kumar'.

Age_n = i_table-age.

ENDIF.

IF NOT name_n IS INITIAL.

SELECT user FROM zuser INTO v_user WHERE

user = i_user AND name = name_n.

ENDSELECT.

IF name_n IS NOT INITIAL.

i_export-NAME = i_table-NAME.

i_export-age = i_table-age.

i_export-sex = 'F'.

ELSE.

i_export-NAME = i_table-NAME.

i_export-age = i_table-age.

i_export-sex = 'M'.

ENDIF.

ENDIF.

ENDLOOP.

ENDFUNCTION.}

Please clarify my doubts experts

1) I have created 2 strcutures one with 2 fields and one with 3 fields eventhouth 2 fields are repeating ie name ,age and sex , is this ok or no .?

2) I am passing the one field as input through import parameter and also a table as input through tables option , is this correct?

3)can i loop directly the table input , is it the right coding practice?

LOOP AT i_table.

4) i want to fetch the name from the table zname , so i need to write the select statement like below or i need to change this ?

SELECT name INTO name_n FROM zname WHERE

age = i_table-age.

ENDSELECT.

5)presently i will pass one username and one table input and get the output ie one record.

but if i want to pass one user , several table inputs at a time and get several output records , how to change my code.

IF name_n IS NOT INITIAL.

i_export-NAME = i_table-NAME.

i_export-age = i_table-age.

i_export-sex = 'F'.

ELSE.

i_export-NAME = i_table-NAME.

i_export-age = i_table-age.

i_export-sex = 'M'.

ENDIF.

6)what kind of general expections we can create for any function module

2 REPLIES 2
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
332

1. Should be OK

2. Ok

3. You can loop through the input parameters.

4. You are using internal table (i_table). So, you have to for all entries syntax. But this may give more than one value.

5. You can use Table parameter for multiple input output values.

6. You can create any exceptions based on your logic

Read only

Former Member
0 Likes
332

Note: Please don't use Vague subject line for your posts, Read documentation on Function module