QID 用表 APQD 里的ID
REPORT Z001
去年6月花了一周的成果,可是玩了一周就没玩了,
现在想来:
研究下程序共性 ,这个总结的多,一定会提高效率
这个用起来程序, 2s 完成程序框架部分,
报表 打印 bdc 单据创建, 都行,
REPORT zrsbdcrec_1 MESSAGE-ID zdemo. *MESSAGE-ID ms. TABLES:progdir, trdir. *---------------------------------------------------------------------* * SELECTION SCREEN *---------------------------------------------------------------------* PARAMETERS: qid LIKE apqd-qid, report LIKE trdir-name. * testdata AS CHECKBOX, * dsn(132) LOWER CASE, * file AS CHECKBOX. * selections of generated program because of texts *---------------------------------------------------------------------* * DATA *---------------------------------------------------------------------* DATA: BEGIN OF source OCCURS 100, line1(72), line2(42), END OF source. DATA: dynprotab LIKE bdcdata OCCURS 0 WITH HEADER LINE. DATA: tcode LIKE tstc-tcode. DATA: text_tab LIKE textpool OCCURS 0 WITH HEADER LINE, text_tab_2 LIKE textpool OCCURS 0 WITH HEADER LINE. DATA: dynpro_fields LIKE bdcdf OCCURS 0 WITH HEADER LINE. DATA: dynpro_fields_index LIKE sy-tabix, tree_name(43). **用 FIELDNAME 、FIELDTEXT DATA:gt_field LIKE STANDARD TABLE OF dfies, gs_field LIKE dfies. *---------------------------------------------------------------------* * CONSTANTS *---------------------------------------------------------------------* CONSTANTS: c_flg1edt TYPE x VALUE '80'. *---------------------------------------------------------------------* * start-of-selection *---------------------------------------------------------------------* START-OF-SELECTION. PERFORM frm_check_prog. ** get bdc records CALL FUNCTION 'BDC_OBJECT_READ' EXPORTING queue_id = qid TABLES dynprotab = dynprotab EXCEPTIONS not_found = 1 system_failure = 2 invalid_datatype = 3 OTHERS = 4. IF sy-subrc >< 0. MESSAGE s627 WITH qid. EXIT. ENDIF. **get field CALL FUNCTION 'BDC_DYNPROTAB_GET_FIELDS' TABLES dynprotab = dynprotab dynprofields = dynpro_fields. ** generate source lines of report IF report = space. STOP. ENDIF. * same lines for all records PERFORM frm_set_top. *&s4.TYPES PERFORM frm_get_table. *&s5.DATA PERFORM frm_set_data. *&s6.SELECTION SCREEN source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* SELECTION SCREEN'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'PARAMETERS: p_file LIKE rlgrap-filename MEMORY ID ws MODIF ID r01,'. APPEND source. CLEAR source. source-line1 = 'p_mode LIKE ctu_params-dismode DEFAULT ''N''.'. APPEND source. CLEAR source. APPEND source. **PARAMETERS: p_file LIKE rlgrap-filename MEMORY ID ws MODIF ID r01. *&s7.set f4 PERFORM frm_set_f4. *&s8.START-OF-SELECTION. PERFORM frm_set_main. PERFORM frm_f4. PERFORM frm_upload_data. PERFORM frm_alv_upload. *&s9.USER-COMMAND. PERFORM frm_pf_statu. PERFORM frm_use_command. *&s10.FORM frm_bdc_save . PERFORM frm_bdc_save . *&s11.BDC-top PERFORM frm_dynpro. **code generate PERFORM frm_close_prog. *---------------------------------------------------------------------* * end-of-selection *---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form FRM_GET_TABLE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_table . DATA: l_dfies LIKE dfies, l_tabname LIKE dcobjdef-name, l_fieldname LIKE dfies-lfieldname, l_dummy LIKE dfies-lfieldname. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* TABLE'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'TYPES:BEGIN OF ty_data,'. APPEND source. CLEAR source. APPEND source. ** LOOP AT dynpro_fields. * *** <field_n>(<length>) CLEAR l_dfies. IF dynpro_fields-fieldname CA '-'. * create dataelement comment line SPLIT dynpro_fields-fieldname AT '-' INTO l_tabname l_fieldname. SPLIT l_fieldname AT '(' INTO l_fieldname l_dummy. CALL FUNCTION 'DDIF_FIELDINFO_GET' EXPORTING tabname = l_tabname * fieldname = l_fieldname * LANGU = SY-LANGU lfieldname = l_fieldname * ALL_TYPES = ' ' IMPORTING * X030L_WA = * DDOBJTYPE = dfies_wa = l_dfies * TABLES * DFIES_TAB = EXCEPTIONS not_found = 1 internal_error = 2 OTHERS = 3. IF sy-subrc <> 0. CLEAR l_dfies. ELSE. * APPEND l_dfies TO gt_field. MOVE l_dfies TO gs_field. gs_field-fieldname = dynpro_fields-recfield. APPEND gs_field TO gt_field. ENDIF. ENDIF. source = '* data element: '. source+16 = l_dfies-rollname. APPEND source. CLEAR source. CONCATENATE dynpro_fields-recfield '(' dynpro_fields-length ')' ',' INTO source+8. APPEND source. CLEAR source. ENDLOOP. source = ' SEL TYPE C,'. APPEND source. CLEAR source. source = ' FLAG TYPE C,'. APPEND source. CLEAR source. source = ' MSG TYPE MSG,'. APPEND source. CLEAR source. ** end of record. source = ' END OF ty_data.'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_GET_TABLE *&---------------------------------------------------------------------* *& Form FRM_SET_F4 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_f4 . source = 'AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.'. APPEND source. CLEAR source. source = ' PERFORM frm_getdata USING p_file.'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_SET_F4 *&---------------------------------------------------------------------* *& Form frm_set_main *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_main . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* START-OF-SELECTION.'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'START-OF-SELECTION.'. APPEND source. CLEAR source. APPEND source. source = ' PERFORM frm_upload_data.'. APPEND source. CLEAR source. source = ' PERFORM frm_alv_upload.'. APPEND source. CLEAR source. APPEND source. ENDFORM. " frm_set_main *&---------------------------------------------------------------------* *& Form FRM_UPLOAD_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_upload_data . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '*& Form FRM_UPLOAD_DATA'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = 'FORM frm_upload_data .'. APPEND source. CLEAR source. source = ' DATA: lv_filename TYPE string.'. APPEND source. CLEAR source. source = ' lv_filename = p_file.'. APPEND source. CLEAR source. source = ' REFRESH gt_data.'. APPEND source. CLEAR source. source-line1 = ' CALL METHOD cl_gui_frontend_services=>gui_upload'. APPEND source. CLEAR source. source-line1 = ' EXPORTING'. APPEND source. CLEAR source. source-line1 = ' filename = lv_filename'. APPEND source. CLEAR source. source-line1 = ' has_field_separator = GC_TRUE '. APPEND source. CLEAR source. source-line1 = ' read_by_line = GC_TRUE '. APPEND source. CLEAR source. source-line1 = ' CHANGING'. APPEND source. CLEAR source. source-line1 = ' data_tab = gt_data[]'. APPEND source. CLEAR source. source-line1 = ' EXCEPTIONS'. APPEND source. CLEAR source. source-line1 = ' file_open_error = 1'. APPEND source. CLEAR source. source-line1 = ' file_read_error = 2'. APPEND source. CLEAR source. source-line1 = ' no_batch = 3'. APPEND source. CLEAR source. source-line1 = ' gui_refuse_filetransfer = 4'. APPEND source. CLEAR source. source-line1 = ' invalid_type = 5'. APPEND source. CLEAR source. source-line1 = ' no_authority = 6'. APPEND source. CLEAR source. source-line1 = ' unknown_error = 7'. APPEND source. CLEAR source. source-line1 = ' bad_data_format = 8'. APPEND source. CLEAR source. source-line1 = ' header_not_allowed = 9'. APPEND source. CLEAR source. source-line1 = ' separator_not_allowed = 10'. APPEND source. CLEAR source. source-line1 = ' header_too_long = 11'. APPEND source. CLEAR source. source-line1 = ' unknown_dp_error = 12'. APPEND source. CLEAR source. source-line1 = ' access_denied = 13'. APPEND source. CLEAR source. source-line1 = ' dp_out_of_memory = 14'. APPEND source. CLEAR source. source-line1 = ' disk_full = 15'. APPEND source. CLEAR source. source-line1 = ' dp_timeout = 16'. APPEND source. CLEAR source. source-line1 = ' error_no_gui = 18'. APPEND source. CLEAR source. source-line1 = ' OTHERS = 19.'. APPEND source. CLEAR source. source-line1 = ' IF sy-subrc <> 0.'. APPEND source. CLEAR source. source-line1 = ' MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno'. APPEND source. CLEAR source. source-line1 = ' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.'. APPEND source. CLEAR source. source-line1 = ' ENDIF.'. APPEND source. CLEAR source. source-line1 = ' gv_tabix = LINES( gt_data[] ).'. APPEND source. CLEAR source. source-line1 = ' IF gv_tabix = 0.'. APPEND source. CLEAR source. source-line1 = ' MESSAGE i003 ."没有上传数据!.'. APPEND source. CLEAR source. source-line1 = ' STOP.'. APPEND source. CLEAR source. source-line1 = ' ENDIF.'. APPEND source. CLEAR source. source = 'ENDFORM. " FRM_UPLOAD_DATA'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_UPLOAD_DATA *&---------------------------------------------------------------------* *& Form FRM_ALV_UPLOAD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_alv_upload . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '*& Form FRM_ALV_UPLOAD'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = 'FORM frm_alv_upload .'. APPEND source. CLEAR source. source = ' DATA: l_nn TYPE i.'. APPEND source. CLEAR source. source = ' DEFINE add_fieldcat.'. APPEND source. CLEAR source. source = ' clear wa_fieldcat.'. APPEND source. CLEAR source. source-line1 = ' wa_fieldcat-fieldname = ''&1''.'. APPEND source. CLEAR source. source-line1 = ' wa_fieldcat-seltext_l = ''&2''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-key = ''&3''.'. APPEND source. CLEAR source. source-line1 = ' wa_fieldcat-col_pos = l_nn + 1.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-edit = ''&4''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-outputlen = ''&5''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-fix_column = ''&6''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-no_zero = ''&7''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-just = ''&8''.'. APPEND source. CLEAR source. source-line1 = '* wa_fieldcat-decimals_out = ''&9''.'. APPEND source. CLEAR source. source-line1 = ' append wa_fieldcat to gt_fieldcat.'. APPEND source. CLEAR source. source-line1 = ' END-OF-DEFINITION.'. APPEND source. CLEAR source. APPEND source. **write display field. LOOP AT gt_field INTO gs_field. CONCATENATE 'add_fieldcat' gs_field-fieldname gs_field-fieldtext '.' INTO source-line1 SEPARATED BY space. APPEND source. CLEAR source. ENDLOOP. CONCATENATE 'add_fieldcat' 'flag' '处理状态' '.' INTO source-line1 SEPARATED BY space. APPEND source. CLEAR source. CONCATENATE 'add_fieldcat' 'msg' '消息' '.' INTO source-line1 SEPARATED BY space. APPEND source. CLEAR source. APPEND source. source-line1 = ' gw_layout-colwidth_optimize = GC_TRUE.'. APPEND source. CLEAR source. source-line1 = ' gw_layout-box_fieldname = ''SEL''.'. APPEND source. CLEAR source. source-line1 = ' gv_repid = sy-repid.'. APPEND source. CLEAR source. APPEND source. source-line1 = ' CALL FUNCTION ''REUSE_ALV_GRID_DISPLAY'' '. APPEND source. CLEAR source. source-line1 = ' EXPORTING'. APPEND source. CLEAR source. source-line1 = ' i_callback_program = gv_repid'. APPEND source. CLEAR source. source-line1 = ' i_save = ''A'' '. APPEND source. CLEAR source. source-line1 = ' is_layout = gw_layout'. APPEND source. CLEAR source. source-line1 = ' it_fieldcat = gt_fieldcat'. APPEND source. CLEAR source. source-line1 = '* it_events = gt_event'. APPEND source. CLEAR source. source-line1 = ' i_callback_pf_status_set = ''PF_STATUS_SET'' '. APPEND source. CLEAR source. source-line1 = ' i_callback_user_command = ''PF_USER_COMMAND'' '. APPEND source. CLEAR source. source-line1 = ' TABLES'. APPEND source. CLEAR source. source-line1 = ' t_outtab = gt_data'. APPEND source. CLEAR source. source-line1 = ' EXCEPTIONS'. APPEND source. CLEAR source. source-line1 = ' program_error = 1'. APPEND source. CLEAR source. source-line1 = ' OTHERS = 2.'. APPEND source. CLEAR source. source-line1 = 'ENDFORM. " FRM_ALV_UPLOAD'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_ALV_UPLOAD *&---------------------------------------------------------------------* *& Form FRM_F4 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_f4 . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '*& Form FRM_F4 '. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'FORM frm_getdata USING so_fiel.'. APPEND source. CLEAR source. source-line1 = ' DATA:l_filetab TYPE filetable,'. APPEND source. CLEAR source. source-line1 = ' l_rc TYPE i.'. APPEND source. CLEAR source. source-line1 = ' CLEAR:l_filetab.'. APPEND source. CLEAR source. source-line1 = ' REFRESH l_filetab.'. APPEND source. CLEAR source. source-line1 = ' CALL METHOD cl_gui_frontend_services=>file_open_dialog'. APPEND source. CLEAR source. source-line1 = ' EXPORTING'. APPEND source. CLEAR source. source-line1 = '* WINDOW_TITLE = ''SAP Custom - Open File'' '. APPEND source. CLEAR source. source-line1 = '* DEFAULT_EXTENSION = '. APPEND source. CLEAR source. source-line1 = ' default_filename = ''*.txt'' '. APPEND source. CLEAR source. source-line1 = ' initial_directory = ''d:\'' '. APPEND source. CLEAR source. source-line1 = ' multiselection = '''' '. APPEND source. CLEAR source. source-line1 = ' CHANGING'. APPEND source. CLEAR source. source-line1 = ' file_table = l_filetab'. APPEND source. CLEAR source. source-line1 = ' rc = l_rc'. APPEND source. CLEAR source. source-line1 = ' EXCEPTIONS'. APPEND source. CLEAR source. source-line1 = ' cntl_error = 1 '. APPEND source. CLEAR source. source-line1 = ' error_no_gui = 2 '. APPEND source. CLEAR source. source-line1 = ' not_supported_by_gui = 3 '. APPEND source. CLEAR source. source-line1 = ' OTHERS = 4.'. APPEND source. CLEAR source. source-line1 = ' CHECK l_rc EQ 1.'. APPEND source. CLEAR source. source-line1 = ' READ TABLE l_filetab INDEX 1 INTO p_file.'. APPEND source. CLEAR source. source-line1 = 'ENDFORM. " FRM_F4'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_F4 *&---------------------------------------------------------------------* *& Form FRM_CHECK_PROG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_check_prog . DATA:ls_trdir LIKE trdir. IF report(1) NE 'Z' AND report(1) NE 'Y'. MESSAGE s001 WITH report(1) DISPLAY LIKE 'E'. STOP. ENDIF. SELECT SINGLE * INTO ls_trdir FROM trdir WHERE name = report. IF sy-subrc EQ 0. MESSAGE s000 WITH report DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. " FRM_CHECK_PROG *&---------------------------------------------------------------------* *& Form FRM_CLOSE_PROG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_close_prog . ** insert report INSERT REPORT report FROM source. ** actualize EU-tree CONCATENATE 'PG_' report INTO tree_name. CALL FUNCTION 'WB_TREE_ACTUALIZE' EXPORTING tree_name = tree_name. * WITHOUT_TREE = ' ' * WITH_TCODE_INDEX = * IMPORTING * SYNTAX_ERROR =. MESSAGE s609 WITH report. ENDFORM. " FRM_CLOSE_PROG *&---------------------------------------------------------------------* *& Form FRM_PF_STATU *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_pf_statu . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* 通过SE41,拷贝程序SAPLSLVC_FULLSCREEN的状态STANDARD_FULLSCREEN过来'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'FORM pf_status_set USING rt_extab TYPE slis_t_extab.'. APPEND source. CLEAR source. source-line1 = ' SET PF-STATUS ''STANDARD_FULLSCREEN'' .'. APPEND source. CLEAR source. source-line1 = 'ENDFORM. "sub_set_pf_status'. APPEND source. CLEAR source. ENDFORM. " FRM_PF_STATU *&---------------------------------------------------------------------* *& Form FRM_USE_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_use_command . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '*& Form PF_USER_COMMAND'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'FORM pf_user_command USING p_ucomm LIKE sy-ucomm'. APPEND source. CLEAR source. source-line1 = ' ps_selfield TYPE slis_selfield .'. APPEND source. CLEAR source. source-line1 = ' DATA:lv_answer TYPE c.'. APPEND source. CLEAR source. source-line1 = ' ps_selfield-refresh = ''X''. '. APPEND source. CLEAR source. source-line1 = ' CASE p_ucomm.'. APPEND source. CLEAR source. source-line1 = ' WHEN ''&DATA_SAVE''.'. APPEND source. CLEAR source. source-line1 = ' PERFORM frm_bdc_save.'. APPEND source. CLEAR source. source-line1 = ' WHEN ''&F03'' OR ''&F12'' OR ''&F15''.'. APPEND source. CLEAR source. source-line1 = ' LEAVE TO SCREEN 0.'. APPEND source. CLEAR source. source-line1 = ' WHEN OTHERS.'. APPEND source. CLEAR source. source-line1 = ' ...'. APPEND source. CLEAR source. source-line1 = ' ENDCASE.'. APPEND source. CLEAR source. source-line1 = ' ps_selfield-refresh = ''X''.'. APPEND source. CLEAR source. source-line1 = 'ENDFORM. "PF_USER_COMMAND'. APPEND source. CLEAR source. ENDFORM. " FRM_USE_COMMAND *&---------------------------------------------------------------------* *& Form FRM_BDC_SAVE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_bdc_save . **text source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '*& Form FRM_BDC_SAVE.'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'FORM frm_bdc_save .'. APPEND source. CLEAR source. source-line1 = ' DATA: t100 LIKE t100.'. APPEND source. CLEAR source. source-line1 = ' DATA: l_mstring(480).'. APPEND source. CLEAR source. APPEND source. source-line1 = ' LOOP AT gt_data INTO gs_data WHERE sel = gc_true.'. APPEND source. CLEAR source. source-line1 = '**清空变量'. APPEND source. CLEAR source. source-line1 = ' CLEAR: gt_bdcd,gt_bdcd[],'. APPEND source. CLEAR source. source-line1 = ' gt_messtab,gt_messtab[].'. APPEND source. CLEAR source. APPEND source. break c_xiangc. **利用标准生产 BDC-form *---------------------------------------------------------------------* LOOP AT dynprotab. CASE dynprotab-dynbegin. **new transaction WHEN 'T'. * store transaction AFTER getting field values! IF NOT tcode IS INITIAL. ****perform bdc_transaction using dynprotab-fnam. source-line1 = 'perform bdc_transaction using'. CONCATENATE '''' tcode '''.' INTO source-line2. APPEND source. CLEAR source. APPEND source. ENDIF. **save tcode for next transaction tcode = dynprotab-fnam. * new dynpro WHEN 'X'. ****perform bdc_dynpro using dynprotab-program dynprotab-dynpro. source-line1 = 'perform bdc_dynpro using'. CONCATENATE '''' dynprotab-program '''' ' ''' dynprotab-dynpro '''.' INTO source-line2. APPEND source. CLEAR source. **dynpro field WHEN space. ****perform bdc_field using <dynprotab-fnam> <dynprotab-fval>. CHECK dynprotab-fnam <> 'BDC_SUBSCR'. source-line1 = 'perform bdc_field using'. CONCATENATE '''' dynprotab-fnam '''' INTO source-line2. APPEND source. CLEAR source. **从文件 读取字段 *IF DYNPROTAB-FNAM = 'BDC_OKCODE' OR IF dynprotab-fnam = 'BDC_OKCODE' OR dynprotab-fnam = 'BDC_CURSOR' OR dynprotab-fnam = 'BDC_SUBSCR'. PERFORM source_line_for_field_content USING dynprotab-fval. ELSE. ADD 1 TO dynpro_fields_index. READ TABLE dynpro_fields INDEX dynpro_fields_index. IF sy-subrc <> 0. MESSAGE a614 WITH dynprotab-fnam. ENDIF. CONCATENATE 'gs_data-' dynpro_fields-recfield '.' INTO source-line2. APPEND source. CLEAR source. ENDIF. * source line for read from dataset * IF FILE = 'X'. ** * ...records-<field> * PERFORM SOURCE_LINE_FOR_VAR_FIELD. ** source line for read from records * ELSE. ** * ...<dynprotab-fval> * PERFORM SOURCE_LINE_FOR_FIELD_CONTENT USING DYNPROTAB-FVAL. * ENDIF. ENDCASE. ENDLOOP. APPEND source. *---------------------------------------------------------------------* **!自定义BDC 子程序 * LOOP AT gt_field INTO gs_field. * CONCATENATE 'add_fieldcat' gs_field-fieldname gs_field-fieldtext '.' INTO source-line1 SEPARATED BY space. * APPEND source. CLEAR source. * ENDLOOP. * CONCATENATE 'add_fieldcat' 'flag' '处理状态' '.' INTO source-line1 SEPARATED BY space. * APPEND source. CLEAR source. * CONCATENATE 'add_fieldcat' 'msg' '消息' '.' INTO source-line1 SEPARATED BY space. * APPEND source. CLEAR source. * APPEND source. CONCATENATE '''' tcode '''' into tcode. concatenate ' CALL TRANSACTION' tcode 'USING gt_bdcd' into source-line1 separated by space. * source-line1 = ' CALL TRANSACTION 'MM01' USING gt_bdcd'. APPEND source. CLEAR source. source-line1 = ' MODE p_mode'. APPEND source. CLEAR source. source-line1 = ' UPDATE ''S'''. APPEND source. CLEAR source. source-line1 = ' MESSAGES INTO gt_messtab.'. APPEND source. CLEAR source. source-line1 = ' IF sy-subrc = 0.'. APPEND source. CLEAR source. source-line1 = ' gs_data-flag = gc_0.'. APPEND source. CLEAR source. source-line1 = ' gs_data-flag = gc_4.'. APPEND source. CLEAR source. source-line1 = ' ENDIF.'. APPEND source. CLEAR source. source-line1 = ' LOOP AT gt_messtab .'. APPEND source. CLEAR source. source-line1 = ' SELECT SINGLE *'. APPEND source. CLEAR source. source-line1 = ' INTO t100 '. APPEND source. CLEAR source. source-line1 = ' FROM t100 '. APPEND source. CLEAR source. source-line1 = ' WHERE sprsl = gt_messtab-msgspra'. APPEND source. CLEAR source. source-line1 = ' AND arbgb = gt_messtab-msgid'. APPEND source. CLEAR source. source-line1 = ' AND msgnr = gt_messtab-msgnr.'. APPEND source. CLEAR source. source-line1 = ' IF sy-subrc = 0.'. APPEND source. CLEAR source. source-line1 = ' l_mstring = t100-text.'. APPEND source. CLEAR source. source-line1 = ' IF l_mstring CS ''&1''.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&1'' WITH gt_messtab-msgv1 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&2'' WITH gt_messtab-msgv2 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&3'' WITH gt_messtab-msgv3 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&4'' WITH gt_messtab-msgv4 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' ELSE.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&'' WITH gt_messtab-msgv1 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&'' WITH gt_messtab-msgv2 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&'' WITH gt_messtab-msgv3 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' REPLACE ''&'' WITH gt_messtab-msgv4 INTO l_mstring.'. APPEND source. CLEAR source. source-line1 = ' ENDIF.'. APPEND source. CLEAR source. source-line1 = ' CONDENSE l_mstring.'. APPEND source. CLEAR source. source-line1 = ' CONCATENATE gs_data-msg l_mstring INTO gs_data-msg.'. APPEND source. CLEAR source. source-line1 = ' ELSE.'. APPEND source. CLEAR source. source-line1 = ' CONCATENATE gs_data-msg gt_messtab INTO gs_data-msg.'. APPEND source. CLEAR source. source-line1 = ' ENDIF.'. APPEND source. CLEAR source. source-line1 = ' ENDLOOP.'. APPEND source. CLEAR source. source-line1 = ' MODIFY gt_data FROM gs_data.'. APPEND source. CLEAR source. source-line1 = ' CLEAR gs_data.'. APPEND source. CLEAR source. source-line1 = ' ENDLOOP.'. APPEND source. CLEAR source. source-line1 = 'ENDFORM. " FRM_BDC_SAVE'. APPEND source. CLEAR source. ENDFORM. " FRM_BDC_SAVE *&---------------------------------------------------------------------* *& Form frm_SET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_data . source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* DATA'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'DATA:gt_data TYPE TABLE OF ty_data,'. APPEND source. CLEAR source. source-line1 = ' gs_data TYPE ty_data.'. APPEND source. CLEAR source. source-line1 = 'DATA:gv_tabix TYPE sy-tabix.'. APPEND source. CLEAR source. **CONSTANTS source-line1 = 'CONSTANTS: GC_TRUE TYPE SAP_BOOL VALUE ''X'', '. APPEND source. CLEAR source. source-line1 = ' gc_0 TYPE sap_bool VALUE ''S'', '. APPEND source. CLEAR source. source-line1 = ' gc_4 TYPE sap_bool VALUE ''E''. '. APPEND source. CLEAR source. source = '*DATA for BDC'. APPEND source. CLEAR source. source-line1 = 'DATA:gt_bdcd LIKE bdcdata OCCURS 0 WITH HEADER LINE.'. APPEND source. CLEAR source. source-line1 = 'DATA:gt_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.'. APPEND source. CLEAR source. source = '*DATA for alv'. APPEND source. CLEAR source. source-line1 = 'DATA: gv_repid TYPE sy-repid,'. APPEND source. CLEAR source. source-line1 = ' gw_layout TYPE slis_layout_alv,'. APPEND source. CLEAR source. source-line1 = ' gt_fieldcat TYPE slis_t_fieldcat_alv,'. APPEND source. CLEAR source. source-line1 = ' wa_fieldcat TYPE slis_fieldcat_alv,'. APPEND source. CLEAR source. source-line1 = ' gt_event TYPE slis_t_event,'. APPEND source. CLEAR source. source-line1 = ' wa_event TYPE slis_alv_event.'. APPEND source. CLEAR source. APPEND source. ENDFORM. " frm_SET_DATA *&---------------------------------------------------------------------* *& Form FRM_SET_TOP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_top . *&s1.report <report> CONCATENATE 'report' report INTO source SEPARATED BY space. APPEND source. CLEAR source. source = ' no standard page heading line-size 255 MESSAGE-ID DEMO.'. APPEND source. CLEAR source. APPEND source. *&s2.include bdcrecx1. "since release 4.5 source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* INCLUDE'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. APPEND source. source-line1 = 'include bdcrecx1.'. APPEND source. CLEAR source. APPEND source. *&s3.TYPE-POOLS source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source = '* TYPE-POOLS'. APPEND source. CLEAR source. source = '*---------------------------------------------------------------------*'. APPEND source. CLEAR source. source-line1 = 'TYPE-POOLS:slis,truxs.'. APPEND source. CLEAR source. APPEND source. ENDFORM. " FRM_SET_TOP *&---------------------------------------------------------------------* *& Form FRM_DYNPRO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_dynpro . ENDFORM. " FRM_DYNPRO **** source_line_for_field_content ************************************ FORM source_line_for_field_content USING p_fval. DATA: l_fval LIKE dynprotab-fval. l_fval = p_fval. IF l_fval+39 = space. CONCATENATE '''' l_fval '''.' INTO source-line2. APPEND source. CLEAR source. ELSE. "field content longer than 38 CONCATENATE '''' l_fval(38) '''' INTO source-line2. APPEND source. CLEAR source. source-line1+28 = '&'. DO 4 TIMES. SHIFT l_fval BY 38 PLACES. IF l_fval+39 = space. CONCATENATE '''' l_fval '''.' INTO source-line2. APPEND source. CLEAR source. EXIT. ELSE. "field content longer than n x 38 CONCATENATE '''' l_fval(38) '''' INTO source-line2. APPEND source. CLEAR source-line2. ENDIF. ENDDO. ENDIF. ENDFORM. "SOURCE_LINE_FOR_FIELD_CONTENT