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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMB/V_EQU_CODE ASSIGNING </SCMB/V_EQU_CODE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMB/V_EQU_CODE>-MANDT = 1.
</SCMB/V_EQU_CODE>-EQUI_TYPE = 1.
</SCMB/V_EQU_CODE>-EQUI_CODE = 1.
</SCMB/V_EQU_CODE>-DESCR = 1.
</SCMB/V_EQU_CODE>-REDUCED_PLANNING_SCOPE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMB/V_EQU_CODE-EQUI_TYPE_RES_GUID, sy-vline,
WA_/SCMB/V_EQU_CODE-TARE_WEIGHT, sy-vline,
WA_/SCMB/V_EQU_CODE-TARE_WEIGHT_UOM, sy-vline,
WA_/SCMB/V_EQU_CODE-TARE_VOLUME, sy-vline,
WA_/SCMB/V_EQU_CODE-TARE_VOLUME_UOM, sy-vline,
WA_/SCMB/V_EQU_CODE-TEU_COUNT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMB/V_EQU_CODE 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_/SCMB/V_EQU_CODE 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_/SCMB/V_EQU_CODE INTO WA_/SCMB/V_EQU_CODE. *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 CUNIT, internal->external for field TARE_WEIGHT_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/V_EQU_CODE-TARE_WEIGHT_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/V_EQU_CODE-TARE_WEIGHT_UOM.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

*Conversion exit MATN1, internal->external for field PACKMATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SCMB/V_EQU_CODE-PACKMATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/V_EQU_CODE-PACKMATNR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit CUNIT, internal->external for field MAX_GROSS_WEIGHT_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCMB/V_EQU_CODE-MAX_GROSS_WEIGHT_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/V_EQU_CODE-MAX_GROSS_WEIGHT_UOM.
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_/SCMB/V_EQU_CODE_STR,
MANDT TYPE STRING,
EQUI_TYPE TYPE STRING,
EQUI_CODE TYPE STRING,
DESCR TYPE STRING,
REDUCED_PLANNING_SCOPE TYPE STRING,
EQUI_TYPE_RES_GUID TYPE STRING,
TARE_WEIGHT TYPE STRING,
TARE_WEIGHT_UOM TYPE STRING,
TARE_VOLUME TYPE STRING,
TARE_VOLUME_UOM TYPE STRING,
TEU_COUNT TYPE STRING,
PAYLOAD_WEIGHT TYPE STRING,
PAYLOAD_WGHT_UOM TYPE STRING,
CUBIC_CAPACITY TYPE STRING,
CUBIC_CAPA_UOM TYPE STRING,
INTERNAL_LENGTH TYPE STRING,
INTERNAL_WIDTH TYPE STRING,
INTERNAL_HEIGHT TYPE STRING,
INTERNAL_LWH_UOM TYPE STRING,
TEMP_CONTROL TYPE STRING,
TEMP_CTRL_MIN TYPE STRING,
TEMP_CTRL_MAX TYPE STRING,
TEMP_UOM TYPE STRING,
VENTILATED TYPE STRING,
ULD_CLASS TYPE STRING,
IATA_COMPLIANT TYPE STRING,
VALDIATE_ULD_NUMBER TYPE STRING,
ULD_LOADING_INSTRUCTIONS TYPE STRING,
MAX_LENGTH TYPE STRING,
MAX_WIDTH TYPE STRING,
MAX_HEIGHT TYPE STRING,
MAX_LWH_UOM TYPE STRING,
PIC_URL TYPE STRING,
PACKMATNR TYPE STRING,
QUAN_UNITS TYPE STRING,
QUAN_UNITS_UOM TYPE STRING,
ALT_QUAN_UNITS TYPE STRING,
ALT_QUAN_UNITS_UOM TYPE STRING,
MAX_GROSS_WEIGHT TYPE STRING,
MAX_GROSS_WEIGHT_UOM TYPE STRING,
FOOD_GRADE_IND TYPE STRING,
TYPE_CLASS TYPE STRING,
DELETION_FLAG TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMB/V_EQU_CODE_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_/SCMB/V_EQU_CODE_STR-MANDT sy-vline
WA_/SCMB/V_EQU_CODE_STR-EQUI_TYPE sy-vline
WA_/SCMB/V_EQU_CODE_STR-EQUI_CODE sy-vline
WA_/SCMB/V_EQU_CODE_STR-DESCR sy-vline
WA_/SCMB/V_EQU_CODE_STR-REDUCED_PLANNING_SCOPE sy-vline
WA_/SCMB/V_EQU_CODE_STR-EQUI_TYPE_RES_GUID sy-vline
WA_/SCMB/V_EQU_CODE_STR-TARE_WEIGHT sy-vline
WA_/SCMB/V_EQU_CODE_STR-TARE_WEIGHT_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-TARE_VOLUME sy-vline
WA_/SCMB/V_EQU_CODE_STR-TARE_VOLUME_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-TEU_COUNT sy-vline
WA_/SCMB/V_EQU_CODE_STR-PAYLOAD_WEIGHT sy-vline
WA_/SCMB/V_EQU_CODE_STR-PAYLOAD_WGHT_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-CUBIC_CAPACITY sy-vline
WA_/SCMB/V_EQU_CODE_STR-CUBIC_CAPA_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-INTERNAL_LENGTH sy-vline
WA_/SCMB/V_EQU_CODE_STR-INTERNAL_WIDTH sy-vline
WA_/SCMB/V_EQU_CODE_STR-INTERNAL_HEIGHT sy-vline
WA_/SCMB/V_EQU_CODE_STR-INTERNAL_LWH_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-TEMP_CONTROL sy-vline
WA_/SCMB/V_EQU_CODE_STR-TEMP_CTRL_MIN sy-vline
WA_/SCMB/V_EQU_CODE_STR-TEMP_CTRL_MAX sy-vline
WA_/SCMB/V_EQU_CODE_STR-TEMP_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-VENTILATED sy-vline
WA_/SCMB/V_EQU_CODE_STR-ULD_CLASS sy-vline
WA_/SCMB/V_EQU_CODE_STR-IATA_COMPLIANT sy-vline
WA_/SCMB/V_EQU_CODE_STR-VALDIATE_ULD_NUMBER sy-vline
WA_/SCMB/V_EQU_CODE_STR-ULD_LOADING_INSTRUCTIONS sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_LENGTH sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_WIDTH sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_HEIGHT sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_LWH_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-PIC_URL sy-vline
WA_/SCMB/V_EQU_CODE_STR-PACKMATNR sy-vline
WA_/SCMB/V_EQU_CODE_STR-QUAN_UNITS sy-vline
WA_/SCMB/V_EQU_CODE_STR-QUAN_UNITS_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-ALT_QUAN_UNITS sy-vline
WA_/SCMB/V_EQU_CODE_STR-ALT_QUAN_UNITS_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_GROSS_WEIGHT sy-vline
WA_/SCMB/V_EQU_CODE_STR-MAX_GROSS_WEIGHT_UOM sy-vline
WA_/SCMB/V_EQU_CODE_STR-FOOD_GRADE_IND sy-vline
WA_/SCMB/V_EQU_CODE_STR-TYPE_CLASS sy-vline
WA_/SCMB/V_EQU_CODE_STR-DELETION_FLAG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.