SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Copy Conversion Job Data between System Instances



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Batch Input (BDC), Background processing and Jobs
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Aug 20, 2008 9:47 am    Post subject: Copy Conversion Job Data between System Instances Reply with quote

Code:
* Source Name is  ZCOPYJOB
REPORT ZCOPYJOB MESSAGE-ID ZZ.
***********************************************************************
* Purpose - Copy  Job Data between System Instances
*
* Author: Joe Mason - SAP Chicago
*
* INSTRUCTIONS - to use
* 1.) In a System (Typically DEV - any Client) - execute this
*     Program with PARAMETER (to EXPORT Data)
* 2.) In System where you want data to reside (Typically QAS or PRD -
*     any Client) - execute this Program with PARAMETER (to IMPORT Data)
*
* This APPROACH - CANNOT Fully Update WHEN THE JOB SHOULD BE SCHEDULED
* (must manually update the Scheduling - i.e Run Periodically,
*  after another JOB, etc.)
* Basis PROBLEM - is that when WE HAVE DEPENDENCIES - the DEPENDENT
* Jobs MAY NOT YET BE IN THE SYSTEM & IF REGFERENCED,
* This PROGRAM would LIKELY FAIL.
***********************************************************************
TABLES:  BTCUEV, BTCUED, TBTCO, TBTCP.
TABLES:  VARIT, VARID, *VARI.
SELECT-OPTIONS: JOBNAME FOR TBTCO-JOBNAME.
*SELTEXT*E*  "Job Name(s) to be Copied
PARAMETERS: OPTEXP DEFAULT 'X' RADIOBUTTON GROUP TJO1,
*SELTEXT*E*  "Export Data to File
            OPTIMP RADIOBUTTON GROUP TJO1,
*SELTEXT*E*  "Export Data to File
            FILE(60) DEFAULT
'/int/D01/050/out/copyjob.dat' LOWER CASE.
*SELTEXT*E*  "File Name

DATA: BEGIN OF TVARI OCCURS 500.
        INCLUDE STRUCTURE VARI.
DATA: END OF TVARI.

DATA: BEGIN OF TVARIT OCCURS 500.
        INCLUDE STRUCTURE VARIT.
DATA: END OF TVARIT.

DATA: BEGIN OF TVARID OCCURS 500.
        INCLUDE STRUCTURE VARID.
DATA: END OF TVARID.

DATA: BEGIN OF TBTCUEV.
        INCLUDE STRUCTURE BTCUEV.
DATA: END OF TBTCUEV.
DATA: BEGIN OF TBTCUED.
        INCLUDE STRUCTURE BTCUED.
DATA: END OF TBTCUED.
DATA: BEGIN OF TTBTCO OCCURS 10.
        INCLUDE STRUCTURE TBTCO.
DATA: END OF TTBTCO.
DATA: BEGIN OF TTBTCP OCCURS 500.
        INCLUDE STRUCTURE TBTCP.
DATA: END OF TTBTCP.
DATA: BEGIN OF PASSREC,
      TABNAME(10),
      TABDATA(3000),
      IND,
      END OF PASSREC.

DATA: BEGIN OF XPASSREC OCCURS 100.
        INCLUDE STRUCTURE PASSREC.
DATA: END OF XPASSREC.

DATA: BEGIN OF VARTAB   OCCURS 100,
      REPORT LIKE VARIT-REPORT,
      VARIANT LIKE VARIT-VARIANT,
      END OF VARTAB.

DATA: REC_COUNT TYPE P VALUE 0.
DATA: VARIANT-COUNT LIKE REC_COUNT.
DATA: JOB-COUNT LIKE REC_COUNT.
DATA: EVENT-COUNT LIKE REC_COUNT.
DATA: TMODE_BD(1).
DATA: TMODE_CT(1) VALUE 'X'.
DATA: SESNAME(12) VALUE ' '.
DATA: SESNAME_ERR(12) VALUE 'ZCOPYJOB_ERR'.
DATA: OLD-JOBNAME LIKE TBTCO-JOBNAME.
DATA: LOOP-COUNT TYPE P.
DATA: OLD-REPORT  LIKE VARI-REPORT.
DATA: OLD-VARIANT LIKE VARI-VARIANT.
DATA: DO-BYPASS.
DATA: FOUND-IND.
DATA: TMP-DSP(10).

INCLUDE ZCONINC4.

IF NOT OPTEXP IS INITIAL.
  OPEN DATASET FILE FOR OUTPUT IN BINARY MODE.
  SELECT * FROM BTCUEV.
    CLEAR PASSREC.
    MOVE 'BTCUEV' TO PASSREC-TABNAME.
    MOVE BTCUEV   TO PASSREC-TABDATA.
    MOVE 'X'      TO PASSREC-IND.
    TRANSFER PASSREC TO FILE.
    ADD 1 TO EVENT-COUNT.
  ENDSELECT.
  SELECT * FROM BTCUED.
    CLEAR PASSREC.
    MOVE 'BTCUED' TO PASSREC-TABNAME.
    MOVE BTCUED   TO PASSREC-TABDATA.
    MOVE 'X'      TO PASSREC-IND.
    TRANSFER PASSREC TO FILE.
    ADD 1 TO EVENT-COUNT.
  ENDSELECT.
  IF JOBNAME-HIGH IS INITIAL
      AND NOT JOBNAME-LOW IS INITIAL.
    SELECT * FROM TBTCO
        WHERE AUTHCKMAN EQ SY-MANDT
          AND      ENDTIME EQ '      '
                        ORDER BY JOBNAME JOBCOUNT.
      IF    TBTCO-JOBNAME CS JOBNAME-LOW.
        PERFORM CHECK-JOB.
      ENDIF.
    ENDSELECT.
  ELSE.
    SELECT * FROM TBTCO
        WHERE JOBNAME IN JOBNAME
          AND AUTHCKMAN EQ SY-MANDT
          AND      ENDTIME EQ '      '
                        ORDER BY JOBNAME JOBCOUNT.
      PERFORM CHECK-JOB.
    ENDSELECT.
  ENDIF.
  LOOP AT VARTAB.
    ADD 1 TO VARIANT-COUNT.
    SELECT * FROM VARI  WHERE REPORT  EQ VARTAB-REPORT
                          AND VARIANT EQ VARTAB-VARIANT.
      MOVE VARI TO TVARI.
      APPEND TVARI.
      CLEAR PASSREC.
      MOVE 'VARI'   TO PASSREC-TABNAME.
      MOVE VARI     TO PASSREC-TABDATA.
      MOVE 'X'      TO PASSREC-IND.
      TRANSFER PASSREC TO FILE.
    ENDSELECT.
  ENDLOOP.
  LOOP AT TVARI.
    CLEAR DO-BYPASS.
    IF TVARI-REPORT EQ OLD-REPORT
        AND TVARI-VARIANT EQ OLD-VARIANT.
      MOVE 'Y' TO DO-BYPASS.
    ENDIF.
    CHECK DO-BYPASS IS INITIAL.
    MOVE TVARI-REPORT TO OLD-REPORT.
    MOVE TVARI-VARIANT TO OLD-VARIANT.
    SELECT * FROM VARIT WHERE REPORT EQ TVARI-REPORT
                          AND VARIANT EQ TVARI-VARIANT.
      CLEAR PASSREC.
      MOVE 'VARIT'  TO PASSREC-TABNAME.
      MOVE VARIT    TO PASSREC-TABDATA.
      MOVE 'X'      TO PASSREC-IND.
      TRANSFER PASSREC TO FILE.
    ENDSELECT.
    SELECT * FROM VARID WHERE REPORT EQ TVARI-REPORT
                          AND VARIANT EQ TVARI-VARIANT.
      CLEAR PASSREC.
      MOVE 'VARID'  TO PASSREC-TABNAME.
      MOVE VARID    TO PASSREC-TABDATA.
      MOVE 'X'      TO PASSREC-IND.
      TRANSFER PASSREC TO FILE.
    ENDSELECT.
  ENDLOOP.
  LOOP AT XPASSREC.
    MOVE XPASSREC TO PASSREC.
    TRANSFER PASSREC TO FILE.
  ENDLOOP.
  CLOSE DATASET FILE.
ENDIF.

IF NOT OPTIMP IS INITIAL.
  OPEN DATASET FILE FOR INPUT IN BINARY MODE.
  DO.
    READ DATASET FILE INTO PASSREC.
    IF SY-SUBRC NE 0.
      EXIT.
    ENDIF.
    IF PASSREC-TABNAME EQ 'BTCUEV'.
      MOVE PASSREC-TABDATA TO TBTCUEV.
      SELECT SINGLE * FROM BTCUEV WHERE EVENTID EQ TBTCUEV-EVENTID.
      MOVE TBTCUEV TO BTCUEV.
      IF SY-SUBRC EQ 0.
        MODIFY BTCUEV.
      ELSE.
        INSERT BTCUEV.
      ENDIF.
      ADD 1 TO EVENT-COUNT.
    ENDIF.

    IF PASSREC-TABNAME EQ 'BTCUED'.
      MOVE PASSREC-TABDATA TO TBTCUED.
      SELECT SINGLE * FROM BTCUED WHERE LANGUAGE EQ TBTCUED-LANGUAGE
                                    AND EVENTID EQ TBTCUED-EVENTID.
      MOVE TBTCUED TO BTCUED.
      IF SY-SUBRC EQ 0.
        MODIFY BTCUED.
      ELSE.
        INSERT BTCUED.
      ENDIF.
      ADD 1 TO EVENT-COUNT.
    ENDIF.

    IF PASSREC-TABNAME EQ 'VARI'.
      MOVE PASSREC-TABDATA TO TVARI.
      SELECT SINGLE FOR UPDATE * FROM VARI
              WHERE RELID   EQ TVARI-RELID
                AND REPORT  EQ TVARI-REPORT
                AND VARIANT EQ TVARI-VARIANT
                AND SRTF2   EQ TVARI-SRTF2.
      MOVE TVARI     TO VARI.
      MOVE SY-MANDT  TO VARI-MANDT.
      IF SY-SUBRC EQ 0.
        MODIFY VARI.
      ELSE.
        INSERT VARI.
      ENDIF.
      ADD 1 TO VARIANT-COUNT.
    ENDIF.

    IF PASSREC-TABNAME EQ 'VARIT'.
      MOVE PASSREC-TABDATA TO TVARIT.
      SELECT SINGLE FOR UPDATE * FROM VARIT
              WHERE LANGU   EQ TVARIT-LANGU
                AND REPORT  EQ TVARIT-REPORT
                AND VARIANT EQ TVARIT-VARIANT.
      MOVE TVARIT    TO VARIT.
      MOVE SY-MANDT  TO VARIT-MANDT.
      IF SY-SUBRC EQ 0.
        MODIFY VARIT.
      ELSE.
        INSERT VARIT.
      ENDIF.
    ENDIF.

    IF PASSREC-TABNAME EQ 'VARID'.
      MOVE PASSREC-TABDATA TO TVARID.
      SELECT SINGLE FOR UPDATE * FROM VARID
              WHERE REPORT  EQ TVARID-REPORT
                AND VARIANT EQ TVARID-VARIANT
                AND FLAG1   EQ TVARID-FLAG1
                AND FLAG2   EQ TVARID-FLAG2.
      MOVE TVARID    TO VARID.
      MOVE SY-MANDT  TO VARID-MANDT.
      IF SY-SUBRC EQ 0.
        MODIFY VARID.
      ELSE.
        INSERT VARID.
      ENDIF.
    ENDIF.

    IF PASSREC-TABNAME EQ 'TBTCO'.
      MOVE PASSREC-TABDATA TO TTBTCO.
      APPEND TTBTCO.
      ADD 1 TO JOB-COUNT.
    ENDIF.

    IF PASSREC-TABNAME EQ 'TBTCP'.
      MOVE PASSREC-TABDATA TO TTBTCP.
      APPEND TTBTCP.
    ENDIF.
    COMMIT WORK.
  ENDDO.
  CLOSE DATASET FILE.
  LOOP AT TTBTCO.
    MOVE 'SM36' TO TCODE.
    REFRESH BDC_TAB.
    PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1140' 'X'.
    PERFORM ADD_BDC_FIELD  USING 'BTCH1140-JOBNAME' TTBTCO-JOBNAME.
    PERFORM ADD_BDC_FIELD  USING 'BTCH1140-JOBCLASS' TTBTCO-JOBCLASS.
    PERFORM ADD_BDC_OKCODE USING 'STPS'.
    CLEAR LOOP-COUNT.
    LOOP AT TTBTCP WHERE JOBNAME EQ TTBTCO-JOBNAME
                     AND JOBCOUNT EQ TTBTCO-JOBCOUNT.
      ADD 1 TO LOOP-COUNT.
      IF LOOP-COUNT NE 1.
        PERFORM ADD_BDC_SCREEN USING 'SAPMSSY0' '0120' 'X'.
        PERFORM ADD_BDC_OKCODE USING 'NEW'.
        PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1120' 'X'.
        PERFORM ADD_BDC_OKCODE USING 'ABAP'.
      ENDIF.
      PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1120' 'X'.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1120-ABAPNAME' TTBTCP-PROGNAME.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1120-VARIANT'  TTBTCP-VARIANT.
      PERFORM ADD_BDC_OKCODE USING 'PVAL'.
      PERFORM ADD_BDC_SCREEN USING 'SAPLSPRI' '0101' 'X'.
      PERFORM ADD_BDC_FIELD  USING 'PRI_PARAMS-PRTXT'  TTBTCP-PRTXT.
      PERFORM ADD_BDC_FIELD  USING 'PRI_PARAMS-PRREL'  ' '.
      PERFORM ADD_BDC_FIELD  USING 'PRI_PARAMS-PRIMM'  ' '.
      PERFORM ADD_BDC_OKCODE USING 'SAVE'.
      PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1120' 'X'.
      PERFORM ADD_BDC_OKCODE USING 'SAVS'.
    ENDLOOP.
    PERFORM ADD_BDC_SCREEN USING 'SAPMSSY0' '0120' 'X'.
    PERFORM ADD_BDC_OKCODE USING 'BACK'.
    PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1140' 'X'.
    PERFORM ADD_BDC_OKCODE USING 'STDT'.    "Update Timing
    PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1010' 'X'.
    IF NOT TTBTCO-EVENTID IS INITIAL.  "Event Dependency
      PERFORM ADD_BDC_OKCODE USING 'AEVT'.
      PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1010' 'X'.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1010-EVENTID'  TTBTCO-EVENTID.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1010-PERIODIC'  'X'.
    ENDIF.
    IF NOT TTBTCO-SDLSTRTDT IS INITIAL."Date & Time Dependency
      PERFORM ADD_BDC_OKCODE USING 'DTTM'.
      PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1010' 'X'.
      WRITE  TTBTCO-SDLSTRTDT TO TMP-DSP.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1010-SDLSTRTDT'
                                      TMP-DSP.
      WRITE  TTBTCO-SDLSTRTTM TO TMP-DSP.
      PERFORM ADD_BDC_FIELD  USING 'BTCH1010-SDLSTRTTM'
                                      TMP-DSP.
    ENDIF.
    PERFORM ADD_BDC_OKCODE USING 'SAVS'.
    PERFORM ADD_BDC_SCREEN USING 'SAPLBTCH' '1140' 'X'.
    PERFORM ADD_BDC_OKCODE USING 'SAVS'.
    PERFORM PROCESS_BDC_DATA.
    COMMIT WORK.
  ENDLOOP.
ENDIF.
WRITE: / 'Number of Events             =', EVENT-COUNT.
WRITE: / 'Number of Jobs               =', JOB-COUNT.
WRITE: / 'Number of Variants           =', VARIANT-COUNT.
*---------------------------------------------------------------------*
*       FORM CHECK-JOB                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK-JOB.
  IF TBTCO-JOBNAME(4) EQ 'ARFC'.
    EXIT.
  ENDIF.
  IF NOT TBTCO-SDLSTRTDT IS INITIAL.
    IF  TBTCO-SDLSTRTDT LT SY-DATUM.
      EXIT.
    ENDIF.
  ENDIF.
  IF   TBTCO-JOBNAME NE OLD-JOBNAME.
    MOVE TBTCO-JOBNAME TO OLD-JOBNAME.
    CLEAR XPASSREC.
    MOVE 'TBTCO'  TO XPASSREC-TABNAME.
    CLEAR TTBTCO.
    MOVE TBTCO               TO  TTBTCO.
    MOVE TTBTCO   TO XPASSREC-TABDATA.
    MOVE 'X'      TO XPASSREC-IND.
    APPEND XPASSREC.
    ADD 1 TO JOB-COUNT.
    SELECT * FROM TBTCP WHERE JOBNAME EQ TBTCO-JOBNAME
                          AND JOBCOUNT EQ TBTCO-JOBCOUNT.
      CLEAR XPASSREC.
      MOVE 'TBTCP'  TO XPASSREC-TABNAME.
      CLEAR TTBTCP.
      MOVE TBTCP-JOBNAME     TO TTBTCP-JOBNAME.
      MOVE TBTCP-JOBCOUNT    TO TTBTCP-JOBCOUNT.
      MOVE TBTCP-PROGNAME    TO TTBTCP-PROGNAME.
      MOVE TBTCP-VARIANT     TO TTBTCP-VARIANT.
      MOVE TBTCP-PRTXT       TO TTBTCP-PRTXT.
      MOVE TTBTCP   TO XPASSREC-TABDATA.
      MOVE 'X'      TO XPASSREC-IND.
      APPEND XPASSREC.
      IF NOT TBTCP-VARIANT IS INITIAL.
        MOVE TBTCP-PROGNAME TO VARTAB-REPORT.
        MOVE TBTCP-VARIANT  TO VARTAB-VARIANT.
        COLLECT VARTAB.
      ENDIF.
    ENDSELECT.
  ENDIF.
ENDFORM.
INCLUDE ZCONINC5.
INCLUDE ZCONINC3.


Code:

* Source Name is  ZCONINC5
***INCLUDE ZCONINC5.
* ZCONINC4 & ZCONINC5 are Matched Pairs
* ZCONINC1 & ZCONINC2 are Matched Pairs - ZCONINC4 in imbeded in
* in ZCONINC4 -- ZCONINC5 is imbeded in  ZCONINC2
FORM WRITE_TRANSACTION_MSG.
* Determine Message that happended at Screen Processing Time
  TABLES:
    T100.                              " System messages table
  DATA:
    TEXT(240),
    TEMP-AMOUNT(15).
* Read the error message text line
  SELECT SINGLE * FROM T100
         WHERE SPRSL = SY-LANGU
         AND   ARBGB = SY-MSGID
         AND   MSGNR = SY-MSGNO.
* Move in the specific components of the error message from the
* system variables SY-MSGV1-4.
  IF SY-SUBRC EQ 0.
    CLEAR TEXT.
    MOVE 'Message:' TO TEXT.
    MOVE   T100-TEXT TO TEXT+8.
    REPLACE '&' WITH SY-MSGV1 INTO TEXT.
    REPLACE '&' WITH SY-MSGV2 INTO TEXT.
    REPLACE '&' WITH SY-MSGV3 INTO TEXT.
    REPLACE '&' WITH SY-MSGV4 INTO TEXT.
    CONDENSE TEXT.
    MOVE SY-TVAR1 TO TEXT+100.
    MOVE SY-TVAR2 TO TEXT+120.
    MOVE SY-TVAR3 TO TEXT+140.
    MOVE SY-TVAR4 TO TEXT+160.
    MOVE SY-TVAR5 TO TEXT+180.
    MOVE ',RecNumber=' TO TEXT+201.
    WRITE REC_COUNT  TO TEMP-AMOUNT.
    MOVE TEMP-AMOUNT TO TEXT+212.
    CONDENSE TEXT.
    CLEAR SY-TVAR1.
    CLEAR SY-TVAR2.
    CLEAR SY-TVAR3.
    CLEAR SY-TVAR4.
    CLEAR SY-TVAR5.
    WRITE: / TEXT(132).
  ENDIF.
ENDFORM.
FORM ADD_BDC_SCREEN USING PROGRAM SCREEN IND.
* BDC Screen Information
  CLEAR   BDC_TAB.
  BDC_TAB-PROGRAM  = PROGRAM.          " Program
  BDC_TAB-DYNPRO   = SCREEN.           " and Screen
  BDC_TAB-DYNBEGIN = IND.
  APPEND BDC_TAB.
ENDFORM.
FORM ADD_BDC_FIELD USING FIELD_NAME FIELD_VALUE.
* BDC Field Information
  CLEAR   BDC_TAB.
  IF NOT FIELD_VALUE IS INITIAL OR SY-REPID+2(2) EQ 'PA'
* These programs/types of programs/field need SPACES to be
* a Valid Entry
* IN ALL OTHERS - field is not Needed if SPACES
                                OR SY-REPID+2(3) EQ 'CUS'
                                OR SY-REPID(8) EQ 'ZFUNCLOC'
                                OR FIELD_NAME EQ 'MARC-SERNP'
                                OR FIELD_NAME EQ 'LTAP-NLQNR'
                                OR FIELD_NAME EQ 'RC271-PLNNR'
                                OR FIELD_NAME CS '*PRPS-POSID'
                                OR FIELD_NAME CS 'PRPS-POSID'
                                OR FIELD_NAME CS 'RV02P-KUNDE'
                                OR FIELD_NAME CS 'RM03S-LGORT'
                                OR FIELD_NAME CS 'MCHA-VFDAT'
                                OR FIELD_NAME CS 'PRI_PARAMS'
                                OR FIELD_NAME CS 'REPOS'.
  PERFORM MOV_BDC_FIELD USING FIELD_NAME FIELD_VALUE.
  ENDIF.
ENDFORM.
FORM MOV_BDC_FIELD USING FIELD_NAME FIELD_VALUE.
  BDC_TAB-FNAM     = FIELD_NAME.       " Field Name
  BDC_TAB-FVAL     = FIELD_VALUE.      " and Value
  APPEND BDC_TAB.
ENDFORM.
FORM process_bdc_data.
* Process either BDC or CALL TRANSACTION - depending on
* Specified Options
  IF load_mode eq load_mode_bd.
    CALL FUNCTION 'BDC_INSERT'
         EXPORTING
              TCODE     = TCODE
         TABLES
              DYNPROTAB = BDC_TAB.
  ELSE.
    CALL TRANSACTION TCODE
              USING       BDC_TAB
             UPDATE      'S'
             MODE        UPMODE.
  endif.
ENDFORM.
FORM ADD_BDC_OKCODE USING F_CODE.
* BDC OKCODE Information
  CLEAR   BDC_TAB.
  BDC_TAB-FNAM     = 'BDC_OKCODE'.     "OK-Code
  BDC_TAB-FVAL     = F_CODE.           " and Value
  APPEND BDC_TAB.
ENDFORM.
FORM open_bdc_session using session_name.
* Open BDC Session Name
 CALL FUNCTION 'BDC_OPEN_GROUP'
      EXPORTING
           CLIENT = SY-MANDT
           GROUP  = session_name    "BDC Session Name
           KEEP   = 'X'
           USER   = SY-UNAME.
ENDFORM.
FORM close_bdc_session.
* Close BDC Session Name
  call function 'BDC_CLOSE_GROUP'.
ENDFORM.
FORM proces_call_transaction_error.
* On Rejected CALL TRANSACTION records - move data into a
*  BDC Session - on First Error -- CREATE A SESSION
  if SESNAME is initial.
      perform OPEN_BDC_SESSION using sesname_err.
      sesname = sesname_err.
  endif.
* Write the error transaction BDC data to the error BDC session
  CALL FUNCTION 'BDC_INSERT'
       EXPORTING
            TCODE     = TCODE
       TABLES
            DYNPROTAB = BDC_TAB.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM CHK-PROCESS_BDC_DATA                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  CHK-LIT                                                       *
*  -->  CHK-VAR                                                       *
*---------------------------------------------------------------------*
FORM CHK-PROCESS_BDC_DATA5 USING CHK-LIT CHK-VAR.
* Determine is Transaction has Processed Successfully
  IF load_mode eq LOAD_MODE_CT.
    IF SY-SUBRC NE 0.
      MOVE 'Y' TO BAD-RECORD.
      PERFORM WRITE_TRANSACTION_MSG.
      PERFORM PROCES_CALL_TRANSACTION_ERROR.
      PERFORM ADD-IN-COUNTS USING CHK-LIT 'BAD'.
    ELSE.
      PERFORM ADD-IN-COUNTS USING CHK-LIT 'GOOD'.
      MOVE SY-MSGV1 TO CHK-VAR.
      IF SHOWAUDT EQ 'X'.
        PERFORM WRITE_TRANSACTION_MSG.
      ENDIF.
    ENDIF.
    ENDIF.
  ENDFORM.
*---------------------------------------------------------------------*
*       FORM ADD-IN-COUNTS                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  DESC-LIT                                                      *
*  -->  STATUS-LIT                                                    *
*---------------------------------------------------------------------*
FORM ADD-IN-COUNTS USING DESC-LIT STATUS-LIT.
* Add in Program Counts - Description of Activity is used
*  as a Key to Control Counts
*  WAS DONE THIS WAY - to avoid setting UP all kinds of Unique
*  Counter Fields in each and every Program
  READ TABLE COUNTS WITH KEY DESC-LIT
     BINARY SEARCH.
  IF SY-SUBRC EQ 0.
    IF STATUS-LIT EQ 'INPUT'.
      ADD 1 TO COUNTS-INPUT.
    ENDIF.
    IF STATUS-LIT EQ 'GOOD'.
      ADD 1 TO COUNTS-GOOD.
    ENDIF.
    IF STATUS-LIT EQ 'BAD'.
      ADD 1 TO COUNTS-BAD.
    ENDIF.
    IF STATUS-LIT EQ 'BYPASS'.
      ADD 1 TO COUNTS-BYPASS.
    ENDIF.
    MODIFY COUNTS INDEX SY-TABIX.
  ELSE.
    CLEAR COUNTS.
    MOVE DESC-LIT TO COUNTS-TYPE.
    IF STATUS-LIT EQ 'INPUT'.
      ADD 1 TO COUNTS-INPUT.
    ENDIF.
    IF STATUS-LIT EQ 'GOOD'.
      ADD 1 TO COUNTS-GOOD.
    ENDIF.
    IF STATUS-LIT EQ 'BAD'.
      ADD 1 TO COUNTS-BAD.
    ENDIF.
    IF STATUS-LIT EQ 'BYPASS'.
      ADD 1 TO COUNTS-BYPASS.
    ENDIF.
    INSERT COUNTS INDEX SY-TABIX.
  ENDIF.
  IF SY-REPID NE 'ZSDORFP004'.
    if status-lit eq 'BAD'.
      write: / 'Rejected During Processing', desc-lit,
       'Rec Number=', rec_count.
    endif.
  endif.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM WRITE-OUT-COUNTS                                         *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM WRITE-OUT-COUNTS.
  LOOP AT COUNTS.
    if counts-input gt 0.
      WRITE: / COUNTS-INPUT, COUNTS-TYPE, 'Derived Inputs'.
    endif.
    if counts-good gt 0.
      WRITE: / COUNTS-GOOD,  COUNTS-TYPE, 'Processed Succesfully'.
    endif.
    if counts-bad gt 0.
      WRITE: / COUNTS-BAD,  COUNTS-TYPE, 'Rejected During Processing'.
    endif.
    IF COUNTS-BYPASS GT 0.
     WRITE: / COUNTS-BYPASS,  COUNTS-TYPE, 'Bypassed During Processing'.
    endif.
  ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM SEND-MESSAGE-VIA-ZZMSG                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM SEND-MESSAGE-VIA-ZZMSG.
*tables: zpgm.
*  Following Code - use Function Module or NOT                       *
*                 - comment out one of the Approaches                *
****TO NOT USE FUNCTION MODULE****************************************
  DATA: Z_TMP-COUNT(8) TYPE P.
  IF NOT SY-BATCH IS INITIAL.
    CLEAR ZZMSG_TAB1.
    MOVE SY-UNAME TO ZZMSG_TAB1.
    COLLECT ZZMSG_TAB1.
  ENDIF.
  DESCRIBE TABLE ZZMSG_TAB1 LINES Z_TMP-COUNT.
  CHECK Z_TMP-COUNT > 0.
  DESCRIBE TABLE ZZMSG_TAB2 LINES Z_TMP-COUNT.
  CHECK Z_TMP-COUNT > 0.
  CLEAR ZZMSG_TAB2.
  MOVE 'Above Message occured in Program' TO ZZMSG_TAB2.
  APPEND ZZMSG_TAB2.
  CLEAR ZZMSG_TAB2.
  MOVE SY-REPID                        TO ZZMSG_TAB2.
  APPEND ZZMSG_TAB2.
  CLEAR ZZBIGTXT.
  MOVE 'On System:' TO ZZBIGTXT.
  MOVE SY-SYSID TO ZZBIGTXT+12(3).
  MOVE 'In Client:' TO ZZBIGTXT+20(15).
  WRITE SY-MANDT    TO ZZBIGTXT+45.
  CONDENSE ZZBIGTXT.
  MOVE ZZBIGTXT TO ZZMSG_TAB2.
  APPEND ZZMSG_TAB2.
  CLEAR ZZBIGTXT.
  MOVE 'On Date:' TO ZZBIGTXT.
  WRITE SY-DATUM TO ZZBIGTXT+12(10).
  MOVE 'At:' TO ZZBIGTXT+25(05).
  WRITE SY-UZEIT    TO ZZBIGTXT+45.
  CONDENSE ZZBIGTXT.
  MOVE ZZBIGTXT TO ZZMSG_TAB2.
  APPEND ZZMSG_TAB2.
* select single * from zpgm where pgm eq sy-repid.
*********************************************************************
* Look UP in a NEW TABLE - if Messages from this Program are        *
*   to be Sent to One or More People                                *
*********************************************************************
* if sy-subrc eq 0.
*   if not zpgm-name1 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name1 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name2 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name2 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name3 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name3 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name4 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name4 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name5 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name5 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name6 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name6 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name7 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name7 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
*   if not zpgm-name8 is initial.
*      clear zzmsg_tab1.
*      move zpgm-name8 to  zzmsg_tab1.
*      collect zzmsg_tab1.
*   endif.
* endif.
  PERFORM SEND-MSG(ZZMSG)  TABLES ZZMSG_TAB1 ZZMSG_TAB2.
***********************************************************************
****TO USE FUNCTION MODULE*********************************************
* call function 'Z_SEND_MESSAGE'
*     exporting       pgm_id        =  z_pgmid
*                     severity_level = z_severity_level
*     tables          zzmsg_tab1     = zzmsg_tab1
*                     zzmsg_tab2     = zzmsg_tab2.
***********************************************************************
ENDFORM.


Code:

* Source Name is  ZCONINC3
FORM STATUS-LINE-MSG USING TMP-TEXT.
* Put a Message at BOTTOM OF SCREEN - to let person executing
*  Interactively Know WHAT RECORD IS BEING PROCESSED
 DATA:  MSG_LINE(100).
 MOVE TMP-TEXT TO MSG_LINE.
 CONDENSE MSG_LINE.
 CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
          TEXT       = MSG_LINE.
ENDFORM.
FORM STATUS-LINE-MESSAGE USING TMP-RECNO TMP-TOTAL-RECNO.
* Put a Message at BOTTOM OF SCREEN - to let person executing
*  Interactively Know WHAT RECORD IS BEING PROCESSED
*  also Show TOTAL NUMBER OF RECORDS IN THE FILE - only know
*  that is we are Processing a PC File
DATA:  MSG_LINE(100).
    CLEAR MSG_LINE.
    MOVE 'Processed Record' TO MSG_LINE.
    WRITE TMP-RECNO          TO MSG_LINE+20(20).
    IF NOT TMP-TOTAL-RECNO IS INITIAL.
      MOVE 'of'              TO MSG_LINE+45(2).
      WRITE TMP-TOTAL-RECNO  TO MSG_LINE+60(20).
    ENDIF.
    CONDENSE MSG_LINE.
 CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          TEXT       = MSG_LINE.

ENDFORM.
*---------------------------------------------------------------------*
*       FORM LEFT-ALIGN-FLD                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  TMP-FLD-AL                                                    *
*---------------------------------------------------------------------*
FORM LEFT-ALIGN-FLD USING TMP-FLD-AL.

********************************************************************
* Purpose - left align all data in fields **************************
********************************************************************
  IF NOT TMP-FLD-AL IS INITIAL.
    SHIFT TMP-FLD-AL LEFT DELETING LEADING ' '.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM MAK-NUM                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  TMP-FLD                                                       *
*---------------------------------------------------------------------*
FORM MAK-NUM USING TMP-FLD.
* If Data Contains Numerics and Spaces - make it a Number for the
* Defned Length of the Field - need the Full Numeric Value in Cases
* Where we are Reading a Data Base
  DATA: LEN1 TYPE I.
  DATA: TMP-FLD-MAX(30) TYPE N.
  IF NOT TMP-FLD IS INITIAL
     AND TMP-FLD CO ' 0123456789'.
    DESCRIBE FIELD TMP-FLD LENGTH LEN1.
    CLEAR TMP-FLD-MAX.
    MOVE TMP-FLD TO TMP-FLD-MAX(LEN1).
    MOVE TMP-FLD-MAX(LEN1) TO TMP-FLD.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM CONVERT-TO-MATH-NUMBER                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  FLDXX                                                         *
*---------------------------------------------------------------------*
FORM CONVERT-TO-MATH-NUMBER USING FLDXX.
* Convert a Number - so Math Can be Done Against it
  TABLES: *USR01.
  CLEAR *USR01.
  SELECT SINGLE * FROM *USR01 WHERE BNAME EQ SY-UNAME.
  IF *USR01-DCPFM EQ 'X'.
    WHILE FLDXX CS ','.                "  '.' is a Decimal Point
      REPLACE ',' WITH '' INTO FLDXX.
      CONDENSE FLDXX NO-GAPS.
    ENDWHILE.
  ELSE.
    WHILE FLDXX CS '.'.               "  ',' is a Decimal Point
      REPLACE '.' WITH '' INTO FLDXX.
      CONDENSE FLDXX NO-GAPS.
    ENDWHILE.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM CHECK-TCODE-AUTHORITY                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  T-TCODE                                                       *
*---------------------------------------------------------------------*
FORM CHECK-TCODE-AUTHORITY USING T-TCODE.
  CALL FUNCTION 'AUTHORITY_CHECK_TCODE'"Only People that
       EXPORTING                       " have access to
         TCODE  = T-TCODE              " Transaction t-tcode
       EXCEPTIONS                      " are ALLOWED to execute
            OK     = 1                 " this Program
            NOT_OK = 2.
  IF SY-SUBRC NE 1.
    MESSAGE A999(ZZ) WITH 'YOU Do Not Have Authority to Execute'.
  ENDIF.
ENDFORM.

TOP-OF-PAGE.
* General Purpose - Page Heading Routine
* Programming NOTE - keep this at BOTTOM OF THIS INCLUDE
* Other Programs USE THIS - and HAVE 'COLUMN HEADING INFORMATION'
* after this INCLUDE
  TABLES: *VARIT.
  DATA: ZCONINC3-ONETIME.
  DATA: NOW-SY-PAGNO LIKE SY-PAGNO.
  FORMAT INTENSIFIED OFF.
  ADD 1 TO NOW-SY-PAGNO.
  WRITE: /01 SY-PRABT,                "Department Receiving Report
*         35 'EXAMPLE COMPANY NAME',  "Name This Customer
          35 'SAPLABS DEMO SYSTEM',   "Name This Customer
           'Page', NOW-SY-PAGNO.
  WRITE: /  SY-REPID,
           'Run by', SY-UNAME(8), 'on', SY-DATUM, SY-UZEIT,
           'System', SY-SYSID(4), 'Client', SY-MANDT.
  WRITE: /  SY-TITLE centered.
* If Variant Used to EXECUTE THIS PROGRAM - put in Variant Description
* into Page Headings
  IF NOT SY-SLSET IS INITIAL.
    IF ZCONINC3-ONETIME IS INITIAL.
       CLEAR *VARIT.
       MOVE 'N' TO ZCONINC3-ONETIME.
       SELECT  * FROM *VARIT WHERE LANGU EQ SY-LANGU
                                     AND REPORT EQ SY-REPID
                                     AND VARIANT EQ SY-SLSET.
         EXIT.
       ENDSELECT.
    ENDIF.
    IF NOT *VARIT-VTEXT IS INITIAL.
       WRITE: / 'Variant', SY-SLSET, *VARIT-VTEXT.
    ENDIF.
  ENDIF.
  FORMAT INTENSIFIED ON.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Batch Input (BDC), Background processing and Jobs All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.