Excel Uploader SAP ABAP Program using field symbol
REPORT zsd_uplode.
TYPES : BEGIN OF tab,
mandt TYPE mandt,
werks TYPE werks_d,
lgort TYPE lgort_d,
bldat TYPE bldat,
pernr TYPE persno,
zgross TYPE zgross,
zfine TYPE zfine,
zston TYPE zston,
zglas TYPE zglas,
zmisc TYPE zmisc,
zleat TYPE zleat,
zrubb TYPE zrubb,
zplas TYPE zplas,
zunit TYPE erfme,
zally TYPE zally,
zco11n TYPE zco11n,
zglwt TYPE zfine,
zglft TYPE zfine,
END OF tab.
DATA: gt_tab TYPE STANDARD TABLE OF tab,
gt_tab1 TYPE STANDARD TABLE OF tab,
gt_tab_r TYPE STANDARD TABLE OF tab,
gs_tab TYPE tab,
gs_tab_r TYPE tab,
gs_tab1 TYPE tab,
c_bcol TYPE i VALUE 1 , "START COLUMN
c_brow TYPE i VALUE 2 , "START ROW
c_ecol TYPE i VALUE 200 , "Ending column
c_erow TYPE i VALUE 40000 , "ENDING ROW
gv_error TYPE c.
DATA : gt_intrn TYPE TABLE OF alsmex_tabline,
gs_intrn TYPE alsmex_tabline,
lv_bland TYPE t005u-bland.
DATA : bapi_flag(1) TYPE c,
lv_ref TYPE vbrk-zzrefno.
PARAMETERS: p_fname TYPE rlgrap-filename,
zcreate RADIOBUTTON GROUP b1,
zdelete RADIOBUTTON GROUP b1..
*DATA : gt_intrn TYPE TABLE OF alsmex_tabline,
* gs_intrn TYPE alsmex_tabline,
* lv_bland TYPE t005u-bland.
DATA : wl_index TYPE i.
DATA : lv_wrbtr TYPE wrbtr.
DATA : lv_fwste TYPE fwste,
lv_fwast TYPE fwste,
lt_mwdat TYPE TABLE OF rtax1u15,
lv_prsdt TYPE komk-prsdt.
DATA : c_lifnr(10) TYPE c,
d_lifnr(17) TYPE c,
lv_ktokk TYPE lfa1-ktokk.
DATA:op_ref TYPE REF TO cx_root,
msg_text TYPE string.
FIELD-SYMBOLS <fs>.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-repid
IMPORTING
file_name = p_fname.
START-OF-SELECTION.
IF NOT p_fname = ' '.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = c_bcol
i_begin_row = c_brow
i_end_col = c_ecol
i_end_row = c_erow
TABLES
intern = gt_intrn
* Begin of changes by Niharika Tejpal CR299501 29.03.19
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2.
IF sy-subrc IS NOT INITIAL.
MESSAGE e002(sy) WITH 'Error while accessing the file!!!'.
gv_error = 'X'.
ELSE.
CLEAR: gv_error.
SORT gt_intrn BY row col.
* Add try catch block LOGIC IS ALREADY WRITTEN,HANDLE THE CONVERSION NUMBER EXCEPTION
TRY .
LOOP AT gt_intrn INTO gs_intrn.
MOVE gs_intrn-col TO wl_index.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT wl_index OF STRUCTURE gs_tab TO <fs>.
IF sy-subrc = 0.
*--- Asigning the field value to a field symbol
CONDENSE gs_intrn-value.
MOVE gs_intrn-value TO <fs>.
ENDIF.
AT END OF row.
APPEND gs_tab TO gt_tab.
CLEAR gs_tab.
ENDAT.
ENDLOOP.
* CATCH cx_sy_conversion_no_number INTO op_ref.
CATCH cx_root INTO op_ref.
msg_text = op_ref->get_text( ).
ENDTRY.
IF msg_text IS NOT INITIAL.
MESSAGE msg_text TYPE 'E'.
ENDIF.
* END OF CHANGES BY TARUN BAGGA DATED 02.04.2019
CLEAR : p_fname.
ENDIF.
ELSE.
MESSAGE i002(sy) WITH 'Select valid file'.
ENDIF.
IF NOT gt_tab[] IS INITIAL.
IF gt_tab[] IS NOT INITIAL.
IF zcreate IS NOT INITIAL.
IF gt_tab[] IS NOT INITIAL.
MODIFY zrktable FROM TABLE gt_tab[].
IF sy-subrc EQ 0.
MESSAGE 'Records Update Sucessfully' TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
IF zdelete IS NOT INITIAL.
IF gt_tab[] IS NOT INITIAL.
DELETE zrktable FROM TABLE gt_tab[].
IF sy-subrc EQ 0.
MESSAGE 'Records Deleted Sucessfully' TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* SORT gt_tab BY refno . "CUSTORD .
ENDIF.
Comments
Post a Comment