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 creation - Not getting data in ITAB

Former Member
0 Likes
1,428

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

15 REPLIES 15
Read only

Former Member
0 Likes
1,306

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

Read only

0 Likes
1,306

The following errors are coming :

Function Module Z_BAPI4

"ITAB" is not an internal table - the "OCCURS n" specification is

missing.

Read only

0 Likes
1,306

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.

Read only

0 Likes
1,306

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

Read only

Former Member
0 Likes
1,306

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

Read only

0 Likes
1,306

hi,

Then what is the solutions :

Where i am wrong.

Read only

Former Member
0 Likes
1,306

Replace write by append.

Press F1 on append to know more.

Read only

Former Member
0 Likes
1,306

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

Read only

Former Member
0 Likes
1,306

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

Read only

0 Likes
1,306

TRIED but still getting the same error message.

Read only

0 Likes
1,306

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.

Read only

0 Likes
1,306

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

Read only

Former Member
0 Likes
1,306

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.

Read only

Former Member
0 Likes
1,306

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.

Read only

Former Member
0 Likes
1,306

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