ABAP Select data from SAP table PCO_PARAMS_TX 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 PCO_PARAMS_TX 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 PCO_PARAMS_TX. 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 PCO_PARAMS_TX 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_PCO_PARAMS_TX TYPE STANDARD TABLE OF PCO_PARAMS_TX, WA_PCO_PARAMS_TX TYPE PCO_PARAMS_TX, 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: <PCO_PARAMS_TX> TYPE PCO_PARAMS_TX. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PCO_PARAMS_TX. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PCO_PARAMS_TX INTO TABLE IT_PCO_PARAMS_TX. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PCO_PARAMS_TX * INTO TABLE @DATA(IT_PCO_PARAMS_TX2). *--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_PCO_PARAMS_TX INDEX 1 INTO DATA(WA_PCO_PARAMS_TX2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PCO_PARAMS_TX ASSIGNING <PCO_PARAMS_TX>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PCO_PARAMS_TX>-APZNR = 1.
<PCO_PARAMS_TX>-CORTD = 1.
<PCO_PARAMS_TX>-CORTG = 1.
<PCO_PARAMS_TX>-CORTH = 1.
<PCO_PARAMS_TX>-CORTI = 1.
ENDLOOP. LOOP AT IT_PCO_PARAMS_TX INTO WA_PCO_PARAMS_TX. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PCO_PARAMS_TX-CORTJ, sy-vline,
WA_PCO_PARAMS_TX-CORPG, sy-vline,
WA_PCO_PARAMS_TX-CORP1, sy-vline,
WA_PCO_PARAMS_TX-CORP2, sy-vline,
WA_PCO_PARAMS_TX-CORTS, sy-vline,
WA_PCO_PARAMS_TX-CORTB, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PCO_PARAMS_TX 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_PCO_PARAMS_TX 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_PCO_PARAMS_TX INTO WA_PCO_PARAMS_TX. *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_PCO_PARAMS_TX_STR,
APZNR TYPE STRING,
CORTD TYPE STRING,
CORTG TYPE STRING,
CORTH TYPE STRING,
CORTI TYPE STRING,
CORTJ TYPE STRING,
CORPG TYPE STRING,
CORP1 TYPE STRING,
CORP2 TYPE STRING,
CORTS TYPE STRING,
CORTB TYPE STRING,
CORT1 TYPE STRING,
CORT2 TYPE STRING,
CORTC TYPE STRING,
CORTC1 TYPE STRING,
CORTC2 TYPE STRING,
CORVI TYPE STRING,
CORV1 TYPE STRING,
CORV2 TYPE STRING,
COSFC TYPE STRING,
COSIN TYPE STRING,
COSB2 TYPE STRING,
COSE2 TYPE STRING,
PROJT TYPE STRING,
PROJI TYPE STRING,
PROJV TYPE STRING,
PROJB TYPE STRING,
LIMFD TYPE STRING,
CPSFD TYPE STRING,
PROPB TYPE STRING,
COSML TYPE STRING,
COSM1 TYPE STRING,
COSM2 TYPE STRING,
INDPO TYPE STRING,
INDPR TYPE STRING,
CORTX TYPE STRING,
CORDM TYPE STRING,
GRARG TYPE STRING,
GRAPS TYPE STRING,
SEMYA TYPE STRING,
CORPS TYPE STRING,
CORPB TYPE STRING,
BEGPS TYPE STRING,
ENDPS TYPE STRING,
DISAB TYPE STRING,
CORIP TYPE STRING,
CORIT TYPE STRING,
APLIC TYPE STRING,
TABRF TYPE STRING,
COUVT TYPE STRING,
COUVT1 TYPE STRING,
COUVT2 TYPE STRING,
COTIU TYPE STRING,
COREP TYPE STRING,
COEPS TYPE STRING,
WAERS TYPE STRING,
ANZP1 TYPE STRING,
CORPT TYPE STRING,
CORTRI1 TYPE STRING,
CORTRI2 TYPE STRING,
CORTRI3 TYPE STRING,
CORTRI4 TYPE STRING,
CORTRI5 TYPE STRING,
COSTA TYPE STRING,
TDECO TYPE STRING,
TOTALDEDUC TYPE STRING,END OF T_EKKO_STR. DATA: WA_PCO_PARAMS_TX_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_PCO_PARAMS_TX_STR-APZNR sy-vline
WA_PCO_PARAMS_TX_STR-CORTD sy-vline
WA_PCO_PARAMS_TX_STR-CORTG sy-vline
WA_PCO_PARAMS_TX_STR-CORTH sy-vline
WA_PCO_PARAMS_TX_STR-CORTI sy-vline
WA_PCO_PARAMS_TX_STR-CORTJ sy-vline
WA_PCO_PARAMS_TX_STR-CORPG sy-vline
WA_PCO_PARAMS_TX_STR-CORP1 sy-vline
WA_PCO_PARAMS_TX_STR-CORP2 sy-vline
WA_PCO_PARAMS_TX_STR-CORTS sy-vline
WA_PCO_PARAMS_TX_STR-CORTB sy-vline
WA_PCO_PARAMS_TX_STR-CORT1 sy-vline
WA_PCO_PARAMS_TX_STR-CORT2 sy-vline
WA_PCO_PARAMS_TX_STR-CORTC sy-vline
WA_PCO_PARAMS_TX_STR-CORTC1 sy-vline
WA_PCO_PARAMS_TX_STR-CORTC2 sy-vline
WA_PCO_PARAMS_TX_STR-CORVI sy-vline
WA_PCO_PARAMS_TX_STR-CORV1 sy-vline
WA_PCO_PARAMS_TX_STR-CORV2 sy-vline
WA_PCO_PARAMS_TX_STR-COSFC sy-vline
WA_PCO_PARAMS_TX_STR-COSIN sy-vline
WA_PCO_PARAMS_TX_STR-COSB2 sy-vline
WA_PCO_PARAMS_TX_STR-COSE2 sy-vline
WA_PCO_PARAMS_TX_STR-PROJT sy-vline
WA_PCO_PARAMS_TX_STR-PROJI sy-vline
WA_PCO_PARAMS_TX_STR-PROJV sy-vline
WA_PCO_PARAMS_TX_STR-PROJB sy-vline
WA_PCO_PARAMS_TX_STR-LIMFD sy-vline
WA_PCO_PARAMS_TX_STR-CPSFD sy-vline
WA_PCO_PARAMS_TX_STR-PROPB sy-vline
WA_PCO_PARAMS_TX_STR-COSML sy-vline
WA_PCO_PARAMS_TX_STR-COSM1 sy-vline
WA_PCO_PARAMS_TX_STR-COSM2 sy-vline
WA_PCO_PARAMS_TX_STR-INDPO sy-vline
WA_PCO_PARAMS_TX_STR-INDPR sy-vline
WA_PCO_PARAMS_TX_STR-CORTX sy-vline
WA_PCO_PARAMS_TX_STR-CORDM sy-vline
WA_PCO_PARAMS_TX_STR-GRARG sy-vline
WA_PCO_PARAMS_TX_STR-GRAPS sy-vline
WA_PCO_PARAMS_TX_STR-SEMYA sy-vline
WA_PCO_PARAMS_TX_STR-CORPS sy-vline
WA_PCO_PARAMS_TX_STR-CORPB sy-vline
WA_PCO_PARAMS_TX_STR-BEGPS sy-vline
WA_PCO_PARAMS_TX_STR-ENDPS sy-vline
WA_PCO_PARAMS_TX_STR-DISAB sy-vline
WA_PCO_PARAMS_TX_STR-CORIP sy-vline
WA_PCO_PARAMS_TX_STR-CORIT sy-vline
WA_PCO_PARAMS_TX_STR-APLIC sy-vline
WA_PCO_PARAMS_TX_STR-TABRF sy-vline
WA_PCO_PARAMS_TX_STR-COUVT sy-vline
WA_PCO_PARAMS_TX_STR-COUVT1 sy-vline
WA_PCO_PARAMS_TX_STR-COUVT2 sy-vline
WA_PCO_PARAMS_TX_STR-COTIU sy-vline
WA_PCO_PARAMS_TX_STR-COREP sy-vline
WA_PCO_PARAMS_TX_STR-COEPS sy-vline
WA_PCO_PARAMS_TX_STR-WAERS sy-vline
WA_PCO_PARAMS_TX_STR-ANZP1 sy-vline
WA_PCO_PARAMS_TX_STR-CORPT sy-vline
WA_PCO_PARAMS_TX_STR-CORTRI1 sy-vline
WA_PCO_PARAMS_TX_STR-CORTRI2 sy-vline
WA_PCO_PARAMS_TX_STR-CORTRI3 sy-vline
WA_PCO_PARAMS_TX_STR-CORTRI4 sy-vline
WA_PCO_PARAMS_TX_STR-CORTRI5 sy-vline
WA_PCO_PARAMS_TX_STR-COSTA sy-vline
WA_PCO_PARAMS_TX_STR-TDECO sy-vline
WA_PCO_PARAMS_TX_STR-TOTALDEDUC sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.