指针2 - SAP指针使用实例

1、工作区内容分配到指针&读取分配后指针里字段内容

DATA: CS_VBKOK TYPE  VBKOK

ASSIGN cs_vbkok TO FIELD-SYMBOL().

CHECK  IS ASSIGNED.

ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE  TO FIELD-SYMBOL().

CHECK  IS ASSIGNED.

WRITE:/ .

UNASSIGN: ,.
DATA: BEGIN OF LINE,
         COL1 TYPE I VALUE 'AA',
         COL2 TYPE I VALUE 'BB',
         COL3 TYPE I VALUE 'CC',
      END OF LINE.

DATA COMP(5) VALUE 'COL3'.

FIELD-SYMBOLS: , , .

ASSIGN LINE TO .
ASSIGN COMP TO .

DO 3 TIMES.
   ASSIGN COMPONENT SY-INDEX OF STRUCTURE  TO .
   WRITE .
ENDDO.

ASSIGN COMPONENT  OF STRUCTURE  TO .
WRITE / .

输出如下:
AA         BB         CC
CC


2、单字段值分配到指针

data: lv_field(14).

concatenate 'IT_WOG-WOG0' l_ind into lv_field.

assign (lv_field) to field-symbols().

check  is assigned.

write:/ .

UNASSIGN .

3、读取内表数据到指针

DATA: CT_VBPOK TYPE  TT_VBPOK

READ TABLE ct_vbpok WITH KEY wms_rfpos = lv_posnr ASSIGNING FIELD-SYMBOL().

CHECK  IS ASSIGNED.

ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE  TO FIELD-SYMBOL().

CHECK  IS ASSIGNED.

WRITE:/ .

UNASSIGN: ,.

4、内表行项目内容修改(不需要MODIFY ... INDEX SY-TABIX)

  LOOP AT gt_out ASSIGNING FIELD-SYMBOL().
    "默认X销售需求,可选择Y试验,C零时插单
    -zjhlx = 'X'.

    READ TABLE gt_makt INTO DATA(ls_makt) WITH KEY matnr = -matnr.
    IF sy-subrc = 0.
      -maktx = ls_makt-maktx.
    ENDIF.

    READ TABLE gt_mkal INTO DATA(ls_mkal) WITH KEY matnr = -matnr
                                                   werks = -pwwrk
                                                   verid = -verid.
    IF sy-subrc = 0.
      -verid_desc = ls_mkal-text1.
    ENDIF.

    -zrets = p_zrets.

  ENDLOOP.

5、内表新增行项目

"新增行项目到内表GT_OUT.

LOOP AT lt_out INTO DATA(ls_out).
    APPEND INITIAL LINE TO gt_out ASSIGNING .
    CHECK  IS ASSIGNED.

    MOVE-CORRESPONDING ls_out TO .

    "销售组织
    READ TABLE lt_tvkot INTO DATA(ls_tvkot) WITH KEY vkorg = -vkorg.
    IF sy-subrc = 0.
      -vkorg_desc = ls_tvkot-vtext.
    ENDIF.

    "部门
    READ TABLE lt_tspat INTO DATA(ls_tspat) WITH KEY spart = -spart.
    IF sy-subrc = 0.
      -spart_desc = ls_tspat-vtext.
    ENDIF.

    "审核状态
    IF -sdabw = 'X'.
      -sdabw_desc = gc_sdabw_1.
    ENDIF.

    UNASSIGN .

  ENDLOOP.

6、增强过程中,跨程序读取值

如:读取MM03 的销售组织数据1的 物料号、销售组织、分销渠道等信息。程序SAPLMGMM对应工作区RMMG1

    ASSIGN ('(SAPLMGMM)RMMG1') TO FIELD-SYMBOL().
    CHECK  IS ASSIGNED.

    ASSIGN COMPONENT 'MATNR' OF STRUCTURE  TO FIELD-SYMBOL().
    ASSIGN COMPONENT 'VKORG' OF STRUCTURE  TO FIELD-SYMBOL().
    ASSIGN COMPONENT 'VTWEG' OF STRUCTURE  TO FIELD-SYMBOL().

    CHECK  IS ASSIGNED AND  IS ASSIGNED AND  IS ASSIGNED.

 

7、

 

 

 

你可能感兴趣的:(指针2 - SAP指针使用实例)