ABAP Select data from SAP table /SAPAPO/STORAGE_PEG_ALERTSTR 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 /SAPAPO/STORAGE_PEG_ALERTSTR 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 /SAPAPO/STORAGE_PEG_ALERTSTR. 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 /SAPAPO/STORAGE_PEG_ALERTSTR 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_/SAPAPO/STORAGE_PEG_ALERTSTR TYPE STANDARD TABLE OF /SAPAPO/STORAGE_PEG_ALERTSTR, WA_/SAPAPO/STORAGE_PEG_ALERTSTR TYPE /SAPAPO/STORAGE_PEG_ALERTSTR, 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: </SAPAPO/STORAGE_PEG_ALERTSTR> TYPE /SAPAPO/STORAGE_PEG_ALERTSTR. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/STORAGE_PEG_ALERTSTR. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SAPAPO/STORAGE_PEG_ALERTSTR INTO TABLE IT_/SAPAPO/STORAGE_PEG_ALERTSTR. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SAPAPO/STORAGE_PEG_ALERTSTR * INTO TABLE @DATA(IT_/SAPAPO/STORAGE_PEG_ALERTSTR2). *--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_/SAPAPO/STORAGE_PEG_ALERTSTR INDEX 1 INTO DATA(WA_/SAPAPO/STORAGE_PEG_ALERTSTR2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SAPAPO/STORAGE_PEG_ALERTSTR ASSIGNING </SAPAPO/STORAGE_PEG_ALERTSTR>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/STORAGE_PEG_ALERTSTR>-AOT = 1.
</SAPAPO/STORAGE_PEG_ALERTSTR>-AT_ID = 1.
</SAPAPO/STORAGE_PEG_ALERTSTR>-STATUS_ICON = 1.
</SAPAPO/STORAGE_PEG_ALERTSTR>-PRIORITY = 1.
</SAPAPO/STORAGE_PEG_ALERTSTR>-PRIOICON = 1.
ENDLOOP. LOOP AT IT_/SAPAPO/STORAGE_PEG_ALERTSTR INTO WA_/SAPAPO/STORAGE_PEG_ALERTSTR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SAPAPO/STORAGE_PEG_ALERTSTR-COLCODE, sy-vline,
WA_/SAPAPO/STORAGE_PEG_ALERTSTR-DESCRIPTION, sy-vline,
WA_/SAPAPO/STORAGE_PEG_ALERTSTR-KEY_FIG, sy-vline,
WA_/SAPAPO/STORAGE_PEG_ALERTSTR-AID_INT, sy-vline,
WA_/SAPAPO/STORAGE_PEG_ALERTSTR-AID, sy-vline,
WA_/SAPAPO/STORAGE_PEG_ALERTSTR-VFROM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/STORAGE_PEG_ALERTSTR 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_/SAPAPO/STORAGE_PEG_ALERTSTR 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_/SAPAPO/STORAGE_PEG_ALERTSTR INTO WA_/SAPAPO/STORAGE_PEG_ALERTSTR. *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 TSTPS, internal->external for field VFROM CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-VFROM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-VFROM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field VTO CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-VTO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-VTO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit VRSIO, internal->external for field PLVER CALL FUNCTION 'CONVERSION_EXIT_VRSIO_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-PLVER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-PLVER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS_OUT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MEINS_OUT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MEINS_OUT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS_IN CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MEINS_IN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/STORAGE_PEG_ALERTSTR-MEINS_IN.
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_/SAPAPO/STORAGE_PEG_ALERTSTR_STR,
AOT TYPE STRING,
AT_ID TYPE STRING,
STATUS_ICON TYPE STRING,
PRIORITY TYPE STRING,
PRIOICON TYPE STRING,
COLCODE TYPE STRING,
DESCRIPTION TYPE STRING,
KEY_FIG TYPE STRING,
AID_INT TYPE STRING,
AID TYPE STRING,
VFROM TYPE STRING,
VTO TYPE STRING,
UNAME_FROM TYPE STRING,
SEC_ATTR TYPE STRING,
AL_NOTE_ID TYPE STRING,
AL_PROCLEV_ID TYPE STRING,
AL_PROCLEV_TEXT TYPE STRING,
AL_PROCESSOR TYPE STRING,
AL_STATUS_ID TYPE STRING,
AL_HIDDEN TYPE STRING,
PLVER TYPE STRING,
RESUID TYPE STRING,
PEGID TYPE STRING,
LOCID TYPE STRING,
LOCNO TYPE STRING,
LOCTX TYPE STRING,
MATID TYPE STRING,
MATNR TYPE STRING,
MAKTX TYPE STRING,
RESNAME TYPE STRING,
RESTEXT TYPE STRING,
ORDERID TYPE STRING,
ORDERTXT_OUT TYPE STRING,
POSITION_NO TYPE STRING,
LINE_NO TYPE STRING,
ACTID TYPE STRING,
OPRNR_OUT TYPE STRING,
ACTQT TYPE STRING,
MEINS_OUT TYPE STRING,
RESUID_IN TYPE STRING,
RESNAME_INPUT TYPE STRING,
RESTEXT_IN TYPE STRING,
ORDERID_IN TYPE STRING,
ORDERTXT_IN TYPE STRING,
POSITION_NO_IN TYPE STRING,
LINE_NO_IN TYPE STRING,
ACTID_IN TYPE STRING,
OPRNR_IN TYPE STRING,
TARQT TYPE STRING,
MEINS_IN TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/STORAGE_PEG_ALERTSTR_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_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AOT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AT_ID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-STATUS_ICON sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-PRIORITY sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-PRIOICON sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-COLCODE sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-DESCRIPTION sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-KEY_FIG sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AID_INT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-VFROM sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-VTO sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-UNAME_FROM sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-SEC_ATTR sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_NOTE_ID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_PROCLEV_ID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_PROCLEV_TEXT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_PROCESSOR sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_STATUS_ID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-AL_HIDDEN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-PLVER sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESUID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-PEGID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-LOCID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-LOCNO sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-LOCTX sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-MATID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-MATNR sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-MAKTX sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESNAME sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESTEXT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ORDERID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ORDERTXT_OUT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-POSITION_NO sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-LINE_NO sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ACTID sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-OPRNR_OUT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ACTQT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-MEINS_OUT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESUID_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESNAME_INPUT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-RESTEXT_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ORDERID_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ORDERTXT_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-POSITION_NO_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-LINE_NO_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-ACTID_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-OPRNR_IN sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-TARQT sy-vline
WA_/SAPAPO/STORAGE_PEG_ALERTSTR_STR-MEINS_IN sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.