Este programa realiza un batch input a la transaccion ABUMN que sirve para realizar el traspaso de activos fijos. Debido a que hay veces que ese traspaso puede ser de cientos de activos este programa realizara esa funcion facilitandole los parametros en un Excel (mas facil de rellenar que las pantallas de SAP).
Este es un programa interesante ya que realiza la gestion de la grabación mediante punteros, dejando la operación en un mero bucle.
Al final de la ejecución imprimirá un log con los resultados de cada grabación indicando si se ha encontrado algún error o todo ha ido correctamente.
Cualquier consulta siempre puede hacerse desde el foro de dudas.
Código Fuente
TYPE-POOLS: TRUXS. tables : t100. SELECTION-SCREEN begin of SCREEN 1001 title tit as window. PARAMETERS: file type file_table-FILENAME. SELECTION-SCREEN END OF SCREEN 1001. call SELECTION-SCREEN 1001 STARTING AT 10 5. DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE. DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE. DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY. data wa like line of itab. data it type TRUXS_T_TEXT_DATA. data fp type RLGRAP-FILENAME. data fecha(10) type c. data campo type string. data campos type table of string WITH HEADER LINE. data tipo LIKE DD01V-DATATYPE. data: begin of excel OCCURS 0, RAIFP2-ANLN1 type RAIFP2-ANLN1, RAIFP1-BLDAT type RAIFP1-BLDAT, RAIFP1-BUDAT type RAIFP1-BUDAT, RAIFP1-BZDAT type RAIFP1-BZDAT, RAIFP2-SGTXT type RAIFP2-SGTXT, RAIFP3-ANLN1 type RAIFP3-ANLN1, RAIFP2-ZUONR type RAIFP2-ZUONR, end of excel. data fd type string value 'RAIFP2-ANLN1 RAIFP1-BLDAT RAIFP1-BUDAT RAIFP1-BZDAT RAIFP2-SGTXT RAIFP3-ANLN1 RAIFP2-ZUONR'. AT SELECTION-SCREEN OUTPUT. tit = 'Seleccione Fichero de Trabajo'. %_file_%_APP_%-TEXT = 'Fichero'. at SELECTION-SCREEN on VALUE-REQUEST FOR file. data ft type filetable. data rc type i. CALL METHOD cl_gui_frontend_services=>FILE_OPEN_DIALOG EXPORTING WINDOW_TITLE = 'Fichero Excel' DEFAULT_EXTENSION = 'XLS,XLSX' CHANGING FILE_TABLE = ft RC = rc EXCEPTIONS OTHERS = 0. loop at ft into file. exit. ENDLOOP. START-OF-SELECTION. if file is initial. message 'ERROR: Ruta del fichero invalida.' type 'I'. exit. endif. split fd at ' ' into table campos. fp = file. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = fp i_begin_col = 1 i_begin_row = 1 i_end_col = 7 i_end_row = 65535 TABLES intern = itab. if sy-subrc is not INITIAL. message 'ERROR: No se ha abierto el fichero para lectura' type 'I'. exit. endif. if itab[] is INITIAL. MESSAGE 'ERROR: No hay datos en el EXCEL' type 'I'. exit. endif. FIELD-SYMBOLS: <wa>, <valor>, <excel>. refresh excel. do. read table itab into wa with key row = sy-index col = 1. if sy-subrc is not initial. exit. endif. call function 'NUMERIC_CHECK' EXPORTING STRING_IN = wa-value IMPORTING STRING_OUT = wa-value HTYPE = tipo. if tipo ne 'NUMC'. delete itab where row eq wa-row. else. exit. endif. enddo. loop at itab into wa. read table campos index wa-col. CONCATENATE 'excel-' campos into campo. ASSIGN (campo) to <excel>. if wa-col >= 7. <excel> = wa-value. append excel. clear excel. else. find 'DAT' in campo. if sy-subrc is initial. call function 'KCD_EXCEL_DATE_CONVERT' EXPORTING Excel_date = wa-value IMPORTING SAP_DATE = <excel>. else. <excel> = wa-value. endif. endif. endloop. perform bdc tables excel[]. end-of-SELECTION. FORM BDC tables p_tabla type STANDARD TABLE. Field-SYMBOLS: <p>, <campos>, <variable>. loop at p_tabla ASSIGNING <p>. perform bdc_dynpro using 'SAPLAMDP' '0100'. perform bdc_field using 'BDC_OKCODE' '=TAB02'. loop at campos. CONCATENATE '<p>-' campos into campo. ASSIGN (campo) to <campos>. find 'ZUONR' in campo. if sy-subrc is initial. perform bdc_dynpro using 'SAPLAMDP' '0100'. perform bdc_field using 'BDC_OKCODE' '=SAVE'. perform bdc_field using campos <campos>. else. find 'DAT' in campo. if sy-subrc is initial. write <campos> to fecha. perform bdc_field using campos fecha. else. perform bdc_field using campos <campos>. endif. endif. endloop. perform bdc_transaction using 'ABUMN'. endloop. ENDFORM. *include bdcrecx1. FORM BDC_DYNPRO USING PROGRAM DYNPRO. CLEAR BDCDATA. BDCDATA-PROGRAM = PROGRAM. BDCDATA-DYNPRO = DYNPRO. BDCDATA-DYNBEGIN = 'X'. APPEND BDCDATA. ENDFORM. FORM BDC_FIELD USING FNAM FVAL. IF FVAL is not INITIAL. CLEAR BDCDATA. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. ENDIF. ENDFORM. FORM BDC_TRANSACTION USING TCODE. DATA: L_MSTRING(480). DATA: L_SUBRC LIKE SY-SUBRC. REFRESH MESSTAB. CALL TRANSACTION TCODE USING BDCDATA MODE 'N' UPDATE 'S' MESSAGES INTO MESSTAB. L_SUBRC = SY-SUBRC. LOOP AT MESSTAB. SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA AND ARBGB = MESSTAB-MSGID AND MSGNR = MESSTAB-MSGNR. IF SY-SUBRC = 0. L_MSTRING = T100-TEXT. IF L_MSTRING CS '&1'. REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING. REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING. REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING. REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING. ELSE. REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING. REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING. REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING. REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING. ENDIF. CONDENSE L_MSTRING. WRITE: / MESSTAB-MSGTYP, L_MSTRING(250). ELSE. WRITE: / MESSTAB. ENDIF. ENDLOOP. REFRESH BDCDATA. ENDFORM. "BDC_TRANSACTION