1, 场景介绍
下面介绍一下如何在SAP script中输出地址(address)。为方便讲解,先统一一下SAP script设置,如下:
2, 创建SAP script
tcode SE71, 输入名字,创建一个SAP script。进入script界面后,然后点击page选项,
然后将默认的page设定为first page和next page,
点击windows按钮,再创建一个windows,指定window名字和meaning
然后在创建其他windows,方法同上。
3, 创建地址的text element
选中显示地址的窗口,然后点击text element按钮
加入控制命令代码,address ...endaddress之间显示地址的控制命令。。。指定addressnumber
new-window,强制分页,protect...endprotect 分页保护
1 2 3 4 5 6 7 8 |
/E address /: BOX WIDTH '5' CM HEIGHT '5' CM FRAME 10 TW /: PROTECT /: ADDRESS /: ADDRESSNUMBER &FS_ADRC-ADDRNUMBER& /: ENDADDRESS /: NEW-WINDOW /: ENDPROTECT |
在其他窗口中也写入上面的代码,保存sap script后激活。script预览如下:
4, 代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
REPORT ztest_address. TABLES:adrc. SELECT-OPTIONS: s_addrno FOR adrc-addrnumber. TYPES: BEGIN OF type_s_adrc, addrnumber TYPE adrc-addrnumber, END OF type_s_adrc. DATA:fs_adrc TYPE type_s_adrc. DATA:t_adrc LIKE STANDARD TABLE OF fs_adrc. START-OF-SELECTION. SELECT addrnumber INTO TABLE t_adrc FROM adrc WHERE addrnumber IN s_addrno. PERFORM open_form. LOOP AT t_adrc INTO fs_adrc. PERFORM write_form. ENDLOOP. " LOOP AT T_ADRC PERFORM close_form. *&---------------------------------------------------------------------* *& Form OPEN_FORM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM open_form . CALL FUNCTION 'OPEN_FORM' EXPORTING * APPLICATION = 'TX' * ARCHIVE_INDEX = * ARCHIVE_PARAMS = * DEVICE = 'PRINTER' * DIALOG = 'X' form = 'ZTEST_FORM' * LANGUAGE = SY-LANGU * OPTIONS = * MAIL_SENDER = * MAIL_RECIPIENT = * MAIL_APPL_OBJECT = * RAW_DATA_INTERFACE = '*' * SPONUMIV = * IMPORTING * LANGUAGE = * NEW_ARCHIVE_PARAMS = * RESULT = * EXCEPTIONS * CANCELED = 1 * DEVICE = 2 * FORM = 3 * OPTIONS = 4 * UNCLOSED = 5 * MAIL_OPTIONS = 6 * ARCHIVE_ERROR = 7 * INVALID_FAX_NUMBER = 8 * MORE_PARAMS_NEEDED_IN_BATCH = 9 * SPOOL_ERROR = 10 * CODEPAGE = 11 * OTHERS = 12 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " If sy-subrc <> 0 ENDFORM. " FORM OPEN_FORM *&---------------------------------------------------------------------* *& Form WRITE_FORM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM write_form . CALL FUNCTION 'WRITE_FORM' EXPORTING element = 'ADDRESS' "script text element中的名字 * FUNCTION = 'SET' * TYPE = 'BODY' window = 'MAIN' "script 中创建的9个main window * IMPORTING * PENDING_LINES = EXCEPTIONS element = 1 function = 2 type = 3 unopened = 4 unstarted = 5 window = 6 bad_pageformat_for_print = 7 spool_error = 8 codepage = 9 OTHERS = 10. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " If sy-subrc <> 0 ENDFORM. " FORM WRITE_FORM *&---------------------------------------------------------------------* *& Form CLOSE_FORM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM close_form . CALL FUNCTION 'CLOSE_FORM' * IMPORTING * RESULT = * RDI_RESULT = * TABLES * OTFDATA = * EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 * SEND_ERROR = 3 * SPOOL_ERROR = 4 * CODEPAGE = 5 * OTHERS = 6 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " If sy-subrc <> 0 ENDFORM. " FORM CLOSE_FORM |
5, 测试
选择画面中输入地址号,
运行,结果如下,9个main窗口中都显示地址了
以上。
发表评论