*&---------------------------------------------------------------------*
*& Report ZSUR_BDCXK01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSUR_BDCXK01.
TYPES : BEGIN OF TY_HEADER,
LIFNR TYPE LIFNR,
BUKRS TYPE BUKRS,
EKORG TYPE EKORG,
KTOKK TYPE KTOKK,
NAME1 TYPE NAME1_GP,
SORTL TYPE SORTL,
LAND1 TYPE LAND1_GP,
AKONT TYPE AKONT,
FDGRV TYPE FDGRV,
WAERS TYPE WAERS,
END OF TY_HEADER,
BEGIN OF TY_ITEM,
LIFNR TYPE LIFNR,
BANKS TYPE BANKS,
BANKL TYPE BANKK,
BANKN TYPE BANKN,
END OF TY_ITEM,
BEGIN OF TY_UPLOAD,
F1 TYPE CHAR10,
F2 TYPE CHAR4,
F3 TYPE CHAR15,
F4 TYPE CHAR18,
F5 TYPE NAME1_GP,
F6 TYPE SORTL,
F7 TYPE LAND1_GP,
F8 TYPE AKONT,
F9 TYPE FDGRV,
F10 TYPE WAERS,
END OF TY_UPLOAD.
DATA : T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD,
T_HEADER TYPE STANDARD TABLE OF TY_HEADER,
T_ITEM TYPE STANDARD TABLE OF TY_ITEM,
T_BDCDATA TYPE STANDARD TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA,
W_HEADER TYPE TY_HEADER,
W_ITEM TYPE TY_ITEM,
W_UPLOAD TYPE TY_UPLOAD,
W_UPLOAD1 TYPE TY_UPLOAD.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Documents and Settings\Admin\Desktop\VENDOR.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = T_UPLOAD
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT T_UPLOAD INTO W_UPLOAD1.
W_UPLOAD = W_UPLOAD1.
AT NEW F1.
*Moving header data to header itab from UPLOAD.
W_HEADER-LIFNR = W_UPLOAD-F1.
W_HEADER-BUKRS = W_UPLOAD-F2.
W_HEADER-EKORG = W_UPLOAD-F3.
W_HEADER-KTOKK = W_UPLOAD-F4.
W_HEADER-NAME1 = W_UPLOAD-F5.
W_HEADER-SORTL = W_UPLOAD-F6.
W_HEADER-LAND1 = W_UPLOAD-F7.
W_HEADER-AKONT = W_UPLOAD-F8.
W_HEADER-FDGRV = W_UPLOAD-F9.
W_HEADER-WAERS = W_UPLOAD-F10.
APPEND W_HEADER TO T_HEADER.
CLEAR:W_HEADER.
CONTINUE.
ENDAT.
*Moving item data to item itab from UPLOAD.
W_ITEM-LIFNR = W_UPLOAD-F1.
W_ITEM-BANKS = W_UPLOAD-F2.
W_ITEM-BANKL = W_UPLOAD-F3.
W_ITEM-BANKN = W_UPLOAD-F4.
APPEND W_ITEM TO T_ITEM.
CLEAR W_ITEM.
ENDLOOP.
DATA : LN TYPE CHAR2,
L_FNAME TYPE CHAR30,
COUNTER TYPE I VALUE 1,
PG TYPE I.
LOOP AT T_HEADER INTO W_HEADER.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RF02K-LIFNR'
W_HEADER-LIFNR.
PERFORM BDC_FIELD USING 'RF02K-BUKRS'
W_HEADER-BUKRS.
PERFORM BDC_FIELD USING 'RF02K-EKORG'
W_HEADER-EKORG.
PERFORM BDC_FIELD USING 'RF02K-KTOKK'
W_HEADER-KTOKK.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-LAND1'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFA1-NAME1'
W_HEADER-NAME1.
PERFORM BDC_FIELD USING 'LFA1-SORTL'
W_HEADER-SORTL.
PERFORM BDC_FIELD USING 'LFA1-LAND1'
W_HEADER-LAND1.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0120'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-KUNNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
LN = 1.
LOOP AT T_ITEM INTO W_ITEM WHERE LIFNR = W_HEADER-LIFNR.
COUNTER = SY-TABIX.
PG = COUNTER MOD 5.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-BANKN(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
CONCATENATE 'LFBK-BANKS(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKS.
CONCATENATE 'LFBK-BANKL(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKL.
CONCATENATE 'LFBK-BANKN(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKN.
*perform bdc_dynpro using 'SAPMF02K' '0130'.
*perform bdc_field using 'BDC_CURSOR'
* 'LFBK-BANKN(02)'.
*perform bdc_field using 'BDC_OKCODE'
* '=ENTR'.
*perform bdc_field using 'LFBK-BANKS(02)'
* 'IN'.
*perform bdc_field using 'LFBK-BANKL(02)'
* 'ICICI'.
*perform bdc_field using 'LFBK-BANKN(02)'
* '789'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
IF PG = 0.
LN = 1.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=P+'.
CONTINUE.
ENDIF.
LN = LN + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0380'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0210'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-FDGRV'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFB1-AKONT'
W_HEADER-AKONT.
PERFORM BDC_FIELD USING 'LFB1-FDGRV'
W_HEADER-FDGRV.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0215'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-ZTERM'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0220'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0310'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFM1-WAERS'
W_HEADER-WAERS.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0320'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
CALL TRANSACTION 'XK01' USING T_BDCDATA MODE 'A'.
ENDLOOP.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
*& Report ZSUR_BDCXK01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSUR_BDCXK01.
TYPES : BEGIN OF TY_HEADER,
LIFNR TYPE LIFNR,
BUKRS TYPE BUKRS,
EKORG TYPE EKORG,
KTOKK TYPE KTOKK,
NAME1 TYPE NAME1_GP,
SORTL TYPE SORTL,
LAND1 TYPE LAND1_GP,
AKONT TYPE AKONT,
FDGRV TYPE FDGRV,
WAERS TYPE WAERS,
END OF TY_HEADER,
BEGIN OF TY_ITEM,
LIFNR TYPE LIFNR,
BANKS TYPE BANKS,
BANKL TYPE BANKK,
BANKN TYPE BANKN,
END OF TY_ITEM,
BEGIN OF TY_UPLOAD,
F1 TYPE CHAR10,
F2 TYPE CHAR4,
F3 TYPE CHAR15,
F4 TYPE CHAR18,
F5 TYPE NAME1_GP,
F6 TYPE SORTL,
F7 TYPE LAND1_GP,
F8 TYPE AKONT,
F9 TYPE FDGRV,
F10 TYPE WAERS,
END OF TY_UPLOAD.
DATA : T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD,
T_HEADER TYPE STANDARD TABLE OF TY_HEADER,
T_ITEM TYPE STANDARD TABLE OF TY_ITEM,
T_BDCDATA TYPE STANDARD TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA,
W_HEADER TYPE TY_HEADER,
W_ITEM TYPE TY_ITEM,
W_UPLOAD TYPE TY_UPLOAD,
W_UPLOAD1 TYPE TY_UPLOAD.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Documents and Settings\Admin\Desktop\VENDOR.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = T_UPLOAD
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT T_UPLOAD INTO W_UPLOAD1.
W_UPLOAD = W_UPLOAD1.
AT NEW F1.
*Moving header data to header itab from UPLOAD.
W_HEADER-LIFNR = W_UPLOAD-F1.
W_HEADER-BUKRS = W_UPLOAD-F2.
W_HEADER-EKORG = W_UPLOAD-F3.
W_HEADER-KTOKK = W_UPLOAD-F4.
W_HEADER-NAME1 = W_UPLOAD-F5.
W_HEADER-SORTL = W_UPLOAD-F6.
W_HEADER-LAND1 = W_UPLOAD-F7.
W_HEADER-AKONT = W_UPLOAD-F8.
W_HEADER-FDGRV = W_UPLOAD-F9.
W_HEADER-WAERS = W_UPLOAD-F10.
APPEND W_HEADER TO T_HEADER.
CLEAR:W_HEADER.
CONTINUE.
ENDAT.
*Moving item data to item itab from UPLOAD.
W_ITEM-LIFNR = W_UPLOAD-F1.
W_ITEM-BANKS = W_UPLOAD-F2.
W_ITEM-BANKL = W_UPLOAD-F3.
W_ITEM-BANKN = W_UPLOAD-F4.
APPEND W_ITEM TO T_ITEM.
CLEAR W_ITEM.
ENDLOOP.
DATA : LN TYPE CHAR2,
L_FNAME TYPE CHAR30,
COUNTER TYPE I VALUE 1,
PG TYPE I.
LOOP AT T_HEADER INTO W_HEADER.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RF02K-LIFNR'
W_HEADER-LIFNR.
PERFORM BDC_FIELD USING 'RF02K-BUKRS'
W_HEADER-BUKRS.
PERFORM BDC_FIELD USING 'RF02K-EKORG'
W_HEADER-EKORG.
PERFORM BDC_FIELD USING 'RF02K-KTOKK'
W_HEADER-KTOKK.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-LAND1'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFA1-NAME1'
W_HEADER-NAME1.
PERFORM BDC_FIELD USING 'LFA1-SORTL'
W_HEADER-SORTL.
PERFORM BDC_FIELD USING 'LFA1-LAND1'
W_HEADER-LAND1.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0120'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-KUNNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
LN = 1.
LOOP AT T_ITEM INTO W_ITEM WHERE LIFNR = W_HEADER-LIFNR.
COUNTER = SY-TABIX.
PG = COUNTER MOD 5.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-BANKN(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
CONCATENATE 'LFBK-BANKS(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKS.
CONCATENATE 'LFBK-BANKL(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKL.
CONCATENATE 'LFBK-BANKN(0' LN ')' INTO L_FNAME.
PERFORM BDC_FIELD USING L_FNAME
W_ITEM-BANKN.
*perform bdc_dynpro using 'SAPMF02K' '0130'.
*perform bdc_field using 'BDC_CURSOR'
* 'LFBK-BANKN(02)'.
*perform bdc_field using 'BDC_OKCODE'
* '=ENTR'.
*perform bdc_field using 'LFBK-BANKS(02)'
* 'IN'.
*perform bdc_field using 'LFBK-BANKL(02)'
* 'ICICI'.
*perform bdc_field using 'LFBK-BANKN(02)'
* '789'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
IF PG = 0.
LN = 1.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=P+'.
CONTINUE.
ENDIF.
LN = LN + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0380'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0210'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-FDGRV'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFB1-AKONT'
W_HEADER-AKONT.
PERFORM BDC_FIELD USING 'LFB1-FDGRV'
W_HEADER-FDGRV.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0215'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-ZTERM'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0220'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0310'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFM1-WAERS'
W_HEADER-WAERS.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0320'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
CALL TRANSACTION 'XK01' USING T_BDCDATA MODE 'A'.
ENDLOOP.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
No comments:
Post a Comment