ABAP Select data from SAP table BAPISDITMX2 into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP BAPISDITMX2 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to BAPISDITMX2. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the BAPISDITMX2 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_BAPISDITMX2 TYPE STANDARD TABLE OF BAPISDITMX2, WA_BAPISDITMX2 TYPE BAPISDITMX2, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <BAPISDITMX2> TYPE BAPISDITMX2. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPISDITMX2. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPISDITMX2 INTO TABLE IT_BAPISDITMX2. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPISDITMX2 * INTO TABLE @DATA(IT_BAPISDITMX22). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_BAPISDITMX2 INDEX 1 INTO DATA(WA_BAPISDITMX22). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPISDITMX2 ASSIGNING <BAPISDITMX2>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPISDITMX2>-ITM_NUMBER = 1.
<BAPISDITMX2>-UPDATEFLAG = 1.
<BAPISDITMX2>-HG_LV_ITEM = 1.
<BAPISDITMX2>-PO_ITM_NO = 1.
<BAPISDITMX2>-MATERIAL = 1.
ENDLOOP. LOOP AT IT_BAPISDITMX2 INTO WA_BAPISDITMX2. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPISDITMX2-ALT_TO_ITM, sy-vline,
WA_BAPISDITMX2-CUST_MAT22, sy-vline,
WA_BAPISDITMX2-BATCH, sy-vline,
WA_BAPISDITMX2-DLV_GROUP, sy-vline,
WA_BAPISDITMX2-PART_DLV, sy-vline,
WA_BAPISDITMX2-REASON_REJ, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPISDITMX2 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_BAPISDITMX2 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_BAPISDITMX2 INTO WA_BAPISDITMX2. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_BAPISDITMX2_STR,
ITM_NUMBER TYPE STRING,
UPDATEFLAG TYPE STRING,
HG_LV_ITEM TYPE STRING,
PO_ITM_NO TYPE STRING,
MATERIAL TYPE STRING,
ALT_TO_ITM TYPE STRING,
CUST_MAT22 TYPE STRING,
BATCH TYPE STRING,
DLV_GROUP TYPE STRING,
PART_DLV TYPE STRING,
REASON_REJ TYPE STRING,
BILL_BLOCK TYPE STRING,
BILL_DATE TYPE STRING,
PLANT TYPE STRING,
STORE_LOC TYPE STRING,
TARGET_QTY TYPE STRING,
TARGET_QU TYPE STRING,
T_UNIT_ISO TYPE STRING,
ITEM_CATEG TYPE STRING,
SHORT_TEXT TYPE STRING,
PRC_GROUP1 TYPE STRING,
PRC_GROUP2 TYPE STRING,
PRC_GROUP3 TYPE STRING,
PRC_GROUP4 TYPE STRING,
PRC_GROUP5 TYPE STRING,
PROD_HIERA TYPE STRING,
MATL_GROUP TYPE STRING,
PURCH_NO_C TYPE STRING,
PURCH_DATE TYPE STRING,
PO_METHOD TYPE STRING,
REF_1 TYPE STRING,
PURCH_NO_S TYPE STRING,
PO_DAT_S TYPE STRING,
PO_METH_S TYPE STRING,
REF_1_S TYPE STRING,
POITM_NO_S TYPE STRING,
PRICE_GRP TYPE STRING,
CUST_GROUP TYPE STRING,
SALES_DIST TYPE STRING,
PRICE_LIST TYPE STRING,
INCOTERMS1 TYPE STRING,
INCOTERMS2 TYPE STRING,
ORDCOMP_IN TYPE STRING,
BILL_SCHED TYPE STRING,
INVO_SCHED TYPE STRING,
MN_INVOICE TYPE STRING,
EX_RATE_FI TYPE STRING,
ADD_VAL_DY TYPE STRING,
FIX_VAL_DY TYPE STRING,
PMNTTRMS TYPE STRING,
PYMT_METH TYPE STRING,
ACCNT_ASGN TYPE STRING,
EXCHG_RATE TYPE STRING,
PRICE_DATE TYPE STRING,
SERV_DATE TYPE STRING,
DUNN_KEY TYPE STRING,
DUNN_BLOCK TYPE STRING,
PROMOTION TYPE STRING,
PMTGAR_PRO TYPE STRING,
DOC_NUM_FI TYPE STRING,
DEPARTM_NO TYPE STRING,
REC_POINT TYPE STRING,
CSTCNDGRP1 TYPE STRING,
CSTCNDGRP2 TYPE STRING,
CSTCNDGRP3 TYPE STRING,
CSTCNDGRP4 TYPE STRING,
CSTCNDGRP5 TYPE STRING,
DLV_TIME TYPE STRING,
SALES_UNIT TYPE STRING,
TRG_QTY_NO TYPE STRING,
TRGQTY_DEN TYPE STRING,
RNDDLV_QTY TYPE STRING,
MAXDEVAMNT TYPE STRING,
MAXDEVPER TYPE STRING,
MAXDEV_DAY TYPE STRING,
USAGE_IND TYPE STRING,
FIXED_QUAN TYPE STRING,
UNLMT_DLV TYPE STRING,
OVERDLVTOL TYPE STRING,
UNDDLV_TOL TYPE STRING,
DIVISION TYPE STRING,
SALQTYNUM TYPE STRING,
SALQTYDEN TYPE STRING,
GROSS_WGHT TYPE STRING,
NET_WEIGHT TYPE STRING,
UNTOF_WGHT TYPE STRING,
VOLUME TYPE STRING,
VOLUNIT TYPE STRING,
DLV_PRIO TYPE STRING,
SHIP_POINT TYPE STRING,
ROUTE TYPE STRING,
TAX_CLASS1 TYPE STRING,
TAX_CLASS2 TYPE STRING,
TAX_CLASS3 TYPE STRING,
TAX_CLASS4 TYPE STRING,
TAX_CLASS5 TYPE STRING,
TAX_CLASS6 TYPE STRING,
TAX_CLASS7 TYPE STRING,
TAX_CLASS8 TYPE STRING,
TAX_CLASS9 TYPE STRING,
MAT_PR_GRP TYPE STRING,
VAL_TYPE TYPE STRING,
FIXDAT_QTY TYPE STRING,
BOMEXPL_NO TYPE STRING,
RESANALKEY TYPE STRING,
REQMTS_TYP TYPE STRING,
NO_GR_POST TYPE STRING,
BUS_TRANST TYPE STRING,
OVERHD_KEY TYPE STRING,
CSTG_SHEET TYPE STRING,
MATFRGTGRP TYPE STRING,
PLDLVSHDIN TYPE STRING,
SEQ_NO TYPE STRING,
BIL_FORM TYPE STRING,
DLI_PROFIL TYPE STRING,
REV_TYPE TYPE STRING,
BEGDEM_PER TYPE STRING,
PR_REF_MAT TYPE STRING,
REFOBJTYPE TYPE STRING,
REFOBJKEY TYPE STRING,
REFLOGSYS TYPE STRING,
ORDER_PROB TYPE STRING,
MAX_PL_DLV TYPE STRING,
CFOP_CODE TYPE STRING,
TAXLAWICMS TYPE STRING,
TAXLAWIPI TYPE STRING,
SD_TAXCODE TYPE STRING,
ASSORT_MOD TYPE STRING,
COMP_QUANT TYPE STRING,
TARGET_VAL TYPE STRING,
PROFIT_CTR TYPE STRING,
ORDERID TYPE STRING,
WBS_ELEM TYPE STRING,
DEPREC_PER TYPE STRING,
REF_DOC TYPE STRING,
REF_DOC_IT TYPE STRING,
REF_DOC_CA TYPE STRING,
CUST_MAT35 TYPE STRING,
EXCH_RATE_FI_V TYPE STRING,
EXCHG_RATE_V TYPE STRING,
ITEMGUID_ATP TYPE STRING,
VAL_CONTR TYPE STRING,
VAL_CON_I TYPE STRING,
BILL_REL TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPISDITMX2_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_BAPISDITMX2_STR-ITM_NUMBER sy-vline
WA_BAPISDITMX2_STR-UPDATEFLAG sy-vline
WA_BAPISDITMX2_STR-HG_LV_ITEM sy-vline
WA_BAPISDITMX2_STR-PO_ITM_NO sy-vline
WA_BAPISDITMX2_STR-MATERIAL sy-vline
WA_BAPISDITMX2_STR-ALT_TO_ITM sy-vline
WA_BAPISDITMX2_STR-CUST_MAT22 sy-vline
WA_BAPISDITMX2_STR-BATCH sy-vline
WA_BAPISDITMX2_STR-DLV_GROUP sy-vline
WA_BAPISDITMX2_STR-PART_DLV sy-vline
WA_BAPISDITMX2_STR-REASON_REJ sy-vline
WA_BAPISDITMX2_STR-BILL_BLOCK sy-vline
WA_BAPISDITMX2_STR-BILL_DATE sy-vline
WA_BAPISDITMX2_STR-PLANT sy-vline
WA_BAPISDITMX2_STR-STORE_LOC sy-vline
WA_BAPISDITMX2_STR-TARGET_QTY sy-vline
WA_BAPISDITMX2_STR-TARGET_QU sy-vline
WA_BAPISDITMX2_STR-T_UNIT_ISO sy-vline
WA_BAPISDITMX2_STR-ITEM_CATEG sy-vline
WA_BAPISDITMX2_STR-SHORT_TEXT sy-vline
WA_BAPISDITMX2_STR-PRC_GROUP1 sy-vline
WA_BAPISDITMX2_STR-PRC_GROUP2 sy-vline
WA_BAPISDITMX2_STR-PRC_GROUP3 sy-vline
WA_BAPISDITMX2_STR-PRC_GROUP4 sy-vline
WA_BAPISDITMX2_STR-PRC_GROUP5 sy-vline
WA_BAPISDITMX2_STR-PROD_HIERA sy-vline
WA_BAPISDITMX2_STR-MATL_GROUP sy-vline
WA_BAPISDITMX2_STR-PURCH_NO_C sy-vline
WA_BAPISDITMX2_STR-PURCH_DATE sy-vline
WA_BAPISDITMX2_STR-PO_METHOD sy-vline
WA_BAPISDITMX2_STR-REF_1 sy-vline
WA_BAPISDITMX2_STR-PURCH_NO_S sy-vline
WA_BAPISDITMX2_STR-PO_DAT_S sy-vline
WA_BAPISDITMX2_STR-PO_METH_S sy-vline
WA_BAPISDITMX2_STR-REF_1_S sy-vline
WA_BAPISDITMX2_STR-POITM_NO_S sy-vline
WA_BAPISDITMX2_STR-PRICE_GRP sy-vline
WA_BAPISDITMX2_STR-CUST_GROUP sy-vline
WA_BAPISDITMX2_STR-SALES_DIST sy-vline
WA_BAPISDITMX2_STR-PRICE_LIST sy-vline
WA_BAPISDITMX2_STR-INCOTERMS1 sy-vline
WA_BAPISDITMX2_STR-INCOTERMS2 sy-vline
WA_BAPISDITMX2_STR-ORDCOMP_IN sy-vline
WA_BAPISDITMX2_STR-BILL_SCHED sy-vline
WA_BAPISDITMX2_STR-INVO_SCHED sy-vline
WA_BAPISDITMX2_STR-MN_INVOICE sy-vline
WA_BAPISDITMX2_STR-EX_RATE_FI sy-vline
WA_BAPISDITMX2_STR-ADD_VAL_DY sy-vline
WA_BAPISDITMX2_STR-FIX_VAL_DY sy-vline
WA_BAPISDITMX2_STR-PMNTTRMS sy-vline
WA_BAPISDITMX2_STR-PYMT_METH sy-vline
WA_BAPISDITMX2_STR-ACCNT_ASGN sy-vline
WA_BAPISDITMX2_STR-EXCHG_RATE sy-vline
WA_BAPISDITMX2_STR-PRICE_DATE sy-vline
WA_BAPISDITMX2_STR-SERV_DATE sy-vline
WA_BAPISDITMX2_STR-DUNN_KEY sy-vline
WA_BAPISDITMX2_STR-DUNN_BLOCK sy-vline
WA_BAPISDITMX2_STR-PROMOTION sy-vline
WA_BAPISDITMX2_STR-PMTGAR_PRO sy-vline
WA_BAPISDITMX2_STR-DOC_NUM_FI sy-vline
WA_BAPISDITMX2_STR-DEPARTM_NO sy-vline
WA_BAPISDITMX2_STR-REC_POINT sy-vline
WA_BAPISDITMX2_STR-CSTCNDGRP1 sy-vline
WA_BAPISDITMX2_STR-CSTCNDGRP2 sy-vline
WA_BAPISDITMX2_STR-CSTCNDGRP3 sy-vline
WA_BAPISDITMX2_STR-CSTCNDGRP4 sy-vline
WA_BAPISDITMX2_STR-CSTCNDGRP5 sy-vline
WA_BAPISDITMX2_STR-DLV_TIME sy-vline
WA_BAPISDITMX2_STR-SALES_UNIT sy-vline
WA_BAPISDITMX2_STR-TRG_QTY_NO sy-vline
WA_BAPISDITMX2_STR-TRGQTY_DEN sy-vline
WA_BAPISDITMX2_STR-RNDDLV_QTY sy-vline
WA_BAPISDITMX2_STR-MAXDEVAMNT sy-vline
WA_BAPISDITMX2_STR-MAXDEVPER sy-vline
WA_BAPISDITMX2_STR-MAXDEV_DAY sy-vline
WA_BAPISDITMX2_STR-USAGE_IND sy-vline
WA_BAPISDITMX2_STR-FIXED_QUAN sy-vline
WA_BAPISDITMX2_STR-UNLMT_DLV sy-vline
WA_BAPISDITMX2_STR-OVERDLVTOL sy-vline
WA_BAPISDITMX2_STR-UNDDLV_TOL sy-vline
WA_BAPISDITMX2_STR-DIVISION sy-vline
WA_BAPISDITMX2_STR-SALQTYNUM sy-vline
WA_BAPISDITMX2_STR-SALQTYDEN sy-vline
WA_BAPISDITMX2_STR-GROSS_WGHT sy-vline
WA_BAPISDITMX2_STR-NET_WEIGHT sy-vline
WA_BAPISDITMX2_STR-UNTOF_WGHT sy-vline
WA_BAPISDITMX2_STR-VOLUME sy-vline
WA_BAPISDITMX2_STR-VOLUNIT sy-vline
WA_BAPISDITMX2_STR-DLV_PRIO sy-vline
WA_BAPISDITMX2_STR-SHIP_POINT sy-vline
WA_BAPISDITMX2_STR-ROUTE sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS1 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS2 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS3 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS4 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS5 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS6 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS7 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS8 sy-vline
WA_BAPISDITMX2_STR-TAX_CLASS9 sy-vline
WA_BAPISDITMX2_STR-MAT_PR_GRP sy-vline
WA_BAPISDITMX2_STR-VAL_TYPE sy-vline
WA_BAPISDITMX2_STR-FIXDAT_QTY sy-vline
WA_BAPISDITMX2_STR-BOMEXPL_NO sy-vline
WA_BAPISDITMX2_STR-RESANALKEY sy-vline
WA_BAPISDITMX2_STR-REQMTS_TYP sy-vline
WA_BAPISDITMX2_STR-NO_GR_POST sy-vline
WA_BAPISDITMX2_STR-BUS_TRANST sy-vline
WA_BAPISDITMX2_STR-OVERHD_KEY sy-vline
WA_BAPISDITMX2_STR-CSTG_SHEET sy-vline
WA_BAPISDITMX2_STR-MATFRGTGRP sy-vline
WA_BAPISDITMX2_STR-PLDLVSHDIN sy-vline
WA_BAPISDITMX2_STR-SEQ_NO sy-vline
WA_BAPISDITMX2_STR-BIL_FORM sy-vline
WA_BAPISDITMX2_STR-DLI_PROFIL sy-vline
WA_BAPISDITMX2_STR-REV_TYPE sy-vline
WA_BAPISDITMX2_STR-BEGDEM_PER sy-vline
WA_BAPISDITMX2_STR-PR_REF_MAT sy-vline
WA_BAPISDITMX2_STR-REFOBJTYPE sy-vline
WA_BAPISDITMX2_STR-REFOBJKEY sy-vline
WA_BAPISDITMX2_STR-REFLOGSYS sy-vline
WA_BAPISDITMX2_STR-ORDER_PROB sy-vline
WA_BAPISDITMX2_STR-MAX_PL_DLV sy-vline
WA_BAPISDITMX2_STR-CFOP_CODE sy-vline
WA_BAPISDITMX2_STR-TAXLAWICMS sy-vline
WA_BAPISDITMX2_STR-TAXLAWIPI sy-vline
WA_BAPISDITMX2_STR-SD_TAXCODE sy-vline
WA_BAPISDITMX2_STR-ASSORT_MOD sy-vline
WA_BAPISDITMX2_STR-COMP_QUANT sy-vline
WA_BAPISDITMX2_STR-TARGET_VAL sy-vline
WA_BAPISDITMX2_STR-PROFIT_CTR sy-vline
WA_BAPISDITMX2_STR-ORDERID sy-vline
WA_BAPISDITMX2_STR-WBS_ELEM sy-vline
WA_BAPISDITMX2_STR-DEPREC_PER sy-vline
WA_BAPISDITMX2_STR-REF_DOC sy-vline
WA_BAPISDITMX2_STR-REF_DOC_IT sy-vline
WA_BAPISDITMX2_STR-REF_DOC_CA sy-vline
WA_BAPISDITMX2_STR-CUST_MAT35 sy-vline
WA_BAPISDITMX2_STR-EXCH_RATE_FI_V sy-vline
WA_BAPISDITMX2_STR-EXCHG_RATE_V sy-vline
WA_BAPISDITMX2_STR-ITEMGUID_ATP sy-vline
WA_BAPISDITMX2_STR-VAL_CONTR sy-vline
WA_BAPISDITMX2_STR-VAL_CON_I sy-vline
WA_BAPISDITMX2_STR-BILL_REL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.