Skip to Content
0
Former Member
Jun 28, 2007 at 03:35 PM

i want in LSMW SAME CODING. THIS IS USING BDC CALL TRANSACTION

47 Views

REPORT ZXX_BDC_PRA NO STANDARD PAGE HEADING LINE-COUNT 20

LINE-SIZE 150 .

***********************************************************

  • Program Name :ZXX_BDC_PRA *

  • Object Id : *

  • Develper Name : praveen *

  • Start Date : 25.06.07 *

  • Description : uploading flat file to sap system *

***********************************************************

*--structure for Data Uploading.

DATA: BEGIN OF IT_STR ,

VKORG LIKE RF02D-VKORG,

VTWEG LIKE RF02D-VTWEG,

SPART LIKE RF02D-SPART,

KTOKD LIKE RF02D-KTOKD,

NAME1 LIKE KNA1-NAME1,

SORTL LIKE KNA1-SORTL,

ORT01 LIKE KNA1-ORT01,

PSTLZ LIKE KNA1-PSTLZ,

LAND1 LIKE KNA1-LAND1,

SPRAS LIKE KNA1-SPRAS,

END OF IT_STR.

*--Internal Table for Data Uploading.

DATA: ITAB LIKE IT_STR OCCURS 0.

*--Internal Table to sucessfull Records.

DATA: ITAB1 LIKE IT_STR OCCURS 0.

*--Internal Table to Store Error Records.

DATA: ITAB2 LIKE STANDARD TABLE OF IT_STR WITH HEADER LINE.

*--Internal Table for Storing the BDC data.

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

*--Internal Table for storing the messages.

DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA: COUNT TYPE I VALUE 1,

S VALUE 0, E VALUE 0.

************************************************************************

  • Selection screen *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1

WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FILE TYPE IBIPPARMS-PATH.

SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

*functionality to use drill down list

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

IMPORTING

FILE_NAME = P_FILE.

.

************************************************************************

  • Start-of-selection *

************************************************************************

START-OF-SELECTION.

DATA FILENAME TYPE STRING.

FILENAME = P_FILE.

*-- Form to upload flatfile data into the internal table.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = FILENAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ITAB

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.

*--Generating the BDC table for the fields of the internal table.

LOOP AT ITAB INTO IT_STR.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0107'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RF02D-KTOKD'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'RF02D-VKORG'

IT_STR-VKORG.

PERFORM BDC_FIELD USING 'RF02D-VTWEG'

IT_STR-VTWEG.

PERFORM BDC_FIELD USING 'RF02D-SPART'

IT_STR-SPART.

PERFORM BDC_FIELD USING 'RF02D-KTOKD'

IT_STR-KTOKD.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0110'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNA1-SPRAS'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'KNA1-NAME1'

IT_STR-NAME1.

PERFORM BDC_FIELD USING 'KNA1-SORTL'

IT_STR-SORTL.

PERFORM BDC_FIELD USING 'KNA1-ORT01'

IT_STR-ORT01.

PERFORM BDC_FIELD USING 'KNA1-PSTLZ'

IT_STR-PSTLZ.

PERFORM BDC_FIELD USING 'KNA1-LAND1'

IT_STR-LAND1.

PERFORM BDC_FIELD USING 'KNA1-SPRAS'

IT_STR-SPRAS.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0120'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNA1-TXJCD'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0125'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNA1-NIELS'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0360'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNVK-NAMEV(01)'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0310'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNVV-BEGRU'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPMF02D' '0324'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'KNVP-PARVW(01)'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

*--Calling the transaction 'Vd01'.

CALL TRANSACTION 'VD01' USING BDCDATA MODE 'N' UPDATE 'S'

MESSAGES INTO MESSTAB.

PERFORM MESSAGES.

REFRESH : BDCDATA, MESSTAB.

ENDLOOP.

END-OF-SELECTION.

*--Populating the Success records internal table.

IF ITAB1[] IS NOT INITIAL.

format color 5.

WRITE: /'SUCCESSFUL RECORDS'.

format color off.

LOOP AT ITAB1 INTO IT_STR.

WRITE:/ IT_STR-VKORG,IT_STR-VTWEG,

IT_STR-SPART,IT_STR-KTOKD,

IT_STR-NAME1,IT_STR-SORTL,

IT_STR-ORT01,

IT_STR-PSTLZ,

IT_STR-LAND1,

IT_STR-SPRAS.

S = S + 1.

ENDLOOP.

REFRESH : ITAB1.

WRITE:/ 'TOTAL RECORDS',S.

ENDIF.

*--Populating the error records internal table.

IF ITAB2[] IS NOT INITIAL.

FORMAT COLOR 3.

WRITE :/ 'ERRORS RECORDS ARE'.

FORMAT COLOR OFF.

LOOP AT ITAB2.

WRITE:/ ITAB2-VKORG,

ITAB2-VTWEG,

ITAB2-SPART,ITAB2-KTOKD,

ITAB2-NAME1,ITAB2-SORTL,

ITAB2-ORT01,

ITAB2-PSTLZ,

ITAB2-LAND1,

ITAB2-SPRAS.

E = E + 1.

ENDLOOP.

REFRESH : ITAB2.

WRITE: / 'TOTAL RECORDS',E.

REFRESH : ITAB2.

ENDIF.

************************************************************************

  • End of Selection *

************************************************************************

END-OF-SELECTION.

************************************************************************

  • TOP-OF-PAGE *

************************************************************************

TOP-OF-PAGE.

WRITE:/ SY-ULINE.

WRITE:/10 'REPORT ID',21 SY-REPID,35 'USERNAME',46 SY-UNAME,

60 'SYSTEM DATE',70 SY-DATUM,80 'SYSTEM TIME',90 SY-UZEIT,

100 'PAGE NO',108 SY-PAGNO.

WRITE:/ SY-ULINE.

&----


  • FOrm to Populate the BDC table.

----


----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> SPACE.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form messages

&----


FORM MESSAGES .

LOOP AT MESSTAB.

IF MESSTAB-MSGTYP = 'I'.

  • WRITE : / MESSTAB-MSGV1.

ELSEIF

MESSTAB-MSGTYP = 'S'.

INSERT LINES OF ITAB FROM COUNT TO COUNT INTO TABLE ITAB1 .

COUNT = COUNT + 1.

  • WRITE : / MESSTAB-MSGV1.

ELSEIF

MESSTAB-MSGTYP = 'E'.

INSERT LINES OF ITAB FROM COUNT TO COUNT INTO TABLE ITAB2.

COUNT = COUNT + 1.

  • WRITE : / MESSTAB-MSGV1.

ENDIF.

ENDLOOP.

ENDFORM. " messages