ABAP Select data from SAP table MDMGENERIC_VENDOR 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 MDMGENERIC_VENDOR 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 MDMGENERIC_VENDOR. 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 MDMGENERIC_VENDOR 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_MDMGENERIC_VENDOR TYPE STANDARD TABLE OF MDMGENERIC_VENDOR,
      WA_MDMGENERIC_VENDOR TYPE MDMGENERIC_VENDOR,
      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: <MDMGENERIC_VENDOR> TYPE MDMGENERIC_VENDOR.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_MDMGENERIC_VENDOR.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM MDMGENERIC_VENDOR
  INTO TABLE IT_MDMGENERIC_VENDOR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM MDMGENERIC_VENDOR
*  INTO TABLE @DATA(IT_MDMGENERIC_VENDOR2).
*--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_MDMGENERIC_VENDOR INDEX 1 INTO DATA(WA_MDMGENERIC_VENDOR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_MDMGENERIC_VENDOR ASSIGNING <MDMGENERIC_VENDOR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<MDMGENERIC_VENDOR>-CONTROLLER = 1.
<MDMGENERIC_VENDOR>-GENERIC_VENDOR_ID = 1.
<MDMGENERIC_VENDOR>-APOLOCATION = 1.
<MDMGENERIC_VENDOR>-BUSINESS_PARTNER = 1.
<MDMGENERIC_VENDOR>-GROUP_ID = 1.
ENDLOOP.

LOOP AT IT_MDMGENERIC_VENDOR INTO WA_MDMGENERIC_VENDOR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_MDMGENERIC_VENDOR-COMPANY_CODE, sy-vline,
WA_MDMGENERIC_VENDOR-COUNTRY, sy-vline,
WA_MDMGENERIC_VENDOR-DUNS_NUMBER, sy-vline,
WA_MDMGENERIC_VENDOR-BACK_END_TYPE, sy-vline,
WA_MDMGENERIC_VENDOR-LOCAL_PARTNER_ID, sy-vline,
WA_MDMGENERIC_VENDOR-SOURCE_SYSTEM_ID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_MDMGENERIC_VENDOR 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_MDMGENERIC_VENDOR 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_MDMGENERIC_VENDOR INTO WA_MDMGENERIC_VENDOR. *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_MDMGENERIC_VENDOR_STR,
CONTROLLER TYPE STRING,
GENERIC_VENDOR_ID TYPE STRING,
APOLOCATION TYPE STRING,
BUSINESS_PARTNER TYPE STRING,
GROUP_ID TYPE STRING,
COMPANY_CODE TYPE STRING,
COUNTRY TYPE STRING,
DUNS_NUMBER TYPE STRING,
BACK_END_TYPE TYPE STRING,
LOCAL_PARTNER_ID TYPE STRING,
SOURCE_SYSTEM_ID TYPE STRING,
SOURCE_SYSTEM_NAME TYPE STRING,
SOURCE_INFO_OBJECT TYPE STRING,
CLIENT_SYSTEM_OBJECT_TYPE TYPE STRING,
MARKET_TRADE_PARTNER TYPE STRING,
POSTAL_CODE TYPE STRING,
REGION TYPE STRING,
LOCAL_VENDOR_ID TYPE STRING,
GLOBAL_ULTIMATE_DUNS_ID TYPE STRING,
COUNTRY_CODE TYPE STRING,
ALTITUDE TYPE STRING,
CITY TYPE STRING,
EMAIL_ADDRESS TYPE STRING,
FAX_NUMBER TYPE STRING,
GENDER TYPE STRING,
HOUSE_NUMBER TYPE STRING,
LANGUAGE_CODE TYPE STRING,
LATITUDE TYPE STRING,
LEGAL_FORM TYPE STRING,
LONGITUDE TYPE STRING,
NATION TYPE STRING,
ORGANIZATIONAL_UNIT TYPE STRING,
GEO_POSTAL_CODE TYPE STRING,
PRECISION_LOCATION TYPE STRING,
GEO_SOURCE_ID TYPE STRING,
STREET60 TYPE STRING,
TAX_JURISDICTION_CODE TYPE STRING,
TEL_NUMBER TYPE STRING,
TIME_ZONE TYPE STRING,
TRANSPORT_ZONE TYPE STRING,
DELETION_FLAG TYPE STRING,
TEXT_SHORT TYPE STRING,
TEXT_MEDIUM TYPE STRING,
TEXT_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_MDMGENERIC_VENDOR_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_MDMGENERIC_VENDOR_STR-CONTROLLER sy-vline
WA_MDMGENERIC_VENDOR_STR-GENERIC_VENDOR_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-APOLOCATION sy-vline
WA_MDMGENERIC_VENDOR_STR-BUSINESS_PARTNER sy-vline
WA_MDMGENERIC_VENDOR_STR-GROUP_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-COMPANY_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-COUNTRY sy-vline
WA_MDMGENERIC_VENDOR_STR-DUNS_NUMBER sy-vline
WA_MDMGENERIC_VENDOR_STR-BACK_END_TYPE sy-vline
WA_MDMGENERIC_VENDOR_STR-LOCAL_PARTNER_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-SOURCE_SYSTEM_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-SOURCE_SYSTEM_NAME sy-vline
WA_MDMGENERIC_VENDOR_STR-SOURCE_INFO_OBJECT sy-vline
WA_MDMGENERIC_VENDOR_STR-CLIENT_SYSTEM_OBJECT_TYPE sy-vline
WA_MDMGENERIC_VENDOR_STR-MARKET_TRADE_PARTNER sy-vline
WA_MDMGENERIC_VENDOR_STR-POSTAL_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-REGION sy-vline
WA_MDMGENERIC_VENDOR_STR-LOCAL_VENDOR_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-GLOBAL_ULTIMATE_DUNS_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-COUNTRY_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-ALTITUDE sy-vline
WA_MDMGENERIC_VENDOR_STR-CITY sy-vline
WA_MDMGENERIC_VENDOR_STR-EMAIL_ADDRESS sy-vline
WA_MDMGENERIC_VENDOR_STR-FAX_NUMBER sy-vline
WA_MDMGENERIC_VENDOR_STR-GENDER sy-vline
WA_MDMGENERIC_VENDOR_STR-HOUSE_NUMBER sy-vline
WA_MDMGENERIC_VENDOR_STR-LANGUAGE_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-LATITUDE sy-vline
WA_MDMGENERIC_VENDOR_STR-LEGAL_FORM sy-vline
WA_MDMGENERIC_VENDOR_STR-LONGITUDE sy-vline
WA_MDMGENERIC_VENDOR_STR-NATION sy-vline
WA_MDMGENERIC_VENDOR_STR-ORGANIZATIONAL_UNIT sy-vline
WA_MDMGENERIC_VENDOR_STR-GEO_POSTAL_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-PRECISION_LOCATION sy-vline
WA_MDMGENERIC_VENDOR_STR-GEO_SOURCE_ID sy-vline
WA_MDMGENERIC_VENDOR_STR-STREET60 sy-vline
WA_MDMGENERIC_VENDOR_STR-TAX_JURISDICTION_CODE sy-vline
WA_MDMGENERIC_VENDOR_STR-TEL_NUMBER sy-vline
WA_MDMGENERIC_VENDOR_STR-TIME_ZONE sy-vline
WA_MDMGENERIC_VENDOR_STR-TRANSPORT_ZONE sy-vline
WA_MDMGENERIC_VENDOR_STR-DELETION_FLAG sy-vline
WA_MDMGENERIC_VENDOR_STR-TEXT_SHORT sy-vline
WA_MDMGENERIC_VENDOR_STR-TEXT_MEDIUM sy-vline
WA_MDMGENERIC_VENDOR_STR-TEXT_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.