ABAP Select data from SAP table CVIS_SUPP_CONT_ADDRESS2 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 CVIS_SUPP_CONT_ADDRESS2 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 CVIS_SUPP_CONT_ADDRESS2. 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 CVIS_SUPP_CONT_ADDRESS2 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_CVIS_SUPP_CONT_ADDRESS2 TYPE STANDARD TABLE OF CVIS_SUPP_CONT_ADDRESS2,
      WA_CVIS_SUPP_CONT_ADDRESS2 TYPE CVIS_SUPP_CONT_ADDRESS2,
      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: <CVIS_SUPP_CONT_ADDRESS2> TYPE CVIS_SUPP_CONT_ADDRESS2.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CVIS_SUPP_CONT_ADDRESS2
*  INTO TABLE @DATA(IT_CVIS_SUPP_CONT_ADDRESS22).
*--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_CVIS_SUPP_CONT_ADDRESS2 INDEX 1 INTO DATA(WA_CVIS_SUPP_CONT_ADDRESS22).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CVIS_SUPP_CONT_ADDRESS2 ASSIGNING <CVIS_SUPP_CONT_ADDRESS2>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CVIS_SUPP_CONT_ADDRESS2>-RUN_ID = 1.
<CVIS_SUPP_CONT_ADDRESS2>-PARNR = 1.
<CVIS_SUPP_CONT_ADDRESS2>-ADDR_VERS = 1.
<CVIS_SUPP_CONT_ADDRESS2>-FROM_DATE = 1.
<CVIS_SUPP_CONT_ADDRESS2>-TO_DATE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CVIS_SUPP_CONT_ADDRESS2-TITLE_P, sy-vline,
WA_CVIS_SUPP_CONT_ADDRESS2-FIRSTNAME, sy-vline,
WA_CVIS_SUPP_CONT_ADDRESS2-LASTNAME, sy-vline,
WA_CVIS_SUPP_CONT_ADDRESS2-BIRTH_NAME, sy-vline,
WA_CVIS_SUPP_CONT_ADDRESS2-MIDDLENAME, sy-vline,
WA_CVIS_SUPP_CONT_ADDRESS2-SECONDNAME, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CVIS_SUPP_CONT_ADDRESS2 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_CVIS_SUPP_CONT_ADDRESS2 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_CVIS_SUPP_CONT_ADDRESS2 INTO WA_CVIS_SUPP_CONT_ADDRESS2. *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 ISOLA, internal->external for field LANGU_P CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_P IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_P.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field LANGU_CR_P CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_CR_P IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_CR_P.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CITY_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-CITY_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-CITY_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field DISTRCT_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-DISTRCT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-DISTRCT_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PBOXCIT_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-PBOXCIT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-PBOXCIT_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field STREET_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-STREET_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-STREET_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ADDRESS_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-ADDRESS_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-ADDRESS_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field LANGU_CR CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_CR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-LANGU_CR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field HOMECITYNO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-HOMECITYNO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-HOMECITYNO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field COUNTY_CODE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-COUNTY_CODE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-COUNTY_CODE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field TOWNSHIP_CODE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CVIS_SUPP_CONT_ADDRESS2-TOWNSHIP_CODE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CVIS_SUPP_CONT_ADDRESS2-TOWNSHIP_CODE.
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_CVIS_SUPP_CONT_ADDRESS2_STR,
RUN_ID TYPE STRING,
PARNR TYPE STRING,
ADDR_VERS TYPE STRING,
FROM_DATE TYPE STRING,
TO_DATE TYPE STRING,
TITLE_P TYPE STRING,
FIRSTNAME TYPE STRING,
LASTNAME TYPE STRING,
BIRTH_NAME TYPE STRING,
MIDDLENAME TYPE STRING,
SECONDNAME TYPE STRING,
FULLNAME TYPE STRING,
FULLNAME_X TYPE STRING,
TITLE_ACA1 TYPE STRING,
TITLE_ACA2 TYPE STRING,
PREFIX1 TYPE STRING,
PREFIX2 TYPE STRING,
TITLE_SPPL TYPE STRING,
NICKNAME TYPE STRING,
INITIALS TYPE STRING,
NAMEFORMAT TYPE STRING,
NAMCOUNTRY TYPE STRING,
NAMCTRYISO TYPE STRING,
PROFESSION TYPE STRING,
SEX TYPE STRING,
LANGU_P TYPE STRING,
LANGUP_ISO TYPE STRING,
SORT1_P TYPE STRING,
SORT2_P TYPE STRING,
LANGU_CR_P TYPE STRING,
LANGUCPISO TYPE STRING,
C_O_NAME TYPE STRING,
CITY TYPE STRING,
DISTRICT TYPE STRING,
CITY_NO TYPE STRING,
DISTRCT_NO TYPE STRING,
CHCKSTATUS TYPE STRING,
REGIOGROUP TYPE STRING,
POSTL_COD1 TYPE STRING,
POSTL_COD2 TYPE STRING,
PCODE1_EXT TYPE STRING,
PCODE2_EXT TYPE STRING,
PO_BOX TYPE STRING,
PO_W_O_NO TYPE STRING,
PO_BOX_CIT TYPE STRING,
PBOXCIT_NO TYPE STRING,
PO_BOX_REG TYPE STRING,
POBOX_CTRY TYPE STRING,
PO_CTRYISO TYPE STRING,
DELIV_DIS TYPE STRING,
TRANSPZONE TYPE STRING,
STREET TYPE STRING,
STREET_NO TYPE STRING,
STR_ABBR TYPE STRING,
HOUSE_NO TYPE STRING,
HOUSE_NO2 TYPE STRING,
HOUSE_NO3 TYPE STRING,
STR_SUPPL1 TYPE STRING,
STR_SUPPL2 TYPE STRING,
STR_SUPPL3 TYPE STRING,
LOCATION TYPE STRING,
BUILDING TYPE STRING,
FLOOR TYPE STRING,
ROOM_NO TYPE STRING,
COUNTRY TYPE STRING,
COUNTRYISO TYPE STRING,
REGION TYPE STRING,
EXTENS_1 TYPE STRING,
EXTENS_2 TYPE STRING,
TIME_ZONE TYPE STRING,
TAXJURCODE TYPE STRING,
ADDRESS_ID TYPE STRING,
LANGU_CR TYPE STRING,
LANGUCRISO TYPE STRING,
COMM_TYPE TYPE STRING,
PERS_GROUP TYPE STRING,
ADDR_GROUP TYPE STRING,
HOME_CITY TYPE STRING,
HOMECITYNO TYPE STRING,
DONT_USE_S TYPE STRING,
DONT_USE_P TYPE STRING,
PO_BOX_LOBBY TYPE STRING,
DELI_SERV_TYPE TYPE STRING,
DELI_SERV_NUMBER TYPE STRING,
COUNTY_CODE TYPE STRING,
COUNTY TYPE STRING,
TOWNSHIP_CODE TYPE STRING,
TOWNSHIP TYPE STRING,END OF T_EKKO_STR. DATA: WA_CVIS_SUPP_CONT_ADDRESS2_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_CVIS_SUPP_CONT_ADDRESS2_STR-RUN_ID sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PARNR sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-ADDR_VERS sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-FROM_DATE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TO_DATE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TITLE_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-FIRSTNAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LASTNAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-BIRTH_NAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-MIDDLENAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-SECONDNAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-FULLNAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-FULLNAME_X sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TITLE_ACA1 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TITLE_ACA2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PREFIX1 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PREFIX2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TITLE_SPPL sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-NICKNAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-INITIALS sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-NAMEFORMAT sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-NAMCOUNTRY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-NAMCTRYISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PROFESSION sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-SEX sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGU_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGUP_ISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-SORT1_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-SORT2_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGU_CR_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGUCPISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-C_O_NAME sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-CITY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DISTRICT sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-CITY_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DISTRCT_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-CHCKSTATUS sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-REGIOGROUP sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-POSTL_COD1 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-POSTL_COD2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PCODE1_EXT sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PCODE2_EXT sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_BOX sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_W_O_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_BOX_CIT sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PBOXCIT_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_BOX_REG sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-POBOX_CTRY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_CTRYISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DELIV_DIS sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TRANSPZONE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STREET sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STREET_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STR_ABBR sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-HOUSE_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-HOUSE_NO2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-HOUSE_NO3 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STR_SUPPL1 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STR_SUPPL2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-STR_SUPPL3 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LOCATION sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-BUILDING sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-FLOOR sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-ROOM_NO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-COUNTRY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-COUNTRYISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-REGION sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-EXTENS_1 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-EXTENS_2 sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TIME_ZONE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TAXJURCODE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-ADDRESS_ID sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGU_CR sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-LANGUCRISO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-COMM_TYPE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PERS_GROUP sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-ADDR_GROUP sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-HOME_CITY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-HOMECITYNO sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DONT_USE_S sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DONT_USE_P sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-PO_BOX_LOBBY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DELI_SERV_TYPE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-DELI_SERV_NUMBER sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-COUNTY_CODE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-COUNTY sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TOWNSHIP_CODE sy-vline
WA_CVIS_SUPP_CONT_ADDRESS2_STR-TOWNSHIP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.