Posted: Tue Nov 18, 2008 10:58 pm Post subject: Changing an Idoc’s status with an Excel upload
Changing an Idoc’s status with an Excel upload Author: Kevin Wilson
Report Description: The following report takes an Excel spreadsheet (maximum 2000 rows) with Idoc number in column A and nothing else, uploads it and processes them with a new Idoc status that is entered as input when running the program.
Main program
Code:
*&---------------------------------------------------------------------*
*& Report Z_IDOC_STATUS_CHANGE *
*&---------------------------------------------------------------------*
*& AUTHOR: Kevin Wilson *
*& DESCRIPTION: Reset Idoc statuses by uploading spreadsheet of IDocs *
*&---------------------------------------------------------------------*
report z_idoc_status_change message-id zedi.
*--- INCLUDES ---------------------------------------------------------*
include z_idoc_status_change_data.
include z_idoc_status_change_forms.
*--- SELECTION OPTIONS ------------------------------------------------*
selection-screen begin of block b1 with frame title text-001.
parameters: filename like sapb-sappfad.
selection-screen skip.
selection-screen begin of block b2 with frame title text-002.
parameters: status like edidc-status default '52',
msgty like edids-statyp default 'I',
msgid like edids-stamid default 'ZEDI',
msgno like edids-stamno default '029',
msgv1 like edids-stapa1 default sy-uname,
msgv2 like edids-stapa2 default sy-datum,
msgv3 like edids-stapa3,
msgv4 like edids-stapa4.
selection-screen end of block b2.
selection-screen end of block b1.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if t_answer = '1'. "Yes
format color col_positive.
write: /5 'Choose to continue.'.
format color off.
perform process_idocs tables itab_idocs
using status msgty msgid msgno
msgv1 msgv2 msgv3 msgv4.
elseif t_answer = '2'. "No
format color col_negative.
write: /5 'Choose not to continue. No records changed'.
format color off.
else. "Cancel
format color col_negative.
write: /5 'Choose to cancel. No records changed'.
format color off.
endif.
endif.
endif.
endif.
*--- AT SELECTION SCREEN ACTION ---------------------------------------*
at selection-screen on value-request for filename.
*--- STRUCTURE DEFINITIONS -------------------------------------------*
types: begin of itab_idoc_structure,
docnum like edidc-docnum.
types: end of itab_idoc_structure.
*--- INTERNAL TABLE AND WORK AREA DEFINITIONS -------------------------*
data: itab_idocs type standard table of itab_idoc_structure,
wa_idocs type itab_idoc_structure.
*--- VARIABLES --------------------------------------------------------*
data: return like sy-subrc,
t_answer.
Include Z_IDOC_STATUS_CHANGE_FORMS
Code:
*----------------------------------------------------------------------*
***INCLUDE Z_IDOC_STATUS_CHANGE_FORMS .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form upload_excel
*&---------------------------------------------------------------------*
* Only handles Excel file upload - Column A has a list of IDoc numbers
* Maximum 2000 IDocs passed
*&---------------------------------------------------------------------*
form upload_excel tables p_itab_idoc like itab_idocs
using p_filename
changing p_return.
data: file_name like rlgrap-filename,
file_type like rlgrap-filetype,
itab_excel like alsmex_tabline occurs 0 with header line.
move p_filename to file_name.
move 'XLS' to file_type.
refresh itab_excel.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file_name
i_begin_col = 1
i_begin_row = 1
i_end_col = 1
i_end_row = 2000
tables
intern = itab_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
p_return = sy-subrc.
message i060 with sy-subrc file_name.
else.
loop at itab_excel.
wa_idocs-docnum = itab_excel-value.
select single docnum into edidc-docnum
from edidc
where docnum = wa_idocs-docnum.
if sy-subrc = 0.
collect wa_idocs into p_itab_idoc.
write: /5 'IDoc', wa_idocs-docnum, 'added for processing.'.
else.
write: /5 wa_idocs-docnum, 'IGNORED for processing.'.
endif.
endloop.
if sy-subrc <> 0.
p_return = sy-subrc.
message i061 with file_name.
endif.
endif.
endform. " upload_excel
*&---------------------------------------------------------------------*
*& Form process_idocs
*&---------------------------------------------------------------------*
form process_idocs tables p_itab_idocs like itab_idocs
using p_status
p_msgty
p_msgid
p_msgno
p_msgv1
p_msgv2
p_msgv3
p_msgv4.
data: bdidocstat like bdidocstat occurs 0 with header line.
if sy-subrc <> 0.
format color col_negative.
write: /10 'IDoc', wa_idocs-docnum, 'had NO status update!'.
format color off.
else.
write: /10 'IDoc', wa_idocs-docnum,
'has had it''s status updated'.
endif.
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 can 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.