Skip to Content
0
Jan 27, 2020 at 08:41 AM

Displaying error details

50 Views

Hi Experts,

I developed a bdc program for displaying error records and also downloading those error records but i don't getting the ouput properly.Can you please help to find what the problem in my code

TYPES: BEGIN OF LINE_TYPE,

      lifnr type lfbk-lifnr,

*      koinh type lfbk-koinh,

      BANKS TYPE LFBK-BANKS,

      bankl type lfbk-bankl,

      bankn type lfbk-bankn,

       koinh type lfbk-koinh,

       banka type bnka-banka,

       brnch type bnka-brnch,

      swift type bnka-swift,

END OF LINE_TYPE.



* TO CREATE INTERNAL TABLE IT_MAT WITH STRUCTURE LINE_TYPE.

DATA IT_MAT TYPE TABLE OF LINE_TYPE WITH HEADER LINE.



* TO CREATE INTERNAL TABLE IT_EXCEL WITH STRUCTURE ALSMEX_TABLINE.

DATA IT_EXCEL TYPE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.



* TO CREATE INTERNAL TABLE IT_BDCDATA WITH STRUCTURE BDCDATA.

DATA IT_BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.



* TO CREATE INTERNAL TABLE IT_MSG WITH STRUCTURE BDCMSGCOLL.

DATA IT_MSG TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.



* TO CREATE INTERNAL TABLE IT_ERRORS.

DATA: BEGIN OF IT_ERRORS OCCURS 10,

      lifnr type lfbk-lifnr,

*      koinh type lfbk-koinh,

*      BANKS TYPE LFBK-BANKS,

*      bankl type lfbk-bankl,

*      bankn type lfbk-bankn,

*       koinh type lfbk-koinh,

*       banka type bnka-banka,

*       brnch type bnka-brnch,

*      swift type bnka-swift,

TEXT(100),

END OF IT_ERRORS.



* TO CREATE VARIABLES

DATA:S1 TYPE I,E1 TYPE I.



* TO CREATE A FILED TO ENTER EXCEL FILE

PARAMETERS P_FILE TYPE IBIPPARMS-PATH.



* TO CRATE A FIELD TO DOWNLOAD FLATFILE.

PARAMETERS P_EFILE TYPE IBIPPARMS-PATH.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

PERFORM BROWSE_FILE USING P_FILE.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EFILE.

PERFORM BROWSE_FILE USING P_EFILE.



START-OF-SELECTION.

PERFORM UPLOAD_EXCELFILE.

PERFORM CONVERT_EXCEL_TO_IT_MAT.

PERFORM VALIDATE_DATA.



END-OF-SELECTION.

IF IT_ERRORS IS NOT INITIAL.

PERFORM DOWLOAD_ERRFILE.

ENDIF.

*&---------------------------------------------------------------------*

*& Form BROWSE_FILE

*&---------------------------------------------------------------------*

FORM BROWSE_FILE USING FILE1.



CALL FUNCTION 'F4_FILENAME'

* EXPORTING

* PROGRAM_NAME = SYST-CPROG

* DYNPRO_NUMBER = SYST-DYNNR

* FIELD_NAME = ' '

IMPORTING

FILE_NAME = FILE1

.



ENDFORM. " BROWSE_FILE

*&---------------------------------------------------------------------*

*& Form UPLOAD_EXCELFILE

*&---------------------------------------------------------------------*

FORM UPLOAD_EXCELFILE .



CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 5

I_END_ROW = 10

TABLES

INTERN = IT_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

*IF SY-SUBRC = 0.

*LOOP AT IT_EXCEL.

*WRITE:/ IT_EXCEL-ROW,IT_EXCEL-COL,IT_EXCEL-VALUE.

*ENDLOOP.

* Implement suitable error handling here

*ENDIF.





ENDFORM. " UPLOAD_EXCELFILE

*&---------------------------------------------------------------------*

*& Form CONVERT_EXCEL_TO_IT_MAT

*&---------------------------------------------------------------------*

FORM CONVERT_EXCEL_TO_IT_MAT .



LOOP AT IT_EXCEL.



CASE IT_EXCEL-COL.

WHEN 1.

IT_MAT-LIFNR = IT_EXCEL-VALUE.

WHEN 2.

IT_MAT-BANKS = IT_EXCEL-VALUE.

WHEN 3.

IT_MAT-BANKL = IT_EXCEL-VALUE.

WHEN 4.

IT_MAT-BANKN = IT_EXCEL-VALUE.

WHEN 5.

IT_MAT-KOINH = IT_EXCEL-VALUE.

WHEN 6.

IT_MAT-BANKA = IT_EXCEL-VALUE.

WHEN 7.

IT_MAT-BRNCH = IT_EXCEL-VALUE.

WHEN 8.

IT_MAT-SWIFT = IT_EXCEL-VALUE.



APPEND IT_MAT.

CLEAR: IT_MAT,IT_EXCEL.

ENDCASE.

ENDLOOP.

ULINE.

LOOP AT IT_MAT.

WRITE: / IT_MAT-LIFNR,IT_MAT-BANKS,IT_MAT-BANKL,IT_MAT-BANKN,

IT_MAT-KOINH,IT_MAT-BANKA,IT_MAT-BRNCH,IT_MAT-SWIFT.

ENDLOOP.



ENDFORM. " CONVERT_EXCEL_TO_IT_MAT

*&---------------------------------------------------------------------*

*& Form VALIDATE_DATA

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM VALIDATE_DATA .



LOOP AT IT_MAT.

REFRESH : IT_BDCDATA,IT_MSG.



perform bdc_dynpro      using 'SAPMF02K' '0101'.

perform bdc_field       using 'BDC_CURSOR'

                              'RF02K-D0130'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'RF02K-LIFNR'

                             IT_MAT-lifnr.

perform bdc_field       using 'RF02K-D0130'

                              'X'.

perform bdc_dynpro      using 'SAPMF02K' '0130'.

perform bdc_field       using 'BDC_CURSOR'

                              'LFBK-KOINH(01)'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'LFBK-BANKS(01)'

                              IT_MAT-BANKS.

perform bdc_field       using 'LFBK-BANKL(01)'

                              IT_MAT-bankl.

perform bdc_field       using 'LFBK-BANKN(01)'

                              IT_MAT-bankn.

perform bdc_field       using 'LFBK-KOINH(01)'

                              IT_MAT-koinh.

perform bdc_dynpro      using 'SAPLBANK' '0100'.

perform bdc_field       using 'BDC_CURSOR'

                              'BNKA-SWIFT'.

perform bdc_field       using 'BDC_OKCODE'

                              '=ENTR'.

perform bdc_field       using 'BNKA-BANKA'

                              IT_MAT-banka.

perform bdc_field       using 'BNKA-BRNCH'

                              IT_MAT-brnch.

perform bdc_field       using 'BNKA-SWIFT'

                              IT_MAT-swift.

perform bdc_dynpro      using 'SAPMF02K' '0130'.

perform bdc_field       using 'BDC_CURSOR'

                              'LFBK-KOINH(01)'.

perform bdc_field       using 'BDC_OKCODE'

                              '=ENTR'.

CALL TRANSACTION 'xk02' USING IT_BDCDATA

UPDATE 'A'

MODE 'N'

MESSAGES INTO IT_MSG.



READ TABLE IT_MSG WITH KEY MSGTYP = 'E'.

IF SY-SUBRC = 0.

IT_ERRORS-LIFNR = IT_MAT-LIFNR.



CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = '-D'

NO = SY-MSGNO

V1 = SY-MSGV1

V2 = SY-MSGV2

V3 = SY-MSGV3

V4 = SY-MSGV4

**V5 = SY-MSGV5

*V6 = SY-MSGV6

*V7 = SY-MSGV7

*V8 = SY-MSGV8

IMPORTING

MSG = IT_ERRORS-TEXT

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

APPEND IT_ERRORS.

E1 = E1 + 1.

ELSE.

S1 = S1 + 1.

ENDIF.

ENDLOOP.

IF SY-SUBRC = 0.

MESSAGE I100(ZMSG1) WITH S1 'RECORDS TRANSFERRED SUCCESSFULLY' E1

'RECORDS CONTAINS ERRORS,PLS REFER DOWNLOAD FILE'.

ENDIF.

ENDFORM. " VALIDATE_DATA

*&---------------------------------------------------------------------*

*& Form BDC_DYNPRO

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_0241 text

* -->P_0242 text

*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROG SCRNO.



IT_BDCDATA-PROGRAM = PROG.

IT_BDCDATA-DYNPRO = SCRNO.

IT_BDCDATA-DYNBEGIN = 'X'.



APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.



ENDFORM. " BDC_DYNPRO

*&---------------------------------------------------------------------*

*& Form BDC_FIELD

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_0301 text

* -->P_IT_MAT_MAKTX text

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAME FVAL.



IT_BDCDATA-FNAM = FNAME.

IT_BDCDATA-FVAL = FVAL.



APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.



ENDFORM. " BDC_FIELD

*&---------------------------------------------------------------------*

*& Form DOWLOAD_ERRFILE

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM DOWLOAD_ERRFILE .



* TO CREATE VARIABLE OF TYPE STRING.

DATA F_EFILE TYPE STRING.

F_EFILE = P_EFILE.



CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

* BIN_FILESIZE =

FILENAME = F_EFILE

FILETYPE = 'ASC'

* APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

* HEADER = '00'

* TRUNC_TRAILING_BLANKS = ' '

* WRITE_LF = 'X'

* COL_SELECT = ' '

* COL_SELECT_MASK = ' '

* DAT_MODE = ' '

* CONFIRM_OVERWRITE = ' '

* NO_AUTH_CHECK = ' '

* CODEPAGE = ' '

* IGNORE_CERR = ABAP_TRUE

* REPLACEMENT = '#'

* WRITE_BOM = ' '

* TRUNC_TRAILING_BLANKS_EOL = 'X'

* WK1_N_FORMAT = ' '

* WK1_N_SIZE = ' '

* WK1_T_FORMAT = ' '

* WK1_T_SIZE = ' '

* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

* SHOW_TRANSFER_STATUS = ABAP_TRUE

* IMPORTING

* FILELENGTH =

TABLES

DATA_TAB = IT_ERRORS

* FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.





ENDFORM. " DOWNLOAD_ERRFILE
Can you please help me by providing solution  for my program.
Regards,
Bhavani