12.Program Parameters

12.1 Parameter In SAP Memory

SAP内存是当前应用程序服务器的一个特定于用户的内存区域,用户会话的所有主会话都可以一次访问该内存区域。SPA/GPA parameter定义ID最长为20个字符,存储在SAP内存中。SPA/GPA parameter参数名维护在Table:TPARA中。

语法:

SET PARAMETER ID pid FIELD dobj.

语法:
GET PARAMETER ID pid FIELD dobj.

 

12.2Language Environment

1.Text Pools

Text Pools支持Executable programs;Class pools;Function groups;Module pools;Subroutine pools。

profile parameter :zcsa/second_language,当没有Text Pools时,使用配置;

使用SET LANGUAGE,在执行program时指定语言;

语法:

SET LANGUAGE lang.

lang:在T002表,字段SPRAS维护。

READ TEXTPOOL,获取读取Text Pools,或使用function: SELECTION_TEXTS_MODIFY and SELECTION_TEXTS_DTEL。

示例:

FORM f_program_param.
  DATA:lt_langu LIKE TABLE OF sy-langu.
  DATA:ls_langu LIKE LINE OF lt_langu.
  "获取t002表语言
  SELECT spras FROM t002 INTO TABLE lt_langu.
  LOOP AT lt_langu INTO ls_langu.
    "设置语言
    SET LANGUAGE ls_langu.
    IF sy-subrc = 0.
      WRITE:/ ls_langu, text-010.
    ENDIF.
  ENDLOOP.
ENDFORM. 

2Text Environment

SAP code page维护表:TCP0C

Name

Key

Meaning

PLATFORM

X

Operating system of the application server

LANGU

X

Language key

COUNTRY

X

Country key

MODIFIER

X

Locale key (is not used)

LOCALE

 

Operating system locale

CHARCO

 

SAP code page number

CHARCOMNLS

 

obsolete

语法:

SET LOCALE LANGUAGE lang [obsolete_parameters].

语法:

GET LOCALE LANGUAGE lang [obsolete_parameters].

示例:

"指定code page
FORM f_program_param1.
  DATA:lv_text TYPE c LENGTH 3.
  FIELD-SYMBOLS:<hex> TYPE x.
  "不同编码规则
  ASSIGN lv_text TO <hex> CASTING.
  lv_text = 'äöü'.
  WRITE:/ <hex>.

  SET LOCALE LANGUAGE 'E'.
  TRANSLATE lv_text TO UPPER CASE.
  WRITE:/ <hex>.

  lv_text = 'äöü'.
  SET LOCALE LANGUAGE 'R'.
  TRANSLATE lv_text TO UPPER CASE.
  WRITE:/ <hex>.
  SET LOCALE LANGUAGE ' '.
ENDFORM. 

3Formatting Settings

数字格式,小数点千分符;

日期格式,顺序及符号;

时间格式,12、24小时格式;

CL_ABAP_TIMEFM时间格式帮助类;

配置表Table:T005X,不同country,数字、日期、时间格式设置;

语法:

SET COUNTRY cntry.

指定T005X表配置默认country格式。

数字格式,栏位XDEZP:

XDEZP

Decimal Separator

Thousands Separator

" "

","

"."

X

"."

","

Y

","

" "

日期格式,栏位DATFM:

DATFM

Date Format

"1"

dd.mm.yyyy

"2"

mm/dd/yyyy

"3"

mm-dd-yyyy

"4"

yyyy.mm.dd

"5"

yyyy/mm/dd

"6"

yyyy-mm-dd

"7"

ggyy.mm.dd, Japanese date

"8"

ggyy/mm/dd, Japanese date

"9"

ggyy-mm-dd, Japanese date

"A"

yyyy/mm/dd, Islamic date 1

"B"

yyyy/mm/dd, Islamic date 2

"C"

yyyy/mm/dd, Iranian date

时间格式,TIMEFM栏位:

TIMEFM

Time Format

0

24-hour format (default setting) hh:mm:ss

1

12-hour format (1 to 12) hh:mm:ss AM and hh:mm:ss PM

2

12-hour format (1 to 12) hh:mm:ss am and hh:mm:ss pm

3

12-hour format (0 to 11) hh:mm:ss AM and hh:mm:ss PM

4

12-hour format (0 to 11) hh:mm:ss am and hh:mm:ss pm

示例:

"指定format
FORM f_program_param2.
  DATA:lt_t005x TYPE TABLE OF t005x.
  DATA:ls_t005x LIKE LINE OF lt_t005x.
  DATA:lv_num TYPE P LENGTH 8 DECIMALS 4 VALUE '123456.6678'.
  DATA:lv_date TYPE D.
  DATA:lv_time TYPE T.
  DATA:lv_str TYPE string.
  lv_date = sy-datum.
  lv_time = sy-uzeit.

  "获取domain
  DATA:lt_fixvals TYPE ddfixvalues.
  DATA:ls_fixvals LIKE LINE OF lt_fixvals.
  DATA:lo_descr TYPE REF TO cl_abap_elemdescr.
  DATA:lv_index TYPE I.
  "获取Domain
  lo_descr ?= cl_abap_elemdescr=>describe_by_name( 'T005X-DATFM' ).
  lt_fixvals = lo_descr->get_ddic_fixed_values( p_langu = sy-langu ).
  LOOP AT lt_fixvals INTO ls_fixvals.
    CLEAR ls_t005x.
    ls_t005x-land = '@' && ls_fixvals-low.
    "数字格式有三种
    lv_index = sy-tabix.
    lv_index = lv_index MOD 3.
    CASE lv_index.
      WHEN 0.
        ls_t005x-xdezp = ''.
      WHEN 1.
        ls_t005x-xdezp = 'X'.
      WHEN 2.
        ls_t005x-xdezp = 'Y'.
    ENDCASE.
    "日期格式
    ls_t005x-datfm = ls_fixvals-low.
    "时间格式
    lv_index = sy-tabix.
    lv_index = lv_index MOD 5.
    CASE lv_index.
      WHEN 0.
        ls_t005x-timefm = '0'.
      WHEN 1.
        ls_t005x-timefm = '1'.
      WHEN 2.
        ls_t005x-timefm = '2'.
      WHEN 3.
        ls_t005x-timefm = '3'.
      WHEN 4.
        ls_t005x-timefm = '4'.
    ENDCASE.
    APPEND ls_t005x TO lt_t005x.
  ENDLOOP.
  "更新到数据库表
  MODIFY t005x FROM TABLE lt_t005x.

  "查询
  SELECT * FROM t005x INTO TABLE lt_t005x WHERE land LIKE '@%'.
  LOOP AT lt_t005x INTO ls_t005x.
   CLEAR lv_str.
   lv_str = 'Language:' && ls_t005x-land && '---'
    && |{ lv_num COUNTRY = ls_t005x-land }|.
   lv_str = lv_str && '---' && |{ lv_date COUNTRY = ls_t005x-land }|.
   lv_str = lv_str && '---' && |{ lv_time COUNTRY = ls_t005x-land }|.
   WRITE:/ lv_str.
  ENDLOOP.

  "删除添加记录
  DELETE FROM t005x WHERE land LIKE '@%'.
ENDFORM.