ABAP Select data from SAP table BAPI2075_7 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 BAPI2075_7 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 BAPI2075_7. 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 BAPI2075_7 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_BAPI2075_7 TYPE STANDARD TABLE OF BAPI2075_7,
      WA_BAPI2075_7 TYPE BAPI2075_7,
      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: <BAPI2075_7> TYPE BAPI2075_7.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI2075_7
*  INTO TABLE @DATA(IT_BAPI2075_72).
*--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_BAPI2075_7 INDEX 1 INTO DATA(WA_BAPI2075_72).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI2075_7 ASSIGNING <BAPI2075_7>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI2075_7>-ORDER = 1.
<BAPI2075_7>-ORDER_TYPE = 1.
<BAPI2075_7>-ORDER_NAME = 1.
<BAPI2075_7>-CO_AREA = 1.
<BAPI2075_7>-COMP_CODE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI2075_7-BUS_AREA, sy-vline,
WA_BAPI2075_7-PLANT, sy-vline,
WA_BAPI2075_7-PROFIT_CTR, sy-vline,
WA_BAPI2075_7-RESPCCTR, sy-vline,
WA_BAPI2075_7-WBS_ELEMENT, sy-vline,
WA_BAPI2075_7-REQUEST_CCTR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI2075_7 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_BAPI2075_7 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_BAPI2075_7 INTO WA_BAPI2075_7. *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 ORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2075_7-ORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2075_7-ORDER.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ABPSN, internal->external for field WBS_ELEMENT CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_BAPI2075_7-WBS_ELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2075_7-WBS_ELEMENT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit ALPHA, internal->external for field REQUEST_ORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2075_7-REQUEST_ORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2075_7-REQUEST_ORDER.
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_BAPI2075_7_STR,
ORDER TYPE STRING,
ORDER_TYPE TYPE STRING,
ORDER_NAME TYPE STRING,
CO_AREA TYPE STRING,
COMP_CODE TYPE STRING,
BUS_AREA TYPE STRING,
PLANT TYPE STRING,
PROFIT_CTR TYPE STRING,
RESPCCTR TYPE STRING,
WBS_ELEMENT TYPE STRING,
REQUEST_CCTR TYPE STRING,
REQU_COMP_CODE TYPE STRING,
SALES_ORD TYPE STRING,
S_ORD_ITEM TYPE STRING,
TAXJURCODE TYPE STRING,
CCTR_POSTED TYPE STRING,
CURRENCY TYPE STRING,
CSTG_SHEET TYPE STRING,
OVERHEAD_KEY TYPE STRING,
RES_ANAL_KEY TYPE STRING,
INTEREST_PROF TYPE STRING,
APPLICANT TYPE STRING,
APPLICANT_PHONE TYPE STRING,
PERSON_RESP TYPE STRING,
PERSON_RESP_PHONE TYPE STRING,
ESTIMATED_COSTS TYPE STRING,
APPLICATION_DATE TYPE STRING,
DEPARTMENT TYPE STRING,
DATE_WORK_BEGINS TYPE STRING,
DATE_WORK_ENDS TYPE STRING,
WORK_PERMIT TYPE STRING,
EXT_ORD_NO TYPE STRING,
PROCESSING_GROUP TYPE STRING,
PLN_RELEASE TYPE STRING,
PLN_COMPLETION TYPE STRING,
PLN_CLOSE TYPE STRING,
REQUEST_ORDER TYPE STRING,
FUNC_AREA TYPE STRING,
FUNC_AREA_LONG TYPE STRING,
IN_CHARGE_USER TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI2075_7_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_BAPI2075_7_STR-ORDER sy-vline
WA_BAPI2075_7_STR-ORDER_TYPE sy-vline
WA_BAPI2075_7_STR-ORDER_NAME sy-vline
WA_BAPI2075_7_STR-CO_AREA sy-vline
WA_BAPI2075_7_STR-COMP_CODE sy-vline
WA_BAPI2075_7_STR-BUS_AREA sy-vline
WA_BAPI2075_7_STR-PLANT sy-vline
WA_BAPI2075_7_STR-PROFIT_CTR sy-vline
WA_BAPI2075_7_STR-RESPCCTR sy-vline
WA_BAPI2075_7_STR-WBS_ELEMENT sy-vline
WA_BAPI2075_7_STR-REQUEST_CCTR sy-vline
WA_BAPI2075_7_STR-REQU_COMP_CODE sy-vline
WA_BAPI2075_7_STR-SALES_ORD sy-vline
WA_BAPI2075_7_STR-S_ORD_ITEM sy-vline
WA_BAPI2075_7_STR-TAXJURCODE sy-vline
WA_BAPI2075_7_STR-CCTR_POSTED sy-vline
WA_BAPI2075_7_STR-CURRENCY sy-vline
WA_BAPI2075_7_STR-CSTG_SHEET sy-vline
WA_BAPI2075_7_STR-OVERHEAD_KEY sy-vline
WA_BAPI2075_7_STR-RES_ANAL_KEY sy-vline
WA_BAPI2075_7_STR-INTEREST_PROF sy-vline
WA_BAPI2075_7_STR-APPLICANT sy-vline
WA_BAPI2075_7_STR-APPLICANT_PHONE sy-vline
WA_BAPI2075_7_STR-PERSON_RESP sy-vline
WA_BAPI2075_7_STR-PERSON_RESP_PHONE sy-vline
WA_BAPI2075_7_STR-ESTIMATED_COSTS sy-vline
WA_BAPI2075_7_STR-APPLICATION_DATE sy-vline
WA_BAPI2075_7_STR-DEPARTMENT sy-vline
WA_BAPI2075_7_STR-DATE_WORK_BEGINS sy-vline
WA_BAPI2075_7_STR-DATE_WORK_ENDS sy-vline
WA_BAPI2075_7_STR-WORK_PERMIT sy-vline
WA_BAPI2075_7_STR-EXT_ORD_NO sy-vline
WA_BAPI2075_7_STR-PROCESSING_GROUP sy-vline
WA_BAPI2075_7_STR-PLN_RELEASE sy-vline
WA_BAPI2075_7_STR-PLN_COMPLETION sy-vline
WA_BAPI2075_7_STR-PLN_CLOSE sy-vline
WA_BAPI2075_7_STR-REQUEST_ORDER sy-vline
WA_BAPI2075_7_STR-FUNC_AREA sy-vline
WA_BAPI2075_7_STR-FUNC_AREA_LONG sy-vline
WA_BAPI2075_7_STR-IN_CHARGE_USER sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.