*----------------------------------------------------------------------* * DECLARATIONS * *----------------------------------------------------------------------* TABLES: p9058. *Strutture DATA: BEGIN OF gs_dati, pernr LIKE p9058-pernr, subty LIKE p9058-subty, endda LIKE p9058-endda, begda LIKE p9058-begda, preas LIKE p9058-preas, importo(20), waers LIKE p9058-waers, trfar LIKE p9058-trfar, trfgb LIKE p9058-trfgb, trfgr LIKE p9058-trfgr, trfst LIKE p9058-trfst, END OF gs_dati. *Tabelle DATA: BEGIN OF gt_bin OCCURS 0, dati TYPE string, END OF gt_bin. DATA gt_split TYPE TABLE OF string WITH HEADER LINE. DATA gt_dati LIKE STANDARD TABLE OF gs_dati WITH HEADER LINE. *Variabili DATA gv_type. *Field-symbols FIELD-SYMBOLS <gf_campo> TYPE ANY. *----------------------------------------------------------------------* * LAYOUT * *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: p_fsrv TYPE string LOWER CASE. SELECTION-SCREEN END OF BLOCK b1. *----------------------------------------------------------------------* * PROGRAM BODY * *----------------------------------------------------------------------* START-OF-SELECTION. OPEN DATASET p_fsrv FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc IS INITIAL. DO. CLEAR gt_bin. READ DATASET p_fsrv INTO gt_bin-dati. IF sy-subrc IS INITIAL. APPEND gt_bin. ELSE. EXIT. ENDIF. ENDDO. CLOSE DATASET p_fsrv. ELSE. MESSAGE e001. "Errore di apertura file ENDIF. LOOP AT gt_bin. CLEAR: gs_dati, gt_split[]. SPLIT gt_bin-dati AT ';' INTO TABLE gt_split. LOOP AT gt_split. ASSIGN COMPONENT sy-tabix OF STRUCTURE gs_dati TO <gf_campo>. IF sy-subrc IS INITIAL. DESCRIBE FIELD <gf_campo> TYPE gv_type. IF gv_type = 'P'. TRANSLATE gt_split USING ',.'. ENDIF. <gf_campo> = gt_split. ENDIF. ENDLOOP. APPEND gs_dati TO gt_dati. ENDLOOP. *----------------------------------------------------------------------*
giovedì 10 novembre 2016
Leggere un file CSV sull'Application Server
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento