‎2009 Nov 24 10:00 AM
Hi ALL,
I have created a function module to get the all the Production Order "AUFK-AUFNR" and Description "AUFK-KTEXT".
Here are the source code of the function module :
*************************************************************************************************************
FUNCTION Z_BAPI4 .
*"----
""Local Interface:
*" EXPORTING
*" VALUE(ITAB) TYPE BAPIRETURN
*"----
data: BEGIN OF itab1 occurs 100,
aufnr TYPE aufk-aufnr,
ktext TYPE aufk-ktext,
END OF itab1.
Select AUFNR KTEXT from AUFK INTO table itab1.
Loop at itab1.
itab1 = itab1
move-corresponding itab1 to itab.
write:/ itab1-aufnr,
10 itab1-ktext.
endloop.
ENDFUNCTION.
****************************************************************************************
Export parameters are :
Parameter Name : ITAB
Type Spec : TYPE
Associated Type : BAPIRETURN
Pass value : Selected ( Tick)
**************************************************************************************
I do get the all data into ITAB1 but while using move-corresponding i used to get the only one record.
My scenario is to get all the data from R3 to webpage using JCO connector.
Please help me out.
Thanks
Edited by: Shyamal Kumar on Nov 24, 2009 11:01 AM
‎2009 Nov 24 10:05 AM
After you are moving itab1 to itab, where are you appending?
Select AUFNR KTEXT from AUFK INTO table itab1.
Loop at itab1.
move-corresponding itab1 to itab.
APPEND itab. "Add this
endloop.
write:/ itab1-aufnr, " These doesnt make sense in a function module
10 itab1-ktext.
Vikranth
‎2009 Nov 24 10:11 AM
The following errors are coming :
Function Module Z_BAPI4
"ITAB" is not an internal table - the "OCCURS n" specification is
missing.
‎2009 Nov 24 10:14 AM
The following errors are coming :
Function Module Z_BAPI4
"ITAB" is not an internal table - the "OCCURS n" specification is
missing.
You are getting the error because of the following code:
MOVE-CORRESPONDING ITAB1 TO ITAB.
Also, Remove 'write' statement as already mentioned by others in the thread.
‎2009 Nov 24 10:14 AM
Hi Shyamal,
Then you have definitely defined a work area for your internal table, it seems. Then your code should look like:-
MOVE-CORRESPONDING WA1 TO WA. APPEND WA TO ITAB.Regards
Abhii
‎2009 Nov 24 10:08 AM
In addition to that,
You are defined ITAB as
ITAB TYPE BAPIRETURN
ITAB1structure dont have any similar fields of the BAPIRETURN
It does not make sense to use move-corresponding.
Thanks and Regards,
Chandra
‎2009 Nov 24 10:12 AM
‎2009 Nov 24 10:09 AM
‎2009 Nov 24 10:11 AM
Hi Shyamal,
You need to append the reocrds using APPEND command, to the internal table body from the header line after suing move-corresponding.
Your code should look like:-
MOVE-CORRESPONDING ITAB1 TO ITAB.
Regards
Abhii
‎2009 Nov 24 10:15 AM
As chandra mentioned, your itab declaration is wrong.
GOTO SE11 and create a Zstructure with the fields aufnr TYPE aufk-aufnr and ktext TYPE aufk-ktext.
Then in the function module declare ITAB in the TABLES parameter instead of EXPORT refering to the structure you created.
Vikranth
‎2009 Nov 24 10:38 AM
‎2009 Nov 24 10:40 AM
Declare the tables parameter as ITAB1 instead of ITAB. The select query will directly load the data into the output table ITAB1. You dont have to loop and use move-corresponding.
‎2009 Nov 24 10:54 AM
Hi Shyamal,
Is there any logic to be performed within the loop? why do u need the loop? you are using the loop only to move data from itab1 to itab . But i dont understadn the necessity to do this. if you declare an export parameter itab1 ,then you can directly pass the itab1 value. iN such a case, your code will be .
data: BEGIN OF itab1 occurs 100,
aufnr TYPE aufk-aufnr,
ktext TYPE aufk-ktext,
END OF itab1.
Select AUFNR KTEXT from AUFK INTO table itab1.
Edited by: Vasuki S Patki on Nov 24, 2009 4:28 PM
‎2009 Nov 24 10:53 AM
Function module do not have a list output. Hence the write statement will not work.
In this case append the itab1 to itab. and give the itab in table parameter.
After execution you can view the values.
‎2009 Nov 24 11:47 AM
Try this code:
*************************************************************************************************************
FUNCTION Z_BAPI4 .
*"----
""Local Interface:
*" EXPORTING
*" VALUE(ITAB) TYPE aufk
*"----
DATA: BEGIN OF itab1 OCCURS 100,
aufnr TYPE aufk-aufnr,
ktext TYPE aufk-ktext,
END OF itab1.
SELECT aufnr ktext
FROM aufk
INTO TABLE itab1.
LOOP AT itab1.
MOVE-CORRESPONDING itab1 TO itab.
APPEND itab.
ENDLOOP.
ENDFUNCTION.
********************************************************
Hope i help.
‎2009 Nov 24 12:18 PM
Hi shyamal,
the structure of itab and itab1 are not same thats why it's not getting transferred.
use READ TABLE itab1 into itab COMPARING aufnr,ktext.
or use the follwing code.
TYPES: BEGIN OF ty_tab,
aufnr TYPE aufk-aufnr,
ktext TYPE aufk-ktext,
END OF ty_tab.
DATA:it_tab TYPE STANDARD TABLE OF ty_tab.
DATA:wa_tab TYPE ty_tab.
SELECT aufnr ktext
FROM aufk
INTO TABLE it_tab.
LOOP AT it_itab INTO wa_tab.
MODIFY itab FROM wa_tab.
ENDLOOP.
ENDFUNCTION.
regards,
viswa