report ZCO_BDC_KS01
no standard page heading line-size 255.
include bdcrecx1.
TYPES: begin of T_IT_record,
* data element: KOKRS
KOKRS(004),
* data element: KOSTL
KOSTL(010),
* data element: DATAB
DATAB_ANFO(010),
* data element: DATBI
DATBI_ANFO(010),
* data element: KTEXT
KTEXT(020),
* data element: KLTXT
LTEXT(040),
* data element: VERAK
VERAK(020),
* data element: ABTEI
ABTEI(012),
* data element: KOSAR
KOSAR(001),
* data element: KHINR
KHINR(012),
* data element: PRCTR
PRCTR(010),
end of T_IT_record.
*&---------------------------------------------------------------------*
*& Internal Table
*&---------------------------------------------------------------------*
DATA: GIT_record TYPE STANDARD TABLE OF T_IT_record INITIAL SIZE 0.
*&---------------------------------------------------------------------*
*& Work Area
*&---------------------------------------------------------------------*
DATA: record TYPE T_IT_record.
*&---------------------------------------------------------------------*
*& Selection Criteria
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME .
PARAMETERS: P_FNAME TYPE LOCALFILE OBLIGATORY . " File Name
SELECTION-SCREEN END OF BLOCK A.
SELECTION-SCREEN SKIP 1.
*----------------------------------------------------------------------*
* Variable
*----------------------------------------------------------------------*
DATA: V_FILENAME TYPE LOCALFILE. " File Name
*&---------------------------------------------------------------------*
*& At Selection Screen on value-request
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
*Get the browser to select the file
PERFORM SUB_GET_FILE.
start-of-selection.
* Move the value from selection to global variable
V_FILENAME = P_FNAME.
* Load the file into the Internal table
PERFORM SUB_UPLOAD_DATA.
perform open_group.
LOOP AT GIT_RECORD INTO RECORD.
perform bdc_dynpro using 'SAPLKMA1' '0200'.
perform bdc_field using 'BDC_CURSOR'
'CSKSZ-DATAB_ANFO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'CSKSZ-KOKRS'
record-KOKRS.
perform bdc_field using 'CSKSZ-KOSTL'
record-KOSTL.
perform bdc_field using 'CSKSZ-DATAB_ANFO'
record-DATAB_ANFO.
perform bdc_field using 'CSKSZ-DATBI_ANFO'
record-DATBI_ANFO.
perform bdc_dynpro using 'SAPLKMA1' '0299'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'CSKSZ-PRCTR'.
perform bdc_field using 'CSKSZ-KTEXT'
record-KTEXT.
perform bdc_field using 'CSKSZ-LTEXT'
record-LTEXT.
perform bdc_field using 'CSKSZ-VERAK'
record-VERAK.
perform bdc_field using 'CSKSZ-ABTEI'
record-ABTEI.
perform bdc_field using 'CSKSZ-KOSAR'
record-KOSAR.
perform bdc_field using 'CSKSZ-KHINR'
record-KHINR.
perform bdc_field using 'CSKSZ-PRCTR'
record-PRCTR.
perform bdc_transaction using 'KS01'.
ENDLOOP.
perform close_group.
*&---------------------------------------------------------------------*
*& Form SUB_GET_FILE
*----------------------------------------------------------------------*
FORM SUB_GET_FILE .
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = P_FNAME.
ENDFORM. " SUB_GET_FILE
*&---------------------------------------------------------------------*
*& Form SUB_UPLOAD_DATA
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_DATA .
DATA: LWA_INTERN TYPE ALSMEX_TABLINE,
LIT_INTERN TYPE STANDARD TABLE OF ALSMEX_TABLINE INITIAL SIZE 0.
DATA LEN TYPE I.
DATA L_ROW TYPE KCD_EX_ROW_N. " Row
DATA int TYPE I. " Row
DATA CHECK.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = V_FILENAME
I_BEGIN_COL = 1 "P_FRMCOL
I_BEGIN_ROW = 5 "P_FRMLIN
I_END_COL = 11 "P_TOCOL
I_END_ROW = 65536 "P_TOLINE
TABLES
INTERN = LIT_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0 .
MESSAGE TEXT-003 TYPE 'I'.
" Error in uploading the file from presentation server
LEAVE LIST-PROCESSING.
ELSE.
L_ROW = 1.
LOOP AT LIT_INTERN INTO LWA_INTERN.
IF L_ROW = LWA_INTERN-ROW.
IF LWA_INTERN-COL = 1.
record-KOKRS = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 2.
record-KOSTL = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 3.
record-DATAB_ANFO = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 4.
record-DATBI_ANFO = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 5.
LEN = STRLEN( LWA_INTERN-VALUE ).
IF LEN > 20.
MESSAGE I001(ZCO_LEN).
CLEAR GIT_record.
EXIT.
ELSE.
record-KTEXT = LWA_INTERN-VALUE.
ENDIF.
ELSEIF LWA_INTERN-COL = 6.
LEN = STRLEN( LWA_INTERN-VALUE ).
IF LEN > 40.
MESSAGE I002(ZCO_LEN).
CLEAR GIT_record.
EXIT.
ELSE.
record-LTEXT = LWA_INTERN-VALUE.
ENDIF.
ELSEIF LWA_INTERN-COL = 7.
record-VERAK = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 8.
LEN = STRLEN( LWA_INTERN-VALUE ).
IF LEN > 12.
MESSAGE I003(ZCO_LEN).
CLEAR GIT_record.
EXIT.
ELSE.
record-ABTEI = LWA_INTERN-VALUE.
ENDIF.
ELSEIF LWA_INTERN-COL = 9.
record-KOSAR = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 10.
record-KHINR = LWA_INTERN-VALUE.
ELSEIF LWA_INTERN-COL = 11.
record-PRCTR = LWA_INTERN-VALUE.
ENDIF.
AT END OF ROW.
L_ROW = L_ROW + 1.
APPEND record TO GIT_record.
CLEAR record.
ENDAT.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " SUB_UPLOAD_DATA
No comments:
Post a Comment