SAP常用系统函数归纳

函数名 描述
CONVERSION_EXIT_ALPHA_INPUT 料号前面补0
CONVERSION_EXIT_ALPHA_OUTPUT 料号前面减0
CONVERSION_EXIT_MATN1_INPUT 料号前面补0
CONVERSION_EXIT_MATN1_OUTPUT 料号前面减0
LAST_DAY_OF_MONTHS 查询某日期的在当月的最后一天
CO_SF_CAUFVD_GET 根据工单号查询订单抬头和项目
SO_NEW_DOCUMENT_ATT_SEND_API1 外发邮件
VIEW_MAINTENANCE_CALL 调用数据表的维护视图
SO_OBJECT_SEND 外发邮件
函数名
CONVERSION_EXIT_ALPHA_INPUT
功能:料号前面补0,
实例:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "料号前面加0”
EXPORTING
input = matnr_in
IMPORTING
output = matnr_out.
说明:1)数字料号入Table需要补0,不会自动产生,有字母料号却会自动补0.
2)只能用’字符型’
CONVERSION_EXIT_MATN1_INPUT
功能:料号前面补0
实例:
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' "料号前面补0”
EXPORTING
input = matnr_in
IMPORTING
output = matnr_out
EXCEPTIONS
length_error = 1
OTHERS = 2.
说明: 1)数字料号入Table需要补0,不会自动产生,有字母料号却会自动补0.
2)只能用于料号转换

CONVERSION_EXIT_ALPHA_OUTPUT
功能:料号前面去0
实例:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "料号前面去0.
EXPORTING
input = wa_ysy1-matnr
IMPORTING
output = wa_ysy1-matnr.
说明:
CONVERSION_EXIT_MATN1_OUTPUT
功能:料号前面去0
实例:
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = t_afpo-matnr
IMPORTING
output = t_afpo-matnr
EXCEPTIONS
OTHERS = 1.
说明:
LAST_DAY_OF_MONTHS
功能:查询某日期的在当月的最后一天
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = f_date "月任意一天 类型必须为D(要完成日期##
IMPORTING
last_day_of_month = p_date "月最后一天 类型必须为D(完整日期)
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
说明:
CO_SF_CAUFVD_GET
功能: 根据工单号查询订单抬头和项目
实例:
DATA: wa_caufvd TYPE caufvd.
CALL FUNCTION 'CO_SF_CAUFVD_GET'"取得订单抬头和项目
EXPORTING
aufnr_imp = aufnr
IMPORTING
caufvd_exp = wa_caufvd “订单抬头和项目结构
EXCEPTIONS
not_found = 1
OTHERS = 2.
说明:
SO_NEW_DOCUMENT_ATT_SEND_API1
功能:邮件发送 SAPoffice: Send new document with attachments using RFC
实例:
FORM email_itab. “邮件内容“
WRITE: '编号' TO email_itab-line+0(3), "255个长度的文本字段:文本"
'记帐日期' TO email_itab-line+3(10),

ENDFORM. "email_itab
FORM reset_objpack .
it_packing_list-transf_bin = space. "标记将以二进制形式传输对象的标志"
it_packing_list-head_start = 0."表头开始行"
it_packing_list-head_num = 1. "表头行数"
it_packing_list-body_start = 1."内容开始行"
it_packing_list-body_num = it_message_lines. "内容行数"
it_packing_list-doc_type = 'RAW'. "信息类型"
APPEND it_packing_list.
ENDFORM. "reset_objpack
FORM reset_doc_chng .
DESCRIBE TABLE email_itab LINES it_message_lines.
gd_doc_data-doc_size = it_message_lines * 255 + STRLEN( email_itab ). "SAPoffice 文档的大小 "
gd_doc_data-obj_langu = sy-langu. "创建文档使用的语言"
gd_doc_data-obj_name = 'SAPRPT'. "文档,文件夹或分配清单的名称"
gd_doc_data-obj_descr = '邮件标题'. "Email标题"
gd_doc_data-sensitivty = 'F'. "对象:灵敏度(个人的,功能的,...) F:功能"
ENDFORM. "reset_doc_chng
FORM reset_reclist .
SELECT zmaaddr
INTO it_receivers-receiver
FROM ziebtemail.
it_receivers-rec_type = 'U'. "互联网地址
APPEND it_receivers.
CLEAR it_receivers.
ENDSELECT.
ENDFORM. "reset_reclist
DATA: gd_doc_data LIKE sodocchgi1,
gd_sent_all(1) TYPE c,
it_message_lines TYPE sy-tabix,
it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF email_itab OCCURS 10.
INCLUDE STRUCTURE soli.
DATA: END OF email_itab.
PERFORM email_itab. "TABLES OUTPUT_TAB.
PERFORM reset_doc_chng.
PERFORM reset_reclist.
PERFORM reset_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data “新文档的属性”
PUT_IN_OUTBOX = 'X' “标志:发送后将文档移到outbox
* COMMIT_WORK = ' '
* IMPORTING
SENT_TO_ALL = gd_sent_all “Flag: Document sent to all”
* NEW_OBJECT_ID = ID of created object (not document!)
tables
packing_list = it_packing_list “SAPoffice:输入对象组件描述”
* OBJECT_HEADER =
* CONTENTS_BIN =
* CONTENTS_TXT =
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = email_itab”SAPoffice:API 收件人清单的结构”
* EXCEPTIONS
* TOO_MANY_RECEIVERS = 1
* DOCUMENT_NOT_SENT = 2
* DOCUMENT_TYPE_NOT_EXIST = 3
* OPERATION_NO_AUTHORIZATION = 4
* PARAMETER_ERROR = 5
* X_ERROR = 6
* ENQUEUE_ERROR = 7
* OTHERS = 8
.
IF sy-subrc <>0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
说明:
VIEW_MAINTENANCE_CALL
功能:调用数据表的维护视图
实例:
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'U' “活动(显示/维护/传输)”
* CORR_NUMBER = ' '
* GENERATE_MAINT_TOOL_IF_MISSING = ' '
* SHOW_SELECTION_POPUP = ' '
view_name = 'ZIEBTEMAIL' “要处理的视图/表格的名称”
* NO_WARNING_FOR_CLIENTINDEP = ' '
* RFC_DESTINATION_FOR_UPGRADE = ' '
* CLIENT_FOR_UPGRADE = ' '
* VARIANT_FOR_SELECTION = ' '
* COMPLEX_SELCONDS_USED = ' '
* CHECK_DDIC_MAINFLAG = ' '
* SUPPRESS_WA_POPUP = ' '
* TABLES
* DBA_SELLIST =
* EXCL_CUA_FUNCT =
* EXCEPTIONS
* CLIENT_REFERENCE = 1
* FOREIGN_LOCK = 2
* INVALID_ACTION = 3
* NO_CLIENTINDEPENDENT_AUTH = 4
* NO_DATABASE_FUNCTION = 5
* NO_EDITOR_FUNCTION = 6
* NO_SHOW_AUTH = 7
* NO_TVDIR_ENTRY = 8
* NO_UPD_AUTH = 9
* ONLY_SHOW_ALLOWED = 10
* SYSTEM_FAILURE = 11
* UNKNOWN_FIELD_IN_DBA_SELLIST = 12
* VIEW_NOT_FOUND = 13
* MAINTENANCE_PROHIBITED = 14
* OTHERS = 15
.
IF sy-subrc <>0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
说明:
SO_OBJECT_SEND
功能:外发邮件
实例:
REPORT ztmail02 .
DATA: BEGIN OF itab OCCURS 0,
pernr LIKE pa0001-pernr,
ename LIKE pa0001-ename,
END OF itab.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli occurs 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1 occurs 100 WITH HEADER LINE,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT pernr ename
INTO CORRESPONDING FIELDS OF TABLE itab
FROM pa0001
WHERE pernr <50.
LOOP AT itab.
WRITE: /02 sy-vline, itab-pernr, 15 sy-vline, itab-ename, 50
sy-vline.
ENDLOOP.
*receivers
receiver_list-recextnam = 'eric.guh@sina.com'. “直接外部地址作为接收方”
receiver_list-recesc = ‘U’. “收件人类型的说明; U 互联网地址”
receiver_list-sndart = ‘MAIL'. “输出设备; MAIL 邮件”
receiver_list-sndpri = '1'. “发送:优先级; 1 最高优先权”
APPEND receiver_list.
*general data
w_object_hd_change-objla = sy-langu. “创建文档使用的语言”
w_object_hd_change-objnam = 'Object name'. “文档,文件夹或分配清单的名称”
w_object_hd_change-objsns = 'F'. “对象:灵敏度(个人的,功能的,...)” F: 功能
w_object_hd_change -OBJDES = ‘Message subject’. “Mail的标题”
APPEND w_object_hd_change.
*content
message_content-line = 'Message content'. “发送的内容”
APPEND message_content.

CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change “通常头数据”
object_type = 'RAW' “对象类型”
OUTBOX_FLAG = 'X' “标志:发送后将文档移到outbox
owner = sy-uname “负责传送的用户”
TABLES
objcont = message_content “发送的内容”
receivers = receiver_list “接收对象属性”
att_cont = compressed_attachment.

---------------------------------------------------------------------------------------------

函数名                                                      描述                         
    SD_VBAP_READ_WITH_VBELN            
根据销售订单读取表 vbap 中的信息
    EDIT_LINES                                            
READ_TEXT 返回的 LINES 中的行按照 TDFORMAT=“*” 重新组织
    VIEW_MAINTENANCE_CALL                  
维护表视图


    
函数名                                  描述                         
DY_GET_FOCUS                
获得屏幕焦点
DY_GET_SET_FIELD_VALUE    
获得或者设置屏幕字段的值


    
函数名                                                            描述                         
    F4IF_INT_TABLE_VALUE_REQUEST          
显示检索 help
    READ_TEXT                                                  
读取长文本
    CONVERSION_EXIT_CUNIT_OUTPUT          
单位转换
    SJIS_DBC_TO_SBC                                      
全角转半角
    SJIS_SBC_TO_DBC                                      
半角转换为全角
    CO_R0_CHECK_DECIMAL_POINT              
根据单位检查数据的小数位
    POSTAL_CODE_CHECK                      
检查邮政编码

 


    
函数名                                        描述                         
    CONVERSION_EXIT_ALPHA_INPUT          
全数字则在前面补 0
    CONVERSION_EXIT_ALPHA_INPUT          
和上面相反
    GET_JOB_RUNTIME_INFO                  
获得 job 相关信息
    TERMINAL_ID_GET                      
获得端末 id
    DATE_CONVERT_TO_FACTORYDATE          
把输入日期转为工厂日历日期
    MESSAGE_TEXT_BUILD                    
把消息转为文本

 


    
函数名                                        描述                         
    POPUP_TO_CONFIRM                      
弹出确认窗口

 


    
函数名                                        描述                         
    CONVERSION_EXIT_MATN1_INPUT                
物料号码转换函数
    CONVERSION_EXIT_MATN1_OUTPUT                
同上相反
    CONVERT_TO_LOCAL_CURRENCY                  
按照指定日期汇率转换金额为指定货币类型
    SSF_FUNCTION_MODULE_NAME                    
根据 form 名取得对应的函数名 (SmartForm)    

 


    
函数名                                        描述                         
    DATE_CHECK_PLAUSIBILITY                
日期 CHECK
    cl_gui_frontend_services=>gui_upload  
上传到服务器
    cl_gui_frontend_services=>gui_download      
下载到服本地
    SSF_FUNCTION_MODULE_NAME    SMARTFORMS
输出报表时,生成一个函数名称,然后 CALL 这个名称

 


    
函数名                                        描述                         
    POPUP_TO_DECIDE_LIST                
弹出供选择窗口   

 

 

1.function SD_VBAP_READ_WITH_VBELN

   功能:根据销售订单读取表 vbap 中的信息

   参数:

      import I_VBELN                             订单号(必输项)

                   I_BYPASSING_BUFFER     是否回避 buffer

                   I_REFRESH_BUFFER         是否清空 buffer

     tables ET_VBAPVB                         不清楚其意义

                  ET_VBAP                            vbap

2.form EDIT_LINES

   功能:把 READ_TEXT 返回的 LINES 中的行按照 TDFORMAT=“*” 重新组织

   原因:如果用 CREATE_TEXT 登录的长文本不存在该问题,如果是在前台业务登录的 text ,那么存到数据库的时候会在 72 位的地方换行,在 lines 这个表中的 TDFORMAT 设置为空,导致 READ_TEXT 返回的表中的行数也许不是你需要的行数。

   代码:

FORM EDIT_LINES TABLES P_IT_LINES STRUCTURE TLINE.
  DATA:
    L_IT_LINES TYPE STANDARD TABLE OF TLINE,
    L_WA_LINES TYPE TLINE,
    L_WA_LINE1 TYPE TLINE,
    L_LINE TYPE
I.
  DATA:
    L_INDEX TYPE I,
    L_I    
TYPE I.
  READ TABLE P_IT_LINES TRANSPORTING NO FIELDS
    WITH KEY TDFORMAT = SPACE.
  CHECK SY-SUBRC = 0.
  L_LINE = LINES( P_IT_LINES ).
  CHECK L_LINE > 1.

  L_IT_LINES[] = P_IT_LINES[].
  CLEAR: P_IT_LINES[].

  L_INDEX = 2.
  DO.
    CLEAR: L_WA_LINES.
    READ TABLE L_IT_LINES INTO L_WA_LINES INDEX L_INDEX.
    IF SY-SUBRC <> 0.
      L_I = L_INDEX - 1.
      READ TABLE L_IT_LINES INTO L_WA_LINES INDEX L_I.
      IF SY-SUBRC = 0 .
        APPEND L_WA_LINES TO P_IT_LINES.
      ENDIF.
      EXIT.
    ENDIF.
    IF L_WA_LINES-TDFORMAT = '*'.
      L_I = L_INDEX - 1.
      CLEAR L_WA_LINE1.
      READ TABLE L_IT_LINES INTO L_WA_LINE1 INDEX L_I.
      APPEND L_WA_LINE1 TO P_IT_LINES.
      L_INDEX = L_I + 2.
    ELSE.
      L_I = L_INDEX - 1.
      READ TABLE L_IT_LINES INTO L_WA_LINE1 INDEX L_I.
      CONCATENATE L_WA_LINE1-TDLINE L_WA_LINES-TDLINE
             INTO L_WA_LINE1-TDLINE.
      APPEND L_WA_LINE1 TO P_IT_LINES.
      L_INDEX = L_INDEX + 2.
    ENDIF.
  ENDDO.
ENDFORM.                    " S4110_EDIT_LINES

3.function:VIEW_MAINTENANCE_CALL

   功能:维护表视图等

        The function module calls the extended table maintenance (View maintenance).

   参数:

    import ACTION       S = Display U = Change T = Transport

            CORR_NUMBER   传送号(上面的 action t

            SHOW_SELECTION_POPUP   是否弹出选择画面

            VIEW_NAME     视图名

            NO_WARNING_FOR_CLIENTINDEP   跨集团是否现实警告

            VARIANT_FOR_SELECTION   变式名

            CHECK_DDIC_MAINFLAG     察看是否为可维护对象

补充: VIEW_MAINTENANCE_CALL

例子:

  CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
    EXPORTING
      ACTION                       = 'U'          "
更新
      SHOW_SELECTION_POPUP         = 'X'          "
显示选择画面
      VIEW_NAME                    = 'ZPPT000020' "
表名
      NO_WARNING_FOR_CLIENTINDEP   = ' '          "
不显示警告
    EXCEPTIONS
      CLIENT_REFERENCE             = 1
      FOREIGN_LOCK                 = 2
      INVALID_ACTION               = 3
      NO_CLIENTINDEPENDENT_AUTH    = 4
      NO_DATABASE_FUNCTION         = 5
      NO_EDITOR_FUNCTION           = 6
      NO_SHOW_AUTH                 = 7
      NO_TVDIR_ENTRY               = 8
      NO_UPD_AUTH                  = 9
      ONLY_SHOW_ALLOWED            = 10
      SYSTEM_FAILURE               = 11
      UNKNOWN_FIELD_IN_DBA_SELLIST = 12
      VIEW_NOT_FOUND               = 13
      MAINTENANCE_PROHIBITED       = 14
      OTHERS                       = 15.
效果:

每天函数讲解系列 ----2006.01.10

 

1.SYSTEM-CALL:DY_GET_FOCUS

   说明:获得屏幕焦点

   参数:

          ID 'SSCREENNAM' FIELD CURRSUBSCREEN
          ID 'SSCREENNBR' FIELD CURRSUBSCREENNO
          ID 'MSCREENNAM' FIELD CURRSCREEN
          ID 'MSCREENNBR' FIELD CURRSCREENNO
          ID 'FIELDNAME' FIELD CURSOR_FIELD
          ID 'FIELDOFFS' FIELD DUMMYOFFS
          ID 'LINE' FIELD CURSOR_LINE.

2.SYSTEM-CALL:DY_GET_SET_FIELD_VALUE

   说明:获得或者设置屏幕字段的值

   参数:

      ID 'GET_SET'    FIELD 'S'    "S:Set mode  G:Get mode
      ID 'SSCREENNAM' FIELD SHSUBSCREEN
      ID 'SSCREENNBR' FIELD SHSUBSCREENNO
      ID 'MSCREENNAM' FIELD SHSCREEN
      ID 'MSCREENNBR' FIELD SHSCREENNO
      ID 'FIELDNAME' FIELD DYNP_EXPORT
      ID 'LINE' FIELD DYNP_EXSTEPL
      ID 'VALUE' FIELD DYNP_EXPVAL.

例子:我做了一个检索 help exit ,例如屏幕上有两个字段,我按了一个字段的检索 help ,那么根据这个字段就会取得相应的另外一个字段的值,然后把这个之设置到第二个字段。

FUNCTION ZTEST_F4.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     REFERENCE(SHLP) TYPE  SHLP_DESCR
*"     REFERENCE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------
* Local data definition
  DATA: L_ZZOINO(3) TYPE C.
  DATA: L_ZZPOSID(10) TYPE C.
  DATA: DYNP_EXPORT(132), DYNP_EXPVAL(132).
  DATA: DYNP_EXSTEPL TYPE I, OK, DUMMYCHAR.
  DATA: DUMMYOFFS TYPE
I.
  DATA: SHSUBSCREEN LIKE HELP_INFO-DYNPPROG,
        SHSUBSCREENNO LIKE HELP_INFO-DYNPRO,
        SHSCREEN LIKE HELP_INFO-DYNPPROG,
        SHSCREENNO LIKE HELP_INFO-DYNPRO.
  DATA: CURRSUBSCREEN LIKE HELP_INFO-DYNPPROG,
        CURRSUBSCREENNO LIKE HELP_INFO-DYNPRO,
        CURRSCREEN LIKE HELP_INFO-DYNPPROG,
        CURRSCREENNO LIKE HELP_INFO-DYNPRO.
  DATA: CURSOR_FIELD LIKE DYNPREAD-FIELDNAME, CURSOR_LINE TYPE I.
  DATA: SETCURSOR_AVAILABLE TYPE I.
* Get record value from record table
  READ TABLE RECORD_TAB INDEX 1.
  L_ZZPOSID = RECORD_TAB+0(10).
  IF SHLP_TAB-INTDESCR-HOTKEY IS INITIAL.
    L_ZZOINO = RECORD_TAB+10(3).
  ENDIF.
* Check command, if return, set screen
  IF CALLCONTROL-STEP = 'RETTOP'.
*   Initialize screen, get screen focus
    CALL 'DY_GET_FOCUS'
          ID 'SSCREENNAM' FIELD CURRSUBSCREEN
          ID 'SSCREENNBR' FIELD CURRSUBSCREENNO
          ID 'MSCREENNAM' FIELD CURRSCREEN
          ID 'MSCREENNBR' FIELD CURRSCREENNO
          ID 'FIELDNAME' FIELD CURSOR_FIELD
          ID 'FIELDOFFS' FIELD DUMMYOFFS
          ID 'LINE' FIELD CURSOR_LINE.
*   Set screen parameter
    GET PARAMETER ID 'RID' FIELD SHSUBSCREEN .
    SHSCREEN = SHSUBSCREEN.
    GET PARAMETER ID 'DYN' FIELD SHSUBSCREENNO.
    SHSCREENNO = SHSUBSCREENNO.
    DYNP_EXPORT   ='V_WA_DYNPRO_9000-ZZOINO'.
    DYNP_EXPVAL   = L_ZZOINO.
*   System call for set screen
    CALL 'DY_GET_SET_FIELD_VALUE'
      ID 'GET_SET'    FIELD 'S'    "Set mode
      ID 'SSCREENNAM' FIELD SHSUBSCREEN
      ID 'SSCREENNBR' FIELD SHSUBSCREENNO
      ID 'MSCREENNAM' FIELD SHSCREEN
      ID 'MSCREENNBR' FIELD SHSCREENNO
      ID 'FIELDNAME' FIELD DYNP_EXPORT
      ID 'LINE' FIELD DYNP_EXSTEPL
      ID 'VALUE' FIELD DYNP_EXPVAL.
*   System call for set screen
    DYNP_EXPORT   ='V_WA_DYNPRO_9000-ZZPOSID'.
    DYNP_EXPVAL   = L_ZZPOSID.
    CALL 'DY_GET_SET_FIELD_VALUE'
      ID 'GET_SET'    FIELD 'S'    "Set mode
      ID 'SSCREENNAM' FIELD SHSUBSCREEN
      ID 'SSCREENNBR' FIELD SHSUBSCREENNO
      ID 'MSCREENNAM' FIELD SHSCREEN
      ID 'MSCREENNBR' FIELD SHSCREENNO
      ID 'FIELDNAME' FIELD DYNP_EXPORT
      ID 'LINE' FIELD DYNP_EXSTEPL
      ID 'VALUE' FIELD DYNP_EXPVAL.
  ENDIF.
ENDFUNCTION.

 

每天函数讲解系列 ----2006.01.11

Function:F4IF_INT_TABLE_VALUE_REQUEST
  
功能:显示检索 help
  
参数:
     Import

        DDIC_STRUCTURE
:返回 table 的结构:
          ‘s’
VALUE_TAB 的结构
          ‘c’
VALUE_TAB 只有一个字段
        RETFIELD
:返回的字段名称 ------------ 必输
        DYNPPROG
:当前程序
        DYNPNR
   屏幕号
        DYNPROFIELD
:屏幕上需要检索 help 的字段名称
        WINDOW_TITLE
:检索 help 的标题
        VALUE_ORG
:检索 help 屏幕显示属性:
        ‘c’
cell by cell
        ‘s’
structured
        CALLBACK_PROGRAM
:在 f4 之前调用的程序
        CALLBACK_FORM
:在 f4 之前调用的程序里面的 form 名称,形式如下
           FORM <NAME> TABLES RECORD_TAB STRUCTURE SEAHLPRES
                    CHANGING SHLP TYPE SHLP_DESCR
                              CALLCONTROL LIKE DDSHF4CTRL.
     Export

        USER_RESET
:如果没有选择(按红 x ),返回 ‘x’
     Tables

        VALUE_TAB
:传进去的表 ----------- 必输
        FIELD_TAB
Fields of the hit list (暂时没用)
        RETURN_TAB
:返回值表,即如果选择了而没有写到屏幕上的值存在这个表中。
        DYNPFLD_MAPPING
:把屏幕上需要 help 的字段可以放在这个表中。
          
推测:如果屏幕上有多个字段关联,那么只作一个 help 的话,这个应该可以满足。

例子:
FORM A3000_SET_F4_FIELD_WERKS USING P_FIELD.
TYPES:
  BEGIN OF T_S_WERKS,
    WERKS TYPE T001W-WERKS,   "
プラント
    NAME1 TYPE T001W-NAME1,   "
名称
    NAME2 TYPE T001W-NAME2,   "
名称 2
    STRAS TYPE T001W-STRAS,   "
地名 / 番地 -
    ORT01 TYPE T001W-ORT01,   "
市区町村名
  END OF T_S_WERKS.
TYPES  T_I_WERKS TYPE STANDARD TABLE OF T_S_WERKS.
*
这个就是 value_tab
DATA   L_IT_WERKS TYPE T_I_WERKS.
*
取数据
  SELECT WERKS    "
プラント
         NAME1    "
名称
         NAME2    "
名称 2
         STRAS    "
地名 / 番地 -
         ORT01    "
市区町村名
    FROM T001W
    INTO CORRESPONDING FIELDS OF TABLE L_IT_WERKS.
*
调用函数
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      RETFIELD               = 'WERKS'    “plant
      DYNPPROG               = SY-REPID   “
程序名
      DYNPNR                 = SY-DYNNR   “
屏幕号
      DYNPROFIELD            = P_FIELD    “
字段名称
      VALUE_ORG              = 'S'        “
显示属性: cell by cell
    TABLES
      VALUE_TAB              = L_IT_WERKS
    EXCEPTIONS
      PARAMETER_ERROR        = 1
      NO_VALUES_FOUND        = 2
      OTHERS                 = 3
            .
  IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " A3000_SET_F4_FIELD_WERKS

程序:

REPORT ZF4IF_INT_TABLE_VALUE_REQUEST                                   .

TYPES:

 BEGIN OF T_S_WERKS,

    WERKS TYPE T001W-WERKS,   "

    NAME1 TYPE T001W-NAME1,   "

    NAME2 TYPE T001W-NAME2,   "2

    STRAS TYPE T001W-STRAS,   "/-

    ORT01 TYPE T001W-ORT01,   "

 END OF T_S_WERKS.

TYPES T_I_WERKS TYPE STANDARD TABLE OF T_S_WERKS.

*value_tab

DATA   L_IT_WERKS TYPE T_I_WERKS.

PARAMETERS: P_WERKS(4) TYPE C.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_WERKS.

*AT SELECTION-SCREEN ON HELP-REQUEST FOR .

*

 SELECT WERKS    "

         NAME1    "

         NAME2    " 2

         STRAS    "/-

         ORT01    "

    FROM T001W

    INTO CORRESPONDING FIELDS OF TABLE L_IT_WERKS.

*

 CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

      RETFIELD               = 'WERKS'    "plant

      DYNPPROG               = SY-REPID   "

      DYNPNR                 = SY-DYNNR   "

      DYNPROFIELD            = 'P_WERKS'    "

      VALUE_ORG              = 'S'        "cell by cell

    TABLES

      VALUE_TAB              = L_IT_WERKS

    EXCEPTIONS

      PARAMETER_ERROR        = 1

      NO_VALUES_FOUND        = 2

      OTHERS                 = 3

            .

 IF SY-SUBRC <> 0.

     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

Function: READ_TEXT/CREATE_TEXT
  
功能:读取长文本 / 创建长文本
  
参数:
  Import

    CLIENT
:集团
    ID
:文本 ID TTXID 中定义)
    LANGUAGE
:语言
    NAME
:文本名字()
    OBJECT
:文本对象( TTXOB 中定义)
  Export

    HEADER
:文本的描述信息
  Tables

    LINES
:文本内容

例子:读取销售订单头文本
     CALL FUNCTION 'READ_TEXT'
        EXPORTING
          ID                      = ‘Y001’
          LANGUAGE                = SY-LANGU
          NAME                    = ‘385’
          OBJECT                  = ‘VBBK’
        TABLES
          LINES                   = L_IT_LINES
        EXCEPTIONS
          ID                      = 1
          LANGUAGE                = 2
          NAME                    = 3
          NOT_FOUND               = 4
          OBJECT                  = 5
          REFERENCE_CHECK         = 6
          WRONG_ACCESS_TO_ARCHIVE = 7
          OTHERS                  = 8.

Function: CONVERSION_EXIT_CUNIT_OUTPUT
  
功能:根据语言决定单位的显示
  
参数:
    Import

      INPUT
:内部单位显示方式
      LANGUAGE
:语言代码
    Export

      LONG_TEXT
:单位的长文本
      OUTPUT
:外部单位显示方式
      SHORT_TEXT
:单位的短文本

例子:单位显示转换
      CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
      EXPORTING
        INPUT          = ‘ST’
        LANGUAGE       = SY-LANGU
      IMPORTING
        OUTPUT         = L_OUT
      EXCEPTIONS
        UNIT_NOT_FOUND = 1
        OTHERS         = 2.

Function: SJIS_DBC_TO_SBC
  
功能:全角转换为半角
  
参数:
    Import

      ALL
:全部转换
      ALPHABET_UPPER
A-Z 转换
      ALPHABET_LOWER
a-z 转换
      NUMERIC
0-9 转换
    Export

      CONVERTED
:转换的字符个数
    Changing

      TEXT
:转换结果
Function: SJIS_SBC_TO_DBC
  
功能:半角转换为全角
  
参数:
    Import

      ALL
:全部转换
      ALPHABET_UPPER
A-Z 转换
      ALPHABET_LOWER
a-z 转换
      NUMERIC
0-9 转换
    Export

      CONVERTED
:转换的字符个数
    Changing

      TEXT
:转换结果

Function: CO_R0_CHECK_DECIMAL_POINT
  
功能:根据单位检查数据的小数位
  
参数:
    Import

      I_QUANTITY
:数量
      I_UNIT
:单位
  
例子:下面的例子会返回错误信息,以为单位 ST 是不能有小数位的。
        CALL FUNCTION 'CO_R0_CHECK_DECIMAL_POINT'
          EXPORTING
            I_QUANTITY       = 3.2
            I_UNIT           =‘ST’
          EXCEPTIONS
            WRONG_DATA       = 1
            OTHERS           = 2.  

Function: POSTAL_CODE_CHECK
  
功能:检查邮政编码
  
参数:
    Import

      COUNTRY
:国家( T005 ---------- 必输
      ONE_TIME_ACCOUNT
:不明确
      POSTAL_CODE
:邮政编码
      POSTAL_CODE_PO_BOX
:没用过,以下为推测:如果输入则会检查,如果 t005 表中的 XPLPF 设置了,那么如果输入 PO_BOX ,这个选项就必须输入。
       PO_BOX
:没用过
       REGION
:区域
    Export

      POSTAL_CODE
:邮编
      EV_POSTAL_CODE
:邮编的格式
      EV_POSTAL_CODE_PO_BOX
:没用过
例子:检查输入的邮编是否有效
        CALL FUNCTION 'POSTAL_CODE_CHECK'
          EXPORTING
            COUNTRY                     = 'JP'
            POSTAL_CODE                 = L_WA_DISP-POST_CODE1
          EXCEPTIONS
            NOT_VALID                   = 1
            OTHERS                      = 2

每天函数讲解系列 ----2006.01.12

 

Funtion CONVERSION_EXIT_ALPHA_INPUT
  
功能:全数字则在前面补 0
  
参数:
    Import

      INPUT
:输入的字符串
    Export

      OUTPUT
:输出的字符串

Funtion CONVERSION_EXIT_ALPHA_INPUT
  
功能:和上面相反


Funtion GET_JOB_RUNTIME_INFO
  
功能:获得 job 相关信息
  
参数:
    Export

     EVENTID
:后台处理的事件 id
     EVENTPARM
:后台事件的参数(例如, job id job 名字)
     TERNAL_PROGRAM_ACTIVE
:没用过
     JOBCOUNT
job id
     JOBNAME
job 名称

Funtion TERMINAL_ID_GET
  
功能:获得端末 id
  
参数:
    Import

      USERNAME
:用户名
    Export

      TERMINAL
terminal id

Funtion DATE_CONVERT_TO_FACTORYDATE
  
功能:把输入日期转为工厂日历日期
  
参数:
    Import

      CORRECT_OPTION
:表示工作日计算方式的标记   
      DATE
:必须转化为工厂日历日期的日期   
      FACTORY_CALENDAR_ID
:工厂日历 ID    
    Export

      DATE
:必须转化为工厂日历日期的日期     
      FACTORYDATE
:指定日历中的工作日数       
      WORKINGDAY_INDICATOR
:表示某日期是否为工作日的标志         

例子:
DATA: DATE1        LIKE SCAL-DATE,
      DATE2        LIKE SCAL-DATE,
      CORRECTION   LIKE SCAL-INDICATOR,
      CALENDAR     LIKE SCAL-FCALID,
      FACTORYDATE  LIKE SCAL-FACDATE,
      WORKDAY      LIKE SCAL-INDICATOR.
      CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
           EXPORTING  DATE                 = DATE1
                       CORRECT_OPTION       = CORRECTION
                       FACTORY_CALENDAR_ID  = CALENDAR
           IMPORTING  DATE                 = DATE2
                       FACTORYDATE          = FACTORYDATE
                       WORKINGDAY_INDICATOR = WORKDAY
           EXCEPTIONS CORRECT_OPTION_INVALID     = 1
                        DATE_AFTER_RANGE           = 2
                       DATE_BEFORE_RANGE          = 3
                       DATE_INVALID               = 4
                       FACTORY_CALENDAR_NOT_FOUND = 5.

Funtion MESSAGE_TEXT_BUILD
  
功能:把消息转为文本
  
参数:
    Import

      MSGID
:消息 id
      MSGNR
:消息号
      MSGV1
:参数 1
      MSGV2
:参数 2
      MSGV3
:参数 3
      MSGV4
:参数 4
    Export

      MESSAGE_TEXT_OUTPUT
:输出的字符串
  
说明:可以用 write <message> to <text> 代替。

每天函数讲解系列 ----2006.01.16

 

Function: POPUP_TO_CONFIRM
Group
SPO1
  
功能:弹出确认窗口
  
参数:
    Import

      TITLEBAR
:弹出窗口的标题,最多 40
      TEXT_QUESTION
:问题,最长 80 位,多出来的截断
      TEXT_BUTTON_1
:第一按钮的 text ,最长 8
      ICON_BUTTON_1
:第一按钮显示的 icon
      TEXT_BUTTON_2
:第二按钮的 text ,最长 8
      ICON_BUTTON_2
:第二按钮显示的 icon
      DEFAULT_BUTTON
:默认的按钮
      DISPLAY_CANCEL_BUTTON
:是否显示取消
      POPUP_TYPE
:弹出的类型: 决定显示的 icon
         ICON_MESSAGE_QUESTION
:问题
          ICON_MESSAGE_INFORMATION
:信息
          ICON_MESSAGE_WARNING
:警告
          ICON_MESSAGE_ERROR
:错误
          ICON_MESSAGE_CRITICAL
:冲突
      START_COLUMN
:弹出位置:列
      START_ROW
:弹出位置:行
      IV_QUICKINFO_BUTTON_1
:第一按钮的显示信息(鼠标放上去后看到的)
      IV_QUICKINFO_BUTTON_2
:第二按钮的显示信息(鼠标放上去后看到的)
    Export

      ANSWER
:返回点击的按钮
        '1'
:第一个按钮
         '2'
:第二个按钮
         'A'
:取消按钮

每天函数讲解系列 ----2006.01.20

 

物料号码转换函数 , 上传文件时可能会用到

1.CONVERSION_EXIT_MATN1_INPUT

    EXPORTING    

      INPUT = ' 要转换的物料号 '

    IMPORTING

      OUTPUT = ' 转换后的内部使用的物料号 '.

   比如输入 123456, 输出 000000000000123456

2.CONVERSION_EXIT_MATN1_OUTPUT.

   作用同上面相反 , 用法较简单 , 就不说了

 call function 'CONVERT_TO_LOCAL_CURRENCY'      " 按照指定日期汇率转换金额为指定货币类型
          exporting
            DATE             = T_EKKO-BEDAT   "
日期
            FOREIGN_AMOUNT   = T_DATA-NETPR   "
待转换金额
            FOREIGN_CURRENCY = WAERS          "
当前货币单位
            LOCAL_CURRENCY   = 'USD'          "
目标货币
          importing
            LOCAL_AMOUNT     = T_DATA-NETPR.  "
转换后金额
      endif.

 call function 'SSF_FUNCTION_MODULE_NAME'      " 根据 form 名取得对应的函数名 (SmartForm)
    exporting
      FORMNAME           = 'ZFI_06'                "Form

    importing
      FM_NAME            = FUNC_MODULE_NAME        "
返回函数名
    exceptions
      NO_FORM            = 1
      NO_FUNCTION_MODULE = 2
      others             = 3.

由于开发机上开发 smartform 传入生产机后有可能会改变其函数名 , 所以在调用 smartform 前使用这个函数

每天函数讲解系列 ----2006.01.23

 

DATE_CHECK_PLAUSIBILITY 日期 CHECK


  CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
    EXPORTING
      date                      = i_date
    EXCEPTIONS
      plausibility_check_failed = 1
      OTHERS                    = 2.

cl_gui_frontend_services=>gui_upload   上传到服务器

  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = l_filename
      filetype                = i_filetype
      has_field_separator     = i_separator
*      HEADER_LENGTH           = 0
*      DAT_MODE                = SPACE
*      CODEPAGE                = SPACE
*      IGNORE_CERR             = ABAP_TRUE
*      REPLACEMENT             = '#'
*      READ_BY_LINE            = 'X'
*    IMPORTING
*      FILELENGTH              =
*      HEADER                  =
    CHANGING
      data_tab                = o_tab_table
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      not_supported_by_gui    = 17
      error_no_gui            = 18
      OTHERS                  = 19.

cl_gui_frontend_services=>gui_download   下载到服务器

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
*      BIN_FILESIZE              =
      filename                  = l_filename
      filetype                  = i_filetype
*      APPEND                    = SPACE
      write_field_separator     = i_separator
*      HEADER                    = '00'
*      TRUNC_TRAILING_BLANKS     = SPACE
*      WRITE_LF                  = 'X'
*      COL_SELECT                = SPACE
*      COL_SELECT_MASK           = SPACE
*      DAT_MODE                  = SPACE
*      CONFIRM_OVERWRITE         = SPACE
*      NO_AUTH_CHECK             = SPACE
*      CODEPAGE                  = SPACE
*      IGNORE_CERR               = ABAP_TRUE
*      REPLACEMENT               = '#'
*      WRITE_BOM                 = SPACE
*      TRUNC_TRAILING_BLANKS_EOL = 'X'
*    IMPORTING
*      FILELENGTH                =
    CHANGING
      data_tab                  = o_tab_table[]
    EXCEPTIONS
      file_write_error          = 1
      no_batch                  = 2
      gui_refuse_filetransfer   = 3
      invalid_type              = 4
      no_authority              = 5
      unknown_error             = 6
      header_not_allowed        = 7
      separator_not_allowed     = 8
      filesize_not_allowed      = 9
      header_too_long           = 10
      dp_error_create           = 11
      dp_error_send             = 12
      dp_error_write            = 13
      unknown_dp_error          = 14
      access_denied             = 15
      dp_out_of_memory          = 16
      disk_full                 = 17
      dp_timeout                = 18
      file_not_found            = 19
      dataprovider_exception    = 20
      control_flush_error       = 21
      not_supported_by_gui      = 22
      error_no_gui              = 23
      OTHERS                    = 24.

SSF_FUNCTION_MODULE_NAME  

SMARTFORMS 输出报表时,生成一个函数名称,然后 CALL 这个名称

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME           = CNS_SMART          "SMARTFORMS
の名称
    IMPORTING
      FM_NAME            = W_FMNAME           "SMARTFORMS
の名称
    EXCEPTIONS
      NO_FORM            = 1
      NO_FUNCTION_MODULE = 2
      OTHERS             = 3.

*  CALL FUNCTION W_FMNAME
*    TABLES
*      I_HEAD           = I_HEAD          
*    EXCEPTIONS
*      FORMATTING_ERROR = 1
*      INTERNAL_ERROR   = 2
*      SEND_ERROR       = 3
*      USER_CANCELED    = 4
*      OTHERS           = 5.
GRAPH_MATRIX_3D  
把数据生成柱状 3D

TIME_CHECK_PLAUSIBILITY   判断是不是时间

每天函数讲解系列 ----2006.02.11

 

Funtion POPUP_TO_DECIDE_LIST  
  
功能:弹出供选择窗口,最多 25 个选项,选择可以是单选按钮也可以是复选按钮,可以设定最多选择的个数。
  
参数:
    Import

      CURSORLINE  
:默认光标所在行
      MARK_FLAG
:选择的标志,一般设为 ‘X’
      MARK_MAX
最大选择的选项个数
      START_COL
:起始行
      START_ROW  
:起始列,用来定位弹出窗口的位置
      TEXTLINE1
:文本行
      TEXTLINE2
:文本行
      TEXTLINE3
:文本行
      TITEL
:弹出窗口的标题
      DISPLAY_ONLY
:仅显示
    Export

      ANSWER
A :取消    空:做了选择
    Tables

      T_SPOPLI
:选择结果

例子:
REPORT  Z_BOBO                                  .
*
定义函数需要的变量
DATA: BEGIN OF SPOPLIST OCCURS 15.
          INCLUDE STRUCTURE SPOPLI.
  DATA: END   OF SPOPLIST.
  DATA: ANTWORT TYPE C.
*
添加选择参数
  SPOPLIST-VAROPTION = 'Creditor'.
  APPEND SPOPLIST.
  SPOPLIST-VAROPTION = 'Material'.
  APPEND SPOPLIST.
  SPOPLIST-VAROPTION = 'Account '.
  SPOPLIST-SELFLAG   = 'X'.

  CALL FUNCTION 'POPUP_TO_DECIDE_LIST'
     EXPORTING  TITEL            = 'Possible entra: Order'
               TEXTLINE1        = 'By which criteria'
               TEXTLINE2        = 'should orders'
               TEXTLINE3        = 'be selected?'
               MARK_MAX         = 2
               MARK_FLAG        = 'X'
    IMPORTING  ANSWER           = ANTWORT
    TABLES     T_SPOPLI         = SPOPLIST
    EXCEPTIONS TOO_MUCH_ANSWERS = 1
               TOO_MUCH_MARKS   = 2.

  IF SY-SUBRC = 2.
    WRITE: 'Too many answers chosen.'.
  ENDIF.
*
取消
  IF ANTWORT = 'A'.
    WRITE: 'Popup canceled.'.
  ELSE.
    WRITE: 'Options chosen:'.
    LOOP AT SPOPLIST WHERE SELFLAG = 'X'.
      WRITE: / SPOPLIST-VAROPTION.
    ENDLOOP.
  ENDIF.

每天函数讲解系列 ----2006.02.13

 

Funtion DDIF_FIELDINFO_GET  
  
功能:获得字段的相关信息
  
参数:
    Import

      TABNAME
:数据库表的名字
      FIELDNAME
:无需指定,由 LFIELDNAME 代替了
      LANGU
语言设定,默认 sy-langu
      LFIELDNAME
:指定关联字段
      ALL_TYPES
:是否指定所有类型
      GROUP_NAMES
:是否包含 include 的字段
      UCLEN
:没用过,应该是和 unicode 相关的
    Export

      X030L_WA
:返回表头的信息
      DDOBJTYPE
:表类型
        'TRANSP'   = transparent table
        'POOL'     = logical pooled table
        'CLUSTER'  = logical cluster table
        'VIEW'     = database or projection view
        'INTTAB'   = structure, help view, maintenance view or structure view
        'TPOOL'    = physical pooled table
        'TCLUSTER' = physical cluster table
        'DTEL'     = data element
        'TTYP'     = table type
      DFIES_WA
:没用过
      LINES_DESCR
:没用过
    Tables

      DFIES_TAB
:字段列表
      FIXED_VALUES
:域的固定值

   说明:该函数可用来获得某个表或者结构或者视图等所有字段的相关信息,所以如果想用 alv 来维护某个表的时候,对设定 field catalog 有帮助。

Funtion DDIF_NAMETAB_GET    
  
功能:获得字段的相关信息 ( 不包含 text)
  
参数:
    Import

      TABNAME
:数据库表的名字
      LFIELDNAME
:指定关联字段
      ALL_TYPES
:是否指定所有类型
      GROUP_NAMES
:是否包含 include 的字段
      UCLEN
:没用过,应该是和 unicode 相关的
    Export

      X030L_WA
:返回表头的信息
      DTELINFO_WA
data element 的信息
      TTYPINFO_WA
:表类型的信息
      DDOBJTYPE
:表类型
        'TRANSP'   = transparent table
        'POOL'     = logical pooled table
        'CLUSTER'  = logical cluster table
        'VIEW'     = database or projection view
        'INTTAB'   = structure, help view, maintenance view or structure view
        'TPOOL'    = physical pooled table
        'TCLUSTER' = physical cluster table
        'DTEL'     = data element
        'TTYP'     = table type
      DFIES_WA
:没用过
      LINES_DESCR
:没用过
    Tables

      DFIES_TAB
:字段列表
      FIXED_VALUES
:域的固定值

Funtion DDIF_NAMETAB_GET    
  
功能:获得字段的相关信息 ( 不包含 text)
  
参数:
    Import

      TABNAME
:数据库表的名字
      LFIELDNAME
:指定关联字段
      ALL_TYPES
:是否指定所有类型
      GROUP_NAMES
:是否包含 include 的字段
      UCLEN
:没用过,应该是和 unicode 相关的
    Export

      X030L_WA
:返回表头的信息
      DTELINFO_WA
data element 的信息
      TTYPINFO_WA
:表类型的信息
      DDOBJTYPE
:表类型
        'TRANSP'   = transparent table
        'POOL'     = logical pooled table
        'CLUSTER'  = logical cluster table
        'VIEW'     = database or projection view
        'INTTAB'   = structure, help view, maintenance view or structure view
        'TPOOL'    = physical pooled table
        'TCLUSTER' = physical cluster table
        'DTEL'     = data element
        'TTYP'     = table type
      DFIES_WA
:没用过
      LINES_DESCR
:没用过
    Tables

      DFIES_TAB
:字段列表
      FIXED_VALUES
:域的固定值

每天函数讲解系列 ----2006.02.14

 

Function: CLOI_PUT_SIGN_IN_FRONT
  
功能:将负号提前
  
参数:
    Changing

      VALUE
:需要负号提前的变量

Function: CLOI_PUT_SIGN_IN_FRONT
  
功能:将负号提前
  
参数:
    Changing

      VALUE
:需要负号提前的变量

Function: BAPI_COMPANYCODE_GET_PERIOD
  
功能:获得公司的会计年度以及过账日期
  
参数:
    Import

      COMPANYCODEID
:公司代码
      POSTING_DATE
posting date
    Export

      FISCAL_YEAR
:会计年度
      FISCAL_PERIOD
:财务期间
      RETURN
:返回值
  
说明:该函数可用来检查会计期间

Function: MARA_SINGLE_READ
  
功能:读取物料信息
  
参数:
    Import

      KZRFB
Indicator: Refresh buffer entry
      MAXTZ
Max. no. of entries in buffer (这两个参数应该和性能优化相关)
      MATNR
:物料号
      SPERRMODUS
Lock mode (none, shared, excl.)
      STD_SPERRMODUS
Standard lock mode (if different) (锁相关)
      OUTPUT_NO_MESSAGE
:是否输出消息
    Export

      WMARA
:返回的物料信息
  
说明:该函数可用于性能优化,例如无法避免在 loop 中有 sql 的情况可以用该函数取代 sql
        
mara 的其它操作参考 function group MG21

Function: KNA1_SINGLE_READ
  
功能:读取 customer 表信息
  
参数:
    Import

      KZRFB
Indicator: Refresh buffer entry
      KNA1_KUNNR
customer code
    Export

      WKNA1
:返回的信息
  
说明:还有很多表的读取参考 function group MG41

Function: ADDR_GET_COMPLETE_ALL_TYPES
  
功能:获得地址的相关信息
  
参数:
    Import

      ADDRNUMBER
address number
      PERSNUMBER
:个人信息
      ADDRESS_OBJECT_TYPE
:类型 1 :组织 2 :个人 3 :客户
    Export

      ADDR1_COMPLETE
:地址 1
      ADDR2_COMPLETE
:地址 2
      ADDR3_COMPLETE
:地址 3
      ADDR1_COMPLETE_BAPI
:地址 1
      ADDR2_COMPLETE_BAPI
:地址 2
      ADDR3_COMPLETE_BAPI
:地址 3 (以上三个 bapi 用)

Function: READ_VBFA
  
功能:取得 document flow (省得 select 了)
  
参数:
    Import

      I_VBELV
Preceding sales and distribution document
      I_POSNV
Preceding item of an SD document
      I_VBTYP_V
Document category of preceding SD document
      I_VBTYP_N
Document category of subsequent document
      I_FKTYP
Billing category
      I_BYPASSING_BUFFER
:是否用 buffer
      I_REFRESH_BUFFER
:删除 buffer
    Tables

      E_VBFA
:凭证流的表
  
说明:可以通过 by passing buffer 来优化性能

Function: LIKP_READ
  
功能: Delivery Header Data
  
参数:
    Import

      I_VBELN
Delivery
      LINE_EXIST
if 'x' check only if line exsists
    Export

      O_ANSWR
send out 'x' for line exsists in table
    Tables

      E_LIKP
SD Document: Delivery Header Data
  
说明:有关读取 delivery 的信息请参考 function group LMGT

每天函数讲解系列 ----2006.02.15

 

Convert currency value from SAP to display


The following code shows how CURRENCY_AMOUNT_SAP_TO_DISPLAY can be used. You pass it a
Currecny code(WAERS) and an SAP stored currency value. It will convert the value into its correct currecny
value. Without using this function module you are not guaranteed to be using the correct value as it is often
missing a number of zeroes.
                        I.e. 28000 JPY is stored within SAP as 280.  

* DATA declaration
*-----------------
* WMTO_S-AMOUNT =  Type DEC :: length 15 :: Deciamls 4

parameter: p_discur like TCURC-WAERS,     "Display currency
           p_intval like WMTO_S-AMOUNT.   "Internal Amount

data:      gd_disval  like WMTO_S-AMOUNT. "Display Amount


************************************************************************
*Start-of-selection.

START-OF-SELECTION.
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
     EXPORTING
          currency        = p_discur
          amount_internal = p_intval
    IMPORTING
         AMOUNT_DISPLAY   = gd_disval
    EXCEPTIONS
         INTERNAL_ERROR   = 1
         OTHERS           = 2.

IF sy-subrc EQ 0.
*  You are now able to manipulate the returned value.
*                         I.e. Convert it to GBP    

*  Without using this function module you would only be manipulating the
*  SAP stored value, which is often missing a number of zeroes.
*       I.e. 28000 JPY is stored within SAP as 280.
          
ENDIF.


************************************************************************
*End-of-selection.

END-OF-SELECTION.

write:/(30)  'Value stored in SAP:', p_intval,
      /(30)  'Displayed currency:',  p_discur,
      /(30)  'Ammount is displayed Currency:', gd_disval.

Convert currency value from display to SAP

The following code shows how CURRENCY_AMOUNT_DISPLAY_TO_SAP can be used. You pass it a
Currecny code(WAERS) and the displayed currency value. It will convert the value so that it can be stored
in SAP. Without using this function module the value stored in SAP is not guaranteed to be correct.
                        I.e. 28000 JPY is stored within SAP as 280.

*Data declaration
*------------
* WMTO_S-AMOUNT =  Type DEC :: length 15 :: Deciamls 4

parameter: p_curr   like TCURC-WAERS,     "Display currency
           p_disval like WMTO_S-AMOUNT.  "Internal Amount

data:      gd_intval  like WMTO_S-AMOUNT. "Display Amount


CALL FUNCTION 'CURRENCY_AMOUNT_DISPLAY_TO_SAP'
     EXPORTING
          currency        = p_curr
          amount_display  = p_disval
    IMPORTING
          AMOUNT_INTERNAL = gd_intval
    EXCEPTIONS
          INTERNAL_ERROR  = 1
          OTHERS          = 2
          .
IF sy-subrc <> 0.

* You are now able to store the return value into an SAP table.

ENDIF.


************************************************************************
*Start-of-selection.

START-OF-SELECTION.

write:/(30)  'Value Displayed on screen in SAP:', p_disval,
      /(30)  'Currency:',  p_curr,
      /(30)  'Internal SAP value', gd_intval.

Retrieve fiscal year and period

 

The below code shows how to use function modules

BAPI_COMPANYCODE_GET_PERIOD and DETERMINE_PERIOD to retrieve fiscal year and fiscal period for a specific date.

*.......................................................................
*: Report:  ZFISCALYR                                                  :
*:                                                                     :
*: Author:  www.SAPdev.co.uk                                           :
*:                                                                     :
*: Date  :  2004                                                       :
*:                                                                     :
*: Description: Demonstrates how to return the corresponding fiscal    :
*:              year and posting period for a company code and posting :
*:              date or posting date and fiscal year variant.          :
*:.....................................................................:

REPORT  zfiscalyr NO STANDARD PAGE HEADING.

TABLES: ekko.

PARAMETERS:     p_bukrs TYPE ekko-bukrs,
                p_bedat TYPE ekko-bedat.

DATA: gd_fiscalyr  TYPE bapi0002_4-fiscal_year,
      gd_fiscalp   TYPE bapi0002_4-fiscal_period.
DATA: gd_fiscalyr2 TYPE T009B-BDATJ,
      gd_fiscalp2  TYPE bapi0002_4-fiscal_period.

DATA: gd_periv     TYPE t009-periv.

************************************************************************
*START-OF-SELECTION.

START-OF-SELECTION.

* get fiscal year and period - (requires date and company code)
  CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
    EXPORTING
      companycodeid = p_bukrs
      posting_date  = p_bedat
    IMPORTING
      fiscal_year   = gd_fiscalyr
      fiscal_period = gd_fiscalp.



* Alternative fiscal year function module
* - (requires date and fiscal year variant code from T009 table)
*--------------------------------------------------------------------

* gets first entry in fiscal year variant table (will need to choose
* correct one from table rather than just using first entry)

  SELECT SINGLE periv
    FROM t009
    INTO gd_periv.

* get fiscal year and period
  CALL FUNCTION 'DETERMINE_PERIOD'
    EXPORTING
      date                      = p_bedat
*    PERIOD_IN                 = '000'
      version                   = gd_periv
   IMPORTING
      period                    = gd_fiscalp2
      year                      = gd_fiscalyr2
   EXCEPTIONS
      period_in_not_valid       = 1
      period_not_assigned       = 2
      version_undefined         = 3
      OTHERS                    = 4.


************************************************************************
*END-OF-SELECTION.

END-OF-SELECTION.
  WRITE:/ 'From function module: BAPI_COMPANYCODE_GET_PERIOD',
        / 'Fiscal year is:', gd_fiscalyr,
        / 'Fiscal period is:', gd_fiscalp.
  SKIP.

WRITE:/ 'From function module: DETERMINE_PERIOD',
        / 'Fiscal year is:', gd_fiscalyr2,
        / 'Fiscal period is:', gd_fiscalp2.

 

一个将数字金额转换为中文大写金额的程序

FUNCTION z_rmbdx.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(RMBXX) LIKE  BSEG-WRBTR
*"  CHANGING
*"     REFERENCE(RMBDX1) TYPE  C
*"----------------------------------------------------------------------
DATA: BEGIN OF rmb,
    by TYPE c,
    sy TYPE c,
    y TYPE c,
    qw TYPE c,
    bw TYPE c,
    sw TYPE c,
    w TYPE c,
    q TYPE c,
    b TYPE c,
    s TYPE c,
    g TYPE c,
    d TYPE c,
    j TYPE c,
    f TYPE c,
    n TYPE c,
    END OF rmb.
DATA: BEGIN OF rmbdx,
    by(2) TYPE c,
    by1(4) TYPE c,
    sy(2) TYPE c,
    sy1(4) TYPE c,
    y(2) TYPE c,
    y1(2) TYPE c,
    qw(2) TYPE c,
    qw1(4) TYPE c,
    bw(2) TYPE c,
    bw1(4) TYPE c,
    sw(2) TYPE c,
    sw1(4) TYPE c,
    w(2) TYPE c,
    w1(4) TYPE c,
    q(2) TYPE c,
    q1(4) TYPE c,
    b(2) TYPE c,
    b1(4) TYPE c,
    s(2) TYPE c,
    s1(4) TYPE c,
    g(2) TYPE c,
    d(2) TYPE c,
    j(2) TYPE c,
    j1(2) TYPE c,
    f(2) TYPE c,
    f1(2) TYPE c,
    z(2) TYPE c,
    END OF rmbdx.

DATA: y(1) TYPE c.

rmb = rmbxx.
IF NOT ( rmb-by IS INITIAL ) AND rmb-by NE '0'.
PERform dx USING rmb-by CHANGING rmbdx-by.
y = 'X'.
IF rmb-by NE '0'.
  IF rmb-sy EQ '0' AND rmb-y EQ '0'.
    rmbdx-by1 = '
佰亿 '.
  ELSE.
    rmbdx-by1 = '
'.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-sy IS INITIAL ).
IF rmb-sy NE '0' OR rmb-y NE '0'.
  PERform dx USING rmb-sy CHANGING rmbdx-sy.
  y = 'X'.
  IF rmb-sy NE '0'.
    IF rmb-y EQ '0'.
      rmbdx-sy1 = '
拾亿 '.
    ELSE.
      rmbdx-sy1 = '
'.
    ENDIF.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-y IS INITIAL ).
IF rmb-y NE '0' OR rmb-qw NE '0'.
  PERform dx USING rmb-y CHANGING rmbdx-y.
  y = 'X'.
  IF rmb-y NE '0'.
    rmbdx-y1 = '
亿 '.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-qw IS INITIAL ).
IF rmb-qw NE '0' OR rmb-bw NE '0'.
  PERform dx USING rmb-qw CHANGING rmbdx-qw.
  y = 'X'.
  IF rmb-qw NE '0'.
    IF rmb-bw EQ '0' AND rmb-sw EQ '0' AND rmb-w EQ '0'.
      rmbdx-qw1 = '
仟万 '.
    ELSE.
      rmbdx-qw1 = '
'.
    ENDIF.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-bw IS INITIAL ).
IF rmb-bw NE '0' OR rmb-sw NE '0'.
  PERform dx USING rmb-bw CHANGING rmbdx-bw.
  y = 'X'.
  IF rmb-bw NE '0'.
    IF rmb-sw EQ '0' AND rmb-w EQ '0'.
      rmbdx-bw1 = '
佰万 '.
    ELSE.
      rmbdx-bw1 = '
'.
    ENDIF.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-sw IS INITIAL ).
IF rmb-sw NE'0' OR rmb-w NE '0'.
  PERform dx USING rmb-sw CHANGING rmbdx-sw.
  y = 'X'.
  IF rmb-sw NE '0'.
    IF rmb-w EQ '0'.
      rmbdx-sw1 = '
拾万 '.
    ELSE.
      rmbdx-sw1 = '
'.
    ENDIF.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-w IS INITIAL ).
IF rmb-w NE '0' OR rmb-q NE '0'.
  PERform dx USING rmb-w CHANGING rmbdx-w.
  y = 'X'.
  IF rmb-w NE '0'.
    rmbdx-w1 = '
'.
  ENDIF.

ENDIF.
ENDIF.
IF NOT ( rmb-q IS INITIAL ).
IF rmb-q NE '0' OR rmb-b NE '0'.
  PERform dx USING rmb-q CHANGING rmbdx-q.
  y = 'X'.
  IF rmb-q NE '0'.
    rmbdx-q1 = '
'.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-b IS INITIAL ).
IF rmb-b NE '0' OR rmb-s NE '0'.
  PERform dx USING rmb-b CHANGING rmbdx-b.
  y = 'X'.
  IF rmb-b NE '0'.
    rmbdx-b1 = '
'.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-s IS INITIAL ).
IF rmb-s NE'0' OR rmb-g NE '0'.
  PERform dx USING rmb-s CHANGING rmbdx-s.
  y = 'X'.
  IF rmb-s NE '0'.
    rmbdx-s1 = '
'.
  ENDIF.
ENDIF.
ENDIF.
IF NOT ( rmb-g IS INITIAL ) AND rmb-g NE '0'.
PERform dx USING rmb-g CHANGING rmbdx-g.
y = 'X'.
ENDIF.
IF y EQ 'X'.
rmbdx-d = '
'.
ENDIF.
IF NOT ( rmb-j IS INITIAL ) AND rmb-j NE '0'.
PERform dx USING rmb-j CHANGING rmbdx-j.
rmbdx-j1 = '
'.
ENDIF.
IF NOT ( rmb-f IS INITIAL ) AND rmb-f NE '0'.
PERform dx USING rmb-f CHANGING rmbdx-f.
rmbdx-f1 = '
'.
ELSE.
rmbdx-z = '
'.
ENDIF.
CONDENSE rmbdx NO-GAPS.
IF rmbxx = 0.
CLEAR rmbdx.
ENDIF.
rmbdx1 = rmbdx.
CLEAR y.
ENDFUNCTION.

*---------------------------------------------------------------------*
*       form dx                                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  value(X)                                                      *
*  -->  DXX                                                           *
*---------------------------------------------------------------------*
form dx USING value(x) CHANGING dxx.
CASE x.
WHEN '0'.
  dxx = '
'.
WHEN '1'.
  dxx = '
'.
WHEN '2'.
  dxx = '
'.
WHEN '3'.
  dxx = '
'.
WHEN '4'.
  dxx = '
'.
WHEN '5'.
  dxx = '
'.
WHEN '6'.
  dxx = '
'.
WHEN '7'.
  dxx = '
'.
WHEN '8'.
  dxx = '
'.
WHEN '9'.
  dxx = '
'.
ENDCASE.
ENDform.

运行该程序前还需定义以下文本段 :
001:

002:

003:

004:

005:

006:

007:

008:

009:

010:

011:

012:

013:

014:

015:

016:

017:


REPORT ZYESE04 .

parameters : p_test type p.
data: result type string,
     test type p.

start-of-selection.
 test = p_test.
 perform select_translate.

end-of-selection.

top-of-page.

end-of-page.


*&---------------------------------------------------------------------*
*&      form  select_translate
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form select_translate.

 data length type i.
 data index type i value '0'.
 data temp type p.
 data temp_s type string.
 data temp_r type i.
 data index_times type i.
 data flag1 type i value '1'.
 data flag2 type i value '1'.
 data flag3 type i value '1'.
 data flag4 type i value '1'.
 data flag5 type i value '1'.
 data flag6 type i value '1'.
 data flag7 type i value '1'.
 data flag8 type i value '1'.
 data flag9 type i value '1'.



 temp = test.
 temp_s = temp.

 length = strlen( temp_s ) - 1.

 do length times.
   index = index + 1.
   index_times = length - index + 1.
   do index_times times.
     temp_r = temp mod 10.
     if sy-index = index_times.
       case index.
         when '1'.
           if temp_r <> '0'.
             concatenate text-013 result into result.
           endif.
         when '2'.
           if temp_r <> '0'.
             concatenate text-012 result into result.
           endif.
         when '3'.
           concatenate text-011 result into result.
         when '4'.
           if temp_r <> '0'.
             concatenate text-014 result into result.
           endif.
         when '5'.
           if temp_r <> '0'.
             concatenate text-015 result into result.
           endif.
         when '6'.
           if temp_r <> '0'.
             concatenate text-016 result into result.
           endif.
         when '7'.
           concatenate text-017 result into result.
         when '8'.
           if temp_r <> '0'.
             concatenate text-014 result into result.
           endif.
         when '9'.
           if temp_r <> '0'.
             concatenate text-015 result into result.
           endif.
         when '10'.
           if temp_r <> '0'.
             concatenate text-016 result into result.
           endif.
       endcase.

       case temp_r.
         when '0'.
           case index.
             when '1'.
               flag1 = 0.
             when '2'.
               flag2 = 0.
               if flag1 = '1'.
                 concatenate text-010 result into result.
               endif.
             when '3'.
               flag3 = 0.
             when '4'.
               flag4 = 0.
               if flag3 = '1'.
                 concatenate text-010 result into result.
               endif.
             when '5'.
               flag5 = 0.
               if flag4 = '1'.
                 concatenate text-010 result into result.
               endif.
             when '6'.
               flag6 = 0.
               if flag5 = '1'.
                 concatenate text-010 result into result.
               endif.
             when '7'.
               flag7 = 0.
*                if flag6 = '1'.
*                  concatenate text-010 result into result.
*                endif.
             when '8'.
               flag8 = 0.
               if flag7 = '1'.
                 concatenate text-010 result into result.
               endif.
             when '9'.
               flag9 = 0.
               if flag8 = '1'.
                 concatenate text-010 result into result.
               endif.
           endcase.
         when '1'.
           concatenate text-001 result into result.
         when '2'.
           concatenate text-002 result into result.
         when '3'.
           concatenate text-003 result into result.
         when '4'.
           concatenate text-004 result into result.
         when '5'.
           concatenate text-005 result into result.
         when '6'.
           concatenate text-006 result into result.
         when '7'.
           concatenate text-007 result into result.
         when '8'.
           concatenate text-008 result into result.
         when '9'.
           concatenate text-009 result into result.
       endcase.



     endif.
   enddo.
   temp = temp div 10.
 enddo.
 write :/ test,
              result.
 clear result.
ENDform.                    " select_translate

一个只有 9 句的程序却可更改 SAP 标准程序

REPORT ZMODISAP .
DATA:ITAB_CODE(72) OCCURS 0 WITH HEADER LINE.
***Change client status,under this status,No access key is asked
UPDATE T000
SET CCCATEGORY = 'C'
CCCORACTIV = '2'
CCNOCLIIND = '3'.
*** Modify LSTRDU34
READ REPORT 'LSTRDU34' INTO ITAB_CODE .
INSERT 'SY-SUBRC = 0 .' INTO ITAB_CODE  INDEX 102.
INSERT REPORT 'LSTRDU34'  FROM ITAB_CODE .
*** Modify LSTRDU44
READ REPORT 'LSTRDU44' INTO ITAB_CODE .
INSERT 'SY-SUBRC = 0 .' INTO itab_code  index 101.
INSERT REPORT 'LSTRDU44'  FROM ITAB_CODE .

 

posted @ 2009-07-11 10:26  elegant  阅读(4084)  评论(0编辑  收藏  举报