ABAP Select data from SAP table BAPIBUSISM008_ADDR1 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 BAPIBUSISM008_ADDR1 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 BAPIBUSISM008_ADDR1. 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 BAPIBUSISM008_ADDR1 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_BAPIBUSISM008_ADDR1 TYPE STANDARD TABLE OF BAPIBUSISM008_ADDR1, WA_BAPIBUSISM008_ADDR1 TYPE BAPIBUSISM008_ADDR1, 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: <BAPIBUSISM008_ADDR1> TYPE BAPIBUSISM008_ADDR1. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPIBUSISM008_ADDR1. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPIBUSISM008_ADDR1 INTO TABLE IT_BAPIBUSISM008_ADDR1. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPIBUSISM008_ADDR1 * INTO TABLE @DATA(IT_BAPIBUSISM008_ADDR12). *--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_BAPIBUSISM008_ADDR1 INDEX 1 INTO DATA(WA_BAPIBUSISM008_ADDR12). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPIBUSISM008_ADDR1 ASSIGNING <BAPIBUSISM008_ADDR1>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPIBUSISM008_ADDR1>-FORMOFADDR = 1.
<BAPIBUSISM008_ADDR1>-NAME = 1.
<BAPIBUSISM008_ADDR1>-NAME_2 = 1.
<BAPIBUSISM008_ADDR1>-NAME_3 = 1.
<BAPIBUSISM008_ADDR1>-NAME_4 = 1.
ENDLOOP. LOOP AT IT_BAPIBUSISM008_ADDR1 INTO WA_BAPIBUSISM008_ADDR1. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPIBUSISM008_ADDR1-C_O_NAME, sy-vline,
WA_BAPIBUSISM008_ADDR1-CITY, sy-vline,
WA_BAPIBUSISM008_ADDR1-DISTRICT, sy-vline,
WA_BAPIBUSISM008_ADDR1-CITY_NO, sy-vline,
WA_BAPIBUSISM008_ADDR1-POSTL_COD1, sy-vline,
WA_BAPIBUSISM008_ADDR1-POSTL_COD2, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPIBUSISM008_ADDR1 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_BAPIBUSISM008_ADDR1 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_BAPIBUSISM008_ADDR1 INTO WA_BAPIBUSISM008_ADDR1. *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 CITY_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIBUSISM008_ADDR1-CITY_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-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_BAPIBUSISM008_ADDR1-STREET_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-STREET_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BAPIBUSISM008_ADDR1-LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-LANGU.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DISTRCT_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIBUSISM008_ADDR1-DISTRCT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-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_BAPIBUSISM008_ADDR1-PBOXCIT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-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_BAPIBUSISM008_ADDR1-E_MAIL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-E_MAIL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field HOMECITYNO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIBUSISM008_ADDR1-HOMECITYNO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-HOMECITYNO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field LANGU_CR CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BAPIBUSISM008_ADDR1-LANGU_CR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIBUSISM008_ADDR1-LANGU_CR.
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_BAPIBUSISM008_ADDR1_STR,
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,
HOME_CITY TYPE STRING,
HOMECITYNO TYPE STRING,
PCODE1_EXT TYPE STRING,
PCODE2_EXT TYPE STRING,
PCODE3_EXT TYPE STRING,
PO_W_O_NO TYPE STRING,
PO_BOX_REG TYPE STRING,
POBOX_CTRY TYPE STRING,
PO_CTRYISO TYPE STRING,
HOMEPAGE TYPE STRING,
DONT_USE_S TYPE STRING,
DONT_USE_P TYPE STRING,
HOUSE_NO3 TYPE STRING,
LANGU_CR TYPE STRING,
LANGUCRISO TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPIBUSISM008_ADDR1_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_BAPIBUSISM008_ADDR1_STR-FORMOFADDR sy-vline
WA_BAPIBUSISM008_ADDR1_STR-NAME sy-vline
WA_BAPIBUSISM008_ADDR1_STR-NAME_2 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-NAME_3 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-NAME_4 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-C_O_NAME sy-vline
WA_BAPIBUSISM008_ADDR1_STR-CITY sy-vline
WA_BAPIBUSISM008_ADDR1_STR-DISTRICT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-CITY_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-POSTL_COD1 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-POSTL_COD2 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-POSTL_COD3 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PO_BOX sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PO_BOX_CIT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-DELIV_DIS sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STREET sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STREET_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STR_ABBR sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOUSE_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STR_SUPPL1 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STR_SUPPL2 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-LOCATION sy-vline
WA_BAPIBUSISM008_ADDR1_STR-BUILDING sy-vline
WA_BAPIBUSISM008_ADDR1_STR-FLOOR sy-vline
WA_BAPIBUSISM008_ADDR1_STR-ROOM_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-COUNTRY sy-vline
WA_BAPIBUSISM008_ADDR1_STR-LANGU sy-vline
WA_BAPIBUSISM008_ADDR1_STR-REGION sy-vline
WA_BAPIBUSISM008_ADDR1_STR-SORT1 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-SORT2 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TIME_ZONE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TAXJURCODE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-ADR_NOTES sy-vline
WA_BAPIBUSISM008_ADDR1_STR-COMM_TYPE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TEL1_NUMBR sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TEL1_EXT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-FAX_NUMBER sy-vline
WA_BAPIBUSISM008_ADDR1_STR-FAX_EXTENS sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STREET_LNG sy-vline
WA_BAPIBUSISM008_ADDR1_STR-DISTRCT_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-CHCKSTATUS sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PBOXCIT_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TRANSPZONE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOUSE_NO2 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-E_MAIL sy-vline
WA_BAPIBUSISM008_ADDR1_STR-STR_SUPPL3 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-TITLE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-COUNTRYISO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-LANGU_ISO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-BUILD_LONG sy-vline
WA_BAPIBUSISM008_ADDR1_STR-REGIOGROUP sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOME_CITY sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOMECITYNO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PCODE1_EXT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PCODE2_EXT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PCODE3_EXT sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PO_W_O_NO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PO_BOX_REG sy-vline
WA_BAPIBUSISM008_ADDR1_STR-POBOX_CTRY sy-vline
WA_BAPIBUSISM008_ADDR1_STR-PO_CTRYISO sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOMEPAGE sy-vline
WA_BAPIBUSISM008_ADDR1_STR-DONT_USE_S sy-vline
WA_BAPIBUSISM008_ADDR1_STR-DONT_USE_P sy-vline
WA_BAPIBUSISM008_ADDR1_STR-HOUSE_NO3 sy-vline
WA_BAPIBUSISM008_ADDR1_STR-LANGU_CR sy-vline
WA_BAPIBUSISM008_ADDR1_STR-LANGUCRISO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.