ABAP Select data from SAP table /SAPSLL/API6800_ITM_S 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 /SAPSLL/API6800_ITM_S 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 /SAPSLL/API6800_ITM_S. 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 /SAPSLL/API6800_ITM_S 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_/SAPSLL/API6800_ITM_S TYPE STANDARD TABLE OF /SAPSLL/API6800_ITM_S,
      WA_/SAPSLL/API6800_ITM_S TYPE /SAPSLL/API6800_ITM_S,
      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: </SAPSLL/API6800_ITM_S> TYPE /SAPSLL/API6800_ITM_S.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SAPSLL/API6800_ITM_S
  INTO TABLE IT_/SAPSLL/API6800_ITM_S.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SAPSLL/API6800_ITM_S
*  INTO TABLE @DATA(IT_/SAPSLL/API6800_ITM_S2).
*--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_/SAPSLL/API6800_ITM_S INDEX 1 INTO DATA(WA_/SAPSLL/API6800_ITM_S2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPSLL/API6800_ITM_S ASSIGNING </SAPSLL/API6800_ITM_S>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPSLL/API6800_ITM_S>-GUID_ITEM = 1.
</SAPSLL/API6800_ITM_S>-ITEM_NUMBER = 1.
</SAPSLL/API6800_ITM_S>-LEGAL_ACTIVE = 1.
</SAPSLL/API6800_ITM_S>-RECHECK_INDICATOR = 1.
</SAPSLL/API6800_ITM_S>-DELETION_INDICATOR = 1.
ENDLOOP.

LOOP AT IT_/SAPSLL/API6800_ITM_S INTO WA_/SAPSLL/API6800_ITM_S.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPSLL/API6800_ITM_S-ITEM_CATEGORY, sy-vline,
WA_/SAPSLL/API6800_ITM_S-INVOICING_COUNTRY, sy-vline,
WA_/SAPSLL/API6800_ITM_S-INVOICING_COUNTRY_ISO, sy-vline,
WA_/SAPSLL/API6800_ITM_S-DEPARTURE_COUNTRY, sy-vline,
WA_/SAPSLL/API6800_ITM_S-DEPARTURE_COUNTRY_ISO, sy-vline,
WA_/SAPSLL/API6800_ITM_S-ARRIVAL_COUNTRY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPSLL/API6800_ITM_S 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_/SAPSLL/API6800_ITM_S 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_/SAPSLL/API6800_ITM_S INTO WA_/SAPSLL/API6800_ITM_S. *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 ITEM_NUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SAPSLL/API6800_ITM_S-ITEM_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPSLL/API6800_ITM_S-ITEM_NUMBER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SLLPR, internal->external for field PRODUCT_ID CALL FUNCTION 'CONVERSION_EXIT_SLLPR_OUTPUT' EXPORTING input = WA_/SAPSLL/API6800_ITM_S-PRODUCT_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPSLL/API6800_ITM_S-PRODUCT_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field DIM_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPSLL/API6800_ITM_S-DIM_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPSLL/API6800_ITM_S-DIM_UOM.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit CUNIT, internal->external for field BASE_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPSLL/API6800_ITM_S-BASE_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPSLL/API6800_ITM_S-BASE_UOM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field LOCATION_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SAPSLL/API6800_ITM_S-LOCATION_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPSLL/API6800_ITM_S-LOCATION_ID.
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_/SAPSLL/API6800_ITM_S_STR,
GUID_ITEM TYPE STRING,
ITEM_NUMBER TYPE STRING,
LEGAL_ACTIVE TYPE STRING,
RECHECK_INDICATOR TYPE STRING,
DELETION_INDICATOR TYPE STRING,
ITEM_CATEGORY TYPE STRING,
INVOICING_COUNTRY TYPE STRING,
INVOICING_COUNTRY_ISO TYPE STRING,
DEPARTURE_COUNTRY TYPE STRING,
DEPARTURE_COUNTRY_ISO TYPE STRING,
ARRIVAL_COUNTRY TYPE STRING,
ARRIVAL_COUNTRY_ISO TYPE STRING,
PRODUCT_ID TYPE STRING,
DIM_UOM TYPE STRING,
DIM_UOM_ISO TYPE STRING,
NUMERATOR TYPE STRING,
DENOMINATOR TYPE STRING,
CONVERSION_FACTOR TYPE STRING,
VAL_CURR TYPE STRING,
VAL_CURR_ISO TYPE STRING,
COUNTRY_OF_ORIGIN TYPE STRING,
COUNTRY_OF_ORIGIN_ISO TYPE STRING,
REGION_OF_ORIGIN TYPE STRING,
PLANT TYPE STRING,
STORAGE_LOCATION TYPE STRING,
PREDECESSOR_QUAL_REFNO TYPE STRING,
PREDECESSOR_REFNO TYPE STRING,
PREDECESSOR_ITEM TYPE STRING,
PREDECESSOR_LOGSYSTEM TYPE STRING,
PREDECESSOR_OBJTP TYPE STRING,
CHANGED_BY TYPE STRING,
PREDECESSOR_REFAPP TYPE STRING,
TAX_DEPARTURE_COUNTRY TYPE STRING,
TAX_DEPARTURE_COUNTRY_ISO TYPE STRING,
TAX_ARRIVAL_COUNTRY TYPE STRING,
TAX_ARRIVAL_COUNTRY_ISO TYPE STRING,
PLANT_GUID TYPE STRING,
SALES_ORGANISATION_GUID TYPE STRING,
PRODUCT_GUID TYPE STRING,
CANCELLATION_INDICATOR TYPE STRING,
CUST_PROCEDURE TYPE STRING,
ADD_DATA1 TYPE STRING,
ADD_DATA2 TYPE STRING,
ADD_DATA3 TYPE STRING,
INCOT TYPE STRING,
INCOLO TYPE STRING,
PAYMENT_TERMS TYPE STRING,
BASE_UOM TYPE STRING,
BASE_UOM_ISO TYPE STRING,
ECPID TYPE STRING,
KMAT_INDICATOR TYPE STRING,
CUS_STAT TYPE STRING,
PRODUCT_ENDUSE TYPE STRING,
LOC_GUID TYPE STRING,
IDENTIFICATION_OF_GOODS TYPE STRING,
LOCATION_ID TYPE STRING,
LOCATION_ID_INDICATOR TYPE STRING,
HG_LV_ITEM TYPE STRING,
ECPID_OP TYPE STRING,
IDENTIFICATION_OF_GOODS_OP TYPE STRING,
MAT_SHORT_TEXT TYPE STRING,
FREE_OF_CHARGE TYPE STRING,
PROJECT_ID TYPE STRING,
BOM_IDENT TYPE STRING,
LOGISTIC_PROCESS TYPE STRING,
HAZARDOUS_GOODS_INDICATOR TYPE STRING,
HAZARDOUS_GOODS_NUMBER TYPE STRING,
TRANSACTION_TYPE TYPE STRING,
EXCISE_MOVEMENT_INDICATOR TYPE STRING,
VEHICLE_IDENTIFICATION TYPE STRING,
THIRD_PARTY_TRANSACTION TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPSLL/API6800_ITM_S_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_/SAPSLL/API6800_ITM_S_STR-GUID_ITEM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ITEM_NUMBER sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-LEGAL_ACTIVE sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-RECHECK_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DELETION_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ITEM_CATEGORY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-INVOICING_COUNTRY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-INVOICING_COUNTRY_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DEPARTURE_COUNTRY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DEPARTURE_COUNTRY_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ARRIVAL_COUNTRY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ARRIVAL_COUNTRY_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PRODUCT_ID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DIM_UOM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DIM_UOM_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-NUMERATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-DENOMINATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-CONVERSION_FACTOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-VAL_CURR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-VAL_CURR_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-COUNTRY_OF_ORIGIN sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-COUNTRY_OF_ORIGIN_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-REGION_OF_ORIGIN sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PLANT sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-STORAGE_LOCATION sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_QUAL_REFNO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_REFNO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_ITEM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_LOGSYSTEM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_OBJTP sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-CHANGED_BY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PREDECESSOR_REFAPP sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-TAX_DEPARTURE_COUNTRY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-TAX_DEPARTURE_COUNTRY_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-TAX_ARRIVAL_COUNTRY sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-TAX_ARRIVAL_COUNTRY_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PLANT_GUID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-SALES_ORGANISATION_GUID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PRODUCT_GUID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-CANCELLATION_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-CUST_PROCEDURE sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ADD_DATA1 sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ADD_DATA2 sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ADD_DATA3 sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-INCOT sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-INCOLO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PAYMENT_TERMS sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-BASE_UOM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-BASE_UOM_ISO sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ECPID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-KMAT_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-CUS_STAT sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PRODUCT_ENDUSE sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-LOC_GUID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-IDENTIFICATION_OF_GOODS sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-LOCATION_ID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-LOCATION_ID_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-HG_LV_ITEM sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-ECPID_OP sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-IDENTIFICATION_OF_GOODS_OP sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-MAT_SHORT_TEXT sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-FREE_OF_CHARGE sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-PROJECT_ID sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-BOM_IDENT sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-LOGISTIC_PROCESS sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-HAZARDOUS_GOODS_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-HAZARDOUS_GOODS_NUMBER sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-TRANSACTION_TYPE sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-EXCISE_MOVEMENT_INDICATOR sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-VEHICLE_IDENTIFICATION sy-vline
WA_/SAPSLL/API6800_ITM_S_STR-THIRD_PARTY_TRANSACTION sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.