Creating documentary batches programmatically with BAPI_GOODSMVT_CREATE? - abap

Summary of the problem
Automatic Documentary Batch handling through custom ABAP code
My employer wishes to perform automatic documentary batch handling on some products from external vendors, and I'm trying to figure out how to set this up through Customizing and ABAP.
It seems to me that Documentary Batches are only meant to be used through MIGO - in any case I'm unable to find a proper solution to assign them programatically, and any hacked-together solution I can come up with, seems insufficient and unstable.
What avenues do I have to solve this issue?
Enhancing BAPI_GOODSMVT_CREATE?
Can I somehow do it through stuff like BAPI_GOODSMVT_CREATE?
Enhancing PPPI Message Destinations?
I also specifically need it to work for consumption messaging through PPPI, and I thought to build on top of the standard Message Destination PI04, FM COCI_CONFIRM_MATERIAL_CONS.
This FM creates a Material Document but does not go through the BAPI_GOODSMVT_CREATE FM.
It does however use MB_CREATE_GOODS_MOVEMENT.
What I've already tried
MIGO Snapshot based Single Use hack solution
I made hack-solution for one area, where I watched which table-updates MIGO performed and with which data (through FM's VB_INSERT_BATCH and VB_BATCH_WHERE_USED_LIST), and then filled out these structures manually.
However, providing all the needed info is not feasible for other implementation areas, as they do not have all the necessary values available, and it doesn't cover unforeseen situations where other parameters might be required.
Reading through BAPI_GOODSMVT_CREATE code
I've tried spying on whether BAPI_GOODSMVT_CREATE performs the same FM's but only found it accessing VB_BATCH_WHERE_USED_LIST.
It seems to be possible to activate this functionality by controlling Memory ID Documentary Batch #1, Documentary Batch #2, Documentary Batch #3 and Documentary Batch #5 (see FM VBDBDM_DATA_POST_IM), but this requires filling out a lot data, including the structure named DOCUBATCH_SCREEN_FIELDS, which again makes it seem like this might not be the correct avenue of approach.
Regardless, this still doesn't allow me to maintain batch through tables MCHA and MCH1.
Hacked together solution based on MIGO snapshot
Here is how my hacked solution looks. Again, this is not a feasible way to go about the problem, as other implementation areas does not have the resulting Material Document immediately available:
FUNCTION zproxy_mdr_goodsreceipt.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IS_GOODSRECEIPT_HEAD) TYPE ZPROXY_GOODSREC_HEAD
*" VALUE(IT_GOODSRECEIPT_ITEM) TYPE ZPROXY_GOODSREC_ITEM_T
*" REFERENCE(I_CREATE_TO_FROM_REQUIREMENTS) TYPE FLAG DEFAULT '-'
*" EXPORTING
*" REFERENCE(E_GOODSMVT_MSG_IDNO) TYPE CHAR23
*" REFERENCE(E_MBLNR) TYPE MBLNR
*" REFERENCE(E_TO_CREATION_SUBRC) TYPE SY-SUBRC
*" REFERENCE(E_LGNUM_ERROR) TYPE LGNUM
*" REFERENCE(E_TBNUM_ERROR) TYPE TBNUM
*" REFERENCE(E_DOCBATCH_SUBRC) TYPE SY-SUBRC
*" REFERENCE(E_DOCBATCH_MSG_IDNO) TYPE CHAR23
*" REFERENCE(E_CLASSNUM) TYPE BAPI1003_KEY-CLASSNUM
*" REFERENCE(E_OBJKEY) TYPE BAPI1003_KEY-OBJECT
*" EXCEPTIONS
*" GOODSMVT_FAILED
*" NO_TRANSFER_REQUIREMENTS
*" TRANSFER_ORDER_CREATION_ERROR
*"----------------------------------------------------------------------
FIELD-SYMBOLS: <return> TYPE bapiret2,
<goods_rec_item> TYPE zproxy_goodsrec_item,
<mseg> TYPE mseg,
<char_char> TYPE bapi1003_alloc_values_char,
<ltap_creat> TYPE LTAP_CREAT.
DATA: ls_header TYPE bapi2017_gm_head_01,
ls_code TYPE bapi2017_gm_code,
ls_item TYPE bapi2017_gm_item_create,
lt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_headret TYPE bapi2017_gm_head_ret,
l_mblnr LIKE bapi2017_gm_head_ret-mat_doc,
l_docubatch TYPE charg_d,
l_subrc TYPE sy-subrc,
lt_mseg TYPE STANDARD TABLE OF mseg.
CLEAR l_subrc.
* ############################## Create goods movement ##############################
* Build structures
MOVE-CORRESPONDING is_goodsreceipt_head TO ls_header.
ls_code-gm_code = '01'.
LOOP AT it_goodsreceipt_item ASSIGNING <goods_rec_item>.
MOVE-CORRESPONDING <goods_rec_item> TO ls_item.
APPEND ls_item TO lt_item.
ENDLOOP.
* BAPI call
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_header
goodsmvt_code = ls_code
IMPORTING
goodsmvt_headret = ls_headret
materialdocument = l_mblnr
TABLES
goodsmvt_item = lt_item
return = lt_return.
* Check errors
READ TABLE lt_return ASSIGNING <return> WITH KEY type = 'E'.
IF sy-subrc = 0.
e_goodsmvt_msg_idno = <return>-id && <return>-number.
ROLLBACK WORK.
RAISE goodsmvt_failed.
ELSE.
e_mblnr = l_mblnr.
COMMIT WORK AND WAIT. "Wait for TO requirements to be created
ENDIF.
* Only proceede if Material Document has been successfully posted
CHECK l_subrc = 0 AND l_mblnr IS NOT INITIAL.
* ############################## Update with Documentary Batch ###################################
DATA: lt_chvw TYPE STANDARD TABLE OF chvw,
ls_chvw TYPE chvw,
lt_mch1 TYPE STANDARD TABLE OF mch1,
ls_mch1 TYPE mch1,
lt_mcha TYPE STANDARD TABLE OF mcha,
ls_mcha TYPE mcha,
lt_mchb TYPE STANDARD TABLE OF mchb,
lt_mska TYPE STANDARD TABLE OF mska,
lt_mspr TYPE STANDARD TABLE OF mspr,
lt_char_num TYPE STANDARD TABLE OF bapi1003_alloc_values_num,
lt_char_char TYPE STANDARD TABLE OF bapi1003_alloc_values_char,
lt_char_curr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr,
l_objkey TYPE bapi1003_key-object,
l_classnum TYPE bapi1003_key-classnum,
l_atnam TYPE atnam.
REFRESH lt_chvw.
* Get material document items
SELECT *
FROM mseg
INTO TABLE lt_mseg
WHERE mblnr = l_mblnr.
* Perpare docubatch registration data
LOOP AT it_goodsreceipt_item ASSIGNING <goods_rec_item>.
* Generate class num and atnam from plant
CONCATENATE 'PI_' <goods_rec_item>-plant INTO l_classnum.
CONCATENATE 'Z_DOC_BATCH_' <goods_rec_item>-plant INTO l_atnam.
* Get material docubatch usage characteristic
REFRESH: lt_return,
lt_char_num,
lt_char_char,
lt_char_curr.
l_objkey(18) = <goods_rec_item>-material.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = l_objkey
objecttable = 'MARA'
classnum = l_classnum
classtype = '001'
TABLES
allocvaluesnum = lt_char_num
allocvalueschar = lt_char_char
allocvaluescurr = lt_char_curr
return = lt_return.
LOOP AT lt_return ASSIGNING <return> WHERE type = 'E'. "Check for errors
* Couldn't read characteristic, assume no docubatch handling
e_docbatch_subrc = '1'.
e_docbatch_msg_idno = <return>-id && <return>-number.
e_classnum = l_classnum.
e_objkey = l_objkey.
CONTINUE.
ENDLOOP.
READ TABLE lt_char_char ASSIGNING <char_char> WITH KEY charact = l_atnam.
IF sy-subrc <> 0 OR <char_char>-value_neutral = 0.
* No docubatch value
CONTINUE.
ENDIF.
* Get associated material document item
READ TABLE lt_mseg ASSIGNING <mseg>
WITH KEY mblnr = ls_headret-mat_doc
mjahr = ls_headret-doc_year
bwart = <goods_rec_item>-move_type
matnr = <goods_rec_item>-material
werks = <goods_rec_item>-plant
menge = <goods_rec_item>-entry_qnt
meins = <goods_rec_item>-entry_uom
hsdat = <goods_rec_item>-prod_date
kzbew = <goods_rec_item>-mvt_ind
lgort = <goods_rec_item>-stge_loc.
IF sy-subrc <> 0.
* No associated material document item
CONTINUE.
ENDIF.
* Check docubatch type
IF <char_char>-value_neutral <> 0.
* Perform basic docubatch actions (MCHA and MCH1)
* Verify that docubatch nr is assigned
IF <goods_rec_item>-vendrbatch IS INITIAL.
* !!!!!!!!!!!!! Venderbatch not filled even though material is docubatch managed, what to do? !!!!!!!!!!!!!!!
CONTINUE.
ENDIF.
* Prepare data for docubatch registration
CLEAR: ls_mch1,
ls_mcha.
ls_mch1-matnr = <goods_rec_item>-material.
ls_mch1-charg = <goods_rec_item>-vendrbatch.
ls_mch1-ersda = sy-datum.
ls_mch1-ernam = sy-uname.
ls_mch1-ersda_tmstp = sy-datum && sy-uzeit.
ls_mch1-ersda_tz_sys = sy-tzone.
ls_mch1-ersda_tz_usr = sy-zonlo.
MOVE-CORRESPONDING ls_mch1 TO ls_mcha. "Same fields from MCH1 are included in MCHA
ls_mcha-werks = <goods_rec_item>-plant.
APPEND: ls_mch1 TO lt_mch1,
ls_mcha TO lt_mcha.
ENDIF.
IF <char_char>-value_neutral = 2. "Also include batch where-used
* Perpare data for batch where-used registration
CLEAR ls_chvw.
ls_chvw-matnr = <goods_rec_item>-material.
ls_chvw-werks = <goods_rec_item>-plant.
ls_chvw-charg = <goods_rec_item>-vendrbatch.
ls_chvw-ebeln = <goods_rec_item>-po_number.
ls_chvw-ebelp = <goods_rec_item>-po_item.
ls_chvw-mblnr = ls_headret-mat_doc.
ls_chvw-mjahr = ls_headret-doc_year.
ls_chvw-zeile = <mseg>-zeile.
ls_chvw-budat = is_goodsreceipt_head-pstng_date.
ls_chvw-shkzg = 'S'. "??? VALUE ???
ls_chvw-bwart = <goods_rec_item>-move_type.
ls_chvw-kzbew = <goods_rec_item>-mvt_ind. "Goods Movement for Purchase Order
ls_chvw-menge = <goods_rec_item>-entry_qnt.
ls_chvw-meins = <goods_rec_item>-entry_uom.
APPEND ls_chvw TO lt_chvw.
ENDIF.
ENDLOOP.
* Perform batch registration
CALL FUNCTION 'VB_INSERT_BATCH'
TABLES
zmch1 = lt_mch1
zmcha = lt_mcha
zmchb = lt_mchb
zmska = lt_mska
zmspr = lt_mspr
.
* Perform batch where-used registration
CALL FUNCTION 'VB_BATCH_WHERE_USED_LIST'
TABLES
xchvw = lt_chvw.
Why this isn't good enough, and what I need
This performs as a snapshot of MIGO configured with documentary batch handling, but doesn't necessarily cover all cases.
It only works in the context of a Purchase Document, and doesn't cover other cases such as Orders and Sales Orders.
Additionally I only have the necessary date because of the material document being created immediately above, which is not possible for all implementation cases.
I would like to know if there is an intended way to perform Documentary Batch handling from custom code.

Quoting from the documentation:
If you work with RFID or TRM functions, or call IDocs/BAPIs, you can only book in documentary
batches by calling up the RFC-capable function module VBDBDM_DATA_MAINTAIN_RFC
beforehand or incorporating it into the process.
So maybe this function module is the key?
However, it seems you may not be the first to experience this pain. A comment on that documentation reads:
Documentary Batch has a lot of constraints and it seems to be a semifinished product of SAP, since is missing a lot of features of real batches.
Be prepared to make a lot of custom enhancements...
ADDENDUM from community: below is the solution taken from the Original Poster two days after this answer, moved away from his question.
Solution
Example call for Purchase Order Goods Receipt
LOOP AT it_goodsreceipt_item ASSIGNING <goods_rec_item>.
CALL FUNCTION 'VBDBDM_DATA_MAINTAIN_RFC'
EXPORTING
i_matnr = <goods_rec_item>-material
i_werks = <goods_rec_item>-plant
i_quantity = <goods_rec_item>-entry_qnt
i_uom = <goods_rec_item>-entry_uom
i_docubatch_charg = <goods_rec_item>-vendrbatch
* IT_DOCUBATCHES =
i_process_id = '01' "Goods Receipt for External Procurement
* I_REPLACE_EXISTING_DATA =
i_ebeln = <goods_rec_item>-po_number
i_ebelp = <goods_rec_item>-po_item
* I_AUFNR =
* I_AUFPS =
* I_RSNUM =
* I_RSPOS =
* I_RSART =
* I_VBELN =
* I_POSNR =
* IS_DOCUBATCH_COM =
* I_LINE_ID =
* I_LGNUM =
* I_TANUM =
* I_TAPOS =
EXCEPTIONS
parameter_error = 1
process_not_active = 2.
ENDLOOP.
* Follow up by creating Material Document, for example through BAPI_GOODSMVT_CREATE

Related

Parameter type error on BAPI_OBJCL_GETDETAIL call?

lv_objectkey2 = ls_mseg-matnr.
"Transport Category
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_objectkey2
objecttable = 'MARA'
classnum = 'Z_MATERIAL_CLASS'
classtype = '001'
TABLES
allocvaluesnum = lt_allocvaluesnum2
allocvalueschar = lt_allocvalueschar2
allocvaluescurr = lt_allocvaluescurr2
return = lt_return2.
READ TABLE lt_allocvaluesnum2 INTO ls_valnum2 WITH KEY charact= 'Z_ADR_QUANTITY'.
IF sy-subrc = 0.
lv_adr_quan = ls_valnum2-value_from + lv_adr_quan.
WRITE: lv_adr_quan TO ls_item-ADR_QUAN EXPONENT 0 DECIMALS 2.
* CONDENSE ls_item-ADR_QUAN.
ENDIF.
Here is my problem : The program gives me that problem : "ADR_QUAN" must be a character-type field (data type C, N, D or T).
I need your opinions to fix the issue or solutions.
CONDENSE Statement works only for the character-like variables. Here, ls_item-ADR_QUAN field is of type Float, That's why you're getting that error.
You can go through the attached documentation link for CONDENSE statement.
CONDENSE Documentation
Even if you want to perform CONDENSE then first, you've to assign ls_item-ADR_QUAN to a character-like variable.

How to get long texts of FI held documents?

I need to get the particulars/long text of FI held documents. I tried the 'read_text' function module but had no luck since the held document has the temporary document number.
I tried looking for data in STXL and STXH tables, I also tried the function modules in FM group FTXT and STXD but had no luck.
Any other method to achieve that goal?
First of all, you need the temporary document number which can be get either from F-43 itself or from RFDT table.
In field SRTFD you should separate it from username.
Then run READ_TEMP_DOCUMENT FM, after running it you should have your texts in ABAP memory.
To get them use GET_TEXT_MEMORY.
ls_uf05a-tempd = '0012312356'. "doc number
ls_uf05a-unamd = 'JOHNDOE'. "username
CALL FUNCTION 'READ_TEMP_DOCUMENT'
EXPORTING
I_UF05A = ls_uf05a
TABLES
T_BKPF = lt_bkpf
T_BSEC = lt_bsec
T_BSED = lt_bsed
T_BSEG = lt_bseg
T_BSET = lt_bset
T_BSEZ = lt_bsez
.
DATA: lt_texts TYPE TABLE OF TCATALOG,
t_tline TYPE STANDARD TABLE OF tline,
memory_id(30) VALUE 'SAPLSTXD'.
CALL FUNCTION 'GET_TEXT_MEMORY'
TABLES
TEXT_MEMORY = lt_texts.
READ TABLE lt_texts ASSIGNING FIELD-SYMBOL(<cat>) WITH KEY tdobject = 'BELEG'
tdid = '0001'
tdspras = 'E' BINARY SEARCH.
IF sy-subrc = 0.
memory_id+8(6) = <cat>-id.
ENDIF.
IMPORT tline = t_tline FROM MEMORY ID memory_id.
LOOP AT t_tline ASSIGNING FIELD-SYMBOL(<tline>).
WRITE: <tline>-tdline. "showing the texts
ENDLOOP.

How to use REUSE_ALV_FIELDCATALOG_MERGE function module?

I'm trying to use the function module REUSE_ALV_FIELDCATALOG_MERGE to pass the field label in ddic to display in the column header of the alv report.
But, that didn't work.
If I comment the I_STRUCTURE_NAME = 'TY_YNAH_CUS_OBJ_REQ' line, it give me runtime error state
The ABAP program lines are wider than the internal table.
But if I uncomment it ,the program still did not work
REPORT YALV_TEST.
tables sscrfields.
type-pools : slis.
"CREATE STRUCTURE -1
TYPES: BEGIN OF TY_YNAH_CUS_OBJ_REQ,
REQID TYPE YNAH_REQ_ID,
REQUESTOR TYPE YNAH_REQUESTOR,
BUSINESS_OWNER TYPE YNAH_BUS_OWN,
FUNCTIONAL_OWNER TYPE YNAH_FUNC_OWN,
REQNUM TYPE YNAH_SERVICE_REQ_NUM,
PROJECT_ID TYPE YNAH_PRO_ID,
SYSTEM_ID TYPE YNAH_SYS_ID,
FUNCTIONAL_AREA TYPE YNAH_FUNC_AREA,
REQUEST_DATE TYPE YNAH_REQ_DATE,
REQUEST_TIME TYPE YNAH_REQ_TIME,
END OF TY_YNAH_CUS_OBJ_REQ.
"defining internal table -2
DATA: IT_YNAH_CUS_OBJ_REQ type TABLE OF TY_YNAH_CUS_OBJ_REQ
* WA_YNAH_CUS_OBJ_REQ type TY_YNAH_CUS_OBJ_REQ.
DATA: it_fcat TYPE slis_t_fieldcat_alv ,
wa_fcat TYPE slis_fieldcat_alv,
gd_layout TYPE slis_layout_alv.
SELECTION-SCREEN BEGIN OF BLOCK menu WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_proid FOR IT_YNAH_CUS_OBJ_REQ-PROJECT_ID.
PARAMETER p_sysid type TY_YNAH_CUS_OBJ_REQ-SYSTEM_ID.
SELECTION-SCREEN: BEGIN OF LINE,
pushbutton 33(8) BUT user-command search.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK menu.
initialization.
BUT = 'SEARCH'. END-OF-SELECTION.
"execute search function when user click search button
at selection-screen. "after processing user input
case SSCRFIELDS.
when 'SEARCH'.
SSCRFIELDS-UCOMM = 'ONLI'.
endcase.
"fetch data using select-4 START-OF-SELECTION.
SELECT *
FROM YNAH_CUS_OBJ_REQ "Database
INTO CORRESPONDING FIELDS OF TABLE IT_YNAH_CUS_OBJ_REQ "Into internal table
WHERE
PROJECT_ID in s_proid and
SYSTEM_ID eq p_sysid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME ='TY_YNAH_CUS_OBJ_REQ'
* I_STRUCTURE_NAME = 'TY_YNAH_CUS_OBJ_REQ'
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = sy-repid
* I_BYPASSING_BUFFER = 'X'
* I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = it_fcat.
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
* .
IF SY-SUBRC <> 0.
** Implement suitable error handling here
ENDIF.
The REUSE_*ALV* function modules are unsupported. I'd suggest switching to the CL_SALV_* classes. The documentation is better, there are more sample programs (DEMO_SALV_*) and you get support.
You need a dictionary structure if you want to get dictionary-based field descriptions (duh). If you assemble a structure type on the ABAP level using TYPE ... BEGIN OF ... END OF ..., as far as I know, the dictionary types for the individual fields are converted to ABAP types first and only then assembled into a structure type. Anyway, the dictionary reference of the original fields is lost. Instead of defining the structure of the output table in your code, use a dictionary structure.
You have some mistakes you might have not known (SAP is very confusing sometimes
and not transparent with error-messages). I got for you a working example of mine, have a look on it, especially on the comments.
First, data definition:
TYPE-POOLS slis. "import you need for REUSE_ALV_FIELDCATALOG_MERGE
DATA:
lt_fieldcat TYPE slis_t_fieldcat_alv,
BEGIN OF G_IT_MATERIAL occurs 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MAKTX_DE LIKE MAKT-MAKTX,
MAKTX_FR LIKE MAKT-MAKTX,
MAKTX_IT LIKE MAKT-MAKTX,
ERNAM LIKE MARA-ERNAM,
ERSDA LIKE MARA-ERSDA,
LAEDA LIKE MARA-LAEDA,
END OF G_IT_MATERIAL.
It is absolutely necessary that you define your local structure directly with LIKE, otherwise the parser from REUSE_ALV_FIELDCATALOG_MERGE will not find it.
Select your stuff:
SELECT ma~matnr ma~mtart ma~ernam ma~ersda ma~laeda
de~maktx as maktx_de fr~maktx as maktx_fr it~maktx as maktx_it
FROM mara as ma
LEFT JOIN MAKT as de ON de~matnr = ma~matnr AND de~spras = 'DE'
LEFT JOIN MAKT as fr ON fr~matnr = ma~matnr AND fr~spras = 'FR'
LEFT JOIN MAKT as it ON it~matnr = ma~matnr AND it~spras = 'IT'
INTO CORRESPONDING FIELDS OF TABLE g_it_material
WHERE ...
Create a field catalog dynamically:
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'G_IT_MATERIAL'
I_INCLNAME = sy-repid
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Now display the ALV grid:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = lt_fieldcat "you could also give a structure
"i_structure_name = 'ZMM_SMATERIAL' "here instead of the fieldcat
TABLES
t_outtab = g_it_material
EXCEPTIONS
program_error = 1
OTHERS = 2.
Note that the parser also needs a max linesize of 72 chars.
There are several different text components provided by structure slis_fieldcat_alv that are used as column labels. The chosen text depends on the current column width (which itself usually depends on the length of the data displayed). Make sure that you change them all accordingly!
The usual technique is: By passing the I_STRUCTURE_NAME, you get a field catalog corresponding to this DDIC structure (the changing parameter ct_fieldcat). You then modify this internal table according to your needs and pass that modified table to the REUSE_ALV_GRID_DISPLAY.
In cases where I don't distinguish the different-sized text versions, I use the following macros to set all the text fields to the same value. The macros require a local work area ls_fieldcat (with the linetype of ct_fieldcat) and a local string variablelv_text` in order to work.
define set_field.
* Feld &1 für Anzeigefeld &2 den Wert &3 zuweisen
ls_fieldcat-&1 = &3.
modify ct_fieldcat from ls_fieldcat
transporting &1
where fieldname cp '&2'.
end-of-definition.
define set_text_direct.
lv_text = &2.
set_field seltext_s &1 lv_text.
lv_text = &2.
set_field seltext_m &1 lv_text.
lv_text = &2.
set_field seltext_l &1 lv_text.
end-of-definition.

SAP MD04 - Overview Tree Export

I would like to find a way to export the SAP MD04 - overview tree in Excel.
I don't understand what will be the best approach.
Thanks in advance for any suggestion.
Regs
S.
I've done this workaround:
You have to use 2 Functional Module CS_BOM_EXPL_MAT_V2 + MD_STOCK_REQUIREMENTS_LIST_API
In the INFOSET Data Reading Program I've used the CS_BOM_EXPL_MAT_V2 for the BOM Explosion.
REPORT RSAQDVP_TEMPLATE .
data:
STPOX type STPOX ,
it_data type standard table of STPOX .
field-symbols: <struc> type STPOX .
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_HEAD>
* (select your data here into internal table IT_DATA)
call function 'CS_BOM_EXPL_MAT_V2'
EXPORTING
auskz = 'X'
capid = p_capid
datuv = p_datuv
emeng = u_qty
mehrs = 'X'
mtnrv = p_mtnrv
werks = p_werks
TABLES
stb = it_data.
loop at it_data assigning <struc>.
move-corresponding <struc> to STPOX .
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_BODY>
endloop.
Than I've added Additional Field calling the MD_STOCK_REQUIREMENTS_LIST_API.
CLEAR MNG01_FM.
call function 'MD_STOCK_REQUIREMENTS_LIST_API'
EXPORTING
matnr = STPOX-IDNRK
werks = p_werks
TABLES
mdezx = it_da2.
READ TABLE it_da2 ASSIGNING <struct2> WITH KEY DELKZ = 'SB'.
if sy-subrc = 0.
MNG01_FM = <struct2>-MNG01.
endif.

How do I use the "call transaction 'se11' and skip first screen" to activate the search box in ABAP?

What I am trying to do is use
Set Parameter ID 'DTB' Field 'z*'.
Call Transaction 'SE11' and skip First Screen.
At this point I want to activate the search box and take the results into an internal table. Any thoughts? Or is there a way to use the data base statistics to pull this information faster?
Instead of accessing the tables directly, you may want to use a semi-official API that not only handles the activation state, but also takes permissions into account as well:
DATA: lt_tables TYPE STANDARD TABLE OF rpy_tabl.
FIELD-SYMBOLS: <ls_table> TYPE rpy_tabl.
CALL FUNCTION 'RPY_TABLE_SELECT'
EXPORTING
table_name = 'Z*'
TABLES
tabl_inf_tab = lt_tables
EXCEPTIONS
cancelled = 1
not_found = 2
permission_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
LOOP AT lt_tables ASSIGNING <ls_table>.
CASE <ls_table>-tablclass.
WHEN 'TRANSP'. " Transparent table
* ...
WHEN 'INTTAB'. " Structure
* ...
WHEN 'CLUSTER'. " Cluster table
* ...
WHEN 'POOL'. " Pooled table
* ...
WHEN 'VIEW'. " Generated view structure
* ...
WHEN 'APPEND'. " Append structure
* ...
ENDCASE.
ENDLOOP.
ENDIF.
The code below will get what you want, you might need to add some more where clauses to only get active tables (AS4LOCAL EQ 'A')or only transparent tables (TABCLASS EQ 'TRANSP') since this table also contains structures.
DATA: t_tabname TYPE STANDARD TABLE OF tabname.
SELECT tabname INTO TABLE t_tabname FROM dd02l WHERE tabname LIKE 'Z%'.