ABAP Select data from SAP table CPS_INPUT_SEGMENT 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 CPS_INPUT_SEGMENT 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 CPS_INPUT_SEGMENT. 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 CPS_INPUT_SEGMENT 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_CPS_INPUT_SEGMENT TYPE STANDARD TABLE OF CPS_INPUT_SEGMENT, WA_CPS_INPUT_SEGMENT TYPE CPS_INPUT_SEGMENT, 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: <CPS_INPUT_SEGMENT> TYPE CPS_INPUT_SEGMENT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CPS_INPUT_SEGMENT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CPS_INPUT_SEGMENT INTO TABLE IT_CPS_INPUT_SEGMENT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CPS_INPUT_SEGMENT * INTO TABLE @DATA(IT_CPS_INPUT_SEGMENT2). *--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_CPS_INPUT_SEGMENT INDEX 1 INTO DATA(WA_CPS_INPUT_SEGMENT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CPS_INPUT_SEGMENT ASSIGNING <CPS_INPUT_SEGMENT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CPS_INPUT_SEGMENT>-E1OANEP = 1.
<CPS_INPUT_SEGMENT>-NODE_TYPE = 1.
<CPS_INPUT_SEGMENT>-NODE_ID = 1.
<CPS_INPUT_SEGMENT>-E1PLPOP = 1.
<CPS_INPUT_SEGMENT>-PLNKN = 1.
ENDLOOP. LOOP AT IT_CPS_INPUT_SEGMENT INTO WA_CPS_INPUT_SEGMENT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CPS_INPUT_SEGMENT-ZAEHL, sy-vline,
WA_CPS_INPUT_SEGMENT-VORNR, sy-vline,
WA_CPS_INPUT_SEGMENT-LTXA1, sy-vline,
WA_CPS_INPUT_SEGMENT-ARBID, sy-vline,
WA_CPS_INPUT_SEGMENT-ARBPL, sy-vline,
WA_CPS_INPUT_SEGMENT-STEUS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CPS_INPUT_SEGMENT 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_CPS_INPUT_SEGMENT 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_CPS_INPUT_SEGMENT INTO WA_CPS_INPUT_SEGMENT. *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_CPS_INPUT_SEGMENT_STR,
E1OANEP TYPE STRING,
NODE_TYPE TYPE STRING,
NODE_ID TYPE STRING,
E1PLPOP TYPE STRING,
PLNKN TYPE STRING,
ZAEHL TYPE STRING,
VORNR TYPE STRING,
LTXA1 TYPE STRING,
ARBID TYPE STRING,
ARBPL TYPE STRING,
STEUS TYPE STRING,
TERM TYPE STRING,
LIEF TYPE STRING,
AUTWE TYPE STRING,
RUEK TYPE STRING,
KAPA TYPE STRING,
REWORK TYPE STRING,
NOT_MES_REL TYPE STRING,
VGW01 TYPE STRING,
PAR01_LTXT TYPE STRING,
VGE01 TYPE STRING,
VGW02 TYPE STRING,
PAR02_LTXT TYPE STRING,
VGE02 TYPE STRING,
VGW03 TYPE STRING,
PAR03_LTXT TYPE STRING,
VGE03 TYPE STRING,
VGW04 TYPE STRING,
PAR04_LTXT TYPE STRING,
VGE04 TYPE STRING,
VGW05 TYPE STRING,
PAR05_LTXT TYPE STRING,
VGE05 TYPE STRING,
VGW06 TYPE STRING,
PAR06_LTXT TYPE STRING,
VGE06 TYPE STRING,
SLWID TYPE STRING,
USR00 TYPE STRING,
USR01 TYPE STRING,
USR02 TYPE STRING,
USR03 TYPE STRING,
USR04 TYPE STRING,
USE04 TYPE STRING,
USR05 TYPE STRING,
USE05 TYPE STRING,
USR08 TYPE STRING,
LTXA2 TYPE STRING,
USR09 TYPE STRING,
TXTSP TYPE STRING,
MEINH TYPE STRING,
USR10 TYPE STRING,
USR11 TYPE STRING,
UMREN TYPE STRING,
SOURCE_PLNKN TYPE STRING,
UMREZ TYPE STRING,
SOURCE_ZAEHL TYPE STRING,
BMSCH TYPE STRING,
RFGRP TYPE STRING,
RFSCH TYPE STRING,
RASCH TYPE STRING,
ZEIMB TYPE STRING,
ZMINB TYPE STRING,
ZEILM TYPE STRING,
ZLMAX TYPE STRING,
ZEILP TYPE STRING,
ZLPRO TYPE STRING,
ZWNOR TYPE STRING,
ZWMIN TYPE STRING,
ZEITN TYPE STRING,
ZTNOR TYPE STRING,
AENNR TYPE STRING,
ZEIWN TYPE STRING,
ZEIWM TYPE STRING,
E1PLMZP TYPE STRING,END OF T_EKKO_STR. DATA: WA_CPS_INPUT_SEGMENT_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_CPS_INPUT_SEGMENT_STR-E1OANEP sy-vline
WA_CPS_INPUT_SEGMENT_STR-NODE_TYPE sy-vline
WA_CPS_INPUT_SEGMENT_STR-NODE_ID sy-vline
WA_CPS_INPUT_SEGMENT_STR-E1PLPOP sy-vline
WA_CPS_INPUT_SEGMENT_STR-PLNKN sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZAEHL sy-vline
WA_CPS_INPUT_SEGMENT_STR-VORNR sy-vline
WA_CPS_INPUT_SEGMENT_STR-LTXA1 sy-vline
WA_CPS_INPUT_SEGMENT_STR-ARBID sy-vline
WA_CPS_INPUT_SEGMENT_STR-ARBPL sy-vline
WA_CPS_INPUT_SEGMENT_STR-STEUS sy-vline
WA_CPS_INPUT_SEGMENT_STR-TERM sy-vline
WA_CPS_INPUT_SEGMENT_STR-LIEF sy-vline
WA_CPS_INPUT_SEGMENT_STR-AUTWE sy-vline
WA_CPS_INPUT_SEGMENT_STR-RUEK sy-vline
WA_CPS_INPUT_SEGMENT_STR-KAPA sy-vline
WA_CPS_INPUT_SEGMENT_STR-REWORK sy-vline
WA_CPS_INPUT_SEGMENT_STR-NOT_MES_REL sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW01 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR01_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE01 sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW02 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR02_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE02 sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW03 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR03_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE03 sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW04 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR04_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE04 sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW05 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR05_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE05 sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGW06 sy-vline
WA_CPS_INPUT_SEGMENT_STR-PAR06_LTXT sy-vline
WA_CPS_INPUT_SEGMENT_STR-VGE06 sy-vline
WA_CPS_INPUT_SEGMENT_STR-SLWID sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR00 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR01 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR02 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR03 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR04 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USE04 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR05 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USE05 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR08 sy-vline
WA_CPS_INPUT_SEGMENT_STR-LTXA2 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR09 sy-vline
WA_CPS_INPUT_SEGMENT_STR-TXTSP sy-vline
WA_CPS_INPUT_SEGMENT_STR-MEINH sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR10 sy-vline
WA_CPS_INPUT_SEGMENT_STR-USR11 sy-vline
WA_CPS_INPUT_SEGMENT_STR-UMREN sy-vline
WA_CPS_INPUT_SEGMENT_STR-SOURCE_PLNKN sy-vline
WA_CPS_INPUT_SEGMENT_STR-UMREZ sy-vline
WA_CPS_INPUT_SEGMENT_STR-SOURCE_ZAEHL sy-vline
WA_CPS_INPUT_SEGMENT_STR-BMSCH sy-vline
WA_CPS_INPUT_SEGMENT_STR-RFGRP sy-vline
WA_CPS_INPUT_SEGMENT_STR-RFSCH sy-vline
WA_CPS_INPUT_SEGMENT_STR-RASCH sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEIMB sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZMINB sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEILM sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZLMAX sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEILP sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZLPRO sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZWNOR sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZWMIN sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEITN sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZTNOR sy-vline
WA_CPS_INPUT_SEGMENT_STR-AENNR sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEIWN sy-vline
WA_CPS_INPUT_SEGMENT_STR-ZEIWM sy-vline
WA_CPS_INPUT_SEGMENT_STR-E1PLMZP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.