ITPub博客

首页 > 应用开发 > IT综合 > ABAP指针field symbol!

ABAP指针field symbol!

原创 IT综合 作者:mmccking 时间:2007-09-03 10:32:50 0 删除 编辑
ABAP指针field symbol![@more@]

例:   頑張れ

*&---------------------------------------------------------------------*
*& Report X *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT X.
*
TYPES: gts_str TYPE STRING.
DATA: gdt_str TYPE TABLE OF gts_str.
DATA: gds_str TYPE gts_str.
DATA: gdf_str TYPE STRING.
*
DATA: gdt_DD02L TYPE TABLE OF DD02L.
DATA: gds_DD02L TYPE TABLE OF DD02L.

* フィールドシンボル定義
FIELD-SYMBOLS: TYPE ANY. " シンボリック項目を宣言




DATA: v_flienm(40).
DATA: wa_str TYPE STRING.
DATA: it_str TYPE TABLE OF STRING.

* APPEND 'TYPE = ''TR'' AND OKFLAG = ''U''' TO it_options_usobx.
*&---------------------------------------------------------------------*
*& Event START-OF-SELECTION <主処理>
*&---------------------------------------------------------------------*
START-OF-SELECTION.
************************************************************************
* PERFORM SUB_SET_SEPARATOR_XXX.
* PERFORM X_A_TEST.
PERFORM X_B_TEST.

*&---------------------------------------------------------------------*
*& Form X_B_TEST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM X_B_TEST .
DATA: v_buf(10000).

* DESCRIBE TABLE
ASSIGN v_buf TO CASTING TYPE DD02L.
SELECT * FROM DD02L UP TO 10 ROWS
INTO .
WRITE: / .

APPEND TO it_str.
ENDSELECT.

ENDFORM. " X_B_TEST
*&---------------------------------------------------------------------*
*& Form X_A_TEST
*&---------------------------------------------------------------------*
FORM X_A_TEST .

DATA: v_buf(10000).

* DESCRIBE TABLE
ASSIGN v_buf TO CASTING TYPE DD02L.
SELECT * FROM DD02L UP TO 10 ROWS
INTO .
WRITE: / .
ENDSELECT.
*
SKIP.
ASSIGN COMPONENT v_buf OF STRUCTURE gds_DD02L TO .
SELECT * FROM DD02L UP TO 10 ROWS
INTO .
WRITE: / .
ENDSELECT.

SKIP.
ASSIGN v_buf TO CASTING TYPE DD03L.
SELECT * FROM DD03L UP TO 10 ROWS
INTO .
WRITE: / .
ENDSELECT.


ENDFORM. " X_A_TEST
*&---------------------------------------------------------------------*
*& Form SUB_SET_SEPARATOR
*&---------------------------------------------------------------------*
* 構造を渡すと、項目間にセパレーターをセットして、1項目で返す
*----------------------------------------------------------------------*
FORM SUB_SET_SEPARATOR_XXX.
DATA: V_DATA(30000).
DATA: V_TABNAME LIKE DD02L-TABNAME VALUE 'T001W'.
DATA: V_CHAR72 LIKE RFC_DB_OPT.
FIELD-SYMBOLS: TYPE ANY.
ASSIGN V_DATA TO CASTING TYPE (V_TABNAME).

IF V_CHAR72 IS INITIAL.
SELECT * FROM (V_TABNAME) INTO .
WRITE V_DATA.
ENDSELECT.
ELSE.
SELECT * FROM (V_TABNAME) INTO WHERE (V_CHAR72).
WRITE V_DATA.
ENDSELECT.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SUB_SET_SEPARATOR
*&---------------------------------------------------------------------*
* 構造を渡すと、項目間にセパレーターをセットして、1項目で返す
*----------------------------------------------------------------------*
* -->U_STR 構造
* -->U_SEPARATOR 区切り文字
* <--C_RET 処理結果
*----------------------------------------------------------------------*
FORM SUB_SET_SEPARATOR USING U_STR
U_SEPARATOR
CHANGING C_RET.

FIELD-SYMBOLS: TYPE ANY.
DATA LDF_WORK(512) TYPE C.
DATA LDF_INDEX LIKE SY-INDEX.
* DATA LDF_LEN TYPE I.

CLEAR SY-INDEX.
CLEAR C_RET.
UNASSIGN .
DO 1000 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE U_STR TO .

IF SY-SUBRC <> 0.
EXIT.
ENDIF.
* LDF_LEN = STRLEN( ).
* DESCRIBE FIELD LENGTH LDF_LEN IN BYTE MODE.
* LDF_WORK = +0(LDF_LEN).
LDF_WORK = .
* CONDENSE LDF_WORK. " 空白削除
LDF_INDEX = SY-INDEX + 1.
ASSIGN COMPONENT LDF_INDEX OF STRUCTURE U_STR TO .
IF SY-SUBRC = 0.
CONCATENATE C_RET LDF_WORK U_SEPARATOR INTO C_RET.
* SEPARATED BY U_SEPARATOR.
ELSE.
" 最終行にはセパレータはセットしない
CONCATENATE C_RET LDF_WORK INTO C_RET.
ENDIF.
ENDDO.

ENDFORM. " SUB_SET_SEPARATOR

*&---------------------------------------------------------------------*
*& Form SUB_SET_SEPARATOR_TAB
*&---------------------------------------------------------------------*
* 構造を渡すと、項目間に TABをセットして、1項目で返す
*----------------------------------------------------------------------*
* -->U_STR 構造
* <--C_RET 処理結果
*----------------------------------------------------------------------*
FORM SUB_SET_SEPARATOR_TAB USING U_STR
CHANGING C_RET TYPE C.
FIELD-SYMBOLS: TYPE ANY.
DATA LDF_WORK(100) TYPE C.
DATA LDF_INDEX LIKE SY-INDEX.
* DATA LDF_LEN TYPE I.

CLEAR SY-INDEX.
CLEAR C_RET.
UNASSIGN .

DO 1000 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE U_STR TO .

IF SY-SUBRC <> 0.
EXIT.
ENDIF.
* LDF_LEN = STRLEN( ).
* DESCRIBE FIELD LENGTH LDF_LEN IN CHARACTER MODE.
* LDF_WORK = +0(LDF_LEN).
LDF_WORK = .
CONDENSE LDF_WORK. " 空白削除
LDF_INDEX = SY-INDEX + 1.
ASSIGN COMPONENT LDF_INDEX OF STRUCTURE U_STR TO .
IF SY-SUBRC = 0.
CONCATENATE C_RET
LDF_WORK
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
INTO C_RET.
* SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
" 最終行にはセパレータはセットしない
CONCATENATE C_RET LDF_WORK INTO C_RET.
ENDIF.

ENDDO.
ENDFORM. " SUB_SET_SEPARATOR_TAB

**********************************************************

来个简单的,比较容易理解的

types: begin of t_date ,
year(4) type n ,
month(2) type n ,
day(2) type n ,
end of t_date .
field-symbols: type t_date .

assign l_first_day to casting .

-year ' -month ' -day 可以分别取到l_first_day 的年月日

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8356764/viewspace-967715/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
你大爷永远是你大爷

注册时间:2008-03-11

  • 博文量
    94
  • 访问量
    379098