[代码]读取物料BOM行项目长文本[READ_TEXT]
1, READ_TEXT参数填写
可以通过函数READ_TEXT读取物料BOM行项目和抬头上的长文本。本文着重介绍如何读取物料BOM行项目上的长文本。
SE37:
读取物料BOM行项目长文本时,函数READ_TEXT的参数如下:
ID: 固定值 ‘MPO’
OBJECT:固定值 ‘BOM’
NAME:客户端号(3位)+ BOM 类别(1位)+BOM号(8位)+BOM 项目节点号(8位)+内部计数器(8位)
name中的BOM相关数据保存在表STPO(BOM行项目表),MAST(物料BOM表)中
先在MAST中找到物料BOM号,
然后通过BOM号STLNR就能到STPO中找到NAME参数中用到的BOM数据了,
这个行项目的长文本信息是保存在表STXH中,如下,READ_TEXT对应的参数其实就是根据这个表中的内容填写的。
2, 例子代码
完整的例子代码如下:
代码中没有直接从STPO,MAST读取BOM数据,而是通过函数 CS_BOM_EXPL_MAT_V2进行物料BOM展开。
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行没有长文本,
由此可以看到程序输出的长文本正确。
以上。