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