ABAP Select data from SAP table BBPS_BAPIEKKOL 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 BBPS_BAPIEKKOL 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 BBPS_BAPIEKKOL. 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 BBPS_BAPIEKKOL 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_BBPS_BAPIEKKOL TYPE STANDARD TABLE OF BBPS_BAPIEKKOL,
      WA_BBPS_BAPIEKKOL TYPE BBPS_BAPIEKKOL,
      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: <BBPS_BAPIEKKOL> TYPE BBPS_BAPIEKKOL.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BBPS_BAPIEKKOL
*  INTO TABLE @DATA(IT_BBPS_BAPIEKKOL2).
*--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_BBPS_BAPIEKKOL INDEX 1 INTO DATA(WA_BBPS_BAPIEKKOL2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BBPS_BAPIEKKOL ASSIGNING <BBPS_BAPIEKKOL>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BBPS_BAPIEKKOL>-PO_NUMBER = 1.
<BBPS_BAPIEKKOL>-CO_CODE = 1.
<BBPS_BAPIEKKOL>-DOC_CAT = 1.
<BBPS_BAPIEKKOL>-DOC_TYPE = 1.
<BBPS_BAPIEKKOL>-CNTRL_IND = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BBPS_BAPIEKKOL-DELETE_IND, sy-vline,
WA_BBPS_BAPIEKKOL-STATUS, sy-vline,
WA_BBPS_BAPIEKKOL-CREATED_ON, sy-vline,
WA_BBPS_BAPIEKKOL-CREATED_BY, sy-vline,
WA_BBPS_BAPIEKKOL-ITEM_INTVL, sy-vline,
WA_BBPS_BAPIEKKOL-LAST_ITEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BBPS_BAPIEKKOL 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_BBPS_BAPIEKKOL 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_BBPS_BAPIEKKOL INTO WA_BBPS_BAPIEKKOL. *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_BBPS_BAPIEKKOL-PO_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-PO_NUMBER.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ISOLA, internal->external for field LANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BBPS_BAPIEKKOL-LANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-LANGUAGE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BIDINV_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_BAPIEKKOL-BIDINV_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-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_BBPS_BAPIEKKOL-SUPPL_VEND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-SUPPL_VEND.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ALPHA, internal->external for field RCVG_VEND CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_BAPIEKKOL-RCVG_VEND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-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_BBPS_BAPIEKKOL-UPDATE_GRP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-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_BBPS_BAPIEKKOL-DIFF_INV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-DIFF_INV.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field LOGSYSTEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBPS_BAPIEKKOL-LOGSYSTEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBPS_BAPIEKKOL-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_BBPS_BAPIEKKOL_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,
PROCEDURE 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,
CURRENCY_ISO TYPE STRING,
EXCH_RATE_CM TYPE STRING,
HOLD TYPE STRING,END OF T_EKKO_STR. DATA: WA_BBPS_BAPIEKKOL_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_BBPS_BAPIEKKOL_STR-PO_NUMBER sy-vline
WA_BBPS_BAPIEKKOL_STR-CO_CODE sy-vline
WA_BBPS_BAPIEKKOL_STR-DOC_CAT sy-vline
WA_BBPS_BAPIEKKOL_STR-DOC_TYPE sy-vline
WA_BBPS_BAPIEKKOL_STR-CNTRL_IND sy-vline
WA_BBPS_BAPIEKKOL_STR-DELETE_IND sy-vline
WA_BBPS_BAPIEKKOL_STR-STATUS sy-vline
WA_BBPS_BAPIEKKOL_STR-CREATED_ON sy-vline
WA_BBPS_BAPIEKKOL_STR-CREATED_BY sy-vline
WA_BBPS_BAPIEKKOL_STR-ITEM_INTVL sy-vline
WA_BBPS_BAPIEKKOL_STR-LAST_ITEM sy-vline
WA_BBPS_BAPIEKKOL_STR-VENDOR sy-vline
WA_BBPS_BAPIEKKOL_STR-LANGUAGE sy-vline
WA_BBPS_BAPIEKKOL_STR-PMNTTRMS sy-vline
WA_BBPS_BAPIEKKOL_STR-DSCNT1_TO sy-vline
WA_BBPS_BAPIEKKOL_STR-DSCNT2_TO sy-vline
WA_BBPS_BAPIEKKOL_STR-DSCNT3_TO sy-vline
WA_BBPS_BAPIEKKOL_STR-CASH_DISC1 sy-vline
WA_BBPS_BAPIEKKOL_STR-CASH_DISC2 sy-vline
WA_BBPS_BAPIEKKOL_STR-PURCH_ORG sy-vline
WA_BBPS_BAPIEKKOL_STR-PUR_GROUP sy-vline
WA_BBPS_BAPIEKKOL_STR-CURRENCY sy-vline
WA_BBPS_BAPIEKKOL_STR-EXCH_RATE sy-vline
WA_BBPS_BAPIEKKOL_STR-EX_RATE_FX sy-vline
WA_BBPS_BAPIEKKOL_STR-DOC_DATE sy-vline
WA_BBPS_BAPIEKKOL_STR-VPER_START sy-vline
WA_BBPS_BAPIEKKOL_STR-VPER_END sy-vline
WA_BBPS_BAPIEKKOL_STR-APPLIC_BY sy-vline
WA_BBPS_BAPIEKKOL_STR-QUOT_DEAD sy-vline
WA_BBPS_BAPIEKKOL_STR-BINDG_PER sy-vline
WA_BBPS_BAPIEKKOL_STR-WARRANTY sy-vline
WA_BBPS_BAPIEKKOL_STR-BIDINV_NO sy-vline
WA_BBPS_BAPIEKKOL_STR-QUOTATION sy-vline
WA_BBPS_BAPIEKKOL_STR-QUOT_DATE sy-vline
WA_BBPS_BAPIEKKOL_STR-REF_1 sy-vline
WA_BBPS_BAPIEKKOL_STR-SALES_PERS sy-vline
WA_BBPS_BAPIEKKOL_STR-TELEPHONE sy-vline
WA_BBPS_BAPIEKKOL_STR-SUPPL_VEND sy-vline
WA_BBPS_BAPIEKKOL_STR-CUSTOMER sy-vline
WA_BBPS_BAPIEKKOL_STR-AGREEMENT sy-vline
WA_BBPS_BAPIEKKOL_STR-REJ_REASON sy-vline
WA_BBPS_BAPIEKKOL_STR-COMPL_DLV sy-vline
WA_BBPS_BAPIEKKOL_STR-GR_MESSAGE sy-vline
WA_BBPS_BAPIEKKOL_STR-SUPPL_PLNT sy-vline
WA_BBPS_BAPIEKKOL_STR-RCVG_VEND sy-vline
WA_BBPS_BAPIEKKOL_STR-INCOTERMS1 sy-vline
WA_BBPS_BAPIEKKOL_STR-INCOTERMS2 sy-vline
WA_BBPS_BAPIEKKOL_STR-TARGET_VAL sy-vline
WA_BBPS_BAPIEKKOL_STR-COLL_NO sy-vline
WA_BBPS_BAPIEKKOL_STR-DOC_COND sy-vline
WA_BBPS_BAPIEKKOL_STR-PROCEDURE sy-vline
WA_BBPS_BAPIEKKOL_STR-UPDATE_GRP sy-vline
WA_BBPS_BAPIEKKOL_STR-DIFF_INV sy-vline
WA_BBPS_BAPIEKKOL_STR-EXPORT_NO sy-vline
WA_BBPS_BAPIEKKOL_STR-OUR_REF sy-vline
WA_BBPS_BAPIEKKOL_STR-LOGSYSTEM sy-vline
WA_BBPS_BAPIEKKOL_STR-SUBITEMINT sy-vline
WA_BBPS_BAPIEKKOL_STR-MAST_COND sy-vline
WA_BBPS_BAPIEKKOL_STR-REL_GROUP sy-vline
WA_BBPS_BAPIEKKOL_STR-REL_STRAT sy-vline
WA_BBPS_BAPIEKKOL_STR-REL_IND sy-vline
WA_BBPS_BAPIEKKOL_STR-REL_STATUS sy-vline
WA_BBPS_BAPIEKKOL_STR-SUBJ_TO_R sy-vline
WA_BBPS_BAPIEKKOL_STR-TAXR_CNTRY sy-vline
WA_BBPS_BAPIEKKOL_STR-SCHED_IND sy-vline
WA_BBPS_BAPIEKKOL_STR-VEND_NAME sy-vline
WA_BBPS_BAPIEKKOL_STR-CURRENCY_ISO sy-vline
WA_BBPS_BAPIEKKOL_STR-EXCH_RATE_CM sy-vline
WA_BBPS_BAPIEKKOL_STR-HOLD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.