ABAP Select data from SAP table /SAPAPO/RET_RP_BUV 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/RET_RP_BUV 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/RET_RP_BUV. 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/RET_RP_BUV 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/RET_RP_BUV TYPE STANDARD TABLE OF /SAPAPO/RET_RP_BUV, WA_/SAPAPO/RET_RP_BUV TYPE /SAPAPO/RET_RP_BUV, 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/RET_RP_BUV> TYPE /SAPAPO/RET_RP_BUV. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/RET_RP_BUV. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SAPAPO/RET_RP_BUV INTO TABLE IT_/SAPAPO/RET_RP_BUV. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SAPAPO/RET_RP_BUV * INTO TABLE @DATA(IT_/SAPAPO/RET_RP_BUV2). *--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/RET_RP_BUV INDEX 1 INTO DATA(WA_/SAPAPO/RET_RP_BUV2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SAPAPO/RET_RP_BUV ASSIGNING </SAPAPO/RET_RP_BUV>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/RET_RP_BUV>-LOCID = 1.
</SAPAPO/RET_RP_BUV>-RETID = 1.
</SAPAPO/RET_RP_BUV>-EFFID = 1.
</SAPAPO/RET_RP_BUV>-LOCNO = 1.
</SAPAPO/RET_RP_BUV>-RETNAME = 1.
ENDLOOP. LOOP AT IT_/SAPAPO/RET_RP_BUV INTO WA_/SAPAPO/RET_RP_BUV. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SAPAPO/RET_RP_BUV-LIMITTYPE, sy-vline,
WA_/SAPAPO/RET_RP_BUV-CELLTAB, sy-vline,
WA_/SAPAPO/RET_RP_BUV-COLORTABLE, sy-vline,
WA_/SAPAPO/RET_RP_BUV-LINECOLOR, sy-vline,
WA_/SAPAPO/RET_RP_BUV-BUCKET001, sy-vline,
WA_/SAPAPO/RET_RP_BUV-BUCKET002, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/RET_RP_BUV 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/RET_RP_BUV 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/RET_RP_BUV INTO WA_/SAPAPO/RET_RP_BUV. *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/RET_RP_BUV_STR,
LOCID TYPE STRING,
RETID TYPE STRING,
EFFID TYPE STRING,
LOCNO TYPE STRING,
RETNAME TYPE STRING,
LIMITTYPE TYPE STRING,
CELLTAB TYPE STRING,
COLORTABLE TYPE STRING,
LINECOLOR TYPE STRING,
BUCKET001 TYPE STRING,
BUCKET002 TYPE STRING,
BUCKET003 TYPE STRING,
BUCKET004 TYPE STRING,
BUCKET005 TYPE STRING,
BUCKET006 TYPE STRING,
BUCKET007 TYPE STRING,
BUCKET008 TYPE STRING,
BUCKET009 TYPE STRING,
BUCKET010 TYPE STRING,
BUCKET011 TYPE STRING,
BUCKET012 TYPE STRING,
BUCKET013 TYPE STRING,
BUCKET014 TYPE STRING,
BUCKET015 TYPE STRING,
BUCKET016 TYPE STRING,
BUCKET017 TYPE STRING,
BUCKET018 TYPE STRING,
BUCKET019 TYPE STRING,
BUCKET020 TYPE STRING,
BUCKET021 TYPE STRING,
BUCKET022 TYPE STRING,
BUCKET023 TYPE STRING,
BUCKET024 TYPE STRING,
BUCKET025 TYPE STRING,
BUCKET026 TYPE STRING,
BUCKET027 TYPE STRING,
BUCKET028 TYPE STRING,
BUCKET029 TYPE STRING,
BUCKET030 TYPE STRING,
BUCKET031 TYPE STRING,
BUCKET032 TYPE STRING,
BUCKET033 TYPE STRING,
BUCKET034 TYPE STRING,
BUCKET035 TYPE STRING,
BUCKET036 TYPE STRING,
BUCKET037 TYPE STRING,
BUCKET038 TYPE STRING,
BUCKET039 TYPE STRING,
BUCKET040 TYPE STRING,
BUCKET041 TYPE STRING,
BUCKET042 TYPE STRING,
BUCKET043 TYPE STRING,
BUCKET044 TYPE STRING,
BUCKET045 TYPE STRING,
BUCKET046 TYPE STRING,
BUCKET047 TYPE STRING,
BUCKET048 TYPE STRING,
BUCKET049 TYPE STRING,
BUCKET050 TYPE STRING,
BUCKET051 TYPE STRING,
BUCKET052 TYPE STRING,
BUCKET053 TYPE STRING,
BUCKET054 TYPE STRING,
BUCKET055 TYPE STRING,
BUCKET056 TYPE STRING,
BUCKET057 TYPE STRING,
BUCKET058 TYPE STRING,
BUCKET059 TYPE STRING,
BUCKET060 TYPE STRING,
BUCKET061 TYPE STRING,
BUCKET062 TYPE STRING,
BUCKET063 TYPE STRING,
BUCKET064 TYPE STRING,
BUCKET065 TYPE STRING,
BUCKET066 TYPE STRING,
BUCKET067 TYPE STRING,
BUCKET068 TYPE STRING,
BUCKET069 TYPE STRING,
BUCKET070 TYPE STRING,
BUCKET071 TYPE STRING,
BUCKET072 TYPE STRING,
BUCKET073 TYPE STRING,
BUCKET074 TYPE STRING,
BUCKET075 TYPE STRING,
BUCKET076 TYPE STRING,
BUCKET077 TYPE STRING,
BUCKET078 TYPE STRING,
BUCKET079 TYPE STRING,
BUCKET080 TYPE STRING,
BUCKET081 TYPE STRING,
BUCKET082 TYPE STRING,
BUCKET083 TYPE STRING,
BUCKET084 TYPE STRING,
BUCKET085 TYPE STRING,
BUCKET086 TYPE STRING,
BUCKET087 TYPE STRING,
BUCKET088 TYPE STRING,
BUCKET089 TYPE STRING,
BUCKET090 TYPE STRING,
BUCKET091 TYPE STRING,
BUCKET092 TYPE STRING,
BUCKET093 TYPE STRING,
BUCKET094 TYPE STRING,
BUCKET095 TYPE STRING,
BUCKET096 TYPE STRING,
BUCKET097 TYPE STRING,
BUCKET098 TYPE STRING,
BUCKET099 TYPE STRING,
BUCKET100 TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/RET_RP_BUV_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/RET_RP_BUV_STR-LOCID sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-RETID sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-EFFID sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-LOCNO sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-RETNAME sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-LIMITTYPE sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-CELLTAB sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-COLORTABLE sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-LINECOLOR sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET001 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET002 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET003 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET004 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET005 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET006 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET007 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET008 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET009 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET010 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET011 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET012 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET013 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET014 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET015 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET016 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET017 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET018 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET019 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET020 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET021 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET022 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET023 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET024 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET025 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET026 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET027 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET028 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET029 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET030 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET031 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET032 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET033 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET034 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET035 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET036 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET037 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET038 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET039 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET040 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET041 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET042 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET043 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET044 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET045 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET046 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET047 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET048 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET049 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET050 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET051 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET052 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET053 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET054 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET055 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET056 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET057 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET058 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET059 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET060 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET061 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET062 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET063 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET064 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET065 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET066 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET067 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET068 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET069 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET070 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET071 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET072 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET073 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET074 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET075 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET076 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET077 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET078 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET079 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET080 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET081 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET082 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET083 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET084 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET085 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET086 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET087 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET088 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET089 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET090 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET091 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET092 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET093 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET094 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET095 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET096 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET097 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET098 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET099 sy-vline
WA_/SAPAPO/RET_RP_BUV_STR-BUCKET100 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.