Sample Abap Code On BAPI
Sample Abap Code On BAPI
*&---------------------------------------------------------------------*
*& 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
*&---------------------------------------------------------------------*
tables : zvtls_sap.
*=====================================================================
* INTERNAL TABLES DECLARATION
*=====================================================================
*=====================================================================
* V A R I A B L E S
*=====================================================================
*======================================================================
* SELECTION SCREEN
*======================================================================
INITIALIZATION.
CLEAR w_filepath.
CONCATENATE c_filepath sy-sysid c_slash sy-mandt c_slash INTO
w_filepath.
p_file1 = text-008.
p_afile1 = text-009.
*======================================================================
* SELECTION SCREEN EVENTS
*======================================================================
AT SELECTION-SCREEN OUTPUT.
IF p_fore = c_x.
w_sscrfields_ucomm1 = space.
ELSE.
w_sscrfields_ucomm1 = c_rg1.
ENDIF.
LOOP AT SCREEN.
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.
IF p_fore EQ c_x.
START-OF-SELECTION.
IF p_fore EQ c_x.
w_file1 = p_file1.
ELSE.
w_file2 = p_afile1.
ENDIF.
*C-- Load the contents of the input file into the internal table
IF w_rc <> 0.
MESSAGE s006 DISPLAY LIKE c_e.
ENDIF.
*C-- Load the contents of the input file into the internal table
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.
*&---------------------------------------------------------------------
*
*& 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.
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).
*&---------------------------------------------------------------------
*
*& Form upload_file
*&---------------------------------------------------------------------
*
* Routine to upload data from file to tables.
*----------------------------------------------------------------------
*
* -->P_fp_flatfile
* -->P_fp_file
* <--P_fp_rc
*----------------------------------------------------------------------
*
IF fp_flatfile[] IS INITIAL.
ENDIF.
*&--------------------------------------------------------------------*
*& 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.
IF sy-subrc NE 0.
* *C-- commented by Bikash
* MESSAGE s107(yaero_ps) DISPLAY LIKE c_e.
message e008.
ELSE.
DO.
CLEAR: l_string.
ENDDO.
ENDIF.
*&--------------------------------------------------------------------*
*& 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.
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.
endform. "get_podata
*&--------------------------------------------------------------------*
*& Form move_to_bapi
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form move_to_bapi.
t_bapi_poheader-po_number = t_poheader-po.
CLEAR t_bapi_poheaderx.
refresh : t_bapi_poitem,t_bapi_poitemx.
clear t_bapi_poitem.
t_bapi_poitem-po_item = t_poitem-item.
t_bapi_poitem-delete_ind = 'X'.
CLEAR t_bapi_poitemx.
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.
CLEAR l_errflag.
LOOP AT t_bapireturn.
l_msgty = t_bapireturn-type.
l_msgid = t_bapireturn-id.
l_msgno = t_bapireturn-number.
l_msgtx = t_bapireturn-message.
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
*----------------------------------------------------------------------
*
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.
*&--------------------------------------------------------------------*
*& Form STORE_MESSAGES
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FP_MESSAGEStext
*---------------------------------------------------------------------*
FORM STORE_MESSAGES TABLES FP_MESSAGES STRUCTURE T_MESSAGE.
FIELD-SYMBOLS <fs>.
CLEAR l_catstr.
IF SY-SUBRC = '0'.
IF fp_messages[] IS NOT INITIAL.
IF sy-subrc NE 0.
LEAVE LIST-PROCESSING.
ELSE.
LOOP AT fp_messages INTO wl_output_data.
DO.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ELSE.
ENDIF.
CLEAR l_fieldvalue.
CLEAR <fs>.
ENDDO.
l_index = c_1.
CLEAR wl_output_data.
CLEAR l_catstr.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "STORE_MESSAGES