使用READ_TEXT FM

时间:2017-11-02 09:03:22

标签: sap abap function-module

我已经设法使READ_TEXT FM在多次调用函数read_text时一次只能处理一个cID(例如我发现了如何访问cID ='GRUN'cObject ='MATERIAL'。任何人都可以建议如何连接read_text函数,以便检查文本(cID ='GRUN'cObject ='MATERIAL')将在我的alv网格中显示在与材料详细信息相同的行上?

Please click here for output FORM READTEXT。

  data: it_MVKE type standard table of MVKE initial size 0.
  data: lMVKE like MVKE, lMAKT like MAKT, lT002 like T002 ,
        lTDNAME like THEAD-TDNAME,"text header

        it_TLINE type standard table of TLINE,
        wa_TLINE type TLINE.

  data: cObject(10) type c, cID(4) type c.


  select MATNR from MARA into corresponding fields of table it_MVKE
  where MATNR in Material order by MATNR.
  cID = 'GRUN'. cObject = 'MATERIAL'. "Text date principale "


  loop at it_MVKE into lMVKE.

    lTDNAME = lMVKE-MATNR.

    select spras from T002 into lT002.

      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          CLIENT   = SY-MANDT
          ID       = cID
          LANGUAGE = lT002-SPRAS
          NAME     = lTDNAME
          OBJECT   = cObject
        TABLES
          LINES    = it_TLINE
        EXCEPTIONS
          ID       = 1
          OTHERS   = 8.

      IF SY-SUBRC EQ 0.

        select single * from MAKT into lMAKT where MATNR eq lMVKE-MATNR
         and SPRAS eq lT002-SPRAS.

        LOOP AT it_TLINE INTO wa_TLINE.
          wa_join-TEXTPRI = wa_TLINE-TDLINE.
          append wa_join to lt_join.
          clear wa_join.
        ENDLOOP.
      ENDIF.
    ENDSELECT.
  ENDLOOP.
ENDFORM.

2 个答案:

答案 0 :(得分:1)

你不能这样做。 SAP中的功能模块一次只接受单个参数,除非将此参数指定为表类型或在TABLES部分中。

但是,这里有一个解决方法from my previous answer,你可以用来摆脱READ_TEXT

  1. 正如 forgetaboutme 所说,将您的cID与TDNAME一起放入itab:

    wa_cids-cid = 'GRUN'.
    wa_cids-cobject = 'MATERIAL'.
    if cID = '0001'.
     concatenate lMVKE-MATNR lMVKE-VKORG lMVKE-VTWEG into wa_cids-lTDNAME.
    else.
     lTDNAME = lMVKE-MATNR.
    endif.
    append wa_cids to it_cids.
    
  2. 考虑你的itab,从db表中选择文本。

    SELECT l~tdname l~clustr l~clustd
     INTO CORRESPONDING FIELDS OF TABLE t_stxl
     FROM stxl AS l
     JOIN stxh AS h
      ON h~tdobject = l~tdobject
       AND h~tdname   = l~tdname
       AND h~tdid     = l~tdid
       FOR ALL ENTRIES it_cids
     WHERE l~relid    = 'TX'          "standard text
       AND h~tdobject = it_cids-cobject
       AND h~tdname   = it_cids-lTDNAME
       AND h~tdid     = it_cids-cid
       AND l~tdspras  = sy-langu.
    
  3. 将它们从原始形式转换为可读形式

    CLEAR: t_stxl_raw[], t_tline[].
    APPEND VALUE ty_stxl_raw( clustr = <stxl>-clustr clustd = <stxl>-clustd ) TO t_stxl_raw.
    IMPORT tline = t_tline FROM INTERNAL TABLE t_stxl_raw.
    
  4. 阅读它们

    LOOP AT t_tline ASSIGNING <tline>.
     wa_Report-TEXT = <tline>-TDLINE.
    append wa_Report to it_Report.
    ENDLOOP.
    

答案 1 :(得分:0)

您可以创建一个cIDs&amp;的内部表格。像这样的cObject:

types: begin of cids,
         cid(4)      type c,
         cobject(10) type c,
       end of cids.

data: wa_cids type cids.
data: it_cids type standard table of cids.

然后你可以简单地将你拥有的所有不同类型的cID / cObject附加到内部表中:

wa_cids-cid = 'GRUN'.
wa_cids-cobject = 'MATERIAL'.

append wa_cids to it_cids.

然后循环遍历内部表格调用函数&#39; READ_TEXT&#39;

loop at it_cids into wa_cids.
  call function 'READ_TEXT'
    exporting
      client   = sy-mandt
      id       = wa_cids-cid
      language = lt002-spras  "p_SPRAS
      name     = ltdname
      object   = wa_cids-cobject
    tables
      lines    = it_tline
    exceptions
      id       = 1
      others   = 8.

* Do what you need to do with it_tline here.

endloop.

* Rest of code here