Este programa carga los datos en cualquier Tabla especificados en la pantalla de selección.
El Archivo debe ser txt, delimitado por TAB y el orden de los campos en el archivo plano debe
corresponder con los campos de la tabla.
Valores en pesos sin puntos ni comas
Fechas sin puntos
Elementos de Datos Mencionados en el reporte:El Archivo debe ser txt, delimitado por TAB y el orden de los campos en el archivo plano debe
corresponder con los campos de la tabla.
Valores en pesos sin puntos ni comas
Fechas sin puntos
IBIPGETTXT-TDFILENAME
ZLOCALFILE : CHAR 128
cl_abap_char_utilities=>horizontal_tab
--------------------------------------------
REPORT ZTABLE_LOAD .
TABLES: DD03L. "Table Fields
DATA: DREF TYPE REF TO DATA. "Reference Variable
DATA : FIELDS_ITAB LIKE DD03L OCCURS 0 WITH HEADER LINE.
DATA : DATA_ITAB(1000) TYPE C OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <T> , "Points to Table work area
<FD>. "Points to Table Field
PARAMETER : P_TABLE LIKE DD03L-TABNAME OBLIGATORY.
PARAMETER : P_FILE LIKE IBIPGETTXT-TDFILENAME OBLIGATORY.
* PARAMETER : P_FILE TYPE ZLOCALFILE OBLIGATORY.
DATA : V_HEX TYPE X VALUE '09'.
* DATA : V_HEX TYPE C VALUE cl_abap_char_utilities=>horizontal_tab.
DATA: I_TMP(100) OCCURS 0 WITH HEADER LINE. "Split internal table
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',*.*,*.*.'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
AT SELECTION-SCREEN.
REFRESH FIELDS_ITAB.
SELECT * FROM DD03L
WHERE TABNAME = P_TABLE
AND AS4LOCAL = 'A'.
IF DD03L-FIELDNAME NE '.INCLUDE '.
MOVE DD03L TO FIELDS_ITAB.
APPEND FIELDS_ITAB.
ENDIF.
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE E005(ZB).
ENDIF.
********************** MAIN PROCESSING BLOCK ***************************
START-OF-SELECTION.
PERFORM F_OPEN_FILE.
PERFORM F_DYNAMIC_TABLE_LOAD.
*---------------------------------------------------------------------*
* FORM f_open_file *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM F_OPEN_FILE.
REFRESH DATA_ITAB.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = 'ASC'
TABLES
DATA_TAB = DATA_ITAB
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
WRITE : ' Error in opening file : ' , P_FILE.
STOP.
ELSE.
DELETE DATA_ITAB INDEX 1.
ENDIF.
ENDFORM. "f_open_file
*---------------------------------------------------------------------*
* FORM f_dynamic_table_load *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM F_DYNAMIC_TABLE_LOAD.
*---Create a new data object of table specified in parameter (p_table)
*---Reference is stored in dref variable. dref now contains a pointer
*---to newly created object.
CREATE DATA DREF TYPE (P_TABLE).
*--Asssign the reference to field-symbol
ASSIGN DREF->* TO <T>.
LOOP AT DATA_ITAB.
REFRESH I_TMP.
*--Split each input row data into tokens with Tab delimiter
SPLIT DATA_ITAB AT V_HEX INTO TABLE I_TMP.
CLEAR <T>.
*---Assign each field of table to field-symbol
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <T> TO <FD>
.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
READ TABLE I_TMP INDEX SY-INDEX.
IF SY-SUBRC EQ 0.
<FD> = I_TMP.
ENDIF.
ENDDO.
*--Now will have all the data - Modify the table
MODIFY (P_TABLE) FROM <T>.
ENDLOOP.
CLEAR SY-TFILL.
DESCRIBE TABLE DATA_ITAB LINES SY-TFILL.
WRITE: /'Total number of records updated in Table ', P_TABLE NO-GAP,
' are : ', SY-TFILL.
ENDFORM. " LOAD_TABLES
TABLES: DD03L. "Table Fields
DATA: DREF TYPE REF TO DATA. "Reference Variable
DATA : FIELDS_ITAB LIKE DD03L OCCURS 0 WITH HEADER LINE.
DATA : DATA_ITAB(1000) TYPE C OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <T> , "Points to Table work area
<FD>. "Points to Table Field
PARAMETER : P_TABLE LIKE DD03L-TABNAME OBLIGATORY.
PARAMETER : P_FILE LIKE IBIPGETTXT-TDFILENAME OBLIGATORY.
* PARAMETER : P_FILE TYPE ZLOCALFILE OBLIGATORY.
DATA : V_HEX TYPE X VALUE '09'.
* DATA : V_HEX TYPE C VALUE cl_abap_char_utilities=>horizontal_tab.
DATA: I_TMP(100) OCCURS 0 WITH HEADER LINE. "Split internal table
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',*.*,*.*.'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
AT SELECTION-SCREEN.
REFRESH FIELDS_ITAB.
SELECT * FROM DD03L
WHERE TABNAME = P_TABLE
AND AS4LOCAL = 'A'.
IF DD03L-FIELDNAME NE '.INCLUDE '.
MOVE DD03L TO FIELDS_ITAB.
APPEND FIELDS_ITAB.
ENDIF.
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE E005(ZB).
ENDIF.
********************** MAIN PROCESSING BLOCK ***************************
START-OF-SELECTION.
PERFORM F_OPEN_FILE.
PERFORM F_DYNAMIC_TABLE_LOAD.
*---------------------------------------------------------------------*
* FORM f_open_file *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM F_OPEN_FILE.
REFRESH DATA_ITAB.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = 'ASC'
TABLES
DATA_TAB = DATA_ITAB
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC NE 0.
WRITE : ' Error in opening file : ' , P_FILE.
STOP.
ELSE.
DELETE DATA_ITAB INDEX 1.
ENDIF.
ENDFORM. "f_open_file
*---------------------------------------------------------------------*
* FORM f_dynamic_table_load *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM F_DYNAMIC_TABLE_LOAD.
*---Create a new data object of table specified in parameter (p_table)
*---Reference is stored in dref variable. dref now contains a pointer
*---to newly created object.
CREATE DATA DREF TYPE (P_TABLE).
*--Asssign the reference to field-symbol
ASSIGN DREF->* TO <T>.
LOOP AT DATA_ITAB.
REFRESH I_TMP.
*--Split each input row data into tokens with Tab delimiter
SPLIT DATA_ITAB AT V_HEX INTO TABLE I_TMP.
CLEAR <T>.
*---Assign each field of table to field-symbol
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <T> TO <FD>
.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
READ TABLE I_TMP INDEX SY-INDEX.
IF SY-SUBRC EQ 0.
<FD> = I_TMP.
ENDIF.
ENDDO.
*--Now will have all the data - Modify the table
MODIFY (P_TABLE) FROM <T>.
ENDLOOP.
CLEAR SY-TFILL.
DESCRIBE TABLE DATA_ITAB LINES SY-TFILL.
WRITE: /'Total number of records updated in Table ', P_TABLE NO-GAP,
' are : ', SY-TFILL.
ENDFORM. " LOAD_TABLES
No hay comentarios:
Publicar un comentario