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

Question conserning a remote-enabled BAPI

Former Member
0 Likes
1,603

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>

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,573

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

18 REPLIES 18
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,574

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

Read only

0 Likes
1,573

Rich, so I don't need the structure in the exporting tab, only the tables tab? I will try your solution, thanks.

Regards,

Davis

Read only

0 Likes
1,573

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

Read only

0 Likes
1,573

Do all table parameters get exported?

Read only

0 Likes
1,573

That's right, TABLES parameters are actually both importing and exporting, sort of like changing parameters, but in your case, you are filling in the function module and exporting the data out.

Regards,

Rich heilman

Read only

0 Likes
1,573

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

Read only

0 Likes
1,573

Please change your coding like so, then it will work.

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.

Regards,

RIch HEilman

Read only

Former Member
0 Likes
1,573

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.

Read only

Former Member
0 Likes
1,573

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

Read only

0 Likes
1,573

Max, thanks for the reply but that is still omitting the leading zeros.

Regards,

Davis

Read only

Former Member
0 Likes
1,573

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.

Read only

0 Likes
1,573

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

Read only

former_member194669
Active Contributor
0 Likes
1,573

Hi,

Use UNPACK to add zeros

UNPACK ZBAPI_DELIVERY_DOC_EXPORT-VBELN TO ZBAPI_DELIVERY_DOC_EXPORT-VBLEN

aRs.

Read only

former_member194669
Active Contributor
0 Likes
1,573

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

Read only

0 Likes
1,573

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

Read only

0 Likes
1,573

Yes. Double click on the grid icon, there should be your data.

Regards,

RIch Heilman

Read only

0 Likes
1,573

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

Read only

former_member194669
Active Contributor
0 Likes
1,573

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