‎2007 Jul 02 7:41 PM
I have created a quick and 'easy' BAPI that will return a table of shipping document numbers. The code is below:
FUNCTION z_bapi_likp_get_list.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(ZBAPI_DELIVERY_DOC_IMPORT) TYPE ZBAPI_DELIVERY_DOC_IMPORT
*" EXPORTING
*" VALUE(ZBAPI_DELIVERY_DOC_EXPORT) TYPE ZBAPI_DELIVERY_DOC_EXPORT
*" VALUE(RETURN) TYPE BAPIRETURN
*"----------------------------------------------------------------------
SELECT vbeln FROM likp INTO zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.
ENDSELECT.
ENDFUNCTION .ZBAPI_DELIVERY_DOC_IMPORT is a structure that contains two fields: LDDAT and VSTEL
ZBAPI_DELIVERY_DOC_EXPORT is a structure that contains one field: VBELN. I tried to follow and it seemed to work great but I have a slight 'problem'.
I need to include the leading zeros on the document numbers. I tried to loop through the structure (after the select) and append the zeros that way but it wasn't allowing me to loop through the structure. Does anybody have any ideas/suggestions?<a href="http://www.erpgenie.com/abap/bapi/example.htm">this step-by-step example</a>
‎2007 Jul 02 7:47 PM
Well first of all, if ZBAPI_DELIVERY_DOC_EXPORT is not a table type, then you are not getting an internal table back from the BAPI, it is a single line, or structure, which is why you can't loop at it. If you want to return this as a table, then you need to either make ZBAPI_DELIVERY_DOC_EXPORT a table type, or use this in the TABLES parameter tab when defining the function module(BAPI) in SE37. Right now it is defined as an EXPORTING paramter.
As far as the leading zeros are concerned, you should be getting the leading zeros, but you may want to code your select like this.
Select vbeln from likp into corresponding fields of table
zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.Of course this coding will only work after you have adjusted the ZBAPI_DELIVERY_DOC_EXPORT parameter.
Regards,
RIch Heilman
‎2007 Jul 02 7:47 PM
Well first of all, if ZBAPI_DELIVERY_DOC_EXPORT is not a table type, then you are not getting an internal table back from the BAPI, it is a single line, or structure, which is why you can't loop at it. If you want to return this as a table, then you need to either make ZBAPI_DELIVERY_DOC_EXPORT a table type, or use this in the TABLES parameter tab when defining the function module(BAPI) in SE37. Right now it is defined as an EXPORTING paramter.
As far as the leading zeros are concerned, you should be getting the leading zeros, but you may want to code your select like this.
Select vbeln from likp into corresponding fields of table
zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.Of course this coding will only work after you have adjusted the ZBAPI_DELIVERY_DOC_EXPORT parameter.
Regards,
RIch Heilman
‎2007 Jul 02 7:49 PM
Rich, so I don't need the structure in the exporting tab, only the tables tab? I will try your solution, thanks.
Regards,
Davis
‎2007 Jul 02 7:54 PM
Hi
If you need to export one single document you can use a structure, else you need to create a TABLE parameter based on your structure just as Rich said.
Max
‎2007 Jul 02 7:58 PM
‎2007 Jul 02 8:01 PM
‎2007 Jul 02 8:06 PM
I now have the following and it doesn't return anything via the table (the select does pick up the doc numbers though):
FUNCTION Z_BAPI_LIKP_GET_LIST.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(ZBAPI_DELIVERY_DOC_IMPORT) TYPE ZBAPI_DELIVERY_DOC_IMPORT
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRETURN
*" TABLES
*" ZBAPI_DELIVERY_DOC_EXPORT STRUCTURE ZBAPI_DELIVERY_DOC_EXPORT
*"----------------------------------------------------------------------
SELECT vbeln FROM likp INTO zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.
UNPACK ZBAPI_DELIVERY_DOC_EXPORT-VBELN TO ZBAPI_DELIVERY_DOC_EXPORT-vbeln.
ENDSELECT.
ENDFUNCTION .Do I need to add an export parameter for the table or do something to the table?
Regards,
Davis
‎2007 Jul 02 8:10 PM
‎2007 Jul 02 7:47 PM
Davis,
If you are trying to loop through ZBAPI_DELIVERY_DOC_EXPORT, it will not work. Check the following:
1. Is it a table type?
2. You are not appending any records. You have a select...endselect without append.
Try using select vblen into table ZBAPI_DELIVER_DOC_EXPORT....
and then remove your endselect statement.
Regards,
Chris H.
‎2007 Jul 02 7:50 PM
Hi
The strucuture is flat, so u can loop it, you need to do into the SELECT/ENDSELECT cycle.
SELECT vbeln FROM likp INTO zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = zbapi_delivery_doc_export-vbeln
IMPORTING
OUTPUT = zbapi_delivery_doc_export-vbeln .
ENDSELECT.Max
‎2007 Jul 02 7:54 PM
Max, thanks for the reply but that is still omitting the leading zeros.
Regards,
Davis
‎2007 Jul 02 7:58 PM
Just move ZBAPI_DELIVERY_DOC_EXPORT to the tables tab and change your select statement to
SELECT vbeln FROM likp INTO TABLE zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat
AND vstel = zbapi_delivery_doc_import-zzvstel.
What is the structure of zbapi_delivery_doc_export? Is it having only VBELN? You don't have to do anything special for the leading zeros as you are directly selecting from the table into the internal table.
‎2007 Jul 02 8:02 PM
Srinivas, I would think that the leading zeros would stay with the doc number too but that isn't the case. I found this out when doing a barcode on a smartform (after it was in production). I am having to do something as follows in that SmartForm:
data: w_vbeln type c
w_vbeln = vbeln.
This way I am able to keep those zeros. Do you know of a better way of doing it?
Regards,
Davis
‎2007 Jul 02 8:02 PM
Hi,
Use UNPACK to add zeros
UNPACK ZBAPI_DELIVERY_DOC_EXPORT-VBELN TO ZBAPI_DELIVERY_DOC_EXPORT-VBLEN
aRs.
‎2007 Jul 02 8:10 PM
Hi,
SELECT vbeln FROM likp INTO zbapi_delivery_doc_export
WHERE lddat = zbapi_delivery_doc_import-lddat AND
vstel = zbapi_delivery_doc_import-zzvstel.
UNPACK ZBAPI_DELIVERY_DOC_EXPORT-VBELN TO ZBAPI_DELIVERY_DOC_EXPORT-vbeln.
append ZBAPI_DELIVERY_DOC_EXPORT.
ENDSELECT.
aRs
‎2007 Jul 02 8:17 PM
Ok, I made the changes everybody suggested and I THINK that it is working now. When I test it I get what follows:
ZBAPI_DELIVERY_DOC_EXPORT 0 Entries
Result: 1 Entry
Excuse my ignorance but is that what I am looking for? I would assume that the entry would be in ZBAPI_DELIVERY_DOC_EXPORT and not Result. I have no idea what Result is but am I correct in assuming that it is what will be returned via the RFC?
Regards,
Davis
‎2007 Jul 02 8:21 PM
‎2007 Jul 02 8:25 PM
Yes, I did that and the entry was there but I wasn't sure if it was supposed to be there (in Result) or the table. Thanks to all for your kind help!
Regards,
Davis
‎2007 Jul 02 8:22 PM
Hi,
use se16 and use likp and give the parameters and check how many records it fetching
then
Put a break-point in line ENDFUNCTION and check number of entries in table ZBAPI_DELIVERY_DOC_EXPORT
aRs