1.BDC 产生SM35批处理会话

 1 *&---------------------------------------------------------------------*
 2 *& Report Z3426BDC001
 3 *&---------------------------------------------------------------------*
 4 *&
 5 *&---------------------------------------------------------------------*
 6 REPORT z3426bdc001.
 7 
 8 DATA:lv_bdcgroup TYPE char12.
 9 DATA: bdcdata TYPE TABLE OF bdcdata,
10       bdcmsg  TYPE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
11 DATA opt TYPE ctu_params.
12 
13 lv_bdcgroup = `JOB_GROUP`.
14 CALL FUNCTION 'BDC_OPEN_GROUP'
15   EXPORTING
16     client              = sy-mandt
17     group               = lv_bdcgroup
18     keep                = 'X'
19     user                = sy-uname
20   EXCEPTIONS
21     client_invalid      = 1
22     destination_invalid = 2
23     group_invalid       = 3
24     group_is_locked     = 4
25     holddate_invalid    = 5
26     internal_error      = 6
27     queue_error         = 7
28     running             = 8
29     system_lock_error   = 9
30     user_invalid        = 10
31     OTHERS              = 11.
32 
33 DATA:gv_copyer TYPE usr02-bname VALUE '3426',
34      gv_user   TYPE usr02-bname VALUE '3426001',
35      gv_pwd    TYPE string VALUE 'Aa123456'.
36 
37 bdcdata = VALUE #(
38   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1050' dynbegin = 'X' )
39   ( fnam = 'BDC_OKCODE'                           fval = '=COPY' )
40   ( fnam = 'SUID_ST_BNAME-BNAME'                  fval = gv_user )
41 
42   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1200' dynbegin = 'X' )
43   ( fnam = 'BDC_OKCODE' fval = '=COPY' )
44   ( fnam = 'GV_COPY_UNAME_SRC'                    fval = gv_copyer )
45   ( fnam = 'GV_COPY_UNAME_DST'                    fval = gv_user )
46   ( fnam = 'GS_COPY_OPTIONS-DEFAULTS'             fval = 'X' )
47   ( fnam = 'GS_COPY_OPTIONS-PARAMETERS'           fval = 'X' )
48   ( fnam = 'GS_COPY_OPTIONS-REFUSER'              fval = 'X' )
49   ( fnam = 'GS_COPY_OPTIONS-ROLES'                fval = 'X' )
50   ( fnam = 'GS_COPY_OPTIONS-PROFILES'             fval = 'X' )
51   ( fnam = 'GS_COPY_OPTIONS-USERGROUPS'           fval = 'X' )
52   ( fnam = 'GS_COPY_OPTIONS-PERS'                 fval = 'X' )
53   ( fnam = 'GS_COPY_OPTIONS-UCLASS'               fval = 'X' )
54   ( fnam = 'GS_COPY_OPTIONS-EASY_ACCESS'          fval = 'X' )
55 
56   ( program = 'SAPLSUID_MAINTENANCE' dynpro   = '1100' dynbegin = 'X' )
57   ( fnam = 'BDC_OKCODE'                           fval = '=UPD' )
58   ( fnam = 'SUID_ST_NODE_LOGONDATA-USTYP'         fval = 'A' )
59   ( fnam = 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD'   fval = gv_pwd )
60   ( fnam = 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD2'  fval = gv_pwd )
61 
62   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1050' dynbegin = 'X' )
63   ( fnam = 'BDC_OKCODE'                           fval = '=UPD' )
64   ( fnam = 'SUID_ST_BNAME-BNAME'                  fval = gv_user ) ).
65 
66 opt-dismode = 'E'.
67 opt-defsize = 'X'.
68 
69 CALL FUNCTION 'BDC_INSERT'
70   EXPORTING
71     tcode            = 'SU01'
72     ctuparams        = opt
73   TABLES
74     dynprotab        = bdcdata
75   EXCEPTIONS
76     internal_error   = 1
77     not_open         = 2
78     queue_error      = 3
79     tcode_invalid    = 4
80     printing_invalid = 5
81     posting_invalid  = 6
82     OTHERS           = 7.
83 
84 CALL FUNCTION 'BDC_CLOSE_GROUP'
85   EXCEPTIONS
86     not_open    = 1
87     queue_error = 2
88     OTHERS      = 3.
View Code

2.BDC 普通应用

  1 *&---------------------------------------------------------------------*
  2 *& Report Z3426BDC001
  3 *&---------------------------------------------------------------------*
  4 *&
  5 *&---------------------------------------------------------------------*
  6 REPORT z3426bdc002.
  7 
  8 DATA:lv_bdcgroup TYPE char12.
  9 DATA: bdcdata TYPE TABLE OF bdcdata,
 10       bdcmsg  TYPE STANDARD TABLE OF bdcmsgcoll.
 11 DATA opt TYPE ctu_params.
 12 
 13 CALL FUNCTION 'BDC_OPEN_GROUP'
 14   EXPORTING
 15     client              = sy-mandt
 16     group               = lv_bdcgroup
 17     keep                = 'X'
 18     user                = sy-uname
 19   EXCEPTIONS
 20     client_invalid      = 1
 21     destination_invalid = 2
 22     group_invalid       = 3
 23     group_is_locked     = 4
 24     holddate_invalid    = 5
 25     internal_error      = 6
 26     queue_error         = 7
 27     running             = 8
 28     system_lock_error   = 9
 29     user_invalid        = 10
 30     OTHERS              = 11.
 31 
 32 DATA:gv_copyer TYPE usr02-bname VALUE '3426',
 33      gv_user   TYPE usr02-bname VALUE '3426001',
 34      gv_pwd    TYPE string VALUE 'Aa123456'.
 35 
 36 bdcdata = VALUE #(
 37   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1050' dynbegin = 'X' )
 38   ( fnam = 'BDC_OKCODE'                           fval = '=COPY' )
 39   ( fnam = 'SUID_ST_BNAME-BNAME'                  fval = gv_user )
 40 
 41   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1200' dynbegin = 'X' )
 42   ( fnam = 'BDC_OKCODE' fval = '=COPY' )
 43   ( fnam = 'GV_COPY_UNAME_SRC'                    fval = gv_copyer )
 44   ( fnam = 'GV_COPY_UNAME_DST'                    fval = gv_user )
 45   ( fnam = 'GS_COPY_OPTIONS-DEFAULTS'             fval = 'X' )
 46   ( fnam = 'GS_COPY_OPTIONS-PARAMETERS'           fval = 'X' )
 47   ( fnam = 'GS_COPY_OPTIONS-REFUSER'              fval = 'X' )
 48   ( fnam = 'GS_COPY_OPTIONS-ROLES'                fval = 'X' )
 49   ( fnam = 'GS_COPY_OPTIONS-PROFILES'             fval = 'X' )
 50   ( fnam = 'GS_COPY_OPTIONS-USERGROUPS'           fval = 'X' )
 51   ( fnam = 'GS_COPY_OPTIONS-PERS'                 fval = 'X' )
 52   ( fnam = 'GS_COPY_OPTIONS-UCLASS'               fval = 'X' )
 53   ( fnam = 'GS_COPY_OPTIONS-EASY_ACCESS'          fval = 'X' )
 54 
 55   ( program = 'SAPLSUID_MAINTENANCE' dynpro   = '1100' dynbegin = 'X' )
 56   ( fnam = 'BDC_OKCODE'                           fval = '=UPD' )
 57   ( fnam = 'SUID_ST_NODE_LOGONDATA-USTYP'         fval = 'A' )
 58   ( fnam = 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD'   fval = gv_pwd )
 59   ( fnam = 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD2'  fval = gv_pwd )
 60 
 61   ( program = 'SAPLSUID_MAINTENANCE' dynpro = '1050' dynbegin = 'X' )
 62   ( fnam = 'BDC_OKCODE'                           fval = '=UPD' )
 63   ( fnam = 'SUID_ST_BNAME-BNAME'                  fval = gv_user ) ).
 64 
 65 opt-dismode = 'E'.
 66 opt-defsize = 'X'.
 67 
 68 CALL TRANSACTION 'SU01' WITH AUTHORITY-CHECK
 69                         USING bdcdata OPTIONS FROM opt
 70                         MESSAGES INTO bdcmsg[].
 71 IF sy-batch = ''.
 72   PERFORM frm_show_msg TABLES bdcmsg[].
 73 ENDIF.
 74 
 75 FORM frm_show_msg TABLES ct_bdcmsg.
 76 
 77   DATA: ls_bdcmsg TYPE bdcmsgcoll.
 78 
 79   DATA: ls_log             TYPE bal_s_log,
 80         l_log_handle       TYPE balloghndl,
 81         lt_log_handle      TYPE bal_t_logh,
 82         ls_display_profile TYPE bal_s_prof,
 83         ls_bal_msg         TYPE bal_s_msg.
 84 
 85   ls_log-aluser = sy-uname.
 86   ls_log-aldate = sy-datlo.
 87   ls_log-altime = sy-timlo.
 88 
 89   CALL FUNCTION 'BAL_LOG_CREATE'
 90     EXPORTING
 91       i_s_log      = ls_log
 92     IMPORTING
 93       e_log_handle = l_log_handle.
 94 
 95   APPEND l_log_handle TO lt_log_handle.
 96 
 97   LOOP AT ct_bdcmsg INTO ls_bdcmsg.
 98 
 99     CLEAR ls_bal_msg.
100 
101     ls_bal_msg-msgty = ls_bdcmsg-msgtyp.
102     ls_bal_msg-msgid = ls_bdcmsg-msgid.
103     ls_bal_msg-msgno = ls_bdcmsg-msgnr.
104     ls_bal_msg-msgv1 = ls_bdcmsg-msgv1.
105     ls_bal_msg-msgv2 = ls_bdcmsg-msgv2.
106     ls_bal_msg-msgv3 = ls_bdcmsg-msgv3.
107     ls_bal_msg-msgv4 = ls_bdcmsg-msgv4.
108 
109     CALL FUNCTION 'BAL_LOG_MSG_ADD'
110       EXPORTING
111         i_log_handle = l_log_handle
112         i_s_msg      = ls_bal_msg.
113 
114   ENDLOOP.
115 
116   CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
117     IMPORTING
118       e_s_display_profile = ls_display_profile.
119 
120   CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
121     EXPORTING
122       i_t_log_handle      = lt_log_handle
123       i_s_display_profile = ls_display_profile.
124 
125 ENDFORM.
View Code

3.BDC 产生后台任务

  1 *&---------------------------------------------------------------------*
  2 *& Report Z3426BDC001
  3 *&---------------------------------------------------------------------*
  4 *&
  5 *&---------------------------------------------------------------------*
  6 REPORT z3426bdc003.
  7 DATA:lv_jobname          LIKE tbtco-jobname,
  8      lv_jobcount         LIKE tbtco-jobcount,
  9      lv_job_released     TYPE c,
 10      lv_job_start_sofort TYPE c,
 11      lv_print_parameters TYPE pri_params.
 12 DATA:lt_joblog TYPE TABLE OF tbtc5.
 13 DATA:lt_rspar TYPE TABLE OF rsparams,
 14      lw_line  LIKE LINE OF lt_rspar.
 15 
 16 lv_jobname = 'JOB_Z3426BDC003'.
 17 
 18 CALL FUNCTION 'JOB_OPEN'
 19   EXPORTING
 20     jobname          = lv_jobname
 21   IMPORTING
 22     jobcount         = lv_jobcount
 23   EXCEPTIONS
 24     cant_create_job  = 1
 25     invalid_job_data = 2
 26     jobname_missing  = 3
 27     OTHERS           = 4.
 28 IF syst-subrc = 0.
 29 
 30   SUBMIT z3426bdc002
 31     WITH SELECTION-TABLE lt_rspar
 32     USER syst-uname
 33      VIA JOB lv_jobname
 34   NUMBER lv_jobcount
 35      AND RETURN.
 36 
 37   IF sy-subrc = 0.
 38     CALL FUNCTION 'JOB_CLOSE'
 39       EXPORTING
 40         jobcount             = lv_jobcount
 41         jobname              = lv_jobname
 42         strtimmed            = 'X'
 43       IMPORTING
 44         job_was_released     = lv_job_released
 45       EXCEPTIONS
 46         cant_start_immediate = 1
 47         invalid_startdate    = 2
 48         jobname_missing      = 3
 49         job_close_failed     = 4
 50         job_nosteps          = 5
 51         job_notex            = 6
 52         lock_failed          = 7
 53         OTHERS               = 8.
 54     IF syst-subrc <> 0.
 55       MESSAGE '关闭后台作业出错' TYPE 'I'.
 56     ELSE.
 57       MESSAGE '后台JOB开始运行' TYPE 'I'.
 58     ENDIF.
 59   ENDIF.
 60 ENDIF.
 61 
 62 CALL FUNCTION 'BP_JOBLOG_READ'
 63   EXPORTING
 64     client                = sy-mandt
 65     jobcount              = lv_jobcount
 66     jobname               = lv_jobname
 67   TABLES
 68     joblogtbl             = lt_joblog
 69   EXCEPTIONS
 70     cant_read_joblog      = 1
 71     jobcount_missing      = 2
 72     joblog_does_not_exist = 3
 73     joblog_is_empty       = 4
 74     joblog_name_missing   = 5
 75     jobname_missing       = 6
 76     job_does_not_exist    = 7
 77     OTHERS                = 8.
 78 IF sy-subrc <> 0.
 79   MESSAGE ID sy-msgid
 80      TYPE sy-msgty
 81    NUMBER sy-msgno
 82      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 83 ENDIF.
 84 
 85 IF sy-batch = ''.
 86   PERFORM frm_show_msg TABLES lt_joblog[].
 87 ENDIF.
 88 
 89 FORM frm_show_msg TABLES ct_joblog.
 90   DATA:ls_joblog TYPE tbtc5.
 91   DATA: ls_log             TYPE bal_s_log,
 92         l_log_handle       TYPE balloghndl,
 93         lt_log_handle      TYPE bal_t_logh,
 94         ls_display_profile TYPE bal_s_prof,
 95         ls_bal_msg         TYPE bal_s_msg.
 96 
 97   ls_log-aluser = sy-uname.
 98   ls_log-aldate = sy-datlo.
 99   ls_log-altime = sy-timlo.
100 
101   CALL FUNCTION 'BAL_LOG_CREATE'
102     EXPORTING
103       i_s_log      = ls_log
104     IMPORTING
105       e_log_handle = l_log_handle.
106 
107   APPEND l_log_handle TO lt_log_handle.
108 
109   LOOP AT ct_joblog INTO ls_joblog.
110 
111     CLEAR ls_bal_msg.
112 
113     ls_bal_msg-msgty = ls_joblog-msgtype.
114     ls_bal_msg-msgid = ls_joblog-msgid.
115     ls_bal_msg-msgno = ls_joblog-msgno.
116     ls_bal_msg-msgv1 = ls_joblog-msgv1.
117     ls_bal_msg-msgv2 = ls_joblog-msgv2.
118     ls_bal_msg-msgv3 = ls_joblog-msgv3.
119     ls_bal_msg-msgv4 = ls_joblog-msgv4.
120 
121     CALL FUNCTION 'BAL_LOG_MSG_ADD'
122       EXPORTING
123         i_log_handle = l_log_handle
124         i_s_msg      = ls_bal_msg.
125 
126   ENDLOOP.
127 
128   CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
129     IMPORTING
130       e_s_display_profile = ls_display_profile.
131 
132   CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
133     EXPORTING
134       i_t_log_handle      = lt_log_handle
135       i_s_display_profile = ls_display_profile.
136 
137 ENDFORM.
View Code

4.SHDB录屏完毕后自动生成程序或者接口

 

 

  1 report Z3426BDC01
  2        no standard page heading line-size 255.
  3 
  4 * Include bdcrecx1_s:
  5 * The call transaction using is called WITH AUTHORITY-CHECK!
  6 * If you have own auth.-checks you can use include bdcrecx1 instead.
  7 include bdcrecx1_s.
  8 
  9 parameters: dataset(132) lower case.
 10 ***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
 11 *
 12 *   If it is nessesary to change the data section use the rules:
 13 *   1.) Each definition of a field exists of two lines
 14 *   2.) The first line shows exactly the comment
 15 *       '* data element: ' followed with the data element
 16 *       which describes the field.
 17 *       If you don't have a data element use the
 18 *       comment without a data element name
 19 *   3.) The second line shows the fieldname of the
 20 *       structure, the fieldname must consist of
 21 *       a fieldname and optional the character '_' and
 22 *       three numbers and the field length in brackets
 23 *   4.) Each field must be type C.
 24 *
 25 *** Generated data section with specific formatting - DO NOT CHANGE  ***
 26 data: begin of record,
 27 * data element: AGKON
 28         AGKON_001(015),
 29 * data element: BUDAT
 30         BUDAT_002(010),
 31 * data element: MONAT
 32         MONAT_003(002),
 33 * data element: BUKRS
 34         BUKRS_004(004),
 35 * data element: WAERS
 36         WAERS_005(005),
 37 * data element: XNOPS
 38         XNOPS_006(001),
 39 * data element: XPOS1
 40         XPOS1_01_007(001),
 41 * data element: XPOS1
 42         XPOS1_03_008(001),
 43 * data element: SELXX_F05A
 44         SEL01_01_009(030),
 45 * data element: SELXX_F05A
 46         SEL01_02_010(030),
 47 * data element: SELXX_F05A
 48         SEL01_03_011(030),
 49 * data element: SELXX_F05A
 50         SEL01_04_012(030),
 51       end of record.
 52 
 53 *** End generated data section ***
 54 
 55 start-of-selection.
 56 
 57 perform open_dataset using dataset.
 58 perform open_group.
 59 
 60 do.
 61 
 62 read dataset dataset into record.
 63 if sy-subrc <> 0. exit. endif.
 64 
 65 perform bdc_dynpro      using 'SAPMF05A' '0131'.
 66 perform bdc_field       using 'BDC_OKCODE'
 67                               '=BU'.
 68 perform bdc_field       using 'RF05A-AGKON'
 69                               record-AGKON_001.
 70 perform bdc_field       using 'BKPF-BUDAT'
 71                               record-BUDAT_002.
 72 perform bdc_field       using 'BKPF-MONAT'
 73                               record-MONAT_003.
 74 perform bdc_field       using 'BKPF-BUKRS'
 75                               record-BUKRS_004.
 76 perform bdc_field       using 'BKPF-WAERS'
 77                               record-WAERS_005.
 78 perform bdc_field       using 'RF05A-XNOPS'
 79                               record-XNOPS_006.
 80 perform bdc_field       using 'RF05A-XPOS1(01)'
 81                               record-XPOS1_01_007.
 82 perform bdc_field       using 'RF05A-XPOS1(03)'
 83                               record-XPOS1_03_008.
 84 perform bdc_dynpro      using 'SAPMF05A' '0731'.
 85 perform bdc_field       using 'BDC_OKCODE'
 86                               '=BU'.
 87 perform bdc_field       using 'RF05A-SEL01(01)'
 88                               record-SEL01_01_009.
 89 perform bdc_field       using 'RF05A-SEL01(02)'
 90                               record-SEL01_02_010.
 91 perform bdc_field       using 'RF05A-SEL01(03)'
 92                               record-SEL01_03_011.
 93 perform bdc_field       using 'RF05A-SEL01(04)'
 94                               record-SEL01_04_012.
 95 perform bdc_transaction using 'F-44'.
 96 
 97 enddo.
 98 
 99 perform close_group.
100 perform close_dataset using dataset.
View Code