ABAP自动生成程序

Posted Rainystuday

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP自动生成程序相关的知识,希望对你有一定的参考价值。

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为啥我在写ABAP程序的时候不会自动生成关键字。 像我打DATA,只要打了D后面的就都会显示出来要怎么设置

ABAP-动态程序生成

怎么用ABAP 代码判断,,某程序的某个屏幕上,输出了 ALV 且 计算 输出ALV 的内表有 多少个字段?

ABAP自动生成程序

abap 开发之创建表维护生成器

菜鸟请教:abap开发释放请求是啥意思?