ABAP Select data from SAP table BAPIEKKOL31I 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 BAPIEKKOL31I 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 BAPIEKKOL31I. 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 BAPIEKKOL31I 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_BAPIEKKOL31I TYPE STANDARD TABLE OF BAPIEKKOL31I, WA_BAPIEKKOL31I TYPE BAPIEKKOL31I, 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: <BAPIEKKOL31I> TYPE BAPIEKKOL31I. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPIEKKOL31I. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPIEKKOL31I INTO TABLE IT_BAPIEKKOL31I. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPIEKKOL31I * INTO TABLE @DATA(IT_BAPIEKKOL31I2). *--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_BAPIEKKOL31I INDEX 1 INTO DATA(WA_BAPIEKKOL31I2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPIEKKOL31I ASSIGNING <BAPIEKKOL31I>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPIEKKOL31I>-PO_NUMBER = 1.
<BAPIEKKOL31I>-CO_CODE = 1.
<BAPIEKKOL31I>-DOC_CAT = 1.
<BAPIEKKOL31I>-DOC_TYPE = 1.
<BAPIEKKOL31I>-CNTRL_IND = 1.
ENDLOOP. LOOP AT IT_BAPIEKKOL31I INTO WA_BAPIEKKOL31I. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPIEKKOL31I-DELETE_IND, sy-vline,
WA_BAPIEKKOL31I-STATUS, sy-vline,
WA_BAPIEKKOL31I-CREATED_ON, sy-vline,
WA_BAPIEKKOL31I-CREATED_BY, sy-vline,
WA_BAPIEKKOL31I-ITEM_INTVL, sy-vline,
WA_BAPIEKKOL31I-LAST_ITEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPIEKKOL31I 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_BAPIEKKOL31I 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_BAPIEKKOL31I INTO WA_BAPIEKKOL31I. *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 PO_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-PO_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-PO_NUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VENDOR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-VENDOR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-VENDOR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field LANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-LANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-LANGUAGE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field BIDINV_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-BIDINV_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-BIDINV_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SUPPL_VEND CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-SUPPL_VEND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-SUPPL_VEND.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CUSTOMER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-CUSTOMER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-CUSTOMER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AGREEMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-AGREEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-AGREEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RCVG_VEND CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-RCVG_VEND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-RCVG_VEND.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field UPDATE_GRP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-UPDATE_GRP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-UPDATE_GRP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DIFF_INV CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-DIFF_INV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-DIFF_INV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LOGSYSTEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIEKKOL31I-LOGSYSTEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIEKKOL31I-LOGSYSTEM.
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_BAPIEKKOL31I_STR,
PO_NUMBER TYPE STRING,
CO_CODE TYPE STRING,
DOC_CAT TYPE STRING,
DOC_TYPE TYPE STRING,
CNTRL_IND TYPE STRING,
DELETE_IND TYPE STRING,
STATUS TYPE STRING,
CREATED_ON TYPE STRING,
CREATED_BY TYPE STRING,
ITEM_INTVL TYPE STRING,
LAST_ITEM TYPE STRING,
VENDOR TYPE STRING,
LANGUAGE TYPE STRING,
PMNTTRMS TYPE STRING,
DSCNT1_TO TYPE STRING,
DSCNT2_TO TYPE STRING,
DSCNT3_TO TYPE STRING,
CASH_DISC1 TYPE STRING,
CASH_DISC2 TYPE STRING,
PURCH_ORG TYPE STRING,
PUR_GROUP TYPE STRING,
CURRENCY TYPE STRING,
EXCH_RATE TYPE STRING,
EX_RATE_FX TYPE STRING,
DOC_DATE TYPE STRING,
VPER_START TYPE STRING,
VPER_END TYPE STRING,
APPLIC_BY TYPE STRING,
QUOT_DEAD TYPE STRING,
BINDG_PER TYPE STRING,
WARRANTY TYPE STRING,
BIDINV_NO TYPE STRING,
QUOTATION TYPE STRING,
QUOT_DATE TYPE STRING,
REF_1 TYPE STRING,
SALES_PERS TYPE STRING,
TELEPHONE TYPE STRING,
SUPPL_VEND TYPE STRING,
CUSTOMER TYPE STRING,
AGREEMENT TYPE STRING,
REJ_REASON TYPE STRING,
COMPL_DLV TYPE STRING,
GR_MESSAGE TYPE STRING,
SUPPL_PLNT TYPE STRING,
RCVG_VEND TYPE STRING,
INCOTERMS1 TYPE STRING,
INCOTERMS2 TYPE STRING,
TARGET_VAL TYPE STRING,
COLL_NO TYPE STRING,
DOC_COND TYPE STRING,
UPDATE_GRP TYPE STRING,
DIFF_INV TYPE STRING,
EXPORT_NO TYPE STRING,
OUR_REF TYPE STRING,
LOGSYSTEM TYPE STRING,
SUBITEMINT TYPE STRING,
MAST_COND TYPE STRING,
REL_GROUP TYPE STRING,
REL_STRAT TYPE STRING,
REL_IND TYPE STRING,
REL_STATUS TYPE STRING,
SUBJ_TO_R TYPE STRING,
TAXR_CNTRY TYPE STRING,
SCHED_IND TYPE STRING,
VEND_NAME TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPIEKKOL31I_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_BAPIEKKOL31I_STR-PO_NUMBER sy-vline
WA_BAPIEKKOL31I_STR-CO_CODE sy-vline
WA_BAPIEKKOL31I_STR-DOC_CAT sy-vline
WA_BAPIEKKOL31I_STR-DOC_TYPE sy-vline
WA_BAPIEKKOL31I_STR-CNTRL_IND sy-vline
WA_BAPIEKKOL31I_STR-DELETE_IND sy-vline
WA_BAPIEKKOL31I_STR-STATUS sy-vline
WA_BAPIEKKOL31I_STR-CREATED_ON sy-vline
WA_BAPIEKKOL31I_STR-CREATED_BY sy-vline
WA_BAPIEKKOL31I_STR-ITEM_INTVL sy-vline
WA_BAPIEKKOL31I_STR-LAST_ITEM sy-vline
WA_BAPIEKKOL31I_STR-VENDOR sy-vline
WA_BAPIEKKOL31I_STR-LANGUAGE sy-vline
WA_BAPIEKKOL31I_STR-PMNTTRMS sy-vline
WA_BAPIEKKOL31I_STR-DSCNT1_TO sy-vline
WA_BAPIEKKOL31I_STR-DSCNT2_TO sy-vline
WA_BAPIEKKOL31I_STR-DSCNT3_TO sy-vline
WA_BAPIEKKOL31I_STR-CASH_DISC1 sy-vline
WA_BAPIEKKOL31I_STR-CASH_DISC2 sy-vline
WA_BAPIEKKOL31I_STR-PURCH_ORG sy-vline
WA_BAPIEKKOL31I_STR-PUR_GROUP sy-vline
WA_BAPIEKKOL31I_STR-CURRENCY sy-vline
WA_BAPIEKKOL31I_STR-EXCH_RATE sy-vline
WA_BAPIEKKOL31I_STR-EX_RATE_FX sy-vline
WA_BAPIEKKOL31I_STR-DOC_DATE sy-vline
WA_BAPIEKKOL31I_STR-VPER_START sy-vline
WA_BAPIEKKOL31I_STR-VPER_END sy-vline
WA_BAPIEKKOL31I_STR-APPLIC_BY sy-vline
WA_BAPIEKKOL31I_STR-QUOT_DEAD sy-vline
WA_BAPIEKKOL31I_STR-BINDG_PER sy-vline
WA_BAPIEKKOL31I_STR-WARRANTY sy-vline
WA_BAPIEKKOL31I_STR-BIDINV_NO sy-vline
WA_BAPIEKKOL31I_STR-QUOTATION sy-vline
WA_BAPIEKKOL31I_STR-QUOT_DATE sy-vline
WA_BAPIEKKOL31I_STR-REF_1 sy-vline
WA_BAPIEKKOL31I_STR-SALES_PERS sy-vline
WA_BAPIEKKOL31I_STR-TELEPHONE sy-vline
WA_BAPIEKKOL31I_STR-SUPPL_VEND sy-vline
WA_BAPIEKKOL31I_STR-CUSTOMER sy-vline
WA_BAPIEKKOL31I_STR-AGREEMENT sy-vline
WA_BAPIEKKOL31I_STR-REJ_REASON sy-vline
WA_BAPIEKKOL31I_STR-COMPL_DLV sy-vline
WA_BAPIEKKOL31I_STR-GR_MESSAGE sy-vline
WA_BAPIEKKOL31I_STR-SUPPL_PLNT sy-vline
WA_BAPIEKKOL31I_STR-RCVG_VEND sy-vline
WA_BAPIEKKOL31I_STR-INCOTERMS1 sy-vline
WA_BAPIEKKOL31I_STR-INCOTERMS2 sy-vline
WA_BAPIEKKOL31I_STR-TARGET_VAL sy-vline
WA_BAPIEKKOL31I_STR-COLL_NO sy-vline
WA_BAPIEKKOL31I_STR-DOC_COND sy-vline
WA_BAPIEKKOL31I_STR-UPDATE_GRP sy-vline
WA_BAPIEKKOL31I_STR-DIFF_INV sy-vline
WA_BAPIEKKOL31I_STR-EXPORT_NO sy-vline
WA_BAPIEKKOL31I_STR-OUR_REF sy-vline
WA_BAPIEKKOL31I_STR-LOGSYSTEM sy-vline
WA_BAPIEKKOL31I_STR-SUBITEMINT sy-vline
WA_BAPIEKKOL31I_STR-MAST_COND sy-vline
WA_BAPIEKKOL31I_STR-REL_GROUP sy-vline
WA_BAPIEKKOL31I_STR-REL_STRAT sy-vline
WA_BAPIEKKOL31I_STR-REL_IND sy-vline
WA_BAPIEKKOL31I_STR-REL_STATUS sy-vline
WA_BAPIEKKOL31I_STR-SUBJ_TO_R sy-vline
WA_BAPIEKKOL31I_STR-TAXR_CNTRY sy-vline
WA_BAPIEKKOL31I_STR-SCHED_IND sy-vline
WA_BAPIEKKOL31I_STR-VEND_NAME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.