‎2007 Nov 13 6:11 AM
Hi Abapers,
My requirement is to read an excel input file from PC and for a each pernr(personnel number) and check against infotype 2001-absences, and read other fields from excel, if it is valid record then i should update the nfotype 2001 with this records else write to error report.
How can i achieve this? kindly help me to accomplish this functionality.. please give some sample code...
Excel Fields:
1. personnel No.
2. First name
3. last name
4. absence type
5. absence from date
6. absence to date
7. absence hours
Kindly help me with sample code..
Points are sure...
‎2007 Nov 13 6:14 AM
Hi,
Use FM " ALSM_EXCEL_TO_INTERNAL_TABLE " to upload data from excel sheet.
Regards,
Prashant
‎2007 Nov 13 6:18 AM
Hi
use the fun module
HR_INFOTYPE_OPERATION for uploading data into infotype
Regards
Anji
‎2007 Nov 13 6:19 AM
Try this it may give you hint.
DATA : BEGIN OF I0585_1 OCCURS 0,
PERNR(8),
BEGDA(8),
ENDDA(8),
ACOPC(1),
SBS01(2),
SBD01(2),
PCN01(12),
ACN01(12).
DATA : END OF I0585_1.
DATA: PERSONALDATAKEY LIKE BAPIPAKEY OCCURS 0 WITH HEADER LINE.
DATA: OPERATION LIKE PSPAR-ACTIO.
get pernr.
perform checkoperation.
PERFORM UPLOADTXT.
PERFORM INFOTYP_UPD.
&----
*& Form CHECKOPERATION
&----
text
----
--> p1 text
<-- p2 text
----
FORM CHECKOPERATION.
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
PERNR = PERNR-PERNR
INFTY = '0585'
TABLES
INFTY_TAB = I0585
EXCEPTIONS
INFTY_NOT_FOUND = 1
OTHERS = 2.
DESCRIBE TABLE I0585 LINES RECNO.
IF RECNO > 0.
MOVE 'MOD' TO OPERATION .
ENDIF.
IF RECNO = 0.
MOVE 'INS' TO OPERATION .
ENDIF.
BREAK-POINT.
ENDFORM. " CHECKOPERATION
&----
*& Form UPLOADTXT
&----
text
----
--> p1 text
<-- p2 text
----
FORM UPLOADTXT.
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = 'C:\TEMP\I0585.TXT'
FILETYPE = 'DAT'
ITEM = ' '
FILEMASK_MASK = ' '
FILEMASK_TEXT = ' '
FILETYPE_NO_CHANGE = ' '
FILEMASK_ALL = ' '
FILETYPE_NO_SHOW = ' '
LINE_EXIT = ' '
USER_FORM = ' '
USER_PROG = ' '
SILENT = 'S'
IMPORTING
FILESIZE =
CANCEL =
ACT_FILENAME =
ACT_FILETYPE =
TABLES
DATA_TAB = I0585_1
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
BREAK-POINT.
LOOP AT I0585_1.
MOVE-CORRESPONDING I0585_1 TO I0585.
APPEND I0585.
ENDLOOP.
ENDFORM. " UPLOADTXT
&----
*& Form INFOTYP_UPD
&----
text
----
--> p1 text
<-- p2 text
----
FORM INFOTYP_UPD.
LOOP AT I0585.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '0585'
NUMBER = I0585-PERNR
VALIDITYEND = I0585-ENDDA
VALIDITYBEGIN = I0585-BEGDA
RECORD = I0585
OPERATION = OPERATION
NOCOMMIT = ' '
IMPORTING
RETURN = SUCCFLAG
KEY = PERSONALDATAKEY
EXCEPTIONS
OTHERS = 0.
ENDLOOP.
ENDFORM. " INFOTYP_UPD
SAP Developer Network Blog: Yet another "from database or internal table to Excel"
SAP Developer Network Blog: Downloading data into Excel with Format Options
SAP Developer Network Blog: Manipulate Excel with OLE & ABAP
Message was edited by:
Karthikeyan Pandurangan