ABAP Select data from SAP table BAPI1240_IPEVA 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 BAPI1240_IPEVA 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 BAPI1240_IPEVA. 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 BAPI1240_IPEVA 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_BAPI1240_IPEVA TYPE STANDARD TABLE OF BAPI1240_IPEVA,
      WA_BAPI1240_IPEVA TYPE BAPI1240_IPEVA,
      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: <BAPI1240_IPEVA> TYPE BAPI1240_IPEVA.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI1240_IPEVA
*  INTO TABLE @DATA(IT_BAPI1240_IPEVA2).
*--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_BAPI1240_IPEVA INDEX 1 INTO DATA(WA_BAPI1240_IPEVA2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI1240_IPEVA ASSIGNING <BAPI1240_IPEVA>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI1240_IPEVA>-FUNCTION = 1.
<BAPI1240_IPEVA>-LOGLOCKMOD = 1.
<BAPI1240_IPEVA>-EXTINFO = 1.
<BAPI1240_IPEVA>-PRIMARYKEY = 1.
<BAPI1240_IPEVA>-FOREIGNKEY = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI1240_IPEVA-FLGPRIMKEY, sy-vline,
WA_BAPI1240_IPEVA-FLGFRGNKEY, sy-vline,
WA_BAPI1240_IPEVA-CLIENT, sy-vline,
WA_BAPI1240_IPEVA-RECORD_NO, sy-vline,
WA_BAPI1240_IPEVA-CHNGSTATUS, sy-vline,
WA_BAPI1240_IPEVA-VALID_FROM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI1240_IPEVA 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_BAPI1240_IPEVA 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_BAPI1240_IPEVA INTO WA_BAPI1240_IPEVA. *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 RECORD_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1240_IPEVA-RECORD_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1240_IPEVA-RECORD_NO.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit CHRID, internal->external for field ACC_NOTIFICATION_NO CALL FUNCTION 'CONVERSION_EXIT_CHRID_OUTPUT' EXPORTING input = WA_BAPI1240_IPEVA-ACC_NOTIFICATION_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1240_IPEVA-ACC_NOTIFICATION_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field HOSPITAL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1240_IPEVA-HOSPITAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1240_IPEVA-HOSPITAL.
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_BAPI1240_IPEVA_STR,
FUNCTION TYPE STRING,
LOGLOCKMOD TYPE STRING,
EXTINFO TYPE STRING,
PRIMARYKEY TYPE STRING,
FOREIGNKEY TYPE STRING,
FLGPRIMKEY TYPE STRING,
FLGFRGNKEY TYPE STRING,
CLIENT TYPE STRING,
RECORD_NO TYPE STRING,
CHNGSTATUS TYPE STRING,
VALID_FROM TYPE STRING,
VALID_TO TYPE STRING,
CHANG_NO TYPE STRING,
DEL_IND TYPE STRING,
PARK_IND TYPE STRING,
CREATED_ON TYPE STRING,
CREATED_BY TYPE STRING,
CHANGD_ON TYPE STRING,
CHANGD_BY TYPE STRING,
DATAORIGIN TYPE STRING,
DATA_PROV TYPE STRING,
RECNO_ROOT TYPE STRING,
FURTHER_TREATMENT TYPE STRING,
PERS_GRP_TREATMENT TYPE STRING,
INTERNAL_NOTE TYPE STRING,
FLAG_INTNOTE_LTEXT TYPE STRING,
EXTERNAL_NOTE TYPE STRING,
FLAG_EXTNOTE_LTEXT TYPE STRING,
CEASED_WORK_DATE TYPE STRING,
CEASED_WORK_TIME TYPE STRING,
ABSENCE_SUBTYPE TYPE STRING,
ABSENCE_START_DATE TYPE STRING,
ABSENCE_END_DATE TYPE STRING,
ABSENCE_SEQNR TYPE STRING,
ESTIM_DURATION TYPE STRING,
ABSENCE_WORKDAYS TYPE STRING,
ABSENCE_CALENDERDAYS TYPE STRING,
RESTRICTION_START_DATE TYPE STRING,
RESTRICTION_END_DATE TYPE STRING,
RESTRICTION_WORKDAYS TYPE STRING,
RESTRICTION_CALENDERDAYS TYPE STRING,
PERS_AFF_REFERENCE TYPE STRING,
ACCIDENT_CATEGORY TYPE STRING,
FLAG_REPORTABLE TYPE STRING,
ACC_NOTIFICATION_NO TYPE STRING,
OBJECT_NO TYPE STRING,
FLAG_MAIN_WORKCENTER TYPE STRING,
FLAG_FATALITY TYPE STRING,
PRIMARY_PHYSICIAN TYPE STRING,
PERS_GRP_PRIM_PHYS TYPE STRING,
HOSPITAL TYPE STRING,
PPE TYPE STRING,
SFTY_DEVICE TYPE STRING,
SAF_MEASURE TYPE STRING,
ACC_CAUSE TYPE STRING,
EXT_INFLUENCE TYPE STRING,
ACC_OBJECT TYPE STRING,
MOVEMENT_ACCOBJ TYPE STRING,
ACTIVITY_INJPERS TYPE STRING,
MOVEMENT_INJPER TYPE STRING,
STATUS TYPE STRING,
REL_WITN TYPE STRING,
PERS_GRP_REL_WITN TYPE STRING,
MONTHAGE_WORKPLACE TYPE STRING,
TIME_ZONE TYPE STRING,
FLAG_PRIVACY TYPE STRING,
FLAG_EMERG_ROOM TYPE STRING,
FLAG_INPAT_TRMT TYPE STRING,
DEATH_DATE TYPE STRING,
ACTWRKTIME_START TYPE STRING,
ACTWRKTIME_END TYPE STRING,
AUTOM_KEY TYPE STRING,
EVENT_LOCATION TYPE STRING,
TRANSPORT_TO_HC TYPE STRING,
TRANSPORT_FROM_HC TYPE STRING,
UNCONSCIOUS TYPE STRING,
RESUSCITATION TYPE STRING,
HOSPITALIZATION TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI1240_IPEVA_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_BAPI1240_IPEVA_STR-FUNCTION sy-vline
WA_BAPI1240_IPEVA_STR-LOGLOCKMOD sy-vline
WA_BAPI1240_IPEVA_STR-EXTINFO sy-vline
WA_BAPI1240_IPEVA_STR-PRIMARYKEY sy-vline
WA_BAPI1240_IPEVA_STR-FOREIGNKEY sy-vline
WA_BAPI1240_IPEVA_STR-FLGPRIMKEY sy-vline
WA_BAPI1240_IPEVA_STR-FLGFRGNKEY sy-vline
WA_BAPI1240_IPEVA_STR-CLIENT sy-vline
WA_BAPI1240_IPEVA_STR-RECORD_NO sy-vline
WA_BAPI1240_IPEVA_STR-CHNGSTATUS sy-vline
WA_BAPI1240_IPEVA_STR-VALID_FROM sy-vline
WA_BAPI1240_IPEVA_STR-VALID_TO sy-vline
WA_BAPI1240_IPEVA_STR-CHANG_NO sy-vline
WA_BAPI1240_IPEVA_STR-DEL_IND sy-vline
WA_BAPI1240_IPEVA_STR-PARK_IND sy-vline
WA_BAPI1240_IPEVA_STR-CREATED_ON sy-vline
WA_BAPI1240_IPEVA_STR-CREATED_BY sy-vline
WA_BAPI1240_IPEVA_STR-CHANGD_ON sy-vline
WA_BAPI1240_IPEVA_STR-CHANGD_BY sy-vline
WA_BAPI1240_IPEVA_STR-DATAORIGIN sy-vline
WA_BAPI1240_IPEVA_STR-DATA_PROV sy-vline
WA_BAPI1240_IPEVA_STR-RECNO_ROOT sy-vline
WA_BAPI1240_IPEVA_STR-FURTHER_TREATMENT sy-vline
WA_BAPI1240_IPEVA_STR-PERS_GRP_TREATMENT sy-vline
WA_BAPI1240_IPEVA_STR-INTERNAL_NOTE sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_INTNOTE_LTEXT sy-vline
WA_BAPI1240_IPEVA_STR-EXTERNAL_NOTE sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_EXTNOTE_LTEXT sy-vline
WA_BAPI1240_IPEVA_STR-CEASED_WORK_DATE sy-vline
WA_BAPI1240_IPEVA_STR-CEASED_WORK_TIME sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_SUBTYPE sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_START_DATE sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_END_DATE sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_SEQNR sy-vline
WA_BAPI1240_IPEVA_STR-ESTIM_DURATION sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_WORKDAYS sy-vline
WA_BAPI1240_IPEVA_STR-ABSENCE_CALENDERDAYS sy-vline
WA_BAPI1240_IPEVA_STR-RESTRICTION_START_DATE sy-vline
WA_BAPI1240_IPEVA_STR-RESTRICTION_END_DATE sy-vline
WA_BAPI1240_IPEVA_STR-RESTRICTION_WORKDAYS sy-vline
WA_BAPI1240_IPEVA_STR-RESTRICTION_CALENDERDAYS sy-vline
WA_BAPI1240_IPEVA_STR-PERS_AFF_REFERENCE sy-vline
WA_BAPI1240_IPEVA_STR-ACCIDENT_CATEGORY sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_REPORTABLE sy-vline
WA_BAPI1240_IPEVA_STR-ACC_NOTIFICATION_NO sy-vline
WA_BAPI1240_IPEVA_STR-OBJECT_NO sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_MAIN_WORKCENTER sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_FATALITY sy-vline
WA_BAPI1240_IPEVA_STR-PRIMARY_PHYSICIAN sy-vline
WA_BAPI1240_IPEVA_STR-PERS_GRP_PRIM_PHYS sy-vline
WA_BAPI1240_IPEVA_STR-HOSPITAL sy-vline
WA_BAPI1240_IPEVA_STR-PPE sy-vline
WA_BAPI1240_IPEVA_STR-SFTY_DEVICE sy-vline
WA_BAPI1240_IPEVA_STR-SAF_MEASURE sy-vline
WA_BAPI1240_IPEVA_STR-ACC_CAUSE sy-vline
WA_BAPI1240_IPEVA_STR-EXT_INFLUENCE sy-vline
WA_BAPI1240_IPEVA_STR-ACC_OBJECT sy-vline
WA_BAPI1240_IPEVA_STR-MOVEMENT_ACCOBJ sy-vline
WA_BAPI1240_IPEVA_STR-ACTIVITY_INJPERS sy-vline
WA_BAPI1240_IPEVA_STR-MOVEMENT_INJPER sy-vline
WA_BAPI1240_IPEVA_STR-STATUS sy-vline
WA_BAPI1240_IPEVA_STR-REL_WITN sy-vline
WA_BAPI1240_IPEVA_STR-PERS_GRP_REL_WITN sy-vline
WA_BAPI1240_IPEVA_STR-MONTHAGE_WORKPLACE sy-vline
WA_BAPI1240_IPEVA_STR-TIME_ZONE sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_PRIVACY sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_EMERG_ROOM sy-vline
WA_BAPI1240_IPEVA_STR-FLAG_INPAT_TRMT sy-vline
WA_BAPI1240_IPEVA_STR-DEATH_DATE sy-vline
WA_BAPI1240_IPEVA_STR-ACTWRKTIME_START sy-vline
WA_BAPI1240_IPEVA_STR-ACTWRKTIME_END sy-vline
WA_BAPI1240_IPEVA_STR-AUTOM_KEY sy-vline
WA_BAPI1240_IPEVA_STR-EVENT_LOCATION sy-vline
WA_BAPI1240_IPEVA_STR-TRANSPORT_TO_HC sy-vline
WA_BAPI1240_IPEVA_STR-TRANSPORT_FROM_HC sy-vline
WA_BAPI1240_IPEVA_STR-UNCONSCIOUS sy-vline
WA_BAPI1240_IPEVA_STR-RESUSCITATION sy-vline
WA_BAPI1240_IPEVA_STR-HOSPITALIZATION sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.