ABAP Select data from SAP table /SAPAPO/CAPREV_LC_GENERATE 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/CAPREV_LC_GENERATE 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/CAPREV_LC_GENERATE. 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/CAPREV_LC_GENERATE 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/CAPREV_LC_GENERATE TYPE STANDARD TABLE OF /SAPAPO/CAPREV_LC_GENERATE, WA_/SAPAPO/CAPREV_LC_GENERATE TYPE /SAPAPO/CAPREV_LC_GENERATE, 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/CAPREV_LC_GENERATE> TYPE /SAPAPO/CAPREV_LC_GENERATE. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/CAPREV_LC_GENERATE. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SAPAPO/CAPREV_LC_GENERATE INTO TABLE IT_/SAPAPO/CAPREV_LC_GENERATE. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SAPAPO/CAPREV_LC_GENERATE * INTO TABLE @DATA(IT_/SAPAPO/CAPREV_LC_GENERATE2). *--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/CAPREV_LC_GENERATE INDEX 1 INTO DATA(WA_/SAPAPO/CAPREV_LC_GENERATE2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SAPAPO/CAPREV_LC_GENERATE ASSIGNING </SAPAPO/CAPREV_LC_GENERATE>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/CAPREV_LC_GENERATE>-RESUID = 1.
</SAPAPO/CAPREV_LC_GENERATE>-SIMVERSID = 1.
</SAPAPO/CAPREV_LC_GENERATE>-SIMSESSID = 1.
</SAPAPO/CAPREV_LC_GENERATE>-UPD = 1.
</SAPAPO/CAPREV_LC_GENERATE>-TSTREAMID = 1.
ENDLOOP. LOOP AT IT_/SAPAPO/CAPREV_LC_GENERATE INTO WA_/SAPAPO/CAPREV_LC_GENERATE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SAPAPO/CAPREV_LC_GENERATE-RESOURCE, sy-vline,
WA_/SAPAPO/CAPREV_LC_GENERATE-TIMESTREAM, sy-vline,
WA_/SAPAPO/CAPREV_LC_GENERATE-BUCKETS, sy-vline,
WA_/SAPAPO/CAPREV_LC_GENERATE-PPBUCKET, sy-vline,
WA_/SAPAPO/CAPREV_LC_GENERATE-CLASSIFICATION, sy-vline,
WA_/SAPAPO/CAPREV_LC_GENERATE-STORAGE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/CAPREV_LC_GENERATE 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/CAPREV_LC_GENERATE 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/CAPREV_LC_GENERATE INTO WA_/SAPAPO/CAPREV_LC_GENERATE. *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/CAPREV_LC_GENERATE_STR,
RESUID TYPE STRING,
SIMVERSID TYPE STRING,
SIMSESSID TYPE STRING,
UPD TYPE STRING,
TSTREAMID TYPE STRING,
RESOURCE TYPE STRING,
TIMESTREAM TYPE STRING,
BUCKETS TYPE STRING,
PPBUCKET TYPE STRING,
CLASSIFICATION TYPE STRING,
STORAGE TYPE STRING,
CAPREV TYPE STRING,
COPY_SIMVERSID TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/CAPREV_LC_GENERATE_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/CAPREV_LC_GENERATE_STR-RESUID sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-SIMVERSID sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-SIMSESSID sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-UPD sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-TSTREAMID sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-RESOURCE sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-TIMESTREAM sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-BUCKETS sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-PPBUCKET sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-CLASSIFICATION sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-STORAGE sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-CAPREV sy-vline
WA_/SAPAPO/CAPREV_LC_GENERATE_STR-COPY_SIMVERSID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.