ABAP Select data from SAP table BBP_PDS_ITMADM 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 BBP_PDS_ITMADM 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 BBP_PDS_ITMADM. 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 BBP_PDS_ITMADM 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_BBP_PDS_ITMADM TYPE STANDARD TABLE OF BBP_PDS_ITMADM, WA_BBP_PDS_ITMADM TYPE BBP_PDS_ITMADM, 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: <BBP_PDS_ITMADM> TYPE BBP_PDS_ITMADM. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BBP_PDS_ITMADM. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BBP_PDS_ITMADM INTO TABLE IT_BBP_PDS_ITMADM. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BBP_PDS_ITMADM * INTO TABLE @DATA(IT_BBP_PDS_ITMADM2). *--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_BBP_PDS_ITMADM INDEX 1 INTO DATA(WA_BBP_PDS_ITMADM2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BBP_PDS_ITMADM ASSIGNING <BBP_PDS_ITMADM>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BBP_PDS_ITMADM>-CLIENT = 1.
<BBP_PDS_ITMADM>-GUID = 1.
<BBP_PDS_ITMADM>-CREATED_AT = 1.
<BBP_PDS_ITMADM>-CREATED_BY = 1.
<BBP_PDS_ITMADM>-CHANGED_AT = 1.
ENDLOOP. LOOP AT IT_BBP_PDS_ITMADM INTO WA_BBP_PDS_ITMADM. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BBP_PDS_ITMADM-CHANGED_BY, sy-vline,
WA_BBP_PDS_ITMADM-OBJECT_TYPE, sy-vline,
WA_BBP_PDS_ITMADM-DESCRIPTION_UC, sy-vline,
WA_BBP_PDS_ITMADM-HEADER, sy-vline,
WA_BBP_PDS_ITMADM-PARENT, sy-vline,
WA_BBP_PDS_ITMADM-ALTERNATIVE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BBP_PDS_ITMADM 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_BBP_PDS_ITMADM 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_BBP_PDS_ITMADM INTO WA_BBP_PDS_ITMADM. *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 TSTLC, internal->external for field CREATED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-CREATED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-CREATED_AT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTLC, internal->external for field CHANGED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-CHANGED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-CHANGED_AT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PRODUCT_SRC_SYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-PRODUCT_SRC_SYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-PRODUCT_SRC_SYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field ITM_LANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-ITM_LANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-ITM_LANGUAGE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field ORDER_DATE CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-ORDER_DATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-ORDER_DATE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LOG_SYSTEM_EXT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-LOG_SYSTEM_EXT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-LOG_SYSTEM_EXT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PARTNER_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-PARTNER_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-PARTNER_ID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field G_L_ACCT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BBP_PDS_ITMADM-G_L_ACCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BBP_PDS_ITMADM-G_L_ACCT.
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_BBP_PDS_ITMADM_STR,
CLIENT TYPE STRING,
GUID TYPE STRING,
CREATED_AT TYPE STRING,
CREATED_BY TYPE STRING,
CHANGED_AT TYPE STRING,
CHANGED_BY TYPE STRING,
OBJECT_TYPE TYPE STRING,
DESCRIPTION_UC TYPE STRING,
HEADER TYPE STRING,
PARENT TYPE STRING,
ALTERNATIVE TYPE STRING,
PRODUCT TYPE STRING,
PRODUCT_SRC_SYS TYPE STRING,
ORDERED_PROD TYPE STRING,
PARTNER_PROD TYPE STRING,
DESCRIPTION TYPE STRING,
ITM_LANGUAGE TYPE STRING,
NUMBER_INT TYPE STRING,
NUMBER_EXT TYPE STRING,
ITM_TYPE TYPE STRING,
ORDER_DATE TYPE STRING,
SUBST_REASON TYPE STRING,
ITM_USAGE TYPE STRING,
ITM_TYPE_USAGE TYPE STRING,
PRODUCT_KIND TYPE STRING,
LOG_SYSTEM_EXT TYPE STRING,
ORDERADM_I_DUMMY TYPE STRING,
DEL_IND TYPE STRING,
ACTIVE_ITEM TYPE STRING,
VERSION_TYPE TYPE STRING,
SELECTED TYPE STRING,
SELECTED_FOR_ACTION TYPE STRING,
VPER_TYPE TYPE STRING,
ACC_CAT TYPE STRING,
GENERIC_ACC TYPE STRING,
DESCR_GENERIC_ACC TYPE STRING,
UNIT_TEXT TYPE STRING,
MULTI TYPE STRING,
UNPLANNED TYPE STRING,
NOT_ALLOWED TYPE STRING,
NO_DETAIL TYPE STRING,
NO_COPY TYPE STRING,
EXPANDED TYPE STRING,
HIER_GROUP TYPE STRING,
LIM_GROUP TYPE STRING,
NUMBER_INT_EXT TYPE STRING,
INITIAL_VALUE TYPE STRING,
PARTNER_CHANGE TYPE STRING,
PARTNER_ID TYPE STRING,
PARTNER_NAME TYPE STRING,
STEPL TYPE STRING,
ACC_CAT_TXT TYPE STRING,
TAX_CODE_TEXT TYPE STRING,
G_L_ACCT TYPE STRING,
MAX_QUANTITY TYPE STRING,
MAX_VALUE TYPE STRING,
NOQUANTITY TYPE STRING,
PO_PRICE TYPE STRING,
PO_PRICE_UNIT TYPE STRING,
PO_QUANTITY TYPE STRING,
PO_VALUE TYPE STRING,
PO_CURRENCY TYPE STRING,
PO_VALIDITY_FROM TYPE STRING,
PO_VALIDITY_TO TYPE STRING,
CF_PRICE TYPE STRING,
CF_PRICE_UNIT TYPE STRING,
CF_QUANTITY TYPE STRING,
CF_VALUE TYPE STRING,
IV_QUANTITY_E TYPE STRING,
IV_VALUE_E TYPE STRING,
BE_LIMIT TYPE STRING,
CATEGORY_TEXT TYPE STRING,
IV_INCOTERM_KEY TYPE STRING,
IV_INCOTERM_LOC TYPE STRING,
DOCUMENTS_AVAIL TYPE STRING,
ERROR_TYPE TYPE STRING,
CF_GROUP TYPE STRING,
RT_SELECTED TYPE STRING,
XML_TAX_INFO TYPE STRING,
DESCR_GL_ACCT TYPE STRING,
POPIN TYPE STRING,
ITEM_KIND_TEXT TYPE STRING,
IMG_SRC_DOC_AVAIL TYPE STRING,
PRICE_UI TYPE STRING,
VALUE_UI TYPE STRING,
CURRENCY_UI TYPE STRING,
FINAL_ORDER TYPE STRING,
COPY_OF_GUID TYPE STRING,
PS_D_STATUS TYPE STRING,
PS_H_LEVEL TYPE STRING,
PS_HAS_CHILD TYPE STRING,
PS_SELECTED_HINDEX TYPE STRING,END OF T_EKKO_STR. DATA: WA_BBP_PDS_ITMADM_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_BBP_PDS_ITMADM_STR-CLIENT sy-vline
WA_BBP_PDS_ITMADM_STR-GUID sy-vline
WA_BBP_PDS_ITMADM_STR-CREATED_AT sy-vline
WA_BBP_PDS_ITMADM_STR-CREATED_BY sy-vline
WA_BBP_PDS_ITMADM_STR-CHANGED_AT sy-vline
WA_BBP_PDS_ITMADM_STR-CHANGED_BY sy-vline
WA_BBP_PDS_ITMADM_STR-OBJECT_TYPE sy-vline
WA_BBP_PDS_ITMADM_STR-DESCRIPTION_UC sy-vline
WA_BBP_PDS_ITMADM_STR-HEADER sy-vline
WA_BBP_PDS_ITMADM_STR-PARENT sy-vline
WA_BBP_PDS_ITMADM_STR-ALTERNATIVE sy-vline
WA_BBP_PDS_ITMADM_STR-PRODUCT sy-vline
WA_BBP_PDS_ITMADM_STR-PRODUCT_SRC_SYS sy-vline
WA_BBP_PDS_ITMADM_STR-ORDERED_PROD sy-vline
WA_BBP_PDS_ITMADM_STR-PARTNER_PROD sy-vline
WA_BBP_PDS_ITMADM_STR-DESCRIPTION sy-vline
WA_BBP_PDS_ITMADM_STR-ITM_LANGUAGE sy-vline
WA_BBP_PDS_ITMADM_STR-NUMBER_INT sy-vline
WA_BBP_PDS_ITMADM_STR-NUMBER_EXT sy-vline
WA_BBP_PDS_ITMADM_STR-ITM_TYPE sy-vline
WA_BBP_PDS_ITMADM_STR-ORDER_DATE sy-vline
WA_BBP_PDS_ITMADM_STR-SUBST_REASON sy-vline
WA_BBP_PDS_ITMADM_STR-ITM_USAGE sy-vline
WA_BBP_PDS_ITMADM_STR-ITM_TYPE_USAGE sy-vline
WA_BBP_PDS_ITMADM_STR-PRODUCT_KIND sy-vline
WA_BBP_PDS_ITMADM_STR-LOG_SYSTEM_EXT sy-vline
WA_BBP_PDS_ITMADM_STR-ORDERADM_I_DUMMY sy-vline
WA_BBP_PDS_ITMADM_STR-DEL_IND sy-vline
WA_BBP_PDS_ITMADM_STR-ACTIVE_ITEM sy-vline
WA_BBP_PDS_ITMADM_STR-VERSION_TYPE sy-vline
WA_BBP_PDS_ITMADM_STR-SELECTED sy-vline
WA_BBP_PDS_ITMADM_STR-SELECTED_FOR_ACTION sy-vline
WA_BBP_PDS_ITMADM_STR-VPER_TYPE sy-vline
WA_BBP_PDS_ITMADM_STR-ACC_CAT sy-vline
WA_BBP_PDS_ITMADM_STR-GENERIC_ACC sy-vline
WA_BBP_PDS_ITMADM_STR-DESCR_GENERIC_ACC sy-vline
WA_BBP_PDS_ITMADM_STR-UNIT_TEXT sy-vline
WA_BBP_PDS_ITMADM_STR-MULTI sy-vline
WA_BBP_PDS_ITMADM_STR-UNPLANNED sy-vline
WA_BBP_PDS_ITMADM_STR-NOT_ALLOWED sy-vline
WA_BBP_PDS_ITMADM_STR-NO_DETAIL sy-vline
WA_BBP_PDS_ITMADM_STR-NO_COPY sy-vline
WA_BBP_PDS_ITMADM_STR-EXPANDED sy-vline
WA_BBP_PDS_ITMADM_STR-HIER_GROUP sy-vline
WA_BBP_PDS_ITMADM_STR-LIM_GROUP sy-vline
WA_BBP_PDS_ITMADM_STR-NUMBER_INT_EXT sy-vline
WA_BBP_PDS_ITMADM_STR-INITIAL_VALUE sy-vline
WA_BBP_PDS_ITMADM_STR-PARTNER_CHANGE sy-vline
WA_BBP_PDS_ITMADM_STR-PARTNER_ID sy-vline
WA_BBP_PDS_ITMADM_STR-PARTNER_NAME sy-vline
WA_BBP_PDS_ITMADM_STR-STEPL sy-vline
WA_BBP_PDS_ITMADM_STR-ACC_CAT_TXT sy-vline
WA_BBP_PDS_ITMADM_STR-TAX_CODE_TEXT sy-vline
WA_BBP_PDS_ITMADM_STR-G_L_ACCT sy-vline
WA_BBP_PDS_ITMADM_STR-MAX_QUANTITY sy-vline
WA_BBP_PDS_ITMADM_STR-MAX_VALUE sy-vline
WA_BBP_PDS_ITMADM_STR-NOQUANTITY sy-vline
WA_BBP_PDS_ITMADM_STR-PO_PRICE sy-vline
WA_BBP_PDS_ITMADM_STR-PO_PRICE_UNIT sy-vline
WA_BBP_PDS_ITMADM_STR-PO_QUANTITY sy-vline
WA_BBP_PDS_ITMADM_STR-PO_VALUE sy-vline
WA_BBP_PDS_ITMADM_STR-PO_CURRENCY sy-vline
WA_BBP_PDS_ITMADM_STR-PO_VALIDITY_FROM sy-vline
WA_BBP_PDS_ITMADM_STR-PO_VALIDITY_TO sy-vline
WA_BBP_PDS_ITMADM_STR-CF_PRICE sy-vline
WA_BBP_PDS_ITMADM_STR-CF_PRICE_UNIT sy-vline
WA_BBP_PDS_ITMADM_STR-CF_QUANTITY sy-vline
WA_BBP_PDS_ITMADM_STR-CF_VALUE sy-vline
WA_BBP_PDS_ITMADM_STR-IV_QUANTITY_E sy-vline
WA_BBP_PDS_ITMADM_STR-IV_VALUE_E sy-vline
WA_BBP_PDS_ITMADM_STR-BE_LIMIT sy-vline
WA_BBP_PDS_ITMADM_STR-CATEGORY_TEXT sy-vline
WA_BBP_PDS_ITMADM_STR-IV_INCOTERM_KEY sy-vline
WA_BBP_PDS_ITMADM_STR-IV_INCOTERM_LOC sy-vline
WA_BBP_PDS_ITMADM_STR-DOCUMENTS_AVAIL sy-vline
WA_BBP_PDS_ITMADM_STR-ERROR_TYPE sy-vline
WA_BBP_PDS_ITMADM_STR-CF_GROUP sy-vline
WA_BBP_PDS_ITMADM_STR-RT_SELECTED sy-vline
WA_BBP_PDS_ITMADM_STR-XML_TAX_INFO sy-vline
WA_BBP_PDS_ITMADM_STR-DESCR_GL_ACCT sy-vline
WA_BBP_PDS_ITMADM_STR-POPIN sy-vline
WA_BBP_PDS_ITMADM_STR-ITEM_KIND_TEXT sy-vline
WA_BBP_PDS_ITMADM_STR-IMG_SRC_DOC_AVAIL sy-vline
WA_BBP_PDS_ITMADM_STR-PRICE_UI sy-vline
WA_BBP_PDS_ITMADM_STR-VALUE_UI sy-vline
WA_BBP_PDS_ITMADM_STR-CURRENCY_UI sy-vline
WA_BBP_PDS_ITMADM_STR-FINAL_ORDER sy-vline
WA_BBP_PDS_ITMADM_STR-COPY_OF_GUID sy-vline
WA_BBP_PDS_ITMADM_STR-PS_D_STATUS sy-vline
WA_BBP_PDS_ITMADM_STR-PS_H_LEVEL sy-vline
WA_BBP_PDS_ITMADM_STR-PS_HAS_CHILD sy-vline
WA_BBP_PDS_ITMADM_STR-PS_SELECTED_HINDEX sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.