02-10-2010 7:16 AM
Dear all,
I prepared one z report . i am getting some messages from that report into an internal table in the same program . I want to pass this to a Z bapi (function module) created by me . The internal table contain only one field of 220 characters.(in report) . I want to pass this table to bapiret1-message which is having the same length in fm . Can any body face this problem previously please share your ideas with me .
Regards,
Madhu.
02-12-2010 8:49 AM
Try declaring it_str like below in both areas.
data: it_str type bapiret2_t.
data: wa_str type bapiret2.
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
IMT_BDCMSGCOLL = it_msg
EXT_RETURN = it_str[].
Then try export and import.
Will the user always execute this in mode 'A'.
Im not sure whether export and import will work in MODE 'N'.
Better to go with two fm's as i suggested before.
02-10-2010 7:31 AM
Hi,
can you paste your code ..I am unable to understand the requirement..
Thanks,
Nagaraj
02-10-2010 9:17 AM
Dear,
In my bdc report this is some part of my code
FORM get_execute.
DATA str TYPE string.
data str(220).
data : begin of it_str occurs 1,
line(220),
end of it_str.
LOOP AT zcust.
PERFORM get_data.
CALL TRANSACTION 'XD01' USING it_bdc MODE 'N' MESSAGES INTO it_msg.
ENDLOOP.
LOOP AT it_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_msg-msgid
lang = sy-langu
no = it_msg-msgnr
v1 = it_msg-msgv1
v2 = it_msg-msgv2
v3 = it_msg-msgv3
v4 = it_msg-msgv4
IMPORTING
msg = str.
WRITE :str.
ENDLOOP.
move str to it_str. "In this table iam collecting messages
append it_str.
clear it_str. "to give messages to bapi
export IT_STR TO MEMORY ID 'MESS' . " to give messages
ENDFORM. "get_execute
******************************************************************************************************************************************************
In my fm i am importing this table which contains messages
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRETURN1
data : begin of it_str occurs 1,
line(220),
end of it_str.
IMPORT IT_STR FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT
MOVE it_str-line TO RETURN.
append return.
I hope i mention it clearly.
Regards,
Madhu.
02-10-2010 9:23 AM
Hello Madhu,
Why dont you populate the BAPIRET1 structure in your main program itself & export it to memory ?
Can you please explain this ?
BR,
Suhas
02-10-2010 1:30 PM
HI Suhas,
Thank you for your reply. I am getting this messages from bdc program . Here my messages structure is bdcmsgcoll. Here in the string i am collecting the messages. Is it possible instead of this can i use bapiret1. Please share me yours if have an idea on this.
Regards,
madhu.
02-10-2010 3:11 PM
data:i_return type table of bapireturn.
data:wa_return type bapireturn.
loop at it_msg.
MESSAGE ID it_msg-msgid
TYPE it_msg-type
NUMBER it_msg-msgnr
WITH it_msg-msgv1
it_msg-msgv2
it_msg-msgv3
it_msg-msgv4
INTO wa_return-Message.
append wa_return to i_return.
endloop.
02-11-2010 4:28 AM
Hi Keshav,
It is some helpful to repeat the loop. Can you give me some clear idea on this. In my bdc i am getting the messages into a table. I want to export this data to a bapiret1 which is in my bapi . When ever i give the import values to the bapi and execute it will export the data to the report. After executing the report it will collect the messages ans pass them to the bapi fm . This is my requirement. Please share your ideas if you have an idea on this.
Regards,
Madhu.
02-11-2010 8:48 AM
Im still confused..
What i understand is you execute a bdc, the messages are populated in messtab.
Now you want to export this messtab to a function module which has a import parameter of type bapireturn1.
Is this correct.
02-11-2010 8:59 AM
HI Kesahv,
1) Passing values from bapi to bdc report.
2) When bapi execute bdc will return and get some messages and they are stored.
3) These messages i have to export to bapi from where i given the values to bdc .
4) These messages should get as return messages
Bapi -> bdc (messages will come)
Bdc -> Bapi (Return messages)
These messages i have to return from bapi.
That is the problem here. I am getting messages from bdc and collecting here in a internal table i want to export this table to bapi. The bapi to should give return that messages.
02-11-2010 9:10 AM
Hey im sorry yar,
Very hard to understand your problem.
You have a recorded routine in a BAPI function module.
This BAPI is executed from report.
After execution of this bapi you need to get the messages in return table( export paremeter ) of the BAPI.
Am i right ?
Just tell what is the exact thing your are doing briefly.
02-11-2010 9:20 AM
HI Keshav,
Thanks for spending a good time with me . Previously you did a good help for me to make a report. My problem is
1) There is no standard bapi to create customer
2) I started to prepare a bapi fm
3) I did one bdc program for xd01.
4) In Bapi fm I took one structure .
5) i took a structure in import tab of fm
6) The values that is given to this structure will pass to bdc report ( here i am using submit statement and export concept )
7) When ever bapi will executed the bdc will run and it will create customer. At this i am collecting messages from this bdc
😎 Now i have to export these values to bapi again .
9) Because i want to execute this bapi from external system . When ever a customer created i have to get a return message.
I hope i mention it clearly. Please share your ideas on this.
Regards,
Madhu.
02-11-2010 9:21 AM
Hi Madhu,
Instead of FORMAT_MESSAGE, try using the following function module.
DATA: it_ret1 TYPE BAPIRET1.
LOOP AT it_msg.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
TYPE = it_msg-MSGTYP
CL = it_msg-msgid
NUMBER = it_msg-msgnr
PAR1 = it_msg-msgv1
PAR2 = it_msg-msgv1
PAR3 = it_msg-msgv1
PAR4 = it_msg-msgv1
IMPORTING
RETURN = it_ret1.
append it_ret1.
ENDLOOP.
Now pass this it_ret1 to your function module and use it as return parameter directly.
Regards,
Swarna Munukoti
02-11-2010 9:35 AM
Hi Swarna,
Thank for your reply. But when i am using this one instead of format_messages it is going to run time error. may be types are different. Please let me know if more changes i have to do .
Regards,
Madhu.
02-11-2010 9:36 AM
Now i got it.
You have written a bdc in a program
then you are calling this program in a custom bapi using submit statement.
And you want your messages in you bapi.
Check this
in your program you will be having the messtab.
after call transaction statement
data:i_return type table of bapireturn1.
data:wa type bapireturn1.
TYPES:BEGIN OF MSG_LINE,
MSGTYPE TYPE BAPIRETURN1-TYPE,
msgid TYPE SY-MSGID,
msgnr TYPE SY-MSGNO,
PAR1 TYPE SY-MSGV1,
par2 TYPE SY-MSGV2,
PAR3 TYPE SY-MSGV3,
PAR4 TYPE SY-MSGV4,
END OF MSG_LINE.
DATA:WALINE TYPE MSG_LINE.
loop at messtab IN WA_MESS.
MOVE:WA_MESS-MSGTYP TO WALINE-MSGTYPE,
WA_MESS-MSGID TO WALINE-msgid,
WA_MESS-MSGNR TO WALINE-MSGNR,
WA_MESS-MSGV1 TO WALINE-MSGV1,
WA_MESS-MSGV2 TO WALINE-MSGV2,
WA_MESS-MSGV3 TO WALINE-MSGV3,
WA_MESS-MSGV4 TO WALINE-MSGV4.
CALL FUNCTION 'MEREP_RETURN_GET'
EXPORTING
type = WALINE-MSGTYP
id = WALINE-MSGID
number = WALINE-MSGNR
par1 = WALINE-MSGV1
par2 = WALINE-MSGV2
par3 = WALINE-MSGV3
par4 = WALINE-MSGV4
IMPORTING
return = wa.
APPEND WA TO i_return.
CLEAR WA.
clear WALINE.
ENDLOOP.
EXPORT I_RETURN TO MEMORY ID 'RET'.
NOW IN YOUR BAPI AFTER SUBMIT STATEMENT
IMPORT I_RETURN FROM MEMORY ID 'RET'.
02-11-2010 9:49 AM
Hi Madhu,
There was a typo mistake. The function module should be 'BALW_BAPIRETURN_GET1' . Try this
Regards,
Swarna Munukoti.
02-11-2010 9:52 AM
Hi Kesahv,
Thank you once again. I will try to finish with this help. can i ask if there is any blocking here.
Regards,
Madhu.
02-11-2010 10:01 AM
02-11-2010 10:05 AM
02-11-2010 10:29 AM
Hi Madhu,
<li>Please go through the code modified. It helps you.
Thanks
Venkat.O
*&---------------------------------------------------------------------*
*& Form get_execute
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_execute.
* DATA str TYPE string.
DATA str(220).
" DATA : BEGIN OF it_str OCCURS 1,
" line(220),
" END OF it_str.
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
LOOP AT zcust.
PERFORM get_data.
CALL TRANSACTION 'XD01' USING it_bdc MODE 'N' MESSAGES INTO it_msg.
ENDLOOP.
LOOP AT it_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_msg-msgid
lang = sy-langu
no = it_msg-msgnr
v1 = it_msg-msgv1
v2 = it_msg-msgv2
v3 = it_msg-msgv3
v4 = it_msg-msgv4
IMPORTING
msg = str.
WRITE :str.
ENDLOOP.
" MOVE str TO it_str. "In this table iam collecting messages
" APPEND it_str.
" CLEAR it_str. "to give messages to bapi
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
imt_bdcmsgcoll = it_msg
ext_return = it_str.
EXPORT it_str TO MEMORY ID 'MESS' . " to give messages
ENDFORM. "get_execute
****************************************************************************
*In my fm i am importing this table which contains messages
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRETURN1
" DATA : BEGIN OF it_str OCCURS 1,
" line(220),
" END OF it_str.
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
IMPORT it_str FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT
LOOP AT it_str.
MOVE-CORRESPONDING it_str to return.
APPEND return.
ENDLOOP.
Edited by: Julius Bussche on Feb 12, 2010 10:56 AM
Formatting corrected.
02-11-2010 11:30 AM
HI venkat,
I am very thankful to you. I did what you said. You given a beautiful FM . It is making my work more easier.
Here i am getting return messages from my report in FM .
But after executing this FM the messages are coming in list screen instead of return .
Is there any more changes i have to here.
Regards,
Madhu.
02-11-2010 1:40 PM
Hi Madhu, <li>You are using <b>WRITE :str.</b> after FORMAT_MESSAGE function module. If you remove that, msgs are not displayed in list screen. Thanks Venkat.O
02-11-2010 3:41 PM
Hi Venkat,
Once again Thank you . Here i removed the format_message and write statement. Then I did debug my program . The data is going into the table and exporting to Fm. But these return messages are not coming in bapi. Here it is not showing any syntax errors but no return messages are coming to bapi . Can you tell me where i have to change.
Regards,
Madhu.
02-12-2010 1:30 AM
Hi Madhu, <li>Give me piece of code where this FM is being called ? I will check that . Thanks Venkat.O
02-12-2010 3:35 AM
Dear Venkat,
I tried in this way
This is my code in bdc report
FORM get_execute.
data str type string.
LOOP AT zcust.
PERFORM get_data.
CALL TRANSACTION 'XD01' USING it_bdc MODE 'A' MESSAGES INTO it_msg.
ENDLOOP.
LOOP AT it_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_msg-msgid
lang = sy-langu
no = it_msg-msgnr
v1 = it_msg-msgv1
v2 = it_msg-msgv2
v3 = it_msg-msgv3
v4 = it_msg-msgv4
IMPORTING
msg = str.
WRITE :str.
ENDLOOP.
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
IMT_BDCMSGCOLL = it_msg
EXT_RETURN = it_str.
.
EXPORT it_str TO MEMORY ID 'MESS' .. "this table i am exporting to table
*****In Bapi this is my code
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*"----
DATA:
t_cust TYPE zcust_table .
***submit the bdc report
***Giving data from
move zcust to t_cust.
EXPORT t_cust TO MEMORY ID 'TABLE'.
SUBMIT ZDUP_CUSTOMER. ( My report name ).
***Getting data from program
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
.
IMPORT it_str FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT.
LOOP AT it_str.
MOVE-CORRESPONDING it_str to return.
APPEND return.
ENDLOOP.
endfunction.
02-12-2010 3:35 AM
Dear Venkat,
I tried in this way
This is my code in bdc report
FORM get_execute.
data str type string.
LOOP AT zcust.
PERFORM get_data.
CALL TRANSACTION 'XD01' USING it_bdc MODE 'A' MESSAGES INTO it_msg.
ENDLOOP.
LOOP AT it_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_msg-msgid
lang = sy-langu
no = it_msg-msgnr
v1 = it_msg-msgv1
v2 = it_msg-msgv2
v3 = it_msg-msgv3
v4 = it_msg-msgv4
IMPORTING
msg = str.
WRITE :str.
ENDLOOP.
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
IMT_BDCMSGCOLL = it_msg
EXT_RETURN = it_str.
.
EXPORT it_str TO MEMORY ID 'MESS' .. "this table i am exporting to table
*****In Bapi this is my code
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*"----
DATA:
t_cust TYPE zcust_table .
***submit the bdc report
***Giving data from
move zcust to t_cust.
EXPORT t_cust TO MEMORY ID 'TABLE'.
SUBMIT ZDUP_CUSTOMER. ( My report name ).
***Getting data from program
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
.
IMPORT it_str FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT.
LOOP AT it_str.
MOVE-CORRESPONDING it_str to return.
APPEND return.
ENDLOOP.
endfunction.
This is my code
Regards,
Madhu.
02-12-2010 3:59 AM
Hi Madhu,
<li>Your BAPI Code
<li>The question I asked is Where are you calling zxyz BAPI Function module.
<li>Are BDC portion and BAPI call in the same program ? Can you brief me the program. When BDC portion is executed and where BAPI is called what is the relation between these two.
Thanks
Venkat.O
FUNCTION zxyz."zxyz
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------
DATA:
t_cust TYPE zcust_table .
***submit the bdc report
***Giving data from
MOVE zcust TO t_cust.
EXPORT t_cust TO MEMORY ID 'TABLE'.
SUBMIT zdup_customer. ( my report name ).
***Getting data from program
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
.
IMPORT it_str FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT.
LOOP AT it_str.
MOVE-CORRESPONDING it_str TO return.
APPEND return.
ENDLOOP.
ENDFUNCTION.
02-12-2010 4:09 AM
Hi Venkat,
Thanks once again.
""Local Interface:
*" IMPORTING
*" VALUE(ZCUST) LIKE ZCUST_TABLE STRUCTURE ZCUST_TABLE
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*"----
DATA:
t_cust TYPE zcust_table .
***submit the bdc report
***Giving data from
MOVE zcust TO t_cust. " "here from zcust contains 63 fields . The same fields i am maintaining in bdc report.
EXPORT t_cust TO MEMORY ID 'TABLE'. ""these values are exporting to bdc report.
SUBMIT zdup_customer. ( my report name ). " "here i am submitting these values to bdc report .They are going smoothly to the report.
***Getting data from program
DATA it_str TYPE bapiret2 OCCURS 0 WITH HEADER LINE. " "i am collecting the bdc messages in a table it_str. Here also same name
.
IMPORT it_str FROM MEMORY ID 'MESS'. "TO GET DATA FROM REPORT. ""from there i am exporting the table .The same table i am importing here.
LOOP AT it_str.
MOVE-CORRESPONDING it_str TO return.
APPEND return.
ENDLOOP.
ENDFUNCTION.
Regards,
Madhu.
02-11-2010 10:08 AM
Hi madhu,
Forum is to help you in solving your problem.
Please donot expect the exact code here.
If there is any syntax errors you should correct it.
02-11-2010 3:52 PM
Hello,
in report
EXPORT i_return to memory id 'RET'.
in bapi
IMPORT i_return from memory id 'RET'.
here type data type of i_return must be same in both the areas.
Instead of all this complications why cant you create two fm's in same function group.
and access the message data globally avoiding export and import.
02-11-2010 4:22 PM
Hi Keshav,
I did not get you. Can you tell me some more i will try it . This scenario i am trying and i am not getting it to create customer.
Regards,
Madhu.
02-11-2010 5:59 PM
What i meant is instead of the report, use the same code in a new function module.
Then create your bapi and wrap the newly created function module in the bapi.
Here you can return the message table into the bapi in two ways
Either specify the message table as export in the new fm.
or Declare the message internal table globally in function pool and access the itab in any function module created under the same function group.
both the the fms must be in same function group.
02-11-2010 6:44 PM
Hi Keshav,
Thank you keshav for your patience. I am not aware of this topic.
Regards,
Madhu.
02-12-2010 7:03 AM
Hi Madhu,
According to my understanding you have created a BDC program and the messages from the BDC output you wanted to show as BAPI output.,
But one thing can u create a ZBAPI with BDC recording in itself??
this is possible and you can directly capture the return messages easily.
Else if u wanted to use the same way as you are doing now, Run the BDC program and capture the messages in a internal table and EXPORT the messages to a ID,
SUBMIT the ZBAPI and capture the MESSAGES there using IMPORT statement..
Regards,
Shravanthi
02-12-2010 7:11 AM
Hi Sravanthi,
Thanks for your reply. You understand what i am doing in my report correctly . The problem here is what ever messages i am collecting in bdc should return to bapi. That is not happening here. Here i can import the return messages from bdc to bapi but Submit statement wont work for function module. If you have any idea share with me .
Regards,
Madhu.
02-12-2010 8:33 AM
02-12-2010 8:40 AM
Dear Keshav,
DATA t_cust LIKE zcust.
DATA it_bdc TYPE bdcdata OCCURS 1 WITH HEADER LINE.
DATA t_message TYPE bapiret1 OCCURS 1 WITH HEADER LINE.
DATA it_msg TYPE bdcmsgcoll OCCURS 1 WITH HEADER LINE.
data it_str type bapiret2 occurs 0 with header line.
data i_return TYPE TABLE OF bapiret2.
DATA wa_return TYPE bapireturn.
DATA str TYPE string.
*data cm TYPE c LENGTH 16.
*data t_cust like zcust.
*IMPORT t_cust FROM MEMORY ID cm.
START-OF-SELECTION.
IMPORT t_cust FROM MEMORY ID 'TABLE'.
MOVE t_cust TO zcust.
APPEND zcust.
*clear zcust.
*free memory.
*PERFORM get_file.
PERFORM get_execute.
END-OF-SELECTION.
PERFORM get_execute.
*EXPORT t_cust TO MEMORY ID 'TABLE'. "EXPORT DATA FROM HERE
&----
*& Form GET_FILE
&----
text
.
----
FORM get_file.
DATA fn1 TYPE ibipparms-path.
DATA fn2 TYPE string.
DATA fn3 TYPE rlgrap-filename.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = fn1.
fn2 = fn1.
FN3 = FN1.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fn2
has_field_separator = 'X'
TABLES
data_tab = zcust[].
ENDFORM. "GET_FILE
----
FORM get_execute.
data str type string.
LOOP AT zcust.
PERFORM get_data.
CALL TRANSACTION 'XD01' USING it_bdc MODE 'A' MESSAGES INTO it_msg.
ENDLOOP.
LOOP AT it_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_msg-msgid
lang = sy-langu
no = it_msg-msgnr
v1 = it_msg-msgv1
v2 = it_msg-msgv2
v3 = it_msg-msgv3
v4 = it_msg-msgv4
IMPORTING
msg = str.
WRITE :str.
ENDLOOP.
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
IMT_BDCMSGCOLL = it_msg
EXT_RETURN = it_str.
.
EXPORT it_str TO MEMORY ID 'MESS' ..
ENDFORM. "get_execute
In this wayi i declared it_str in my report.
Regards,
Madhu.
02-12-2010 8:49 AM
Try declaring it_str like below in both areas.
data: it_str type bapiret2_t.
data: wa_str type bapiret2.
CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
TABLES
IMT_BDCMSGCOLL = it_msg
EXT_RETURN = it_str[].
Then try export and import.
Will the user always execute this in mode 'A'.
Im not sure whether export and import will work in MODE 'N'.
Better to go with two fm's as i suggested before.
02-12-2010 9:02 AM
HI Keshav,
I tried a lot till i did not reach my goal. As you suggested before i will try with two FM. I am thinking to keep the bdc code directly in bapi FM directly. The messages that will given by BDC will pass to the Bapi return. Can you tell tell me how to go with two FM instead of bdc and bapi. Dont mind asking this many times.
Regards,
Madhu.
02-12-2010 9:19 AM
Hi Madhu, <li> We use EXPORT and IMPORT statements in the same session. If you are using EXPORT in one program and after that if you run another with IMPORT statement, it wont work. It seems that you are using in different sessions. <li>Hello madhu, are you getting what I am trying to say. Both export and import must be executed in one run( one session). Thanks Venkat.O
02-12-2010 9:22 AM
Hi Venkat,
Does submit progarm creates new session ?
i think
SUBMIT ZDUP_CUSTOMER and return . ( My report name ). "<--THis will solve the issue
Keshav