ABAP Select data from SAP table MMPUR_ANA_CENCTR 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 MMPUR_ANA_CENCTR 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 MMPUR_ANA_CENCTR. 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 MMPUR_ANA_CENCTR 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_MMPUR_ANA_CENCTR TYPE STANDARD TABLE OF MMPUR_ANA_CENCTR, WA_MMPUR_ANA_CENCTR TYPE MMPUR_ANA_CENCTR, 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: <MMPUR_ANA_CENCTR> TYPE MMPUR_ANA_CENCTR. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_MMPUR_ANA_CENCTR. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM MMPUR_ANA_CENCTR INTO TABLE IT_MMPUR_ANA_CENCTR. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM MMPUR_ANA_CENCTR * INTO TABLE @DATA(IT_MMPUR_ANA_CENCTR2). *--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_MMPUR_ANA_CENCTR INDEX 1 INTO DATA(WA_MMPUR_ANA_CENCTR2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_MMPUR_ANA_CENCTR ASSIGNING <MMPUR_ANA_CENCTR>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<MMPUR_ANA_CENCTR>-MANDT = 1.
<MMPUR_ANA_CENCTR>-ACTIVE_DOC_NUMBER = 1.
<MMPUR_ANA_CENCTR>-DOCUMENT_VERSION = 1.
<MMPUR_ANA_CENCTR>-ITEM = 1.
<MMPUR_ANA_CENCTR>-PLANT_UNIQUE_ID = 1.
ENDLOOP. LOOP AT IT_MMPUR_ANA_CENCTR INTO WA_MMPUR_ANA_CENCTR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_MMPUR_ANA_CENCTR-VALIDITY_UUID, sy-vline,
WA_MMPUR_ANA_CENCTR-IS_CURRENT_VERSION, sy-vline,
WA_MMPUR_ANA_CENCTR-DOCUMENT_NUMBER, sy-vline,
WA_MMPUR_ANA_CENCTR-DOCUMENT_SUB_TYPE, sy-vline,
WA_MMPUR_ANA_CENCTR-CONTRACT_TYPE, sy-vline,
WA_MMPUR_ANA_CENCTR-PRICE_VALIDITY_START_DATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_MMPUR_ANA_CENCTR 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_MMPUR_ANA_CENCTR 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_MMPUR_ANA_CENCTR INTO WA_MMPUR_ANA_CENCTR. *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.
*Conversion exit ALPHA, internal->external for field ACTIVE_DOC_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-ACTIVE_DOC_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-ACTIVE_DOC_NUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DOCUMENT_VERSION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-DOCUMENT_VERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-DOCUMENT_VERSION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DOCUMENT_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-DOCUMENT_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-DOCUMENT_NUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-SUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-SUPPLIER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field EXTMATERIALFORPURG CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-EXTMATERIALFORPURG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-EXTMATERIALFORPURG.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_OF_MEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_MMPUR_ANA_CENCTR-UNIT_OF_MEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MMPUR_ANA_CENCTR-UNIT_OF_MEASURE.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_MMPUR_ANA_CENCTR_STR,
MANDT TYPE STRING,
ACTIVE_DOC_NUMBER TYPE STRING,
DOCUMENT_VERSION TYPE STRING,
ITEM TYPE STRING,
PLANT_UNIQUE_ID TYPE STRING,
VALIDITY_UUID TYPE STRING,
IS_CURRENT_VERSION TYPE STRING,
DOCUMENT_NUMBER TYPE STRING,
DOCUMENT_SUB_TYPE TYPE STRING,
CONTRACT_TYPE TYPE STRING,
PRICE_VALIDITY_START_DATE TYPE STRING,
PRICE_VALIDITY_END_DATE TYPE STRING,
NET_PRICE_DOC_CURR TYPE STRING,
NET_PRICE_REP_CURRENCY1 TYPE STRING,
NET_PRICE_REP_CURRENCY2 TYPE STRING,
EFFECTIVE_PRICE_DOC_CURR TYPE STRING,
EFFECTIVE_PRICE_REP_CURR1 TYPE STRING,
EFFECTIVE_PRICE_REP_CURR2 TYPE STRING,
BASE_PRICE_DOC_CURR TYPE STRING,
BASE_PRICE_REP_CURRENCY1 TYPE STRING,
BASE_PRICE_REP_CURRENCY2 TYPE STRING,
DOCUMENT_CURRENCY TYPE STRING,
REPORTING_CURRENCY1 TYPE STRING,
REPORTING_CURRENCY2 TYPE STRING,
VERSION_CREATION_DATE TYPE STRING,
SUPPLIER TYPE STRING,
COMPANY_CODE TYPE STRING,
PURCHASING_ORG TYPE STRING,
PURCHASING_GROUP TYPE STRING,
EXTMATERIALFORPURG TYPE STRING,
ITEM_DESCRIPTION TYPE STRING,
MATERIAL_GROUP TYPE STRING,
CHANGE_REASON_INDICATOR TYPE STRING,
UNIT_OF_MEASURE TYPE STRING,
CHANGED_BY TYPE STRING,
INCOTERMS1 TYPE STRING,
INCOTERMS2 TYPE STRING,
PAYMENT_TERMS TYPE STRING,
SHIPPING_INSTRUCTIONS TYPE STRING,
COMPANY_CODE_GROUP TYPE STRING,END OF T_EKKO_STR. DATA: WA_MMPUR_ANA_CENCTR_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_MMPUR_ANA_CENCTR_STR-MANDT sy-vline
WA_MMPUR_ANA_CENCTR_STR-ACTIVE_DOC_NUMBER sy-vline
WA_MMPUR_ANA_CENCTR_STR-DOCUMENT_VERSION sy-vline
WA_MMPUR_ANA_CENCTR_STR-ITEM sy-vline
WA_MMPUR_ANA_CENCTR_STR-PLANT_UNIQUE_ID sy-vline
WA_MMPUR_ANA_CENCTR_STR-VALIDITY_UUID sy-vline
WA_MMPUR_ANA_CENCTR_STR-IS_CURRENT_VERSION sy-vline
WA_MMPUR_ANA_CENCTR_STR-DOCUMENT_NUMBER sy-vline
WA_MMPUR_ANA_CENCTR_STR-DOCUMENT_SUB_TYPE sy-vline
WA_MMPUR_ANA_CENCTR_STR-CONTRACT_TYPE sy-vline
WA_MMPUR_ANA_CENCTR_STR-PRICE_VALIDITY_START_DATE sy-vline
WA_MMPUR_ANA_CENCTR_STR-PRICE_VALIDITY_END_DATE sy-vline
WA_MMPUR_ANA_CENCTR_STR-NET_PRICE_DOC_CURR sy-vline
WA_MMPUR_ANA_CENCTR_STR-NET_PRICE_REP_CURRENCY1 sy-vline
WA_MMPUR_ANA_CENCTR_STR-NET_PRICE_REP_CURRENCY2 sy-vline
WA_MMPUR_ANA_CENCTR_STR-EFFECTIVE_PRICE_DOC_CURR sy-vline
WA_MMPUR_ANA_CENCTR_STR-EFFECTIVE_PRICE_REP_CURR1 sy-vline
WA_MMPUR_ANA_CENCTR_STR-EFFECTIVE_PRICE_REP_CURR2 sy-vline
WA_MMPUR_ANA_CENCTR_STR-BASE_PRICE_DOC_CURR sy-vline
WA_MMPUR_ANA_CENCTR_STR-BASE_PRICE_REP_CURRENCY1 sy-vline
WA_MMPUR_ANA_CENCTR_STR-BASE_PRICE_REP_CURRENCY2 sy-vline
WA_MMPUR_ANA_CENCTR_STR-DOCUMENT_CURRENCY sy-vline
WA_MMPUR_ANA_CENCTR_STR-REPORTING_CURRENCY1 sy-vline
WA_MMPUR_ANA_CENCTR_STR-REPORTING_CURRENCY2 sy-vline
WA_MMPUR_ANA_CENCTR_STR-VERSION_CREATION_DATE sy-vline
WA_MMPUR_ANA_CENCTR_STR-SUPPLIER sy-vline
WA_MMPUR_ANA_CENCTR_STR-COMPANY_CODE sy-vline
WA_MMPUR_ANA_CENCTR_STR-PURCHASING_ORG sy-vline
WA_MMPUR_ANA_CENCTR_STR-PURCHASING_GROUP sy-vline
WA_MMPUR_ANA_CENCTR_STR-EXTMATERIALFORPURG sy-vline
WA_MMPUR_ANA_CENCTR_STR-ITEM_DESCRIPTION sy-vline
WA_MMPUR_ANA_CENCTR_STR-MATERIAL_GROUP sy-vline
WA_MMPUR_ANA_CENCTR_STR-CHANGE_REASON_INDICATOR sy-vline
WA_MMPUR_ANA_CENCTR_STR-UNIT_OF_MEASURE sy-vline
WA_MMPUR_ANA_CENCTR_STR-CHANGED_BY sy-vline
WA_MMPUR_ANA_CENCTR_STR-INCOTERMS1 sy-vline
WA_MMPUR_ANA_CENCTR_STR-INCOTERMS2 sy-vline
WA_MMPUR_ANA_CENCTR_STR-PAYMENT_TERMS sy-vline
WA_MMPUR_ANA_CENCTR_STR-SHIPPING_INSTRUCTIONS sy-vline
WA_MMPUR_ANA_CENCTR_STR-COMPANY_CODE_GROUP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.