ABAP Select data from SAP table BBPS_BS_PO_ADDR_DELIVERY_470 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 BBPS_BS_PO_ADDR_DELIVERY_470 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 BBPS_BS_PO_ADDR_DELIVERY_470. 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 BBPS_BS_PO_ADDR_DELIVERY_470 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_BBPS_BS_PO_ADDR_DELIVERY_470 TYPE STANDARD TABLE OF BBPS_BS_PO_ADDR_DELIVERY_470,
      WA_BBPS_BS_PO_ADDR_DELIVERY_470 TYPE BBPS_BS_PO_ADDR_DELIVERY_470,
      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: <BBPS_BS_PO_ADDR_DELIVERY_470> TYPE BBPS_BS_PO_ADDR_DELIVERY_470.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BBPS_BS_PO_ADDR_DELIVERY_470
*  INTO TABLE @DATA(IT_BBPS_BS_PO_ADDR_DELIVERY_4702).
*--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_BBPS_BS_PO_ADDR_DELIVERY_470 INDEX 1 INTO DATA(WA_BBPS_BS_PO_ADDR_DELIVERY_4702).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BBPS_BS_PO_ADDR_DELIVERY_470 ASSIGNING <BBPS_BS_PO_ADDR_DELIVERY_470>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BBPS_BS_PO_ADDR_DELIVERY_470>-PO_ITEM = 1.
<BBPS_BS_PO_ADDR_DELIVERY_470>-ADDR_NO = 1.
<BBPS_BS_PO_ADDR_DELIVERY_470>-FORMOFADDR = 1.
<BBPS_BS_PO_ADDR_DELIVERY_470>-NAME = 1.
<BBPS_BS_PO_ADDR_DELIVERY_470>-NAME_2 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BBPS_BS_PO_ADDR_DELIVERY_470-NAME_3, sy-vline,
WA_BBPS_BS_PO_ADDR_DELIVERY_470-NAME_4, sy-vline,
WA_BBPS_BS_PO_ADDR_DELIVERY_470-C_O_NAME, sy-vline,
WA_BBPS_BS_PO_ADDR_DELIVERY_470-CITY, sy-vline,
WA_BBPS_BS_PO_ADDR_DELIVERY_470-DISTRICT, sy-vline,
WA_BBPS_BS_PO_ADDR_DELIVERY_470-CITY_NO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BBPS_BS_PO_ADDR_DELIVERY_470 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_BBPS_BS_PO_ADDR_DELIVERY_470 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_BBPS_BS_PO_ADDR_DELIVERY_470 INTO WA_BBPS_BS_PO_ADDR_DELIVERY_470. *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 ADDR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_BS_PO_ADDR_DELIVERY_470-ADDR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BS_PO_ADDR_DELIVERY_470-ADDR_NO.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field DISTRCT_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_BS_PO_ADDR_DELIVERY_470-DISTRCT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BS_PO_ADDR_DELIVERY_470-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_BBPS_BS_PO_ADDR_DELIVERY_470-PBOXCIT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BS_PO_ADDR_DELIVERY_470-PBOXCIT_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SXIDN, internal->external for field E_MAIL CALL FUNCTION 'CONVERSION_EXIT_SXIDN_OUTPUT' EXPORTING input = WA_BBPS_BS_PO_ADDR_DELIVERY_470-E_MAIL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BS_PO_ADDR_DELIVERY_470-E_MAIL.
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_BBPS_BS_PO_ADDR_DELIVERY_470_STR,
PO_ITEM TYPE STRING,
ADDR_NO TYPE STRING,
FORMOFADDR TYPE STRING,
NAME TYPE STRING,
NAME_2 TYPE STRING,
NAME_3 TYPE STRING,
NAME_4 TYPE STRING,
C_O_NAME TYPE STRING,
CITY TYPE STRING,
DISTRICT TYPE STRING,
CITY_NO TYPE STRING,
POSTL_COD1 TYPE STRING,
POSTL_COD2 TYPE STRING,
POSTL_COD3 TYPE STRING,
PO_BOX TYPE STRING,
PO_BOX_CIT TYPE STRING,
DELIV_DIS TYPE STRING,
STREET TYPE STRING,
STREET_NO TYPE STRING,
STR_ABBR TYPE STRING,
HOUSE_NO TYPE STRING,
STR_SUPPL1 TYPE STRING,
STR_SUPPL2 TYPE STRING,
LOCATION TYPE STRING,
BUILDING TYPE STRING,
FLOOR TYPE STRING,
ROOM_NO TYPE STRING,
COUNTRY TYPE STRING,
LANGU TYPE STRING,
REGION TYPE STRING,
SORT1 TYPE STRING,
SORT2 TYPE STRING,
TIME_ZONE TYPE STRING,
TAXJURCODE TYPE STRING,
ADR_NOTES TYPE STRING,
COMM_TYPE TYPE STRING,
TEL1_NUMBR TYPE STRING,
TEL1_EXT TYPE STRING,
FAX_NUMBER TYPE STRING,
FAX_EXTENS TYPE STRING,
STREET_LNG TYPE STRING,
DISTRCT_NO TYPE STRING,
CHCKSTATUS TYPE STRING,
PBOXCIT_NO TYPE STRING,
TRANSPZONE TYPE STRING,
HOUSE_NO2 TYPE STRING,
E_MAIL TYPE STRING,
STR_SUPPL3 TYPE STRING,
TITLE TYPE STRING,
COUNTRYISO TYPE STRING,
LANGU_ISO TYPE STRING,
BUILD_LONG TYPE STRING,
REGIOGROUP TYPE STRING,END OF T_EKKO_STR. DATA: WA_BBPS_BS_PO_ADDR_DELIVERY_470_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_BBPS_BS_PO_ADDR_DELIVERY_470_STR-PO_ITEM sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-ADDR_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-FORMOFADDR sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-NAME sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-NAME_2 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-NAME_3 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-NAME_4 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-C_O_NAME sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-CITY sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-DISTRICT sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-CITY_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-POSTL_COD1 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-POSTL_COD2 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-POSTL_COD3 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-PO_BOX sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-PO_BOX_CIT sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-DELIV_DIS sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STREET sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STREET_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STR_ABBR sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-HOUSE_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STR_SUPPL1 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STR_SUPPL2 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-LOCATION sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-BUILDING sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-FLOOR sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-ROOM_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-COUNTRY sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-LANGU sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-REGION sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-SORT1 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-SORT2 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TIME_ZONE sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TAXJURCODE sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-ADR_NOTES sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-COMM_TYPE sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TEL1_NUMBR sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TEL1_EXT sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-FAX_NUMBER sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-FAX_EXTENS sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STREET_LNG sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-DISTRCT_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-CHCKSTATUS sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-PBOXCIT_NO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TRANSPZONE sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-HOUSE_NO2 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-E_MAIL sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-STR_SUPPL3 sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-TITLE sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-COUNTRYISO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-LANGU_ISO sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-BUILD_LONG sy-vline
WA_BBPS_BS_PO_ADDR_DELIVERY_470_STR-REGIOGROUP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.