‎2007 Apr 03 10:25 AM
Can any one provide the code for how to get success records and error records into seperate flat files
thanks
Sambasiva
‎2007 Apr 03 10:30 AM
hi,
Refer to this code
REPORT ztest_report
NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZRASH.
************************************************************************
* Internal Table Declarations *
************************************************************************
*--Internal Table for Data Uploading.
DATA : BEGIN OF IT_FFCUST OCCURS 0,
KUNNR(10),
BUKRS(4),
KTOKD(4),
ANRED(15),
NAME1(35),
SORTL(10),
STRAS(35),
ORT01(35),
PSTLZ(10),
LAND1(3),
SPRAS(2),
AKONT(10),
END OF IT_FFCUST.
*--Internal Table to Store Error Records.
DATA : BEGIN OF IT_ERRCUST OCCURS 0,
KUNNR(10),
EMSG(255),
END OF IT_ERRCUST.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF IT_SUCCUST OCCURS 0,
KUNNR(10),
SMSG(255),
END OF IT_SUCCUST.
*--Internal Table for Storing the BDC data.
DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages.
DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA : V_FLAG1(1) VALUE ' ',
"Flag used for opening session.
V_TLINES LIKE SY-TABIX,
"For storing total records processed.
V_ELINES LIKE SY-TABIX,
"For storing the no of error records.
V_SLINES LIKE SY-TABIX.
"For storing the no of success records.
************************************************************************
* Selection screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1.
PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,
V_SESNAM LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* Start-of-selection *
************************************************************************
START-OF-SELECTION.
*-- Form to upload flatfile data into the internal table.
PERFORM FORM_UPLOADFF.
************************************************************************
* TOP-OF-PAGE *
************************************************************************
TOP-OF-PAGE.
WRITE:/ 'Details of the error and success records for the transaction'
.
ULINE.
SKIP.
************************************************************************
* End of Selection *
************************************************************************
END-OF-SELECTION.
*-- Form to Generate a BDC from the Uploaded Internal table
PERFORM FORM_BDCGENERATE.
*--To write the totals and the session name.
PERFORM FORM_WRITEOP.
*&---------------------------------------------------------------------*
*& Form form_uploadff
*&---------------------------------------------------------------------*
* Form to upload flatfile data into the internal table.
*----------------------------------------------------------------------*
FORM FORM_UPLOADFF .
*--Variable to change the type of the parameter file name.
DATA : LV_FILE TYPE STRING.
LV_FILE = V_FNAME.
*--Function to upload the flat file to the internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_FFCUST
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.
*--Deleting the headings from the internal table.
DELETE IT_FFCUST INDEX 1.
*--Getting the total number of records uploaded.
DESCRIBE TABLE IT_FFCUST LINES V_TLINES.
ENDIF.
ENDFORM. " form_uploadff
*&---------------------------------------------------------------------*
*& Form Form_bdcgenerate
*&---------------------------------------------------------------------*
* Form to Generate a BDC from the Uploaded Internal table
*----------------------------------------------------------------------*
FORM FORM_BDCGENERATE .
*--Generating the BDC table for the fields of the internal table.
LOOP AT IT_FFCUST.
PERFORM POPULATEBDC USING :
'X' 'SAPMF02D' '0105',
' ' 'BDC_OKCODE' '/00' ,
' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,
' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,
' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,
'X' 'SAPMF02D' '0110' ,
' ' 'BDC_OKCODE' '/00',
' ' 'KNA1-ANRED' IT_FFCUST-ANRED,
' ' 'KNA1-NAME1' IT_FFCUST-NAME1,
' ' 'KNA1-SORTL' IT_FFCUST-SORTL,
' ' 'KNA1-STRAS' IT_FFCUST-STRAS,
' ' 'KNA1-ORT01' IT_FFCUST-ORT01,
' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,
' ' 'KNA1-LAND1' IT_FFCUST-LAND1,
' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,
'X' 'SAPMFO2D' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0125',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0340',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0360',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0210',
' ' 'KNB1-AKONT' IT_FFCUST-AKONT,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0215',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0220',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0230',
' ' 'BDC_OKCODE' '=UPDA'.
*--Calling the transaction 'fd01'.
CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'
MESSAGES INTO IT_CUSTMSG.
IF SY-SUBRC <> 0.
*--Populating the error records internal table.
IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_ERRCUST.
CLEAR IT_ERRCUST.
*--Opening a session if there is an error record.
IF V_FLAG1 = ' '.
PERFORM FORM_OPENSESSION.
V_FLAG1 = 'X'.
ENDIF.
*--Inserting the error records into already open session.
IF V_FLAG1 = 'X'.
PERFORM FORM_INSERT.
ENDIF.
*--Populating the Success records internal table.
ELSE.
IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_SUCCUST.
CLEAR IT_SUCCUST.
ENDIF.
*--Displaying the messages.
IF NOT IT_CUSTMSG[] IS INITIAL.
PERFORM FORM_FORMATMSG.
ENDIF.
*--Clearing the message and bdc tables.
CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].
ENDLOOP.
*--Getting the total no of error records.
DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.
*--Getting the total no of successful records.
DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.
*--Closing the session only if it is open.
IF V_FLAG1 = 'X'.
PERFORM FORM_CLOSESESS.
ENDIF.
ENDFORM. " Form_bdcgenerate
*&---------------------------------------------------------------------*
*& Form populatebdc
*&---------------------------------------------------------------------*
* FOrm to Populate the BDC table.
*----------------------------------------------------------------------*
FORM POPULATEBDC USING VALUE(P_0178)
VALUE(P_0179)
VALUE(P_0180).
IF P_0178 = 'X'.
IT_CUSTBDC-PROGRAM = P_0179.
IT_CUSTBDC-DYNPRO = P_0180.
IT_CUSTBDC-DYNBEGIN = 'X'.
ELSE.
IT_CUSTBDC-FNAM = P_0179.
IT_CUSTBDC-FVAL = P_0180.
ENDIF.
APPEND IT_CUSTBDC.
CLEAR IT_CUSTBDC.
ENDFORM. " populatebdc
*&---------------------------------------------------------------------*
*& Form FORM_OPENSESSION
*&---------------------------------------------------------------------*
* Form to Open a session.
*----------------------------------------------------------------------*
FORM FORM_OPENSESSION .
*--Variable to convert the given session name into reqd type.
DATA : LV_SESNAM(12).
LV_SESNAM = V_SESNAM.
*--Opening a session.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = LV_SESNAM
HOLDDATE = '20040805'
KEEP = 'X'
USER = SY-UNAME
PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
WRITE :/ 'Session not open'.
ENDIF.
ENDFORM. " FORM_OPENSESSION
*&---------------------------------------------------------------------*
*& Form FORM_INSERT
*&---------------------------------------------------------------------*
* fORM TO INSERT ERROR RECOED INTO A SESSION.
*----------------------------------------------------------------------*
FORM FORM_INSERT .
*--Inserting the record into session.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FD01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = IT_CUSTBDC
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
WRITE :/ 'Unable to insert the record'.
ENDIF.
ENDFORM. " FORM_INSERT
*&---------------------------------------------------------------------*
*& Form FORM_CLOSESESS
*&---------------------------------------------------------------------*
* Form to Close the Open Session.
*----------------------------------------------------------------------*
FORM FORM_CLOSESESS .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " FORM_CLOSESESS
*&---------------------------------------------------------------------*
*& Form FORM_FORMATMSG
*&---------------------------------------------------------------------*
* Form to format messages.
*----------------------------------------------------------------------*
FORM FORM_FORMATMSG .
*--Var to store the formatted msg.
DATA : LV_MSG(255).
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = SY-LANGU
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = LV_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE :/ LV_MSG.
ENDIF.
ULINE.
ENDFORM. " FORM_FORMATMSG
*&---------------------------------------------------------------------*
*& Form form_writeop
*&---------------------------------------------------------------------*
* To write the totals and the session name.
*----------------------------------------------------------------------*
FORM FORM_WRITEOP .
WRITE :/ 'Total Records Uploaded :',V_TLINES,
/ 'No of Error Records :',V_ELINES,
/ 'No of Success Records :',V_SLINES,
/ 'Name of the Session :',V_SESNAM.
ULINE.
ENDFORM. " form_writeop
‎2007 Apr 03 10:30 AM
hi,
Refer to this code
REPORT ztest_report
NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZRASH.
************************************************************************
* Internal Table Declarations *
************************************************************************
*--Internal Table for Data Uploading.
DATA : BEGIN OF IT_FFCUST OCCURS 0,
KUNNR(10),
BUKRS(4),
KTOKD(4),
ANRED(15),
NAME1(35),
SORTL(10),
STRAS(35),
ORT01(35),
PSTLZ(10),
LAND1(3),
SPRAS(2),
AKONT(10),
END OF IT_FFCUST.
*--Internal Table to Store Error Records.
DATA : BEGIN OF IT_ERRCUST OCCURS 0,
KUNNR(10),
EMSG(255),
END OF IT_ERRCUST.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF IT_SUCCUST OCCURS 0,
KUNNR(10),
SMSG(255),
END OF IT_SUCCUST.
*--Internal Table for Storing the BDC data.
DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages.
DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA : V_FLAG1(1) VALUE ' ',
"Flag used for opening session.
V_TLINES LIKE SY-TABIX,
"For storing total records processed.
V_ELINES LIKE SY-TABIX,
"For storing the no of error records.
V_SLINES LIKE SY-TABIX.
"For storing the no of success records.
************************************************************************
* Selection screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1.
PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,
V_SESNAM LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* Start-of-selection *
************************************************************************
START-OF-SELECTION.
*-- Form to upload flatfile data into the internal table.
PERFORM FORM_UPLOADFF.
************************************************************************
* TOP-OF-PAGE *
************************************************************************
TOP-OF-PAGE.
WRITE:/ 'Details of the error and success records for the transaction'
.
ULINE.
SKIP.
************************************************************************
* End of Selection *
************************************************************************
END-OF-SELECTION.
*-- Form to Generate a BDC from the Uploaded Internal table
PERFORM FORM_BDCGENERATE.
*--To write the totals and the session name.
PERFORM FORM_WRITEOP.
*&---------------------------------------------------------------------*
*& Form form_uploadff
*&---------------------------------------------------------------------*
* Form to upload flatfile data into the internal table.
*----------------------------------------------------------------------*
FORM FORM_UPLOADFF .
*--Variable to change the type of the parameter file name.
DATA : LV_FILE TYPE STRING.
LV_FILE = V_FNAME.
*--Function to upload the flat file to the internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_FFCUST
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.
*--Deleting the headings from the internal table.
DELETE IT_FFCUST INDEX 1.
*--Getting the total number of records uploaded.
DESCRIBE TABLE IT_FFCUST LINES V_TLINES.
ENDIF.
ENDFORM. " form_uploadff
*&---------------------------------------------------------------------*
*& Form Form_bdcgenerate
*&---------------------------------------------------------------------*
* Form to Generate a BDC from the Uploaded Internal table
*----------------------------------------------------------------------*
FORM FORM_BDCGENERATE .
*--Generating the BDC table for the fields of the internal table.
LOOP AT IT_FFCUST.
PERFORM POPULATEBDC USING :
'X' 'SAPMF02D' '0105',
' ' 'BDC_OKCODE' '/00' ,
' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,
' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,
' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,
'X' 'SAPMF02D' '0110' ,
' ' 'BDC_OKCODE' '/00',
' ' 'KNA1-ANRED' IT_FFCUST-ANRED,
' ' 'KNA1-NAME1' IT_FFCUST-NAME1,
' ' 'KNA1-SORTL' IT_FFCUST-SORTL,
' ' 'KNA1-STRAS' IT_FFCUST-STRAS,
' ' 'KNA1-ORT01' IT_FFCUST-ORT01,
' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,
' ' 'KNA1-LAND1' IT_FFCUST-LAND1,
' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,
'X' 'SAPMFO2D' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0125',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0340',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0360',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0210',
' ' 'KNB1-AKONT' IT_FFCUST-AKONT,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0215',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0220',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0230',
' ' 'BDC_OKCODE' '=UPDA'.
*--Calling the transaction 'fd01'.
CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'
MESSAGES INTO IT_CUSTMSG.
IF SY-SUBRC <> 0.
*--Populating the error records internal table.
IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_ERRCUST.
CLEAR IT_ERRCUST.
*--Opening a session if there is an error record.
IF V_FLAG1 = ' '.
PERFORM FORM_OPENSESSION.
V_FLAG1 = 'X'.
ENDIF.
*--Inserting the error records into already open session.
IF V_FLAG1 = 'X'.
PERFORM FORM_INSERT.
ENDIF.
*--Populating the Success records internal table.
ELSE.
IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_SUCCUST.
CLEAR IT_SUCCUST.
ENDIF.
*--Displaying the messages.
IF NOT IT_CUSTMSG[] IS INITIAL.
PERFORM FORM_FORMATMSG.
ENDIF.
*--Clearing the message and bdc tables.
CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].
ENDLOOP.
*--Getting the total no of error records.
DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.
*--Getting the total no of successful records.
DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.
*--Closing the session only if it is open.
IF V_FLAG1 = 'X'.
PERFORM FORM_CLOSESESS.
ENDIF.
ENDFORM. " Form_bdcgenerate
*&---------------------------------------------------------------------*
*& Form populatebdc
*&---------------------------------------------------------------------*
* FOrm to Populate the BDC table.
*----------------------------------------------------------------------*
FORM POPULATEBDC USING VALUE(P_0178)
VALUE(P_0179)
VALUE(P_0180).
IF P_0178 = 'X'.
IT_CUSTBDC-PROGRAM = P_0179.
IT_CUSTBDC-DYNPRO = P_0180.
IT_CUSTBDC-DYNBEGIN = 'X'.
ELSE.
IT_CUSTBDC-FNAM = P_0179.
IT_CUSTBDC-FVAL = P_0180.
ENDIF.
APPEND IT_CUSTBDC.
CLEAR IT_CUSTBDC.
ENDFORM. " populatebdc
*&---------------------------------------------------------------------*
*& Form FORM_OPENSESSION
*&---------------------------------------------------------------------*
* Form to Open a session.
*----------------------------------------------------------------------*
FORM FORM_OPENSESSION .
*--Variable to convert the given session name into reqd type.
DATA : LV_SESNAM(12).
LV_SESNAM = V_SESNAM.
*--Opening a session.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = LV_SESNAM
HOLDDATE = '20040805'
KEEP = 'X'
USER = SY-UNAME
PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
WRITE :/ 'Session not open'.
ENDIF.
ENDFORM. " FORM_OPENSESSION
*&---------------------------------------------------------------------*
*& Form FORM_INSERT
*&---------------------------------------------------------------------*
* fORM TO INSERT ERROR RECOED INTO A SESSION.
*----------------------------------------------------------------------*
FORM FORM_INSERT .
*--Inserting the record into session.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FD01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = IT_CUSTBDC
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
WRITE :/ 'Unable to insert the record'.
ENDIF.
ENDFORM. " FORM_INSERT
*&---------------------------------------------------------------------*
*& Form FORM_CLOSESESS
*&---------------------------------------------------------------------*
* Form to Close the Open Session.
*----------------------------------------------------------------------*
FORM FORM_CLOSESESS .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " FORM_CLOSESESS
*&---------------------------------------------------------------------*
*& Form FORM_FORMATMSG
*&---------------------------------------------------------------------*
* Form to format messages.
*----------------------------------------------------------------------*
FORM FORM_FORMATMSG .
*--Var to store the formatted msg.
DATA : LV_MSG(255).
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = SY-LANGU
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = LV_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE :/ LV_MSG.
ENDIF.
ULINE.
ENDFORM. " FORM_FORMATMSG
*&---------------------------------------------------------------------*
*& Form form_writeop
*&---------------------------------------------------------------------*
* To write the totals and the session name.
*----------------------------------------------------------------------*
FORM FORM_WRITEOP .
WRITE :/ 'Total Records Uploaded :',V_TLINES,
/ 'No of Error Records :',V_ELINES,
/ 'No of Success Records :',V_SLINES,
/ 'Name of the Session :',V_SESNAM.
ULINE.
ENDFORM. " form_writeop
‎2007 Apr 03 12:49 PM
Hi, this is call transaction method.
REPORT zrecord02
NO STANDARD PAGE HEADING LINE-SIZE 255.
CONSTANTS: gc_x TYPE c VALUE 'X', "constants for true value
gc_dynbegin TYPE c VALUE 'X', "constants used in call transaction
gc_mode TYPE c VALUE 'A', "constants used in call transaction
gc_mode1 TYPE c VALUE 'N', "constants used in call transaction
gc_sucess TYPE c VALUE 'S', "constants used in call transaction
gc_flag TYPE c VALUE 'X', "constants used in call transaction
gc_read TYPE dxfields-fileoper VALUE 'R', "Constants used in form file selection.
gc_applic TYPE dxfields-location VALUE 'A', "application server location
gc_presen TYPE dxfields-location VALUE 'P', "Presentation server location
gc_root(01) TYPE c VALUE '/'. "constant used in file selection
DATA: gv_datab TYPE char12, "Varible to hold the data
gv_date TYPE char2, "Variable to hold the date
gv_mon TYPE char2, "Variable to hold the month
gv_year TYPE char4, "Variable to hold the year
gv_no_succs TYPE i, "Variable to hold the number of correct records
gv_no_error TYPE i, "Variable to hold the number of error records
gv_msg TYPE char100, "Variable to hold the message
gv_id TYPE i. "Variable to hold the tabix value
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-t01.
PARAMETERS: p_upl_ps RADIOBUTTON GROUP g DEFAULT 'X', "radiobutton for presentation server
p_upl_as RADIOBUTTON GROUP g, "radiobutton for application server
p_file TYPE rlgrap-filename, "file name
p_test AS CHECKBOX. "for testmode
SELECTION-SCREEN END OF BLOCK b.
TYPES: BEGIN OF gs_itab , " structure containing the fields of flat file.
land1 TYPE v_t604-land1, "Land value from ex
stawn TYPE v_t604-stawn,
text1 TYPE v_t604-text1,
bemeh TYPE v_t604-bemeh,
impma TYPE v_t604-impma,
minol TYPE v_t604-minol,
END OF gs_itab.
DATA: gi_itab TYPE TABLE OF gs_itab , "internal table for the structure gs_itab
gi_valid_itab TYPE TABLE OF gs_itab, "internal table for the structure gs_itab with valid fields alone.
gi_dup_itab TYPE TABLE OF gs_itab, "internal table for the structure gs_itab to capture the duplicate values
gw_itab TYPE gs_itab, " work area of gs_itab
gw_validitab TYPE gs_itab.
TYPES: BEGIN OF gs_e_itab, " structure containing the error fields of flat file.
land1 TYPE v_t604-land1,
stawn TYPE v_t604-stawn,
text1 TYPE v_t604-text1,
bemeh TYPE v_t604-bemeh,
impma TYPE v_t604-impma,
minol TYPE v_t604-minol,
err(30) TYPE c,
END OF gs_e_itab.
DATA: gi_err_itab TYPE TABLE OF gs_e_itab, " internal table for the structure gs_e_itab.
gw_err_itab TYPE gs_e_itab. "work area for the structure gs_itab
TYPES: BEGIN OF gs_land_stawn, "structure containing land and import codes of flat file.
land1 TYPE t005-land1,
stawn TYPE t604-stawn,
END OF gs_land_stawn.
DATA: gi_land_stawn TYPE TABLE OF gs_land_stawn, " internal table containing valid land and import codes of flat file
gi_err_land_stawn TYPE TABLE OF gs_land_stawn, " internal table containing error land and import codes of flat file
gw_land_stawn TYPE gs_land_stawn. " work area for the above internal table.
TYPES: BEGIN OF gs_land, "structure containing land field alone
land1 TYPE t005-land1,
END OF gs_land.
DATA: gi_land TYPE TABLE OF gs_land, " internal table for the structure gs_land
gi_c_land TYPE TABLE OF gs_land, " gi_b_land, " internal table for the structure gs_land with only valid land fields
gw_land TYPE gs_land. "work area for gs_land
DATA: BEGIN OF gs_temp, "structure containing the fields of legacy file.
line(1000) TYPE c,
END OF gs_temp.
DATA: gi_temp LIKE TABLE OF gs_temp, "internal table for the structure gs_temp,
gw_temp LIKE gs_temp. "work area for gs_temp
DATA: gi_bdcdata TYPE TABLE OF bdcdata, "internal table for bdcdata
gi_msg TYPE TABLE OF bdcmsgcoll. "internal table for bdcmsgcoll
DATA: gw_bdcdata TYPE bdcdata, "workarea for bdcdata
gw_msg TYPE bdcmsgcoll. "workarea for bdcmsgcoll
*********************************************************************************
&----
AT SELECTION-SCREEN
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM file_selection. "Selecting the file from the server
&----
TOP-OF-PAGE
----
TOP-OF-PAGE.
PERFORM gf_header. "Calling the header Section
&----
END-OF-PAGE
----
END-OF-PAGE.
EXIT.
&----
START-OF-SELECTION
----
START-OF-SELECTION.
PERFORM upload. "Uploading the file to internal table
PERFORM get_data. "Splitting the pipe delimited data
IF p_test = gc_x. "In test mode
PERFORM validations.
PERFORM remove_duplicate.
PERFORM display.
ELSE. "not in test mode
PERFORM validations.
PERFORM remove_duplicate.
PERFORM bdc.
PERFORM display.
ENDIF.
PERFORM no_of_records.
&----
END-OF-SELECTION
----
END-OF-SELECTION.
EXIT.
&----
*& Form file_selection.
&----
text
----
FORM file_selection.
CONSTANTS: lc_slash(2) TYPE c VALUE '//'.
DATA : lv_file_path TYPE dxfields-longpath,
lv_location TYPE dxfields-location,
lv_server TYPE msxxlist-name,
ls_rfcsi TYPE rfcsi.
CLEAR:lv_server,lv_location, lv_file_path.
MOVE gc_read TO lv_file_path.
IF lv_file_path IS INITIAL.
lv_file_path = gc_root.
ENDIF.
IF NOT p_upl_ps IS INITIAL.
lv_location = gc_presen. "if presentation server is selected
ELSE.
lv_location = gc_applic. "if application server is selected
ENDIF.
CALL FUNCTION 'RFC_SYSTEM_INFO'
IMPORTING
rfcsi_export = ls_rfcsi.
lv_server = ls_rfcsi-rfcdest.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = lv_location
i_server = lv_server
i_path = lv_file_path
FILEMASK = '.'
fileoperation = p_upl_ps
IMPORTING
O_LOCATION_FLAG =
O_SERVER =
o_path = lv_file_path
ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
ERROR_WITH_GUI = 2
OTHERS = 2
.
IF sy-subrc <> 0.
EXIT.
ELSE.
MOVE lv_file_path TO p_file.
ENDIF.
IF p_file(2) EQ lc_slash.
SHIFT p_file LEFT.
ENDIF.
ENDFORM. " FILE_SELECTION
&----
*& Form upload
&----
text
----
FORM upload.
DATA: lv_file TYPE string.
lv_file = p_file.
IF NOT p_upl_ps IS INITIAL. "if presentation server is selected
CLEAR gi_itab.
REFRESH gi_itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
filetype = 'ASC'
has_field_separator = ''
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
dat_mode = 'X'
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = gi_temp
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE. "If application server is selected
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT "If the data is available on the UNIX/Appl. server get the data
WITH SMART LINEFEED.
IF sy-subrc <> 0.
EXIT.
ENDIF.
DO.
READ DATASET p_file INTO gw_temp-line. "read file which is opened.
APPEND gw_temp TO gi_temp.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_file. "close the file.
ENDIF.
ENDFORM. "upload
*
&----
*& Form get_data
&----
text
----
FORM get_data.
DATA:lv_id TYPE sy-tabix.
gv_id = 0.
IF gi_temp[] IS INITIAL. "If the uploaded internal table is empty.
WRITE: /5 text-001.
EXIT.
ELSE.
LOOP AT gi_temp INTO gw_temp.
lv_id = sy-tabix.
SPLIT gw_temp-line
AT '|'
INTO gw_itab-land1
gw_itab-stawn
gw_itab-text1 "Splitting the pipe delimited data.
gw_itab-bemeh
gw_itab-impma
gw_itab-minol.
IF gw_itab-land1 IS INITIAL. " If the user fails to enter land key
gw_itab-land1 = 'CA'. " Default land to 'CA'.
ENDIF.
IF gw_itab-stawn IS NOT INITIAL. " If import code is present
APPEND gw_itab TO gi_itab.
ELSE.
APPEND gw_itab TO gi_itab.
CLEAR gw_itab.
READ TABLE gi_itab
INTO gw_itab WITH KEY stawn = space. "Read the internal table with empty import code
IF sy-subrc = 0.
gw_err_itab-land1 = gw_itab-land1.
gw_err_itab-stawn = gw_itab-stawn.
gw_err_itab-text1 = gw_itab-text1.
gw_err_itab-bemeh = gw_itab-bemeh.
gw_err_itab-impma = gw_itab-impma.
gw_err_itab-minol = gw_itab-minol.
gw_err_itab-err = text-032.
APPEND gw_err_itab TO gi_err_itab.
gv_id = gv_id + 1.
DELETE gi_itab INDEX lv_id.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "get_data
&----
*& Form gf_header
&----
text
----
FORM gf_header.
NEW-LINE. " Dispalay the header section
ULINE.
WRITE:/ text-006.
WRITE:/ text-019.
SKIP 1.
WRITE: AT /1 'PROGRAM NAME:'(022),sy-repid,
'DATE :'(023),sy-datum,
AT 100 'TIME :'(024),sy-timlo.
WRITE: AT /1 'FILENAME:'(025),p_file.
ULINE.
SKIP 1.
WRITE:/ text-008.
WRITE:/ text-009.
WRITE:/ text-010.
WRITE: AT 20 text-011.
WRITE: AT 33 text-012.
WRITE: AT 55 text-013.
WRITE: AT 70 text-014.
WRITE: AT 95 text-015.
WRITE: AT 120 text-016.
ULINE.
NEW-LINE.
NEW-LINE.
ENDFORM. "gf_header
&----
*& Form validations
&----
text
----
FORM validations.
DATA: lv_id TYPE sy-tabix.
LOOP AT gi_itab INTO gw_itab.
APPEND gw_itab-land1 TO gi_land. "Land code alone is taken into internal table
ENDLOOP.
LOOP AT gi_itab INTO gw_itab.
gw_land_stawn-land1 = gw_itab-land1. "land along with import code is taken into another internal table
gw_land_stawn-stawn = gw_itab-stawn.
APPEND gw_land_stawn TO gi_land_stawn.
ENDLOOP.
SORT gi_land BY land1.
REFRESH gi_c_land.
IF gi_land[] IS INITIAL.
SELECT land1
FROM t005
INTO TABLE gi_c_land
FOR ALL ENTRIES IN gi_land
WHERE land1 EQ gi_land-land1.
ENDIF.
IF sy-subrc = 0.
LOOP AT gi_itab INTO gw_itab.
READ TABLE gi_c_land "Read table with correct land keys
INTO gw_land
WITH KEY land1 = gw_itab-land1 BINARY SEARCH.
IF sy-subrc = 0.
gw_validitab-land1 = gw_itab-land1.
gw_validitab-stawn = gw_itab-stawn.
gw_validitab-text1 = gw_itab-text1.
gw_validitab-bemeh = gw_itab-bemeh.
gw_validitab-impma = gw_itab-impma.
gw_validitab-minol = gw_itab-minol.
APPEND gw_validitab TO gi_valid_itab. "appending correct values to internal table.
ELSE.
gw_err_itab-land1 = gw_itab-land1.
gw_err_itab-stawn = gw_itab-stawn.
gw_err_itab-text1 = gw_itab-text1.
gw_err_itab-bemeh = gw_itab-bemeh.
gw_err_itab-impma = gw_itab-impma.
gw_err_itab-minol = gw_itab-minol.
gw_err_itab-err = text-033.
APPEND gw_err_itab TO gi_err_itab. "Appending incorrect values.
ENDIF.
ENDLOOP.
ENDIF.
IF gi_land_stawn[] IS INITIAL.
SELECT land1 stawn
FROM t604 "Selecting already present land and import codes from gi_land_stawn
INTO TABLE gi_err_land_stawn
FOR ALL ENTRIES IN gi_land_stawn
WHERE land1 = gi_land_stawn-land1 AND stawn = gi_land_stawn-stawn.
ENDIF.
IF sy-subrc <> 0.
EXIT.
ELSE.
LOOP AT gi_valid_itab INTO gw_validitab. " gi_itab_a into gw_validitab.
CLEAR gw_err_itab.
lv_id = sy-tabix.
READ TABLE gi_err_land_stawn
INTO gw_land_stawn "Reading internal table containing error import codes
WITH KEY land1 = gw_validitab-land1
stawn = gw_validitab-stawn.
IF sy-subrc = 0.
gw_err_itab-land1 = gw_validitab-land1.
gw_err_itab-stawn = gw_validitab-stawn.
gw_err_itab-text1 = gw_validitab-text1.
gw_err_itab-bemeh = gw_validitab-bemeh.
gw_err_itab-impma = gw_validitab-impma.
gw_err_itab-minol = gw_validitab-minol.
gw_err_itab-err = text-034.
APPEND gw_err_itab TO gi_err_itab. "Appending error values to error internal table.
DELETE gi_valid_itab INDEX lv_id.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "validations
&----
*& Form remove_duplicate
&----
text
----
FORM remove_duplicate.
DATA: lv_id TYPE sy-tabix.
LOOP AT gi_valid_itab INTO gw_itab.
APPEND gw_itab TO gi_dup_itab.
ENDLOOP.
CLEAR gw_itab.
SORT gi_valid_itab BY land1 stawn ASCENDING.
SORT gi_dup_itab BY land1 stawn ASCENDING.
DELETE ADJACENT DUPLICATES FROM gi_valid_itab COMPARING land1 stawn. "deleting duplicates from gi_valid_itab.
LOOP AT gi_valid_itab INTO gw_itab.
lv_id = sy-tabix.
READ TABLE gi_dup_itab
INTO gw_validitab
WITH TABLE KEY land1 = gw_itab-land1 "Reading from the internal table containing duplicate values.
stawn = gw_itab-stawn
text1 = gw_itab-text1
bemeh = gw_itab-bemeh
impma = gw_itab-impma
minol = gw_itab-minol.
IF sy-subrc = 0.
DELETE gi_dup_itab
WHERE land1 = gw_itab-land1
AND stawn = gw_itab-stawn "Deleting the correct values from duplicated internal table.
AND text1 = gw_itab-text1
AND bemeh = gw_itab-bemeh "Now it has only duplicaed values.
AND impma = gw_itab-impma
AND minol = gw_itab-minol.
ENDIF.
ENDLOOP.
LOOP AT gi_dup_itab INTO gw_itab.
gw_err_itab-land1 = gw_itab-land1.
gw_err_itab-stawn = gw_itab-stawn.
gw_err_itab-text1 = gw_itab-text1.
gw_err_itab-bemeh = gw_itab-bemeh.
gw_err_itab-impma = gw_itab-impma.
gw_err_itab-minol = gw_itab-minol.
gw_err_itab-err = text-035.
APPEND gw_err_itab TO gi_err_itab. "Appending the duplicate errors to gi_err_itab
ENDLOOP.
ENDFORM. "remove_duplicate
&----
*& Form no_of_records
&----
text
----
FORM no_of_records.
DATA: lv_line TYPE i,
lv_line1 TYPE i,
lv_corr TYPE i,
lv_dup TYPE i,
lv_tot TYPE i,
lv_total TYPE i.
DESCRIBE TABLE gi_itab LINES lv_tot. "Total number of records in the flat file
lv_total = lv_tot + gv_id.
WRITE: /5 text-002, 44 lv_total. "'Total number of Records from flat file:', 44 lv_total.
DESCRIBE TABLE gi_valid_itab LINES lv_line. "Total number of valid records.
WRITE: /5 text-003, 44 lv_line. " 'No of correctly processed records:', 44 lv_line.
DESCRIBE TABLE gi_err_itab LINES lv_line1. "Total number of error records.
WRITE: /5 text-004, 44 lv_line1. "'No of Error Records:', 44 lv_line1.
lv_corr = lv_line + lv_line1. "Total number of duplicate records.
lv_dup = lv_total - lv_corr.
WRITE: /5 text-030, 44 lv_dup. "'Total number of exact duplicates:', 44 lv_dup.
ENDFORM. "validations
&----
*& Form display
&----
text
----
FORM display.
IF gi_err_itab[] IS INITIAL. "If error internal table is empty
WRITE: / sy-uline.
WRITE: /5 text-031."'All the datas are successfully uploaded'.
WRITE: / sy-uline.
ELSE.
LOOP AT gi_err_itab INTO gw_err_itab.
WRITE: / gw_err_itab-land1, 21 gw_err_itab-stawn, 34 gw_err_itab-text1,56 gw_err_itab-bemeh, 71 gw_err_itab-impma, 97 gw_err_itab-minol, 121 gw_err_itab-err.
ENDLOOP.
WRITE: / sy-uline.
ENDIF.
ENDFORM. "display
&----
*& Form bdc
&----
text
----
FORM bdc.
DATA: lv_tcode(4) TYPE c VALUE 'SM30'.
IF gi_valid_itab[] IS INITIAL. "If correct internal table is empty, exit.
EXIT.
ELSE.
CONSTANTS: lc_slash TYPE c VALUE '/'.
CLEAR: gv_year, gv_mon, gv_date, gi_bdcdata, gv_datab.
REFRESH gi_bdcdata.
MOVE: sy-datum+0(4) TO gv_year, "Todays data.
sy-datum+4(2) TO gv_mon,
sy-datum+6(2) TO gv_date.
CONCATENATE gv_mon lc_slash gv_date lc_slash gv_year INTO gv_datab.
LOOP AT gi_valid_itab INTO gw_itab.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VIEWNAME'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPD'.
PERFORM bdc_field USING 'VIEWNAME'
'V_T604'.
PERFORM bdc_field USING 'VIMDYNFLDS-LTD_DTA_NO'
'X'.
PERFORM bdc_dynpro USING 'SAPL080E' '0020'.
PERFORM bdc_field USING 'BDC_CURSOR'
'V_T604-BEMEH(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=NEWL'.
PERFORM bdc_dynpro USING 'SAPL080E' '0040'.
PERFORM bdc_field USING 'BDC_CURSOR'
'V_T604-MINOL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UEBE'.
PERFORM bdc_field USING 'V_T604-LAND1'
gw_itab-land1.
PERFORM bdc_field USING 'V_T604-STAWN'
gw_itab-stawn.
PERFORM bdc_field USING 'V_T604-TEXT1'
gw_itab-text1.
PERFORM bdc_field USING 'V_T604-BEMEH'
gw_itab-bemeh.
PERFORM bdc_field USING 'V_T604-IMPMA'
gw_itab-impma.
PERFORM bdc_field USING 'V_T604-MINOL'
gw_itab-minol.
PERFORM bdc_dynpro USING 'SAPL080E' '0020'.
PERFORM bdc_field USING 'BDC_CURSOR'
'V_T604-BEMEH(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BACK'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=YES'.
PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KO008-TRKORR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=INSA'.
PERFORM bdc_field USING 'KO008-TRKORR'
'BS7K900776'.
PERFORM bdc_dynpro USING 'SAPLSTR8' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KO013-PROJECT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=DOUBLECLICK'.
PERFORM bdc_field USING 'KO013-TARSYSTEM'
'BS7.200'.
PERFORM bdc_dynpro USING 'SAPLSTR8' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KO013-AS4TEXT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=CREA'.
PERFORM bdc_field USING 'KO013-AS4TEXT'
'another req'.
PERFORM bdc_field USING 'KO013-TARSYSTEM'
'BS7.200'.
PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KO008-TRKORR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=LOCK'.
PERFORM bdc_field USING 'KO008-TRKORR'
'BS7K900778'.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/EBACK'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VIEWNAME'.
PERFORM bdc_transaction USING lv_tcode
.
REFRESH gi_bdcdata.
ENDLOOP.
ENDIF.
ENDFORM. "bdc
&----
*& Form bdc_dynpro
&----
text
----
-->X_PROGRAM text
-->X_DYNPRO text
----
FORM bdc_dynpro USING x_program TYPE any x_dynpro TYPE any. " BDC sturucture
CLEAR gw_bdcdata.
gw_bdcdata-program = x_program.
gw_bdcdata-dynpro = x_dynpro.
gw_bdcdata-dynbegin = gc_dynbegin.
APPEND gw_bdcdata TO gi_bdcdata.
ENDFORM. "bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->X_FNAM text
-->X_FVAL text
----
FORM bdc_field USING x_fnam TYPE any x_fval TYPE any.
IF NOT x_fval IS INITIAL.
CLEAR gw_bdcdata.
gw_bdcdata-fnam = x_fnam.
gw_bdcdata-fval = x_fval.
APPEND gw_bdcdata TO gi_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
&----
*& Form bdc_transaction
&----
text
----
-->X_TCODE text
----
FORM bdc_transaction USING x_tcode TYPE any. "BDC Transaction
DATA: lv_flag TYPE c.
CALL TRANSACTION x_tcode USING gi_bdcdata
MODE gc_mode
UPDATE gc_mode1
MESSAGES INTO gi_msg.
IF sy-subrc NE 0.
EXIT.
ENDIF.
CLEAR: lv_flag.
LOOP AT gi_msg INTO gw_msg.
IF gw_msg-msgtyp EQ gc_sucess.
IF lv_flag EQ space.
gv_no_succs = gv_no_succs + 1.
lv_flag = gc_flag.
ENDIF.
ELSE.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = gw_msg-msgid
msgnr = gw_msg-msgnr
msgv1 = gw_msg-msgv1
msgv2 = gw_msg-msgv2
msgv3 = gw_msg-msgv3
msgv4 = gw_msg-msgv4
IMPORTING
message_text_output = gv_msg.
APPEND gv_msg TO gi_msg.
IF lv_flag EQ space.
gv_no_error = gv_no_error + 1.
lv_flag = gc_flag.
ENDIF.
ENDIF.
ENDLOOP.
REFRESH gi_bdcdata.
ENDFORM. "bdc_transaction
Reward points if helpful.
Regards,
Buvana