Simple BDC with error log
*&---------------------------------------------------------------------*
*& Report ZHCM_BDC_IT1000_PP02_O
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zhcm_bdc_it1000_pp02_o
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS: truxs,slis.
TYPES truxs_t_text_data(4096) TYPE c OCCURS 0.
DATA: it_raw TYPE truxs_t_text_data.
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: l_mstring(480).
TYPES: BEGIN OF ty_tab,
plvar(02),
otype(02),
seark(12),
infty(04),
istat(01),
begda(10),
endda(10),
rsign(01),
relat(03),
sclas(02),
sobid(45),
END OF ty_tab,
*include bdcrecx1.
BEGIN OF ty_message,
message TYPE string,
END OF ty_message.
DATA : it_tab TYPE STANDARD TABLE OF ty_tab ,
it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
it_msg TYPE STANDARD TABLE OF bdcmsgcoll,
wa_msg LIKE LINE OF it_msg,
s_msg TYPE bdcmsgcoll ,
wa_tab TYPE ty_tab.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcatalog TYPE slis_fieldcat_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
DATA : it_sortcat TYPE slis_t_sortinfo_alv.
DATA: lv_rec_count(3) VALUE 0.
DATA : it_message TYPE TABLE OF ty_message,
wa_message TYPE ty_message.
*&--------------------- SELECTION SCREEN ------------------------------------&*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.
PARAMETERS: filenam1 TYPE rlgrap-filename OBLIGATORY,
p_mode TYPE ctu_mode DEFAULT 'A'.
SELECTION-SCREEN END OF BLOCK blk.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME .
PARAMETERS p_frmlin TYPE i DEFAULT 2. " FROM LINE NO
PARAMETERS p_toline TYPE i DEFAULT 65000. " TO LINE NO
PARAMETERS p_frmcol TYPE i DEFAULT 1. " FROM COL NO
PARAMETERS p_tocol TYPE i DEFAULT 57. " TO COL NO
SELECTION-SCREEN END OF BLOCK b.
*&-------------------------------------------------------------------------&*
DATA: BEGIN OF it_file_upload1 OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline. " ROWS FOR TABLE WITH EXCEL DATA
DATA: END OF it_file_upload1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filenam1.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'FILENAME'
IMPORTING
file_name = filenam1.
*&----------------------------------------------------------------------------&*
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filenam1
i_begin_col = p_frmcol
i_begin_row = p_frmlin
i_end_col = p_tocol
i_end_row = p_toline
TABLES
intern = it_file_upload1
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&----------------------------------------------------------------------------&*
SORT it_file_upload1 BY row col.
LOOP AT it_file_upload1.
CASE it_file_upload1-col.
WHEN 1.
wa_tab-plvar = it_file_upload1-value.
WHEN 2.
wa_tab-otype = it_file_upload1-value .
WHEN 3.
wa_tab-seark = it_file_upload1-value.
WHEN 4.
wa_tab-infty = it_file_upload1-value.
WHEN 5.
wa_tab-istat = it_file_upload1-value.
WHEN 6.
wa_tab-begda = it_file_upload1-value.
WHEN 7.
wa_tab-endda = it_file_upload1-value.
WHEN 8.
wa_tab-rsign = it_file_upload1-value.
WHEN 9.
wa_tab-relat = it_file_upload1-value.
WHEN 10.
wa_tab-sclas = it_file_upload1-value.
WHEN 11.
wa_tab-sobid = it_file_upload1-value.
ENDCASE.
AT END OF row.
APPEND wa_tab TO it_tab.
CLEAR: wa_tab.
ENDAT.
ENDLOOP.
LOOP AT it_tab INTO wa_tab..
REFRESH: it_bdcdata.
PERFORM bdc_dynpro USING 'SAPMH5A0' '1000'.
PERFORM bdc_field USING 'BDC_CURSOR'
'PPHDR-ENDDA'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=INSE'.
PERFORM bdc_field USING 'PPHDR-PLVAR'
wa_tab-plvar."'01'.
PERFORM bdc_field USING 'PPHDR-OTYPE'
wa_tab-otype."'O'.
PERFORM bdc_field USING 'PM0D1-SEARK'
wa_tab-seark."'10000002'.
PERFORM bdc_field USING 'PPHDR-INFTY'
wa_tab-infty."'1001'.
PERFORM bdc_field USING 'PPHDR-ISTAT'
wa_tab-istat."'1'.
PERFORM bdc_field USING 'PPHDR-BEGDA'
wa_tab-begda."'01.01.1900'.
PERFORM bdc_field USING 'PPHDR-ENDDA'
wa_tab-endda."'31.12.9999'.
PERFORM bdc_dynpro USING 'MP100100' '2000'.
PERFORM bdc_field USING 'BDC_CURSOR'
'P1001-SOBID'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPD'.
PERFORM bdc_field USING 'P1001-BEGDA'
wa_tab-begda."'01.01.1900'.
PERFORM bdc_field USING 'P1001-ENDDA'
wa_tab-endda."'31.12.9999'.
PERFORM bdc_field USING 'P1001-RSIGN'
wa_tab-rsign."'b'.
PERFORM bdc_field USING 'P1001-RELAT'
wa_tab-relat."'002'.
PERFORM bdc_field USING 'P1001-SCLAS'
wa_tab-sclas."'O'.
PERFORM bdc_field USING 'P1001-SOBID'
wa_tab-sobid."'10000003'.
**perform bdc_dynpro using 'SAPLSPO1' '0500'.
**perform bdc_field using 'BDC_OKCODE'
** '=OPT1'.
PERFORM bdc_dynpro USING 'SAPMH5A0' '1000'.
PERFORM bdc_field USING 'BDC_CURSOR'
'PPHDR-PLVAR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BACK'.
**perform bdc_field using 'PPHDR-PLVAR'
** '01'.
**perform bdc_field using 'PPHDR-OTYPE'
** 'O'.
**perform bdc_field using 'PM0D1-SEARK'
** '10000002'.
**perform bdc_field using 'PPHDR-INFTY'
** '1001'.
**perform bdc_field using 'PPHDR-ISTAT'
** '1'.
**perform bdc_field using 'PPHDR-BEGDA'
** '01.01.1900'.
**perform bdc_field using 'PPHDR-ENDDA'
** '31.12.9999'.
CALL TRANSACTION 'PP02' USING it_bdcdata
MODE p_mode
UPDATE 'S'
MESSAGES INTO it_msg.
REFRESH: it_bdcdata.
ENDLOOP.
DATA: v_msg(255).
LOOP AT it_msg INTO s_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = s_msg-msgid
lang = s_msg-msgspra
no = s_msg-msgnr
v1 = s_msg-msgv1
v2 = s_msg-msgv2
v3 = s_msg-msgv3
v4 = s_msg-msgv4
IMPORTING
msg = wa_message-message
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
APPEND wa_message TO it_message.
CLEAR : wa_message.
ENDLOOP.
IF NOT it_message IS INITIAL.
PERFORM build_catalog.
PERFORM alv_display.
PERFORM layout.
ENDIF.
***&---------------------------------------------------------------------*
*& FORM BDC_DYNPRO
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->PROGRAM TEXT
* -->DYNPRO TEXT
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* INSERT FIELD *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form BUILD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM build_catalog .
wa_fieldcatalog-fieldname = 'MESSAGE'.
wa_fieldcatalog-seltext_m = 'MESSAGE.'.
APPEND wa_fieldcatalog TO i_fieldcat.
CLEAR wa_fieldcatalog.
ENDFORM. " BUILD_CATALOG
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_display .
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = it_message
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
ENDFORM. "ALV_DISPLAY
*&---------------------------------------------------------------------*
*& FORM LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM layout .
CLEAR gd_layout.
gd_layout-colwidth_optimize = 'X'." OPTIMIZATION OF COL WIDTH
gd_layout-zebra = 'X'.
ENDFORM. " LAYOUT
No comments:
Post a Comment