ABAP Select data from SAP table /SAPAPO/SPP_SM 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/SPP_SM 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/SPP_SM. 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/SPP_SM 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/SPP_SM TYPE STANDARD TABLE OF /SAPAPO/SPP_SM, WA_/SAPAPO/SPP_SM TYPE /SAPAPO/SPP_SM, 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/SPP_SM> TYPE /SAPAPO/SPP_SM. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/SPP_SM. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SAPAPO/SPP_SM INTO TABLE IT_/SAPAPO/SPP_SM. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SAPAPO/SPP_SM * INTO TABLE @DATA(IT_/SAPAPO/SPP_SM2). *--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/SPP_SM INDEX 1 INTO DATA(WA_/SAPAPO/SPP_SM2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SAPAPO/SPP_SM ASSIGNING </SAPAPO/SPP_SM>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/SPP_SM>-MANDT = 1.
</SAPAPO/SPP_SM>-SPP_APP = 1.
</SAPAPO/SPP_SM>-AGED_REMARKS = 1.
</SAPAPO/SPP_SM>-DAYS_DEMAND = 1.
</SAPAPO/SPP_SM>-DAYS_ORDER = 1.
ENDLOOP. LOOP AT IT_/SAPAPO/SPP_SM INTO WA_/SAPAPO/SPP_SM. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SAPAPO/SPP_SM-CRITICAL, sy-vline,
WA_/SAPAPO/SPP_SM-POT_CRITICAL, sy-vline,
WA_/SAPAPO/SPP_SM-CRITICAL_PERIOD, sy-vline,
WA_/SAPAPO/SPP_SM-GRPTYPE1, sy-vline,
WA_/SAPAPO/SPP_SM-GRPTYPE2, sy-vline,
WA_/SAPAPO/SPP_SM-GRPTYPE3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/SPP_SM 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/SPP_SM 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/SPP_SM INTO WA_/SAPAPO/SPP_SM. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/SAPAPO/SPP_SM_STR,
MANDT TYPE STRING,
SPP_APP TYPE STRING,
AGED_REMARKS TYPE STRING,
DAYS_DEMAND TYPE STRING,
DAYS_ORDER TYPE STRING,
CRITICAL TYPE STRING,
POT_CRITICAL TYPE STRING,
CRITICAL_PERIOD TYPE STRING,
GRPTYPE1 TYPE STRING,
GRPTYPE2 TYPE STRING,
GRPTYPE3 TYPE STRING,
GRPTYPE4 TYPE STRING,
GRPTYPE5 TYPE STRING,
LEAD_TIME TYPE STRING,
GRPTYPE_ASSIGN TYPE STRING,
REMARK_EXP_DAYS TYPE STRING,
SO_TPOP_ATP TYPE STRING,
SO_TPOP_BO TYPE STRING,
SO_NON_TPOP_ATP TYPE STRING,
SO_NON_TPOP_BO TYPE STRING,
SO_NON_TPOP_FD TYPE STRING,
REMARK_DISP_SO TYPE STRING,
SM_DAYS_HOLD TYPE STRING,
PLANNED_DEMAND TYPE STRING,
CALC_LOGIC TYPE STRING,
HIDE_SO TYPE STRING,
SKIP_CALC_BO_RO TYPE STRING,
FORCE_AGGREGATE TYPE STRING,
SM_MAX_DAYS TYPE STRING,
SM_SHORTAGE_FROM TYPE STRING,
SM_SHORTAGE_TO TYPE STRING,
SPP_CONF_CREA TYPE STRING,
SPP_CP_INCL_SALO TYPE STRING,
SPP_PO_STO_INCL_LPV TYPE STRING,
SPP_CONS_DELIV TYPE STRING,
SPP_CALC_DRP TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/SPP_SM_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/SPP_SM_STR-MANDT sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_APP sy-vline
WA_/SAPAPO/SPP_SM_STR-AGED_REMARKS sy-vline
WA_/SAPAPO/SPP_SM_STR-DAYS_DEMAND sy-vline
WA_/SAPAPO/SPP_SM_STR-DAYS_ORDER sy-vline
WA_/SAPAPO/SPP_SM_STR-CRITICAL sy-vline
WA_/SAPAPO/SPP_SM_STR-POT_CRITICAL sy-vline
WA_/SAPAPO/SPP_SM_STR-CRITICAL_PERIOD sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE1 sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE2 sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE3 sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE4 sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE5 sy-vline
WA_/SAPAPO/SPP_SM_STR-LEAD_TIME sy-vline
WA_/SAPAPO/SPP_SM_STR-GRPTYPE_ASSIGN sy-vline
WA_/SAPAPO/SPP_SM_STR-REMARK_EXP_DAYS sy-vline
WA_/SAPAPO/SPP_SM_STR-SO_TPOP_ATP sy-vline
WA_/SAPAPO/SPP_SM_STR-SO_TPOP_BO sy-vline
WA_/SAPAPO/SPP_SM_STR-SO_NON_TPOP_ATP sy-vline
WA_/SAPAPO/SPP_SM_STR-SO_NON_TPOP_BO sy-vline
WA_/SAPAPO/SPP_SM_STR-SO_NON_TPOP_FD sy-vline
WA_/SAPAPO/SPP_SM_STR-REMARK_DISP_SO sy-vline
WA_/SAPAPO/SPP_SM_STR-SM_DAYS_HOLD sy-vline
WA_/SAPAPO/SPP_SM_STR-PLANNED_DEMAND sy-vline
WA_/SAPAPO/SPP_SM_STR-CALC_LOGIC sy-vline
WA_/SAPAPO/SPP_SM_STR-HIDE_SO sy-vline
WA_/SAPAPO/SPP_SM_STR-SKIP_CALC_BO_RO sy-vline
WA_/SAPAPO/SPP_SM_STR-FORCE_AGGREGATE sy-vline
WA_/SAPAPO/SPP_SM_STR-SM_MAX_DAYS sy-vline
WA_/SAPAPO/SPP_SM_STR-SM_SHORTAGE_FROM sy-vline
WA_/SAPAPO/SPP_SM_STR-SM_SHORTAGE_TO sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_CONF_CREA sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_CP_INCL_SALO sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_PO_STO_INCL_LPV sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_CONS_DELIV sy-vline
WA_/SAPAPO/SPP_SM_STR-SPP_CALC_DRP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.