ABAP Select data from SAP table BAPI2097EXCASE 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 BAPI2097EXCASE 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 BAPI2097EXCASE. 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 BAPI2097EXCASE 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_BAPI2097EXCASE TYPE STANDARD TABLE OF BAPI2097EXCASE, WA_BAPI2097EXCASE TYPE BAPI2097EXCASE, 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: <BAPI2097EXCASE> TYPE BAPI2097EXCASE. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI2097EXCASE. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI2097EXCASE INTO TABLE IT_BAPI2097EXCASE. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI2097EXCASE * INTO TABLE @DATA(IT_BAPI2097EXCASE2). *--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_BAPI2097EXCASE INDEX 1 INTO DATA(WA_BAPI2097EXCASE2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI2097EXCASE ASSIGNING <BAPI2097EXCASE>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI2097EXCASE>-CLIENT = 1.
<BAPI2097EXCASE>-INSTITUTION = 1.
<BAPI2097EXCASE>-PATCASEID = 1.
<BAPI2097EXCASE>-CASETYPE_STEXT = 1.
<BAPI2097EXCASE>-CASETYPE_EXT = 1.
ENDLOOP. LOOP AT IT_BAPI2097EXCASE INTO WA_BAPI2097EXCASE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI2097EXCASE-CASETYPE, sy-vline,
WA_BAPI2097EXCASE-PATIENTID, sy-vline,
WA_BAPI2097EXCASE-TREATMCATEGORY, sy-vline,
WA_BAPI2097EXCASE-BILLING_STATUS, sy-vline,
WA_BAPI2097EXCASE-RESTRICTED, sy-vline,
WA_BAPI2097EXCASE-GEOGR_AREA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI2097EXCASE 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_BAPI2097EXCASE 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_BAPI2097EXCASE INTO WA_BAPI2097EXCASE. *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 INSTITUTION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-INSTITUTION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-INSTITUTION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PATCASEID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-PATCASEID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-PATCASEID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PATIENTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-PATIENTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-PATIENTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TREATMCATEGORY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-TREATMCATEGORY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-TREATMCATEGORY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REC_ORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-REC_ORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-REC_ORDER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CHILDREN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-CHILDREN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-CHILDREN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EMPLOYEE_TYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-EMPLOYEE_TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-EMPLOYEE_TYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SPECIALTY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-SPECIALTY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-SPECIALTY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DOC_TYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-DOC_TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-DOC_TYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NLJUS, internal->external for field DOC_NO CALL FUNCTION 'CONVERSION_EXIT_NLJUS_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-DOC_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-DOC_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CHOICE_CL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-CHOICE_CL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-CHOICE_CL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field WEIGHT_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-WEIGHT_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-WEIGHT_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field HEIGHT_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-HEIGHT_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-HEIGHT_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REF_PRETRT_TYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-REF_PRETRT_TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-REF_PRETRT_TYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REF_PSTTRT_TYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-REF_PSTTRT_TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-REF_PSTTRT_TYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DEPARTMENT_AD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-DEPARTMENT_AD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-DEPARTMENT_AD.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field NURS_TREAT_OU_AD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-NURS_TREAT_OU_AD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-NURS_TREAT_OU_AD.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DEPARTMENT_DI CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-DEPARTMENT_DI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-DEPARTMENT_DI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field NURS_TREAT_OU_DI CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-NURS_TREAT_OU_DI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-NURS_TREAT_OU_DI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ASLRESIDENCE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI2097EXCASE-ASLRESIDENCE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2097EXCASE-ASLRESIDENCE.
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_BAPI2097EXCASE_STR,
CLIENT TYPE STRING,
INSTITUTION TYPE STRING,
PATCASEID TYPE STRING,
CASETYPE_STEXT TYPE STRING,
CASETYPE_EXT TYPE STRING,
CASETYPE TYPE STRING,
PATIENTID TYPE STRING,
TREATMCATEGORY TYPE STRING,
BILLING_STATUS TYPE STRING,
RESTRICTED TYPE STRING,
GEOGR_AREA TYPE STRING,
CASE_COMMENT TYPE STRING,
CASE_STATUS TYPE STRING,
CHKDIGITCASE TYPE STRING,
EMERG_ADM TYPE STRING,
QUICK_ADM TYPE STRING,
WORK_INCAPACITY TYPE STRING,
START_DATE TYPE STRING,
END_DATE TYPE STRING,
BILL_BLOCK TYPE STRING,
CREATION_DATE TYPE STRING,
CREATION_USER TYPE STRING,
UPDATE_DATE TYPE STRING,
UPDATE_USER TYPE STRING,
CANCEL_IND TYPE STRING,
CANCEL_USER TYPE STRING,
CANCEL_DATE TYPE STRING,
PREVTREATDAYS TYPE STRING,
STATSTC_BLOCK TYPE STRING,
PPA_RELEV TYPE STRING,
REC_ORDER TYPE STRING,
PPA_STATUS TYPE STRING,
PREVIOUS_DAYS TYPE STRING,
OBJECT_NO TYPE STRING,
NON_RESIDENT TYPE STRING,
CHILDREN TYPE STRING,
FOREIGN_CASE TYPE STRING,
CASE_CATEGORY TYPE STRING,
EMPLOYEE_TYPE TYPE STRING,
CANTON_TARIFF TYPE STRING,
CANTON_CONVTN TYPE STRING,
HEALED_DATE TYPE STRING,
APPLSTATUS TYPE STRING,
SPECIALTY TYPE STRING,
CASEENDTYPE TYPE STRING,
DOC_TYPE TYPE STRING,
DOC_NO TYPE STRING,
CHOICE_CL TYPE STRING,
PAT_WEIGHT TYPE STRING,
WEIGHT_UNIT TYPE STRING,
WEIGHT_UNIT_ISO TYPE STRING,
PAT_HEIGHT TYPE STRING,
HEIGHT_UNIT TYPE STRING,
HEIGHT_UNIT_ISO TYPE STRING,
DOC_REF_FL TYPE STRING,
PAT_REF_FL TYPE STRING,
RESPIRATION TYPE STRING,
EXT_CASE_ID TYPE STRING,
MOVEMNT_DATE_AD TYPE STRING,
MOVEMNT_TIME_AD TYPE STRING,
REF_PRETRT_TYPE TYPE STRING,
REF_PSTTRT_TYPE TYPE STRING,
DEPARTMENT_AD TYPE STRING,
NURS_TREAT_OU_AD TYPE STRING,
MOVEMNT_DATE_DI TYPE STRING,
MOVEMNT_TIME_DI TYPE STRING,
DEPARTMENT_DI TYPE STRING,
NURS_TREAT_OU_DI TYPE STRING,
NOBILL_DAYS TYPE STRING,
ASLRESIDENCE TYPE STRING,
ISTATRESIDENCE TYPE STRING,
EXTRABUDGETTREAT TYPE STRING,
PLS_NO TYPE STRING,
INVOICE_COPY TYPE STRING,
MENTAL_HEALTH_LEGAL_STATUS TYPE STRING,
READMISSION TYPE STRING,
SAPS_SC TYPE STRING,
PIM2_SC TYPE STRING,
CRIB_SC TYPE STRING,
NEMS TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI2097EXCASE_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_BAPI2097EXCASE_STR-CLIENT sy-vline
WA_BAPI2097EXCASE_STR-INSTITUTION sy-vline
WA_BAPI2097EXCASE_STR-PATCASEID sy-vline
WA_BAPI2097EXCASE_STR-CASETYPE_STEXT sy-vline
WA_BAPI2097EXCASE_STR-CASETYPE_EXT sy-vline
WA_BAPI2097EXCASE_STR-CASETYPE sy-vline
WA_BAPI2097EXCASE_STR-PATIENTID sy-vline
WA_BAPI2097EXCASE_STR-TREATMCATEGORY sy-vline
WA_BAPI2097EXCASE_STR-BILLING_STATUS sy-vline
WA_BAPI2097EXCASE_STR-RESTRICTED sy-vline
WA_BAPI2097EXCASE_STR-GEOGR_AREA sy-vline
WA_BAPI2097EXCASE_STR-CASE_COMMENT sy-vline
WA_BAPI2097EXCASE_STR-CASE_STATUS sy-vline
WA_BAPI2097EXCASE_STR-CHKDIGITCASE sy-vline
WA_BAPI2097EXCASE_STR-EMERG_ADM sy-vline
WA_BAPI2097EXCASE_STR-QUICK_ADM sy-vline
WA_BAPI2097EXCASE_STR-WORK_INCAPACITY sy-vline
WA_BAPI2097EXCASE_STR-START_DATE sy-vline
WA_BAPI2097EXCASE_STR-END_DATE sy-vline
WA_BAPI2097EXCASE_STR-BILL_BLOCK sy-vline
WA_BAPI2097EXCASE_STR-CREATION_DATE sy-vline
WA_BAPI2097EXCASE_STR-CREATION_USER sy-vline
WA_BAPI2097EXCASE_STR-UPDATE_DATE sy-vline
WA_BAPI2097EXCASE_STR-UPDATE_USER sy-vline
WA_BAPI2097EXCASE_STR-CANCEL_IND sy-vline
WA_BAPI2097EXCASE_STR-CANCEL_USER sy-vline
WA_BAPI2097EXCASE_STR-CANCEL_DATE sy-vline
WA_BAPI2097EXCASE_STR-PREVTREATDAYS sy-vline
WA_BAPI2097EXCASE_STR-STATSTC_BLOCK sy-vline
WA_BAPI2097EXCASE_STR-PPA_RELEV sy-vline
WA_BAPI2097EXCASE_STR-REC_ORDER sy-vline
WA_BAPI2097EXCASE_STR-PPA_STATUS sy-vline
WA_BAPI2097EXCASE_STR-PREVIOUS_DAYS sy-vline
WA_BAPI2097EXCASE_STR-OBJECT_NO sy-vline
WA_BAPI2097EXCASE_STR-NON_RESIDENT sy-vline
WA_BAPI2097EXCASE_STR-CHILDREN sy-vline
WA_BAPI2097EXCASE_STR-FOREIGN_CASE sy-vline
WA_BAPI2097EXCASE_STR-CASE_CATEGORY sy-vline
WA_BAPI2097EXCASE_STR-EMPLOYEE_TYPE sy-vline
WA_BAPI2097EXCASE_STR-CANTON_TARIFF sy-vline
WA_BAPI2097EXCASE_STR-CANTON_CONVTN sy-vline
WA_BAPI2097EXCASE_STR-HEALED_DATE sy-vline
WA_BAPI2097EXCASE_STR-APPLSTATUS sy-vline
WA_BAPI2097EXCASE_STR-SPECIALTY sy-vline
WA_BAPI2097EXCASE_STR-CASEENDTYPE sy-vline
WA_BAPI2097EXCASE_STR-DOC_TYPE sy-vline
WA_BAPI2097EXCASE_STR-DOC_NO sy-vline
WA_BAPI2097EXCASE_STR-CHOICE_CL sy-vline
WA_BAPI2097EXCASE_STR-PAT_WEIGHT sy-vline
WA_BAPI2097EXCASE_STR-WEIGHT_UNIT sy-vline
WA_BAPI2097EXCASE_STR-WEIGHT_UNIT_ISO sy-vline
WA_BAPI2097EXCASE_STR-PAT_HEIGHT sy-vline
WA_BAPI2097EXCASE_STR-HEIGHT_UNIT sy-vline
WA_BAPI2097EXCASE_STR-HEIGHT_UNIT_ISO sy-vline
WA_BAPI2097EXCASE_STR-DOC_REF_FL sy-vline
WA_BAPI2097EXCASE_STR-PAT_REF_FL sy-vline
WA_BAPI2097EXCASE_STR-RESPIRATION sy-vline
WA_BAPI2097EXCASE_STR-EXT_CASE_ID sy-vline
WA_BAPI2097EXCASE_STR-MOVEMNT_DATE_AD sy-vline
WA_BAPI2097EXCASE_STR-MOVEMNT_TIME_AD sy-vline
WA_BAPI2097EXCASE_STR-REF_PRETRT_TYPE sy-vline
WA_BAPI2097EXCASE_STR-REF_PSTTRT_TYPE sy-vline
WA_BAPI2097EXCASE_STR-DEPARTMENT_AD sy-vline
WA_BAPI2097EXCASE_STR-NURS_TREAT_OU_AD sy-vline
WA_BAPI2097EXCASE_STR-MOVEMNT_DATE_DI sy-vline
WA_BAPI2097EXCASE_STR-MOVEMNT_TIME_DI sy-vline
WA_BAPI2097EXCASE_STR-DEPARTMENT_DI sy-vline
WA_BAPI2097EXCASE_STR-NURS_TREAT_OU_DI sy-vline
WA_BAPI2097EXCASE_STR-NOBILL_DAYS sy-vline
WA_BAPI2097EXCASE_STR-ASLRESIDENCE sy-vline
WA_BAPI2097EXCASE_STR-ISTATRESIDENCE sy-vline
WA_BAPI2097EXCASE_STR-EXTRABUDGETTREAT sy-vline
WA_BAPI2097EXCASE_STR-PLS_NO sy-vline
WA_BAPI2097EXCASE_STR-INVOICE_COPY sy-vline
WA_BAPI2097EXCASE_STR-MENTAL_HEALTH_LEGAL_STATUS sy-vline
WA_BAPI2097EXCASE_STR-READMISSION sy-vline
WA_BAPI2097EXCASE_STR-SAPS_SC sy-vline
WA_BAPI2097EXCASE_STR-PIM2_SC sy-vline
WA_BAPI2097EXCASE_STR-CRIB_SC sy-vline
WA_BAPI2097EXCASE_STR-NEMS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.