[Code] reading material BOM item long lines of text [READ_TEXT]

1, READ_TEXT parameter fill

Long text can be read on the material BOM line items and looked up through the function READ_TEXT. This article focuses on how to read long texts on the material BOM line items.

SE37:

When reading material BOM line item long text, function parameters READ_TEXT as follows:

ID:  fixed value 'MPO'

OBJECT: fixed value 'BOM'

NAME: Client Number (3 bits) + the BOM category (a) + the BOM number (8 bits) + the BOM item node number (8 bits) + internal counter (8)

name of the BOM data stored in the table STPO (BOM line items table), MAST (Material BOM table)

First find the material BOM in the number of MAST,

Then by BOM number STLNR STPO able to find the BOM data used in the NAME parameter,

Long text of this line item information is stored in the table STXH as follows, READ_TEXT corresponding parameter in fact, according to this table to fill in.

2, an example of the code

Examples of complete code is as follows:

BOM code is not read data directly from STPO, MAST, but by the function for material of BOM CS_BOM_EXPL_MAT_V2.

REPORT ztest_read_longtxt_mbom.

DATA:git_stb TYPE STANDARD TABLE OF stpox,
     gwa_stb TYPE stpox.
DATA:git_line TYPE STANDARD TABLE OF tline WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b_kopvor
                 WITH FRAME TITLE text-001.
PARAMETERS: p_matnr1 LIKE mast-matnr MEMORY ID mat,
            p_werks1 LIKE mast-werks OBLIGATORY MEMORY ID wrk, "plant
            p_stlan1 LIKE mast-stlan DEFAULT '1' MODIF ID mod. "BOM Usage
SELECTION-SCREEN END OF BLOCK b_kopvor.

* 物料BOM展开
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
  EXPORTING
    mtnrv                 = p_matnr1
    werks                 = p_werks1
    stlan                 = p_stlan1
    datuv                 = sy-datum
    ehndl                 = '1'
    mmory                 = '1'
    capid                 = 'PP01'
    aufsw                 = ' '
    mbwls                 = ' '
    mehrs                 = ' '
  TABLES
    stb                   = git_stb
  EXCEPTIONS
    alt_not_found         = 1
    call_invalid          = 2
    material_not_found    = 3
    missing_authorization = 4
    no_bom_found          = 5
    no_plant_data         = 6
    no_suitable_bom_found = 7.


LOOP AT git_stb INTO gwa_stb.
  PERFORM frm_read_text TABLES git_line
                         USING gwa_stb-stlnr "Bill of material
                               gwa_stb-stlkn "BOM item node number
                               gwa_stb-stpoz "Internal counter
                               gwa_stb-stlty."BOM category

ENDLOOP.
LOOP AT git_line.
  WRITE:/ git_line-tdformat, git_line-tdline.
ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  FRM_READ_TEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GIT_LINE  text
*      -->P_GWA_STB_STLNR  text
*      -->P_GWA_STB_STLKN  text
*      -->P_GWA_STB_STPOZ  text
*      -->P_GWA_STB_STLTY  text
*----------------------------------------------------------------------*
FORM frm_read_text  TABLES   it_line STRUCTURE tline
                    USING    i_stlnr
                             i_stlkn
                             i_stpoz
                             i_stlty.

  DATA:lwa_line TYPE csltx_line.
  DATA:lit_tline      TYPE STANDARD TABLE OF tline,
       lwa_tline      TYPE tline,
       lwa_textheader TYPE thead.
  DATA: BEGIN OF lwa_htext,
          tdobject LIKE thead-tdobject,
          tdname   LIKE thead-tdname,
          tdid     LIKE thead-tdid,
          tdspras  LIKE thead-tdspras.
  DATA: END OF lwa_htext.

* Fill textheader
  CLEAR lwa_htext.
  lwa_htext-tdid         = 'MPO'.
  lwa_htext-tdspras      = sy-langu.
  lwa_htext-tdobject     = 'BOM'.
  lwa_htext-tdname(3)    = sy-mandt.
  lwa_htext-tdname+3(1)  = i_stlty. "BOM category
  lwa_htext-tdname+4(8)  = i_stlnr. "Bill of material
  lwa_htext-tdname+12(8) = i_stlkn. "BOM item node number
  lwa_htext-tdname+20(8) = i_stpoz. "Internal counter

* read longtext into table textlines
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id       = lwa_htext-tdid
      language = lwa_htext-tdspras
      name     = lwa_htext-tdname
      object   = lwa_htext-tdobject
    IMPORTING
      header   = lwa_textheader
    TABLES
      lines    = lit_tline
    EXCEPTIONS
      OTHERS   = 1.

  APPEND LINES OF lit_tline TO it_line.

ENDFORM.

3, 测试结果

输入选择条件,点击运行,

将物料BOM每个行项目上的长文本write出来,

前台CS03查看一下物料BOM 0010行项目上的长文本,

0020行也有如下长文本,

0030行没有长文本,

由此可以看到程序输出的长文本正确。

以上。

Guess you like

Origin www.cnblogs.com/datie/p/11433872.html