ABAP Select data from SAP table BAPI_ILOA1 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 BAPI_ILOA1 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 BAPI_ILOA1. 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 BAPI_ILOA1 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_BAPI_ILOA1 TYPE STANDARD TABLE OF BAPI_ILOA1,
      WA_BAPI_ILOA1 TYPE BAPI_ILOA1,
      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: <BAPI_ILOA1> TYPE BAPI_ILOA1.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI_ILOA1
*  INTO TABLE @DATA(IT_BAPI_ILOA12).
*--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_BAPI_ILOA1 INDEX 1 INTO DATA(WA_BAPI_ILOA12).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI_ILOA1 ASSIGNING <BAPI_ILOA1>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_ILOA1>-OPERATION = 1.
<BAPI_ILOA1>-LOC_ACC = 1.
<BAPI_ILOA1>-FUNCT_LOC = 1.
<BAPI_ILOA1>-ABCINDIC = 1.
<BAPI_ILOA1>-ABCINDIC_I = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI_ILOA1-SORTFIELD, sy-vline,
WA_BAPI_ILOA1-SORTFIELD_I, sy-vline,
WA_BAPI_ILOA1-MAINTPLANT, sy-vline,
WA_BAPI_ILOA1-MAINTPLANT_I, sy-vline,
WA_BAPI_ILOA1-MAINTLOC, sy-vline,
WA_BAPI_ILOA1-MAINTLOC_I, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_ILOA1 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_BAPI_ILOA1 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_BAPI_ILOA1 INTO WA_BAPI_ILOA1. *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 TPLNR, internal->external for field FUNCT_LOC CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_BAPI_ILOA1-FUNCT_LOC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ILOA1-FUNCT_LOC.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ABPSP, internal->external for field WBS_ELEM CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_BAPI_ILOA1-WBS_ELEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ILOA1-WBS_ELEM.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit ALPHA, internal->external for field ADDR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ILOA1-ADDR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ILOA1-ADDR_NO.
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_BAPI_ILOA1_STR,
OPERATION TYPE STRING,
LOC_ACC TYPE STRING,
FUNCT_LOC TYPE STRING,
ABCINDIC TYPE STRING,
ABCINDIC_I TYPE STRING,
SORTFIELD TYPE STRING,
SORTFIELD_I TYPE STRING,
MAINTPLANT TYPE STRING,
MAINTPLANT_I TYPE STRING,
MAINTLOC TYPE STRING,
MAINTLOC_I TYPE STRING,
MAINTROOM TYPE STRING,
MAINTROOM_I TYPE STRING,
PLSECTN TYPE STRING,
PLSECTN_I TYPE STRING,
CIM_TYPE TYPE STRING,
PP_WKCTR TYPE STRING,
PP_WKCTR_I TYPE STRING,
BUS_AREA TYPE STRING,
BUS_AREA_I TYPE STRING,
CO_AREA TYPE STRING,
CO_AREA_I TYPE STRING,
COSTCENTER TYPE STRING,
COSTCENTER_I TYPE STRING,
WBS_ELEM TYPE STRING,
WBS_ELEM_I TYPE STRING,
COMP_CODE TYPE STRING,
COMP_CODE_I TYPE STRING,
ASSET_NO TYPE STRING,
ASSET_NO_I TYPE STRING,
SUB_NUMBER TYPE STRING,
SUB_NUMBER_I TYPE STRING,
STDGORD TYPE STRING,
STDGORD_I TYPE STRING,
STLMTORDER TYPE STRING,
STLMTORDER_I TYPE STRING,
TPLNR_I TYPE STRING,
SALES_ORG TYPE STRING,
SALES_ORG_I TYPE STRING,
DISTR_CHAN TYPE STRING,
DISTR_CHAN_I TYPE STRING,
DIVISION TYPE STRING,
DIVISION_I TYPE STRING,
ADDR_NO TYPE STRING,
ADDR_NO_I TYPE STRING,
OBJECT_REF TYPE STRING,
SALES_OFF TYPE STRING,
SALES_GRP TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_ILOA1_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_BAPI_ILOA1_STR-OPERATION sy-vline
WA_BAPI_ILOA1_STR-LOC_ACC sy-vline
WA_BAPI_ILOA1_STR-FUNCT_LOC sy-vline
WA_BAPI_ILOA1_STR-ABCINDIC sy-vline
WA_BAPI_ILOA1_STR-ABCINDIC_I sy-vline
WA_BAPI_ILOA1_STR-SORTFIELD sy-vline
WA_BAPI_ILOA1_STR-SORTFIELD_I sy-vline
WA_BAPI_ILOA1_STR-MAINTPLANT sy-vline
WA_BAPI_ILOA1_STR-MAINTPLANT_I sy-vline
WA_BAPI_ILOA1_STR-MAINTLOC sy-vline
WA_BAPI_ILOA1_STR-MAINTLOC_I sy-vline
WA_BAPI_ILOA1_STR-MAINTROOM sy-vline
WA_BAPI_ILOA1_STR-MAINTROOM_I sy-vline
WA_BAPI_ILOA1_STR-PLSECTN sy-vline
WA_BAPI_ILOA1_STR-PLSECTN_I sy-vline
WA_BAPI_ILOA1_STR-CIM_TYPE sy-vline
WA_BAPI_ILOA1_STR-PP_WKCTR sy-vline
WA_BAPI_ILOA1_STR-PP_WKCTR_I sy-vline
WA_BAPI_ILOA1_STR-BUS_AREA sy-vline
WA_BAPI_ILOA1_STR-BUS_AREA_I sy-vline
WA_BAPI_ILOA1_STR-CO_AREA sy-vline
WA_BAPI_ILOA1_STR-CO_AREA_I sy-vline
WA_BAPI_ILOA1_STR-COSTCENTER sy-vline
WA_BAPI_ILOA1_STR-COSTCENTER_I sy-vline
WA_BAPI_ILOA1_STR-WBS_ELEM sy-vline
WA_BAPI_ILOA1_STR-WBS_ELEM_I sy-vline
WA_BAPI_ILOA1_STR-COMP_CODE sy-vline
WA_BAPI_ILOA1_STR-COMP_CODE_I sy-vline
WA_BAPI_ILOA1_STR-ASSET_NO sy-vline
WA_BAPI_ILOA1_STR-ASSET_NO_I sy-vline
WA_BAPI_ILOA1_STR-SUB_NUMBER sy-vline
WA_BAPI_ILOA1_STR-SUB_NUMBER_I sy-vline
WA_BAPI_ILOA1_STR-STDGORD sy-vline
WA_BAPI_ILOA1_STR-STDGORD_I sy-vline
WA_BAPI_ILOA1_STR-STLMTORDER sy-vline
WA_BAPI_ILOA1_STR-STLMTORDER_I sy-vline
WA_BAPI_ILOA1_STR-TPLNR_I sy-vline
WA_BAPI_ILOA1_STR-SALES_ORG sy-vline
WA_BAPI_ILOA1_STR-SALES_ORG_I sy-vline
WA_BAPI_ILOA1_STR-DISTR_CHAN sy-vline
WA_BAPI_ILOA1_STR-DISTR_CHAN_I sy-vline
WA_BAPI_ILOA1_STR-DIVISION sy-vline
WA_BAPI_ILOA1_STR-DIVISION_I sy-vline
WA_BAPI_ILOA1_STR-ADDR_NO sy-vline
WA_BAPI_ILOA1_STR-ADDR_NO_I sy-vline
WA_BAPI_ILOA1_STR-OBJECT_REF sy-vline
WA_BAPI_ILOA1_STR-SALES_OFF sy-vline
WA_BAPI_ILOA1_STR-SALES_GRP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.