Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How Session Or call Transaction works in case of failuers

Former Member
0 Kudos

Hi All,

Please let me know what happens when a failure occurs while processing in a session or call transaction.

For example, if there are 1000 records in flat file- whemn processed in the session (SM30), if any faliure or system breaksdown, what happens-

Will the records be processed

Or Will it start again from the first

Or Do we need to remove the processed ones from flat file or

And run the session again for the error ones.

What if same is applied to CALL TRANSACTION.

Reward if helpful.

Chandralekha

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi Chandra,

Please find the below sample code which helps you to understand the erroreneous records .....


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



*  if routeindicator is initial.
*   LOOP AT IT_YMMEE00090.
*      LV_LENGTH = STRLEN( IT_YMMEE00090-CHANGETYPE ).
*      IF SY-TABIX = '1'.
*        IF  IT_YMMEE00090-CHANGETYPE = 'B' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'R' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'S' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE CA 'BRSCD' AND LV_LENGTH GT 1
*                                          AND LV_LENGTH LE 5.
*          ROUTEINDICATOR = 'S'.
*        ENDIF.
*      ELSE.
*        IF  IT_YMMEE00090-CHANGETYPE = 'B' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'R' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'S' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE CA 'BRSCD' AND LV_LENGTH GT 1
*                  AND LV_LENGTH LE 5 AND ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ENDIF.
*      ENDIF.
*  ENDLOOP.
* endif. 

6 REPLIES 6

Former Member
0 Kudos

hi Chandra,

Please find the below sample code which helps you to understand the erroreneous records .....


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



*  if routeindicator is initial.
*   LOOP AT IT_YMMEE00090.
*      LV_LENGTH = STRLEN( IT_YMMEE00090-CHANGETYPE ).
*      IF SY-TABIX = '1'.
*        IF  IT_YMMEE00090-CHANGETYPE = 'B' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'R' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'S' AND LV_LENGTH = 1.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE CA 'BRSCD' AND LV_LENGTH GT 1
*                                          AND LV_LENGTH LE 5.
*          ROUTEINDICATOR = 'S'.
*        ENDIF.
*      ELSE.
*        IF  IT_YMMEE00090-CHANGETYPE = 'B' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'R' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE = 'S' AND LV_LENGTH = 1 AND
*                                         ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ELSEIF IT_YMMEE00090-CHANGETYPE CA 'BRSCD' AND LV_LENGTH GT 1
*                  AND LV_LENGTH LE 5 AND ROUTEINDICATOR = 'S'.
*          ROUTEINDICATOR = 'S'.
*        ENDIF.
*      ENDIF.
*  ENDLOOP.
* endif. 

0 Kudos

Hi,

Thanks Much . But, I need more clarification from you,

If we porcess records only in Session, if the the faliure occurs in session and if we try to run the same session again, will all the records from first will be processd if I use the same flat file Or we need to explictiy handle the records that are not processed and delete those records from flat file and process the session for thie updated file.

Pls Clarify my doubt.

Rewaurd if helpful.

Chandralekha

Former Member
0 Kudos

hi check this..

in the session if an error occurs then it will stops the processing...because it is synchronous processing

in the call transaction method the error records are skipped and they will be processed...because it is asynchrous..

but the error records occured in both the cases will be processed through the session only

Former Member
0 Kudos

Hi Chandralekha,

Your problem falls in the general concept of Threading in Operating System. Any job process is done in 3 phases,

1> processing of job in Job queue of the system. At the end of which a temporary replica of the updated verssion of new status is generated.

2> Then the system pointer transfers its location from its old verssion to the new one.

3> Old verssion is deleted.

needless to say, step 2 is instanteneous.

if faliure happens during step 1, system will remain store old status i.e. it hold the old thread.

and if happens during step 3, it will be in new tread i.e hold the new status.

Reward if found helpful.

Anirban Bhattacharjee

Former Member
0 Kudos

Hi Chandrakala,

If u use 'Synchronous' and the power goes off the records will rollback. The records will not updated means the updation has to be fully completed or fully rollback.

In 'Asynchronous' if the records have been updated partially like out of 100 some records say 80 updated and power goes off then when you start next time it will start updation from 81st record.

Hope you got it.

Former Member
0 Kudos

Hi,

generally when the error occurs in the session we can reprocess the errors in foreground mode where we can correct the invalid values in the real time...

in case of call transaction...when ever an error occurs during call transaction we can capture them and sent it to a session..and again we can reprocess the session....

look at the code below for second point..




 data:  l_msgcount type i,           " Total no of msgs
         l_flag    type c.            " Flag.

*   Create the initial BDC session

  if not i_tmp[] is initial.

    sort i_tmp by  indicator.
    clear wa_tmp.

    loop at i_tmp into wa_tmp .

      if wa_tmp-indicator = 'D'.

        read table i_tcj04 into wa_tcj04 with key
                   vernr = wa_tmp-pernr
                   binary search.

        if sy-subrc = 0.
          refresh i_bdc.
          perform sub_fill_bdc2 using wa_tmp .

          call transaction    c_tcode      " TCode (OPS6)
               using          i_bdc        " BDC table
               mode           c_mode       " Mode type ('N'),Back ground
               update         c_update     " Update type ('S')
               messages into  i_bdcmsg.    " Messages table

* Read message table for success records
          read table i_bdcmsg into wa_bdcmsg
                     with key msgtyp  = c_msgtyp_s  "Succ Msgs 'S'
                              msgid   = c_msgid     "Msg. id 'SV'
                              msgnr   = c_msgnr.    "Msg.no'018'

* If record exists
          if sy-subrc = 0.

* Increment the counter
            v_succ_counter = v_succ_counter + 1.

          else.

            clear wa_sessions.

* Get the number of records
            describe table i_bdcmsg lines l_msgcount.

* Read message table for error record
            read table i_bdcmsg into wa_bdcmsg index l_msgcount.

            call function 'FORMAT_MESSAGE'
              exporting
                id        = wa_bdcmsg-msgid
                lang      = sy-langu
                no        = wa_bdcmsg-msgnr
                v1        = wa_bdcmsg-msgv1
                v2        = wa_bdcmsg-msgv2
                v3        = wa_bdcmsg-msgv3
                v4        = wa_bdcmsg-msgv4
              importing
                msg       = wa_sessions-message
              exceptions
                not_found = 1
                others    = 2.
            if sy-subrc <> 0.

            endif.

            wa_sessions-sname   = 'Call Tran.'(027). " v_sname.
            wa_sessions-status  = c_check.

            append wa_sessions to i_sessions.

            if  l_flag is initial.
* Create the initial BDC session
              perform sub_openbdc using p_uname      " Username
                                        c_session
                                  changing l_flag.  " Session name
            endif.

* * call fm bdc_insert for delete
            call function 'BDC_INSERT'
              exporting
                tcode            = c_tcode
              tables
                dynprotab        = i_bdc
              exceptions
                internal_error   = 1
                not_open         = 2
                queue_error      = 3
                tcode_invalid    = 4
                printing_invalid = 5
                posting_invalid  = 6
                others           = 7.

            if sy-subrc ne 0.

              clear wa_sessions.
              wa_sessions-sname   = 'Session'(028). "v_sname.
              wa_sessions-status  = c_check.
              wa_sessions-message =  'BDC record insert failed'(031).
              append wa_sessions to i_sessions.

            endif.
            refresh i_bdc[].

          endif.

        endif.

      else.

        read table i_tcj04 into wa_tcj04 with key
                                         vernr = wa_tmp-pernr
                                         binary search.

        if sy-subrc = 0.
          refresh i_bdc.
          perform sub_fill_bdc3 using wa_tmp.

          call transaction    c_tcode      " TCode (OPS6)
               using          i_bdc        " BDC table
               mode           c_mode       " Mode type ('N'),Back ground
               update         c_update     " Update type ('S')
               messages into  i_bdcmsg.    " Messages table

* Read message table for success records
          read table i_bdcmsg into wa_bdcmsg
                              with key msgtyp  = c_msgtyp_s
                              "Succ Msgs 'S'
                                       msgid   = c_msgid
                                       "Msg. id 'SV'
                                       msgnr   = c_msgnr.
          "Msg.no'018'

* If record exists
          if sy-subrc = 0.

* Increment the counter
            v_succ_counter = v_succ_counter + 1.

          else.

            clear wa_sessions.

* Get the number of records
            describe table i_bdcmsg lines l_msgcount.

* Read message table for error record
            read table i_bdcmsg into wa_bdcmsg index l_msgcount.

            call function 'FORMAT_MESSAGE'
              exporting
                id        = wa_bdcmsg-msgid
                lang      = sy-langu
                no        = wa_bdcmsg-msgnr
                v1        = wa_bdcmsg-msgv1
                v2        = wa_bdcmsg-msgv2
                v3        = wa_bdcmsg-msgv3
                v4        = wa_bdcmsg-msgv4
              importing
                msg       = wa_sessions-message
              exceptions
                not_found = 1
                others    = 2.
            if sy-subrc <> 0.

            endif.

            wa_sessions-sname   = 'Call Tran.'(027). " v_sname.
            wa_sessions-status  = c_check.

            append wa_sessions to i_sessions.

            if  l_flag is initial.
* Create the initial BDC session
              perform sub_openbdc using p_uname      " Username
                                        c_session
                                  changing l_flag.  " Session name

            endif.

* * call fm bdc_insert for delete
            call function 'BDC_INSERT'
              exporting
                tcode            = c_tcode
              tables
                dynprotab        = i_bdc
              exceptions
                internal_error   = 1
                not_open         = 2
                queue_error      = 3
                tcode_invalid    = 4
                printing_invalid = 5
                posting_invalid  = 6
                others           = 7.

            if sy-subrc ne 0.

              clear wa_sessions.
              wa_sessions-sname   = 'Session'(028). "v_sname.
              wa_sessions-status  = c_check.
              wa_sessions-message =  'BDC record insert failed'(031).
              append wa_sessions to i_sessions.

            endif.
            refresh i_bdc[].

          endif.



        else.

          refresh i_bdc.
          perform sub_fill_bdc1 using wa_tmp .

          call transaction    c_tcode      " TCode (OPS6)
               using          i_bdc        " BDC table
               mode           c_mode       " Mode type ('N'),Back ground
               update         c_update     " Update type ('S')
               messages into  i_bdcmsg.    " Messages table

* Read message table for success records
          read table i_bdcmsg into wa_bdcmsg
                     with key msgtyp  = c_msgtyp_s  "Succ Msgs 'S'
                              msgid   = c_msgid     "Msg. id 'SV'
                              msgnr   = c_msgnr.    "Msg.no'018'

* If record exists
          if sy-subrc = 0.

* Increment the counter
            v_succ_counter = v_succ_counter + 1.

          else.

            clear wa_sessions.

* Get the number of records
            describe table i_bdcmsg lines l_msgcount.

* Read message table for error record
            read table i_bdcmsg into wa_bdcmsg index l_msgcount.

            call function 'FORMAT_MESSAGE'
              exporting
                id        = wa_bdcmsg-msgid
                lang      = sy-langu
                no        = wa_bdcmsg-msgnr
                v1        = wa_bdcmsg-msgv1
                v2        = wa_bdcmsg-msgv2
                v3        = wa_bdcmsg-msgv3
                v4        = wa_bdcmsg-msgv4
              importing
                msg       = wa_sessions-message
              exceptions
                not_found = 1
                others    = 2.
            if sy-subrc <> 0.

            endif.

            wa_sessions-sname   = 'Call Tran.'(027). " v_sname.
            wa_sessions-status  = c_check.

            append wa_sessions to i_sessions.

            if  l_flag is initial.

* Create the initial BDC session
              perform sub_openbdc using p_uname      " Username
                                        c_session
                                  changing l_flag.  " Session name
            endif.

* * call fm bdc_insert for delete
            call function 'BDC_INSERT'
              exporting
                tcode            = c_tcode
              tables
                dynprotab        = i_bdc
              exceptions
                internal_error   = 1
                not_open         = 2
                queue_error      = 3
                tcode_invalid    = 4
                printing_invalid = 5
                posting_invalid  = 6
                others           = 7.

            if sy-subrc ne 0.

              clear wa_sessions.
              wa_sessions-sname   = 'Session'(028). "v_sname.
              wa_sessions-status  = c_check.
              wa_sessions-message =  'BDC record insert failed'(031).
              append wa_sessions to i_sessions.

            endif.

            refresh i_bdc[].

          endif.

        endif.

      endif.

    endloop.

    if l_flag = c_check.
* Close Current BDC session
      perform sub_closebdc.
      clear l_flag.
    endif.

  endif.