Posted: Sun Oct 14, 2007 7:40 pm Post subject: Places a DELETION indicator for the Purchase Order
Code:
*&---------------------------------------------------------------------*
*& 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.
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 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.
*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.
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.
*&--------------------------------------------------------------------*
*& 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).
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.
*&--------------------------------------------------------------------*
*& 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.
*&---------------------------------------------------------------------
*
*& 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.
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
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.
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).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.