ABAP Select data from SAP table PRU_RSV1_PART1 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 PRU_RSV1_PART1 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 PRU_RSV1_PART1. 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 PRU_RSV1_PART1 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_PRU_RSV1_PART1 TYPE STANDARD TABLE OF PRU_RSV1_PART1,
      WA_PRU_RSV1_PART1 TYPE PRU_RSV1_PART1,
      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: <PRU_RSV1_PART1> TYPE PRU_RSV1_PART1.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM PRU_RSV1_PART1
  INTO TABLE IT_PRU_RSV1_PART1.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PRU_RSV1_PART1
*  INTO TABLE @DATA(IT_PRU_RSV1_PART12).
*--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_PRU_RSV1_PART1 INDEX 1 INTO DATA(WA_PRU_RSV1_PART12).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PRU_RSV1_PART1 ASSIGNING <PRU_RSV1_PART1>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PRU_RSV1_PART1>-T1003 = 1.
<PRU_RSV1_PART1>-T1004 = 1.
<PRU_RSV1_PART1>-T1005 = 1.
<PRU_RSV1_PART1>-T1006 = 1.
<PRU_RSV1_PART1>-T1007 = 1.
ENDLOOP.

LOOP AT IT_PRU_RSV1_PART1 INTO WA_PRU_RSV1_PART1.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PRU_RSV1_PART1-T1008, sy-vline,
WA_PRU_RSV1_PART1-T1103, sy-vline,
WA_PRU_RSV1_PART1-T1104, sy-vline,
WA_PRU_RSV1_PART1-T1105, sy-vline,
WA_PRU_RSV1_PART1-T1106, sy-vline,
WA_PRU_RSV1_PART1-T1107, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PRU_RSV1_PART1 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_PRU_RSV1_PART1 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_PRU_RSV1_PART1 INTO WA_PRU_RSV1_PART1. *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_PRU_RSV1_PART1_STR,
T1003 TYPE STRING,
T1004 TYPE STRING,
T1005 TYPE STRING,
T1006 TYPE STRING,
T1007 TYPE STRING,
T1008 TYPE STRING,
T1103 TYPE STRING,
T1104 TYPE STRING,
T1105 TYPE STRING,
T1106 TYPE STRING,
T1107 TYPE STRING,
T1108 TYPE STRING,
T1113 TYPE STRING,
T1114 TYPE STRING,
T1115 TYPE STRING,
T1116 TYPE STRING,
T1117 TYPE STRING,
T1118 TYPE STRING,
T1123 TYPE STRING,
T1124 TYPE STRING,
T1125 TYPE STRING,
T1126 TYPE STRING,
T1127 TYPE STRING,
T1128 TYPE STRING,
T1133 TYPE STRING,
T1134 TYPE STRING,
T1135 TYPE STRING,
T1136 TYPE STRING,
T1137 TYPE STRING,
T1138 TYPE STRING,
T1143 TYPE STRING,
T1144 TYPE STRING,
T1145 TYPE STRING,
T1146 TYPE STRING,
T1147 TYPE STRING,
T1148 TYPE STRING,
T1203 TYPE STRING,
T1204 TYPE STRING,
T1205 TYPE STRING,
T1206 TYPE STRING,
T1207 TYPE STRING,
T1208 TYPE STRING,
T1213 TYPE STRING,
T1218 TYPE STRING,
T1303 TYPE STRING,
T1304 TYPE STRING,
T1305 TYPE STRING,
T1306 TYPE STRING,
T1307 TYPE STRING,
T1308 TYPE STRING,
T1403 TYPE STRING,
T1404 TYPE STRING,
T1405 TYPE STRING,
T1406 TYPE STRING,
T1407 TYPE STRING,
T1408 TYPE STRING,
T1413 TYPE STRING,
T1414 TYPE STRING,
T1415 TYPE STRING,
T1416 TYPE STRING,
T1417 TYPE STRING,
T1418 TYPE STRING,
T1423 TYPE STRING,
T1424 TYPE STRING,
T1425 TYPE STRING,
T1426 TYPE STRING,
T1427 TYPE STRING,
T1428 TYPE STRING,
T1433 TYPE STRING,
T1434 TYPE STRING,
T1435 TYPE STRING,
T1436 TYPE STRING,
T1437 TYPE STRING,
T1438 TYPE STRING,
T1443 TYPE STRING,
T1444 TYPE STRING,
T1445 TYPE STRING,
T1446 TYPE STRING,
T1447 TYPE STRING,
T1448 TYPE STRING,
T1503 TYPE STRING,
T1504 TYPE STRING,
T1505 TYPE STRING,
T1506 TYPE STRING,
T1507 TYPE STRING,
T1508 TYPE STRING,
T1453 TYPE STRING,
T1454 TYPE STRING,
T1455 TYPE STRING,
T1456 TYPE STRING,
T1457 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PRU_RSV1_PART1_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_PRU_RSV1_PART1_STR-T1003 sy-vline
WA_PRU_RSV1_PART1_STR-T1004 sy-vline
WA_PRU_RSV1_PART1_STR-T1005 sy-vline
WA_PRU_RSV1_PART1_STR-T1006 sy-vline
WA_PRU_RSV1_PART1_STR-T1007 sy-vline
WA_PRU_RSV1_PART1_STR-T1008 sy-vline
WA_PRU_RSV1_PART1_STR-T1103 sy-vline
WA_PRU_RSV1_PART1_STR-T1104 sy-vline
WA_PRU_RSV1_PART1_STR-T1105 sy-vline
WA_PRU_RSV1_PART1_STR-T1106 sy-vline
WA_PRU_RSV1_PART1_STR-T1107 sy-vline
WA_PRU_RSV1_PART1_STR-T1108 sy-vline
WA_PRU_RSV1_PART1_STR-T1113 sy-vline
WA_PRU_RSV1_PART1_STR-T1114 sy-vline
WA_PRU_RSV1_PART1_STR-T1115 sy-vline
WA_PRU_RSV1_PART1_STR-T1116 sy-vline
WA_PRU_RSV1_PART1_STR-T1117 sy-vline
WA_PRU_RSV1_PART1_STR-T1118 sy-vline
WA_PRU_RSV1_PART1_STR-T1123 sy-vline
WA_PRU_RSV1_PART1_STR-T1124 sy-vline
WA_PRU_RSV1_PART1_STR-T1125 sy-vline
WA_PRU_RSV1_PART1_STR-T1126 sy-vline
WA_PRU_RSV1_PART1_STR-T1127 sy-vline
WA_PRU_RSV1_PART1_STR-T1128 sy-vline
WA_PRU_RSV1_PART1_STR-T1133 sy-vline
WA_PRU_RSV1_PART1_STR-T1134 sy-vline
WA_PRU_RSV1_PART1_STR-T1135 sy-vline
WA_PRU_RSV1_PART1_STR-T1136 sy-vline
WA_PRU_RSV1_PART1_STR-T1137 sy-vline
WA_PRU_RSV1_PART1_STR-T1138 sy-vline
WA_PRU_RSV1_PART1_STR-T1143 sy-vline
WA_PRU_RSV1_PART1_STR-T1144 sy-vline
WA_PRU_RSV1_PART1_STR-T1145 sy-vline
WA_PRU_RSV1_PART1_STR-T1146 sy-vline
WA_PRU_RSV1_PART1_STR-T1147 sy-vline
WA_PRU_RSV1_PART1_STR-T1148 sy-vline
WA_PRU_RSV1_PART1_STR-T1203 sy-vline
WA_PRU_RSV1_PART1_STR-T1204 sy-vline
WA_PRU_RSV1_PART1_STR-T1205 sy-vline
WA_PRU_RSV1_PART1_STR-T1206 sy-vline
WA_PRU_RSV1_PART1_STR-T1207 sy-vline
WA_PRU_RSV1_PART1_STR-T1208 sy-vline
WA_PRU_RSV1_PART1_STR-T1213 sy-vline
WA_PRU_RSV1_PART1_STR-T1218 sy-vline
WA_PRU_RSV1_PART1_STR-T1303 sy-vline
WA_PRU_RSV1_PART1_STR-T1304 sy-vline
WA_PRU_RSV1_PART1_STR-T1305 sy-vline
WA_PRU_RSV1_PART1_STR-T1306 sy-vline
WA_PRU_RSV1_PART1_STR-T1307 sy-vline
WA_PRU_RSV1_PART1_STR-T1308 sy-vline
WA_PRU_RSV1_PART1_STR-T1403 sy-vline
WA_PRU_RSV1_PART1_STR-T1404 sy-vline
WA_PRU_RSV1_PART1_STR-T1405 sy-vline
WA_PRU_RSV1_PART1_STR-T1406 sy-vline
WA_PRU_RSV1_PART1_STR-T1407 sy-vline
WA_PRU_RSV1_PART1_STR-T1408 sy-vline
WA_PRU_RSV1_PART1_STR-T1413 sy-vline
WA_PRU_RSV1_PART1_STR-T1414 sy-vline
WA_PRU_RSV1_PART1_STR-T1415 sy-vline
WA_PRU_RSV1_PART1_STR-T1416 sy-vline
WA_PRU_RSV1_PART1_STR-T1417 sy-vline
WA_PRU_RSV1_PART1_STR-T1418 sy-vline
WA_PRU_RSV1_PART1_STR-T1423 sy-vline
WA_PRU_RSV1_PART1_STR-T1424 sy-vline
WA_PRU_RSV1_PART1_STR-T1425 sy-vline
WA_PRU_RSV1_PART1_STR-T1426 sy-vline
WA_PRU_RSV1_PART1_STR-T1427 sy-vline
WA_PRU_RSV1_PART1_STR-T1428 sy-vline
WA_PRU_RSV1_PART1_STR-T1433 sy-vline
WA_PRU_RSV1_PART1_STR-T1434 sy-vline
WA_PRU_RSV1_PART1_STR-T1435 sy-vline
WA_PRU_RSV1_PART1_STR-T1436 sy-vline
WA_PRU_RSV1_PART1_STR-T1437 sy-vline
WA_PRU_RSV1_PART1_STR-T1438 sy-vline
WA_PRU_RSV1_PART1_STR-T1443 sy-vline
WA_PRU_RSV1_PART1_STR-T1444 sy-vline
WA_PRU_RSV1_PART1_STR-T1445 sy-vline
WA_PRU_RSV1_PART1_STR-T1446 sy-vline
WA_PRU_RSV1_PART1_STR-T1447 sy-vline
WA_PRU_RSV1_PART1_STR-T1448 sy-vline
WA_PRU_RSV1_PART1_STR-T1503 sy-vline
WA_PRU_RSV1_PART1_STR-T1504 sy-vline
WA_PRU_RSV1_PART1_STR-T1505 sy-vline
WA_PRU_RSV1_PART1_STR-T1506 sy-vline
WA_PRU_RSV1_PART1_STR-T1507 sy-vline
WA_PRU_RSV1_PART1_STR-T1508 sy-vline
WA_PRU_RSV1_PART1_STR-T1453 sy-vline
WA_PRU_RSV1_PART1_STR-T1454 sy-vline
WA_PRU_RSV1_PART1_STR-T1455 sy-vline
WA_PRU_RSV1_PART1_STR-T1456 sy-vline
WA_PRU_RSV1_PART1_STR-T1457 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.