BAPI SAMPLE CODE FOR FLAT FILE in SAP ABAP

BAPI SAMPLE CODE FOR FLAT FILE in SAP ABAP

REPORT ZBAPI.

DATA: BEGIN OF i_data OCCURS 0,
text(255),
END OF i_data.
DATA: i_ekko TYPE bapiekkoc.
DATA: it_ekko LIKE TABLE OF i_ekko INITIAL SIZE 0 WITH HEADER LINE.
DATA: BEGIN OF i_ekpo OCCURS 0,
po_item(5),
pur_mat(18),
plant(4),
net_price(23),
disp_quan(13),
END OF i_ekpo.
DATA: it_ekpo LIKE TABLE OF bapiekpoc INITIAL SIZE 0 WITH HEADER LINE .

DATA: BEGIN OF i_eket OCCURS 0,
po_item(5),
deliv_date(8),
quantity(13),
END OF i_eket.
DATA: it_eket LIKE TABLE OF bapieket INITIAL SIZE 0 WITH HEADER LINE.
DATA: v_index TYPE i.
DATA: return TYPE TABLE OF bapireturn INITIAL SIZE 0 WITH HEADER LINE.
DATA: po_num(10).

START-OF-SELECTION.

CALL FUNCTION 'UPLOAD'
  • EXPORTING
  • CODEPAGE = ' '
  • FILENAME = ' '
  • FILETYPE = ' '
  • ITEM = ' '
  • FILEMASK_MASK = ' '
  • FILEMASK_TEXT = ' '
  • FILETYPE_NO_CHANGE = ' '
  • FILEMASK_ALL = ' '
  • FILETYPE_NO_SHOW = ' '
  • LINE_EXIT = ' '
  • USER_FORM = ' '
  • USER_PROG = ' '
  • SILENT = 'S'
  • IMPORTING
  • FILESIZE =
  • CANCEL =
  • ACT_FILENAME =
  • ACT_FILETYPE =
TABLES
data_tab = i_data
  • EXCEPTIONS
  • CONVERSION_ERROR = 1
  • INVALID_TABLE_WIDTH = 2
  • INVALID_TYPE = 3
  • NO_BATCH = 4
  • UNKNOWN_ERROR = 5
  • GUI_REFUSE_FILETRANSFER = 6
  • OTHERS = 7
.
IF sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

loop at i_data.
if i_data-text(1) = 'H'.
shift i_data-text.
v_index = v_index + 1.
split i_data-text at ',' into i_ekko-doc_type
i_ekko-purch_org
i_ekko-pur_group
i_ekko-vendor.
append i_ekko to it_ekko.

elseif i_data-text(1) = 'I'.
shift i_data-text.
split i_data-text at ',' into i_ekpo-po_item
i_ekpo-pur_mat
i_ekpo-plant
i_ekpo-net_price
i_ekpo-disp_quan.
append i_ekpo.
move-corresponding i_ekpo to it_ekpo.
append it_ekpo.
clear it_ekpo.
else.
shift i_data-text.
split i_data-text at ',' into i_eket-po_item
i_eket-deliv_date
i_eket-quantity.

append it_eket .
move-corresponding i_eket to it_eket.
append it_eket.
clear it_eket.
endif.
endloop.

CALL FUNCTION 'BAPI_PO_CREATE'
EXPORTING
po_header = i_ekko
  • PO_HEADER_ADD_DATA =
  • HEADER_ADD_DATA_RELEVANT =
  • PO_ADDRESS =
  • SKIP_ITEMS_WITH_ERROR = 'X'
  • ITEM_ADD_DATA_RELEVANT =
  • HEADER_TECH_FIELDS =
  • IMPORTING
  • PURCHASEORDER =
tables
po_items = it_ekpo
  • PO_ITEM_ADD_DATA =
po_item_schedules = it_eket
  • PO_ITEM_ACCOUNT_ASSIGNMENT =
  • PO_ITEM_TEXT =
RETURN = return
  • PO_LIMITS =
  • PO_CONTRACT_LIMITS =
  • PO_SERVICES =
  • PO_SRV_ACCASS_VALUES =
  • PO_SERVICES_TEXT =
  • PO_BUSINESS_PARTNER =
  • EXTENSIONIN =
  • POADDRDELIVERY =
.
write: po_num.
loop at return.

write:/ return-message,return-type.
endloop.

Here it is.


RELATED POSTS

SAP ABAP BAPI 1
SAP ABAP BAPI 2
SAP ABAP BAPI 3
SAP ABAP BAPI 4


BADI and Customer exits in SAP ABAP

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. They can be inserted into the SAP System to accommodate user requirements too specific to be included inthe standard delivery. Since specific industries often require special functions, SAP allows you to predefine these points in your software.

As with customer exits two different views are available:

1·In the definition view, an application programmer predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software to standard SAP source code without having to modify the original object.

2· In the implementation view, the users of Business Add-Ins can customize the logic they need or use a standard logic if one is available.

In contrast to customer exits, Business Add-Ins no longer assume a two-level infrastructure (SAP and customer solutions), but instead allow for a multi-level system landscape (SAP, partner, and customer solutions, as well as country versions, industry solutions, and the like). Definitions and implementations of Business Add-Ins can be created at each level within such a system infrastructure.

SAP guarantees the upward compatibility of all Business Add-In interfaces. Release upgrades do not affect enhancement calls from within the standard software nor do they affect the validity of call interfaces. You do not have to register Business Add-Ins in SSCR.

The Business Add-In enhancement technique differentiates between enhancements that can only
 be implemented once and enhancements that can be used actively by any number of customers at the same time. In addition, Business Add-Ins can be defined according to filter values. This allows you to control add-in implementation and make it dependent on specific criteria (on a specific Country value, for example).

All ABAP sources, screens, GUIs, and table interfaces created using this enhancement technique are defined in a manner that allows customers to include their own enhancements in the standard. A single Business Add-In contains all of the interfaces necessary to implement a specific task.

Related Posts:

Handling errors in BAPI in SAP ABAP

You have to create a parameter named Return for every BAPI. This parameter returns exception messages or success messages to the calling program.

BAPIs themselves must not trigger any messages (such as MESSAGE xnnn) in the coding. In particular they must not generate terminations or display dialog boxes. Instead, all messages must be intercepted internally and reported back to the calling program in the Return parameter. Otherwise the BAPI will not be processed correctly and control may not be given back to the calling program.

All error messages or indeed any message that may be returned by the BAPI, must be defined in message table (Tools -> ABAP Workbench -> Development -> Programming environment -> Messages) and described in the documentation for the return parameter. This also applies to the most important or most likely error messages generated by other programs that can be indirectly passed via the BAPI to the application program.

ans in BAPI'S u can handle the errors with the help of BAPI RETURN parameter.

U have to declare an internal table like BAPIRET2. u need to pass this internal table to the RETURN structure .Now this internal table will capture the error messages once u run the BAPI.

In Every Bapi there will be a RETURN parameter of type BAPIRET2.

WE PASS IT AS TABLES PARAMETERS
AND ALL THE ERRORS ARE COLLECTED INTO IT
see the sample code
REPORT z34332_bdc_create_material .

data: la_headdata type BAPIMATHEAD,
la_clientdata type BAPI_MARA,
la_CLIENTDATAX type BAPI_MARAX,
la_return type BAPIRET2.

data: i_materialdescription type table of BAPI_MAKT,
wa_materialdescription like line of i_materialdescription.

la_headdata-MATERIAL = '000000000000000004'.
la_headdata-IND_SECTOR = 'M'.
la_headdata-MATL_TYPE = 'FERT'.

la_clientdata-BASE_UOM = 'FT3'.
la_CLIENTDATAX-BASE_UOM = 'X'.
la_clientdata-MATL_GROUP = '01'.
la_CLIENTDATAX-MATL_GROUP = 'X'.

wa_materialdescription = 'TEST'.
append wa_materialdescription to i_materialdescription.
clear: wa_materialdescription.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = la_headdata
CLIENTDATA = la_clientdata
CLIENTDATAX = la_CLIENTDATAX

* PLANTDATA =
* PLANTDATAX =
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '

IMPORTING
RETURN = la_return
TABLES
MATERIALDESCRIPTION = i_materialdescription

* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =

.

write: la_return-TYPE, ',', la_return-MESSAGE.
clear: la_headdata, la_return, la_clientdata, la_clientdatax.

Related Posts