ABAP 函数

  首页  新闻动态  销售(SD)  物料(MM)  生产(PP)  财务控制(FI/CO)  Basis  ABAP  其它模块  下载  培训与活动  
   SapSky SAP天下 → ABAP  

ABAP 函数
[日期:2007-08-23] 来源:  作者: [字体:大 中 小] 

每日函数讲解---函数列表

2006.01.09 : http://www.100easy.com/dispbbs.asp?boardID=66&ID=17483&page=1

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

2006.01.10: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17538&page=1


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

2006.01.11: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17555&page=1


    函数名                                                           描述                        
    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                      检查邮政编码

2006.01.12: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17597&page=1


    函数名                                       描述                        
    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                    把消息转为文本

2006.01.16: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17639&page=1


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

2006.01.20: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17732&page=1


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

2006.01.23: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17856&page=1


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

2006.02.11: http://www.100easy.com/dispbbs.asp?boardID=66&ID=18065&page=1


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

 

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

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 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 to 代替。

 

每天函数讲解系列----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 .

 

每日函数讲解---函数列表

2006.01.09 : http://www.100easy.com/dispbbs.asp?boardID=66&ID=17483&page=1

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

2006.01.10: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17538&page=1


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

2006.01.11: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17555&page=1


    函数名                                                           描述                        
    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                      检查邮政编码

2006.01.12: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17597&page=1


    函数名                                       描述                        
    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                    把消息转为文本

2006.01.16: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17639&page=1


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

2006.01.20: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17732&page=1


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

2006.01.23: http://www.100easy.com/dispbbs.asp?boardID=66&ID=17856&page=1


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

2006.02.11: http://www.100easy.com/dispbbs.asp?boardID=66&ID=18065&page=1


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

 

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

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 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 to 代替。

 

每天函数讲解系列----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 . 

http://www.sapsky.com/html/2007-08/788.htm

你可能感兴趣的:(SAP-ABAP,function,table,structure,import,date,sap)