Skip to Content
author's profile photo Former Member
Former Member

IDOC Very Urgent

Hi,

Please send me some code example of BAPI (Including Funtional Specification )

Regards

Srikanta Gope

srikanta.gope@tcs.com

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 05:33 AM

    Hi

    BAPI stands for Business API(Application Program Interface).

    A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..

    You can make your function module remotely enabled in attributes of Function module but

    A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).

    BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

    The following standardized BAPIs are provided:

    Reading instances of SAP business objects

    GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

    The BAPI GetList() is a class method.

    GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

    The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

    Create( ) and CreateFromData! ( )

    The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

    Change( )

    The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

    Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

    The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

    Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

    Add<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing object inst! ance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.

    BAPI-step by step

    http://www.sapgenie.com/abap/bapi/example.htm

    list of all bapis

    http://www.planetsap.com/LIST_ALL_BAPIs.htm

    for BAPI's

    http://www.sappoint.com/abap/bapiintro.pdf

    http://www.sappoint.com/abap/bapiprg.pdf

    http://www.sappoint.com/abap/bapiactx.pdf

    http://www.sappoint.com/abap/bapilst.pdf

    http://www.sappoint.com/abap/bapiexer.pdf

    http://service.sap.com/ale

    http://service.sap.com/bapi

    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf

    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf

    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE8/BCFESDE8.pdf

    http://www.planetsap.com/Bapi_main_page.htm

    http://www.topxml.com/sap/sap_idoc_xml.asp

    http://www.sapdevelopment.co.uk/

    http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf

    Also refer to the following links..

    www.sappoint.com/abap/bapiintro.pdf

    www.sap-img.com/bapi.htm

    www.sap-img.com/abap/bapi-conventions.htm

    www.planetsap.com/Bapi_main_page.htm

    www.sapgenie.com/abap/bapi/index.htm

    Checkout !!

    http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html

    http://techrepublic.com.com/5100-6329-1051160.html#

    http://www.sap-img.com/bapi.htm

    http://www.sap-img.com/abap/bapi-conventions.htm

    http://www.sappoint.com/abap/bapiintro.pdf

    u can check the below the material also

    Example Code

    U need to give the step_nr, item_nr, cond_count and cond_type so the correct conditon will be updated. If no condition exists for the given parameters, a new condition will be created.

    U can find these parameters for a particular condition type in table KONV.

    &----


    *& Form saveTransactionJOCR

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM saveTransactionJOCR .

    data: salesdocument like BAPIVBELN-VBELN,

    order_header_inx like bapisdh1x,

    order_header_in like bapisdh1,

    return type standard table of bapiret2 with header line,

    conditions_in type standard table of bapicond with header line,

    conditions_inx type standard table of bapicondx with header line,

    logic_switch like BAPISDLS,

    step_nr like conditions_in-cond_st_no,

    item_nr like conditions_in-itm_number,

    cond_count like conditions_in-cond_count,

    cond_type like conditions_in-cond_type.

    salesdocument = wa_order_information-VBELN.

    LOGIC_SWITCH-COND_HANDL = 'X'.

    order_header_inx-updateflag = 'U'.

    • conditions

    clear conditions_in[].

    clear conditions_inx[].

    clear: step_nr,

    item_nr,

    cond_count,

    cond_type.

    step_nr = '710'.

    item_nr = '000000'.

    cond_count = '01'.

    cond_type = 'ZCP2'.

    CONDITIONS_IN-ITM_NUMBER = item_nr.

    conditions_in-cond_st_no = step_nr.

    CONDITIONS_IN-COND_COUNT = cond_count.

    CONDITIONS_IN-COND_TYPE = cond_type.

    CONDITIONS_IN-COND_VALUE = 666.

    CONDITIONS_IN-CURRENCY = 'EUR'.

    append conditions_in.

    CONDITIONS_INX-ITM_NUMBER = item_nr.

    conditions_inx-cond_st_no = step_nr.

    CONDITIONS_INX-COND_COUNT = cond_count.

    CONDITIONS_INX-COND_TYPE = cond_type.

    CONDITIONS_INX-UPDATEFLAG = 'U'.

    CONDITIONS_INX-COND_VALUE = 'X'.

    CONDITIONS_INX-CURRENCY = 'X'.

    append conditions_inx.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

    EXPORTING

    SALESDOCUMENT = salesdocument

    ORDER_HEADER_IN = order_header_in

    ORDER_HEADER_INX = order_header_inx

    LOGIC_SWITCH = logic_switch

    TABLES

    RETURN = return

    CONDITIONS_IN = conditions_in

    CONDITIONS_INX = conditions_inx.

    if return-type ne 'E'.

    commit work and wait.

    endif.

    ENDFORM. " saveTransactionJOCR

    <b>Reward points for useful Answers</b>

    Regards

    Anji

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 05:38 AM

    Hi,

    example using this bapi for posting goods issue in VL02N :

    BAPI_OUTB_DELIVERY_CONFIRM_DEC

    Please check this sample codes.

    DATA: BAPI_Z05DOGI_DELIVERY LIKE BAPIOBDLVHDRCON-DELIV_NUMB ,

    BAPI_Z05DOGI_HEADER_DATA LIKE BAPIOBDLVHDRCON OCCURS 0 WITH HEADER LINE ,

    BAPI_Z05DOGI_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCON OCCURS 0 WITH HEADER LINE,

    BAPI_Z05DOGI_ITEM_DATA LIKE BAPIOBDLVITEMCON OCCURS 0 WITH HEADER LINE,

    BAPI_Z05DOGI_ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCON OCCURS 0 WITH HEADER LINE ,

    BAPI_Z05DOGI_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE .

    CLEAR: BAPI_Z05DOGI_DELIVERY , BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA ,BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .

    REFRESH: BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA , BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .

    BAPI_Z05DOGI_DELIVERY = ZMM_WB1-ISSUE .

    BAPI_Z05DOGI_HEADER_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.

    APPEND BAPI_Z05DOGI_HEADER_DATA.

    BAPI_Z05DOGI_HEADER_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.

    BAPI_Z05DOGI_HEADER_CONTROL-POST_GI_FLG = 'X'.

    APPEND BAPI_Z05DOGI_HEADER_CONTROL.

    BAPI_Z05DOGI_ITEM_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.

    BAPI_Z05DOGI_ITEM_DATA-DELIV_ITEM = 10.

    BAPI_Z05DOGI_ITEM_DATA-DLV_QTY = LFIMGGIA.

    BAPI_Z05DOGI_ITEM_DATA-SALES_UNIT = XTAB-MEINS.

    • BAPI_Z05DOGI_ITEM_DATA-DLV_QTY_IMUNIT = LFIMGGIA.

    BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_NOM = UMVKZLIPS.

    BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_DENOM = UMVKNLIPS.

    APPEND BAPI_Z05DOGI_ITEM_DATA.

    BAPI_Z05DOGI_ITEM_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.

    BAPI_Z05DOGI_ITEM_CONTROL-DELIV_ITEM = 10.

    BAPI_Z05DOGI_ITEM_CONTROL-CHG_DELQTY = 'X'.

    APPEND BAPI_Z05DOGI_ITEM_CONTROL.

    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'

    EXPORTING

    DELIVERY = BAPI_Z05DOGI_DELIVERY

    HEADER_DATA = BAPI_Z05DOGI_HEADER_DATA

    HEADER_CONTROL = BAPI_Z05DOGI_HEADER_CONTROL

    TABLES

    ITEM_DATA = BAPI_Z05DOGI_ITEM_DATA

    ITEM_CONTROL = BAPI_Z05DOGI_ITEM_CONTROL

    RETURN = BAPI_Z05DOGI_RETURN.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = BAPI_Z05DOGI_RETURN

    Please take a look at this links for sample coding of BAPI_GOODSMVT_CREATE.

    http://www.sap-img.com/abap/bapi-goodsmvt-create-to-post-goods-movement.htm

    http://www.4ap.de/abap/bapi_goodsmvt_create.php

    <b>Reward points</b>

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 13, 2007 at 05:57 AM

    Hi,

    Sample Abap code on BAPI_PO_CHANGE :

    DELETING PURCHASE ORDERS

    &----


    *& Report ZMMR_DELETEPO *

    &----


    *& Author : Bikash Agarwal

    *& Description : VTLS PO Change

    *& Program Objective : Places a DELETION indicator for the PO

    *& items given in the VTLS data

    *& Remarks : NA

    &----


    REPORT ZMMR_DELETEPO NO STANDARD PAGE HEADING MESSAGE-ID zisb.

    tables : zvtls_sap.

    *C-- Types Declarations

    TYPES : BEGIN OF tp_flatfile_vtls,

    ebeln(10),

    ebelp type ekpo-ebelp,

    END OF tp_flatfile_vtls.

    *=====================================================================

    • INTERNAL TABLES DECLARATION

    *=====================================================================

    DATA: t_flatfile_vtls TYPE tp_flatfile_vtls OCCURS 0 WITH HEADER LINE.

    data : begin of t_sapdata occurs 0,

    po like zvtls_sap-posap,

    item like zvtls_sap-itemsap,

    end of t_sapdata.

    data : begin of t_flatfile_vtls1 occurs 0,

    po(10),

    item like zvtls_sap-itemsap,

    end of t_flatfile_vtls1.

    data : begin of t_update occurs 0,

    mandt like zvtls_sap-mandt,

    povtls like zvtls_sap-povtls,

    itemvtls like zvtls_sap-itemvtls,

    posap like zvtls_sap-posap,

    itemsap like zvtls_sap-itemsap,

    aedat like zvtls_sap-aedat,

    paedt like zvtls_sap-paedt,

    loekz like zvtls_sap-loekz,

    end of t_update.

    data : begin of t_poheader occurs 0,

    po like zvtls_sap-posap,

    end of t_poheader.

    data : begin of t_poitem occurs 0,

    po like zvtls_sap-posap,

    item like zvtls_sap-itemsap,

    end of t_poitem.

    DATA : BEGIN OF T_MESSAGE OCCURS 0,

    MSGTY,

    MSGID(2),

    MSGNO(3),

    MSGTX(100),

    PO like zvtls_sap-povtls,

    item like zvtls_sap-itemvtls,

    END OF T_MESSAGE.

    DATA : BEGIN OF t_bapi_poheader OCCURS 0.

    INCLUDE STRUCTURE bapimepoheader.

    DATA : END OF t_bapi_poheader.

    DATA : BEGIN OF t_bapi_poheaderx OCCURS 0.

    INCLUDE STRUCTURE bapimepoheaderx.

    DATA : END OF t_bapi_poheaderx.

    DATA : BEGIN OF t_bapi_poitem OCCURS 0.

    INCLUDE STRUCTURE bapimepoitem.

    DATA : END OF t_bapi_poitem.

    DATA : BEGIN OF t_bapi_poitemx OCCURS 0.

    INCLUDE STRUCTURE bapimepoitemx.

    DATA : END OF t_bapi_poitemx.

    DATA : BEGIN OF t_bapireturn OCCURS 0.

    INCLUDE STRUCTURE bapiret2.

    DATA : END OF t_bapireturn.

    *=====================================================================

    • V A R I A B L E S

    *=====================================================================

    DATA: w_success(6) TYPE n,

    w_bklas like t023-bklas,

    w_curryear(4),

    w_begda like sy-datum,

    w_endda like sy-datum,

    w_begyr(4),

    w_endyr(4),

    w_currmon(2),

    w_assetclass like ankt-anlkl,

    w_price type p,

    w_recordsap type i,

    w_povtls(10),

    w_count type i.

    DATA: w_filepath TYPE rlgrap-filename,

    w_rc TYPE sy-subrc,

    w_sscrfields_ucomm1 TYPE sscrfields-ucomm,

    w_file1 TYPE string,

    w_file2 TYPE FILENAME-FILEINTERN.

    *=====================================================================

    • C O N S T A N T S

    *=====================================================================

    CONSTANTS: c_x TYPE c VALUE 'X',

    c_hyp TYPE c VALUE '-',

    c_err TYPE bdc_mart VALUE 'E'.

    CONSTANTS: c_slash(1) TYPE c VALUE '/',

    c_hash(1) TYPE c VALUE '#',

    c_pipe TYPE c VALUE '|',

    c_1 TYPE i VALUE 1,

    c_zero TYPE n VALUE '0',

    c_rg1(3) TYPE c VALUE 'rg1',

    c_gr3(3) TYPE c VALUE 'GR3',

    c_gr2(3) TYPE c VALUE 'GR2',

    c_e(1) TYPE c VALUE 'E',

    c_filepath(8) TYPE c VALUE '/interf/',

    c_filetype(10) TYPE c VALUE 'ASC'.

    CONSTANTS : c_bapimepoheaderx TYPE x030l-tabname

    VALUE 'bapimepoheaderx',

    c_bapimepoitem TYPE x030l-tabname

    VALUE 'bapimepoitem',

    c_bapimepoaccount TYPE x030l-tabname

    VALUE 'bapimepoaccount',

    c_t_bapi_poheader(15) TYPE c

    VALUE 't_bapi_poheader',

    c_t_bapi_poitem(13) TYPE c

    VALUE 't_bapi_poitem',

    c_t_bapi_poitemx(14) TYPE c

    VALUE 't_bapi_poitemx',

    c_t_bapi_poheaderx(16) TYPE c

    VALUE 't_bapi_poheaderx'.

    CLASS cl_abap_char_utilities DEFINITION LOAD.

    CONSTANTS:con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

    *======================================================================

    • SELECTION SCREEN

    *======================================================================

    SELECTION-SCREEN BEGIN OF BLOCK inputpath WITH FRAME TITLE text-001.

    SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.

    PARAMETERS : p_fore RADIOBUTTON GROUP rg1

    USER-COMMAND pc,

    p_back RADIOBUTTON GROUP rg1 DEFAULT 'X'.

    SELECTION-SCREEN : END OF BLOCK blk2.

    SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-003.

    PARAMETERS : p_file1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr2.

    PARAMETERS : p_afile1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr3.

    SELECTION-SCREEN : END OF BLOCK blk1.

    SELECTION-SCREEN END OF BLOCK inputpath.

    *C-- Initialization Event

    INITIALIZATION.

    CLEAR w_filepath.

    CONCATENATE c_filepath sy-sysid c_slash sy-mandt c_slash INTO

    w_filepath.

    CONDENSE w_filepath NO-GAPS.

    p_file1 = text-008.

    p_afile1 = text-009.

    *======================================================================

    • SELECTION SCREEN EVENTS

    *======================================================================

    *C-- Selection Screen Output

    AT SELECTION-SCREEN OUTPUT.

    IF p_fore = c_x.

    w_sscrfields_ucomm1 = space.

    ELSE.

    w_sscrfields_ucomm1 = c_rg1.

    ENDIF.

    LOOP AT SCREEN.

    *C--Modify selection screen if presentation

    *C--or application server radio button is chosen

    IF w_sscrfields_ucomm1 = space.

    IF screen-group1 = c_gr3.

    screen-active = c_zero.

    ENDIF.

    ELSE.

    IF screen-group1 = c_gr2.

    screen-active = c_zero.

    ENDIF.

    ENDIF.

    if screen-name = 'P_AFILE1'.

    screen-input = 0.

    ENDIF.

    MODIFY SCREEN.

    ENDLOOP.

    *C-- Selection Screen VALUE-REQUEST FOR File path

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.

    IF p_fore EQ c_x.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    program_name = syst-cprog

    dynpro_number = syst-dynnr

    IMPORTING

    file_name = p_file1.

    ENDIF.

    *C-- At Start of the Selection Process

    START-OF-SELECTION.

    IF p_fore EQ c_x.

    w_file1 = p_file1.

    ELSE.

    w_file2 = p_afile1.

    ENDIF.

    IF p_fore EQ c_x. " Presentaion Server

    *C--Validations for the input files

    PERFORM validate_pre_file USING p_file1.

    *C-- Load the contents of the input file into the internal table

    PERFORM upload_file TABLES t_flatfile_vtls

    USING w_file1

    CHANGING w_rc.

    IF w_rc <> 0.

    MESSAGE s006 DISPLAY LIKE c_e.

    ENDIF.

    ELSE. " Application Server

    *C--Validations for the input files

    PERFORM validate_app_file USING w_file2.

    *C-- Load the contents of the input file into the internal table

    PERFORM upload_file_app TABLES t_flatfile_vtls

    USING w_file2

    CHANGING w_rc.

    ENDIF.

    loop at t_flatfile_vtls.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    EXPORTING

    input = t_flatfile_vtls-ebeln

    IMPORTING

    output = t_flatfile_vtls1-po.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    EXPORTING

    input = t_flatfile_vtls-ebelp

    IMPORTING

    output = t_flatfile_vtls1-item.

    append t_flatfile_vtls1.

    clear t_flatfile_vtls1.

    endloop.

    perform get_podata.

    loop at t_poheader.

    perform move_to_bapi.

    perform call_bapi.

    endloop.

    PERFORM STORE_MESSAGES TABLES T_MESSAGE.

    *&----


    *

    *& Form validate_pre_file

    *&----


    *

    • Routine to validate presentation server file path.

    *----


    *

    • -->fp_name text

    *----


    *

    FORM validate_pre_file USING fp_name TYPE rlgrap-filename.

    DATA : l_result,

    l_filename TYPE string.

    l_filename = fp_name.

    CLEAR l_result.

    CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

    file = l_filename

    RECEIVING

    result = l_result

    EXCEPTIONS

    cntl_error = 1

    error_no_gui = 2

    wrong_parameter = 3

    not_supported_by_gui = 4

    OTHERS = 5.

    IF sy-subrc <> 0.

    MESSAGE s007 DISPLAY LIKE c_e.

    LEAVE LIST-PROCESSING.

    ELSEIF l_result IS INITIAL.

    MESSAGE s008 DISPLAY LIKE c_e.

    LEAVE LIST-PROCESSING.

    ENDIF.

    ENDFORM. " validate_pre_file_hdr

    *&----


    *

    *& Form validate_app_file

    *&----


    *

    • text - Checks if the path entered and filename is correct

    *----


    *

    FORM validate_app_file USING fp_file TYPE FILENAME-FILEINTERN.

    data : l_fname(60).

    CALL FUNCTION 'FILE_GET_NAME'

    EXPORTING

    LOGICAL_FILENAME = FP_FILE

    OPERATING_SYSTEM = SY-OPSYS

    IMPORTING

    FILE_NAME = L_FNAME

    EXCEPTIONS

    FILE_NOT_FOUND = 1

    OTHERS = 2.

    IF SY-SUBRC = '0'.

    OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc NE 0.

    MESSAGE s007 DISPLAY LIKE c_e.

    ELSE.

    CLOSE DATASET l_fname.

    ENDIF.

    ENDIF.

    ENDFORM. " validate_app_file

    *&----


    *

    *& Form upload_file

    *&----


    *

    • Routine to upload data from file to tables.

    *----


    *

    • -->P_fp_flatfile

    • -->P_fp_file

    • <--P_fp_rc

    *----


    *

    FORM upload_file TABLES fp_flatfile

    USING fp_file TYPE string

    CHANGING fp_rc TYPE sy-subrc.

    IF fp_flatfile[] IS INITIAL.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = fp_file

    filetype = c_filetype

    has_field_separator = c_x

    TABLES

    data_tab = fp_flatfile

    EXCEPTIONS

    file_open_error = 1

    file_read_error = 2

    no_batch = 3

    gui_refuse_filetransfer = 4

    invalid_type = 5

    no_authority = 6

    unknown_error = 7

    bad_data_format = 8

    header_not_allowed = 9

    separator_not_allowed = 10

    header_too_long = 11

    unknown_dp_error = 12

    access_denied = 13

    dp_out_of_memory = 14

    disk_full = 15

    dp_timeout = 16

    OTHERS = 17.

    MOVE sy-subrc TO fp_rc.

    ENDIF.

    ENDFORM. " upload_file

    &----


    *& Form upload_file_app

    &----


    • text

    ----


    • -->FP_FLATFILEtext

    • -->FP_FILE text

    • -->FP_RC text

    ----


    FORM upload_file_app TABLES fp_flatfile

    USING fp_file TYPE FILENAME-FILEINTERN

    CHANGING fp_rc TYPE sy-subrc.

    DATA: l_string TYPE tedata-data.

    DATA: wa_data_file TYPE tp_flatfile_vtls,

    l_wllength TYPE i,

    FNAME(60).

    CALL FUNCTION 'FILE_GET_NAME'

    EXPORTING

    LOGICAL_FILENAME = FP_FILE

    OPERATING_SYSTEM = SY-OPSYS

    IMPORTING

    FILE_NAME = FNAME

    EXCEPTIONS

    FILE_NOT_FOUND = 1

    OTHERS = 2.

    IF SY-SUBRC = 0.

    OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc NE 0.

    • *C-- commented by Bikash

    • MESSAGE s107(yaero_ps) DISPLAY LIKE c_e.

    message e008.

    ELSE.

    DO.

    CLEAR: l_string.

    READ DATASET FNAME INTO l_string LENGTH l_wllength.

    IF sy-subrc NE 0.

    EXIT.

    ELSE.

    SPLIT l_string AT con_tab INTO wa_data_file-ebeln

    wa_data_file-ebelp.

    APPEND wa_data_file TO fp_flatfile.

    ENDIF.

    ENDDO.

    CLOSE DATASET FNAME.

    ENDIF.

    ENDIF.

    ENDFORM. " upload_file_app

    &----


    *& Form get_podata

    &----


    • text

    ----


    form get_podata.

    select *

    into table t_update

    from zvtls_sap

    for all entries in t_flatfile_vtls1

    where itemvtls = t_flatfile_vtls1-item

    and povtls = t_flatfile_vtls1-po.

    sort t_update by posap itemsap.

    loop at t_update.

    at new posap.

    t_poheader-po = t_update-posap.

    append t_poheader.

    clear t_poheader.

    endat.

    t_poitem-po = t_update-posap.

    t_poitem-item = t_update-itemsap.

    append t_poitem.

    clear t_poitem.

    t_update-paedt = sy-datum.

    t_update-loekz = 'X'.

    modify t_update.

    endloop.

    modify zvtls_sap from table t_update.

    endform. "get_podata

    &----


    *& Form move_to_bapi

    &----


    • text

    ----


    form move_to_bapi.

    t_bapi_poheader-po_number = t_poheader-po.

    CLEAR t_bapi_poheaderx.

    PERFORM fill_check_structure USING c_bapimepoheaderx

    c_t_bapi_poheader

    c_t_bapi_poheaderx

    c_x.

    refresh : t_bapi_poitem,t_bapi_poitemx.

    loop at t_poitem where po = t_poheader-po.

    clear t_bapi_poitem.

    t_bapi_poitem-po_item = t_poitem-item.

    t_bapi_poitem-delete_ind = 'X'.

    CLEAR t_bapi_poitemx.

    PERFORM fill_check_structure USING c_bapimepoitem

    c_t_bapi_poitem

    c_t_bapi_poitemx

    c_x.

    t_bapi_poitemx-po_item = t_poitem-item.

    t_bapi_poitemx-po_itemx = c_x.

    APPEND t_bapi_poitem.

    APPEND t_bapi_poitemx.

    clear t_bapi_poitem.

    clear t_bapi_poitemx.

    endloop.

    endform. "move_to_bapi

    *&----


    *

    *& Form call_bapi

    *&----


    *

    • This form Routine is used to commit the data records

    ----


    FORM call_bapi .

    DATA : l_msgty TYPE c,

    l_msgid(2) TYPE c,

    l_msgno(3) TYPE c,

    l_msgtx(100) TYPE c,

    l_errflag TYPE c.

    CLEAR: t_bapireturn.

    REFRESH: t_bapireturn.

    CALL FUNCTION 'BAPI_PO_CHANGE'

    EXPORTING

    PURCHASEORDER = T_POHEADER-PO

    POHEADER = T_BAPI_POHEADER

    POHEADERX = T_BAPI_POHEADERX

    TABLES

    RETURN = T_BAPIRETURN

    POITEM = T_BAPI_POITEM

    POITEMX = T_BAPI_POITEMX.

    READ TABLE t_bapireturn WITH KEY type = c_err TRANSPORTING NO FIELDS.

    IF sy-subrc NE 0.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    wait = c_x.

    ENDIF.

    *C-- Write messages

    WRITE: / 'PO Number', t_poheader-po.

    clear : t_update,w_povtls.

    read table t_update with key posap = t_poheader-po.

    w_povtls = t_update-povtls.

    CLEAR l_errflag.

    LOOP AT t_bapireturn.

    CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.

    l_msgty = t_bapireturn-type.

    l_msgid = t_bapireturn-id.

    l_msgno = t_bapireturn-number.

    l_msgtx = t_bapireturn-message.

    WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.

    if l_msgtx cs t_poheader-po.

    w_count = w_count + 1.

    loop at t_update.

    if sy-tabix = w_count.

    t_message-item = t_update-itemvtls.

    endif.

    endloop.

    endif.

    t_message-msgty = l_msgty.

    t_message-msgid = l_msgid.

    t_message-msgno = l_msgno.

    t_message-msgtx = l_msgtx.

    t_message-po = w_povtls.

    append t_message.

    clear t_message.

    IF l_msgty EQ c_err.

    l_errflag = c_x.

    ENDIF. " l_msgty EQ 'E'

    ENDLOOP.

    ULINE.

    IF l_errflag NE c_x.

    w_success = w_success + 1.

    ENDIF. " l_errflag NE C_X

    endform. "call_bapi

    *&----


    *

    *& Form fill_check_structure

    *&----


    *

    • This form Routine will check whether the specified structure

    • exist/active

    *----


    *

    FORM fill_check_structure USING fp_tabname TYPE any

    fp_orgtabname TYPE any

    fp_chktabname TYPE any

    fp_check TYPE c.

    FIELD-SYMBOLS : <fs_chk>, <fs_org>.

    DATA: l_char1(61) TYPE c,

    l_char2(61) TYPE c.

    DATA: BEGIN OF tl_nametab OCCURS 60.

    INCLUDE STRUCTURE x031l.

    DATA: END OF tl_nametab.

    REFRESH tl_nametab.

    CALL FUNCTION 'RFC_GET_NAMETAB'

    EXPORTING

    tabname = fp_tabname

    TABLES

    nametab = tl_nametab

    EXCEPTIONS

    table_not_active = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    CLEAR tl_nametab.

    ENDIF.

    LOOP AT tl_nametab.

    CLEAR: l_char1, l_char2.

    CONCATENATE fp_chktabname c_hyp tl_nametab-fieldname INTO l_char1.

    ASSIGN (l_char1) TO <fs_chk>.

    CONCATENATE fp_orgtabname c_hyp tl_nametab-fieldname INTO l_char2.

    ASSIGN (l_char2) TO <fs_org>.

    IF <fs_org> IS NOT INITIAL.

    <fs_chk> = fp_check.

    ENDIF.

    ENDLOOP.

    ENDFORM. " fill_check_structure

    &----


    *& Form STORE_MESSAGES

    &----


    • text

    ----


    • -->FP_MESSAGEStext

    ----


    FORM STORE_MESSAGES TABLES FP_MESSAGES STRUCTURE T_MESSAGE.

    DATA: wl_output_data LIKE t_MESSAGE.

    DATA: l_catstr TYPE string.

    DATA: l_fieldvalue TYPE string.

    DATA: l_index TYPE i VALUE 1.

    DATA: L_FNAME(60).

    FIELD-SYMBOLS <fs>.

    CLEAR l_catstr.

    CALL FUNCTION 'FILE_GET_NAME'

    EXPORTING

    LOGICAL_FILENAME = '/USR/SAP/VTLS/POCHANGE/LOG'

    OPERATING_SYSTEM = SY-OPSYS

    IMPORTING

    FILE_NAME = L_FNAME

    EXCEPTIONS

    FILE_NOT_FOUND = 1

    OTHERS = 2.

    IF SY-SUBRC = '0'.

    IF fp_messages[] IS NOT INITIAL.

    OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc NE 0.

    LEAVE LIST-PROCESSING.

    ELSE.

    LOOP AT fp_messages INTO wl_output_data.

    DO.

    ASSIGN COMPONENT l_index OF STRUCTURE wl_output_data TO <fs>.

    IF sy-subrc <> 0.

    EXIT.

    ENDIF.

    MOVE <fs> TO l_fieldvalue.

    IF l_catstr IS NOT INITIAL.

    CONCATENATE l_catstr l_fieldvalue INTO l_catstr SEPARATED

    BY con_tab.

    ELSE.

    MOVE l_fieldvalue TO l_catstr.

    ENDIF.

    l_index = l_index + c_1.

    CLEAR l_fieldvalue.

    CLEAR <fs>.

    ENDDO.

    l_index = c_1.

    TRANSFER l_catstr TO L_FNAME .

    CLEAR wl_output_data.

    CLEAR l_catstr.

    ENDLOOP.

    CLOSE DATASET L_FNAME.

    ENDIF.

    ENDIF.

    ENDIF.

    ENDFORM. "STORE_MESSAGES

    Pls reward points.

    Regards,

    Ameet

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 06:49 AM

    <b>BAPI Programming Tips and Tricks</b>

    SAP created the Business Framework to allow the technical integration and exchange of business data among SAP components and between SAP and non-SAP components. Important components of the Business Framework are the Business Application Programming Interfaces (BAPIs), which represent visible interfaces at the component boundaries and whose properties serve to integrate these components.

    The integration can include both components within a local network and components that are connected with one another through the Internet.

    BAPIs allow integration at the business level, not the technical level. This provides for greater stability in the link, and independence from the underlying communication technology.

    You can get all the standard SAP BAPI functions with the transactions code 'BAPI'.

    <b>What is the different between ALE, IDOC and BAPI?</b>

    <b>ALE</b>

    ALE is SAP proprietary technology that enables data communications between two or more SAP R/3 systems and/or R/3 and external systems. When a new enterprise resource planning (ERP) solution such as R/3 is implemented, companies have to interface the ERP system with legacy systems or other ERP systems.

    ALE provides intelligent mechanisms where by clients can achieve integration as well as distribution of applications and data.

    ALE technology facilitates rapid application prototyping and application interface development, thus reducing implementation time.

    The ALE components are inherently integrated with SAP applications and are robust, leading to a highly reliable system.

    ALE comes with application distribution/integration scenarios as well as a set of tools, programs, data definitions, and methodologies that you can easily configure to get an interface up and running.

    <b>BAPI</b>

    BAPIs provide a stable, standardized method for third-party applications and components to integrate into the Business Framework. These interfaces are being specified as part of SAP's initiative with customers, partners and leading standards organizations. Also, SAP has implemented the emerging Object Application Group (OAG) specifications with BAPIs.

    <b>Pros and Cons for both BAPI and Call Transaction</b>

    BAPI

    One of the big plusses for BAPIs is that the interface and function are not supposed to change. This is a big plus when you do upgrades or hot packs because the transaction can change (format, required inputs etc) which means you then need to update the call transaction.

    Some of the BAPIs are better documented and easier to use than others.

    You usually need to perform the BAPI that actually does the COMMIT after you call your BAPI.

    The Program coding for calling a BAPI is usually cleaner than setting up the screen flow etc for the Call Transaction.

    You don't need to worry about special data circumstances interrupting the normal data flow of the screens and causing errors because of that.

    BAPIs probably have better performance since they don't do the screen flow processing.

    In general if the BAPI exists for the transaction you want to perform and you can figure out how to use it the BAPI is probably the best way to go.

    This is just from my experience working with both BAPI and Call Transaction. I have had some very good successes with BAPIs, but very occasionally found that I could not get the BAPI to perform the update I needed.

    The interface concept of the classic R/3 is based on two different strategies: Remote Function Calls (RFC) and data exchange through IDoc message documents. RFC makes direct and synchronous calls of a program in the remote system. If the caller is an external program it will call an RFC-enabled function in R/3 and if the calling program is the R/3 system it will call an

    RFC-function in another R/3-system or it will call a non-R/3 program through a gateway-proxy (usually rfcexec.exe). BAPIs are a subset of the RFC-enabled function modules, especially designed as Application Programming Interface (API) to the SAP business object, or in other words: are function modules officially released by SAP to be called from external programs.

    IDocs are text encoded documents with a rigid structure that are used to exchange data between R/3 and a foreign system. Instead of calling a program in the destination system directly, the data is first packed into an IDoc and then sent to the receiving system, where it is analyzed and properly processed. Therefore an IDoc data exchange is always an

    asynchronous process. The significant difference between simple RFC-calls and IDoc data exchange is the fact, that every action performed on IDocs are protocolled by R/3 and IDocs can be reprocessed if an error occurred in one of the message steps.

    While IDocs have to be understood as a data exchange protocol, EDI and ALE are typical use cases for IDocs. R/3 uses IDocs for both EDI and ALE to deliver data to the receiving system. ALE is basically the scheduling mechanism that defines when and between which partners and what kind of data will be exchanged on a regular or event triggered basis. Such a set-up is called an ALE-scenario.

    The philosophical difference between EDI and ALE can be pinned as follows: If we send data to an external partner, we generally speak of EDI, while ALE is a mechanism to reliable replicate data between trusting systems to store a redundant copy of the IDoc data. The difference is made clear, when we think of a purchase order that is sent as an IDoc. If we send the purchase order to a supplier then the supplier will store the purchase order as a sales order. However, if we send the purchase order via ALE to another R/3 system, then the receiving system will store the purchase order also as a purchase order.

    <b>

    How to Find Bapi for Particular Transaction in SAP

    How to find function module or Bapi for particular transaction in sap?</b>

    If you mean that you need to know what BAPI's a particular tranx uses, which I can only assume that's what you mean, then you should access the code behind the transaction and search for 'CALL'. That normally is the standard method that think that most people use.

    Suppose you want to find the bapi for creating a sales order, you usually use transaction VA01 for this.

    <b>1. Find out the package of the transaction. </b>

    Start Va01 go to system --> status.

    Double click on transaction

    Package is VA

    Open this package in SE80

    Open business engineering-->Business object types

    Find the BO which sounds the most appropriate

    I would suggest BUS2032 Sales Order

    Double click.

    Open methods.

    Find the released method with from data or something similar in the name

    , Createfromdat2

    Position the cursor in it and click the program button

    Scroll down to find the bapi used in this method

    <b>With this way you can also find out programs and FM's </b>

    2. Start va01 go to system-->status

    Double click transaction VA01

    Double click on package

    Read the application component. (this is SD-SLS Sales)

    Then open the transaction BAPI

    Sales and distribution >Sales >sales order

    createfromdat2

    http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html#Finding%20BAPIs>

    http://help.sap.com/saphelp_nw04/helpdata/en/5c/f3f0371bc15d73e10000009b38f8cf/frameset.htm>

    reward points if it is usefull......

    Girish

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.