ABAP Select data from SAP table PEBRRPROJRSLT 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 PEBRRPROJRSLT 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 PEBRRPROJRSLT. 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 PEBRRPROJRSLT 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_PEBRRPROJRSLT TYPE STANDARD TABLE OF PEBRRPROJRSLT,
      WA_PEBRRPROJRSLT TYPE PEBRRPROJRSLT,
      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: <PEBRRPROJRSLT> TYPE PEBRRPROJRSLT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PEBRRPROJRSLT
*  INTO TABLE @DATA(IT_PEBRRPROJRSLT2).
*--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_PEBRRPROJRSLT INDEX 1 INTO DATA(WA_PEBRRPROJRSLT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PEBRRPROJRSLT ASSIGNING <PEBRRPROJRSLT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PEBRRPROJRSLT>-MANDT = 1.
<PEBRRPROJRSLT>-CLOSINGTASKUUID = 1.
<PEBRRPROJRSLT>-EVTBSDREVNRECGNCLSGRUNRSLTITEM = 1.
<PEBRRPROJRSLT>-PROJECT = 1.
<PEBRRPROJRSLT>-WBSELEMENT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PEBRRPROJRSLT-COMPANYCODE, sy-vline,
WA_PEBRRPROJRSLT-COMPANYCODENAME, sy-vline,
WA_PEBRRPROJRSLT-PROFITCENTER, sy-vline,
WA_PEBRRPROJRSLT-CONTROLLINGOBJECT, sy-vline,
WA_PEBRRPROJRSLT-FISCALYEAR, sy-vline,
WA_PEBRRPROJRSLT-FISCALPERIOD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PEBRRPROJRSLT 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_PEBRRPROJRSLT 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_PEBRRPROJRSLT INTO WA_PEBRRPROJRSLT. *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.

*Conversion exit ABPSN, internal->external for field PROJECT CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_PEBRRPROJRSLT-PROJECT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEBRRPROJRSLT-PROJECT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ABPSN, internal->external for field WBSELEMENT CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_PEBRRPROJRSLT-WBSELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEBRRPROJRSLT-WBSELEMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PROFITCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PEBRRPROJRSLT-PROFITCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEBRRPROJRSLT-PROFITCENTER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field FISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PEBRRPROJRSLT-FISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEBRRPROJRSLT-FISCALYEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PEBRRPROJRSLT-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEBRRPROJRSLT-LEDGER.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PEBRRPROJRSLT_STR,
MANDT TYPE STRING,
CLOSINGTASKUUID TYPE STRING,
EVTBSDREVNRECGNCLSGRUNRSLTITEM TYPE STRING,
PROJECT TYPE STRING,
WBSELEMENT TYPE STRING,
COMPANYCODE TYPE STRING,
COMPANYCODENAME TYPE STRING,
PROFITCENTER TYPE STRING,
CONTROLLINGOBJECT TYPE STRING,
FISCALYEAR TYPE STRING,
FISCALPERIOD TYPE STRING,
LEDGER TYPE STRING,
RESULTANALYSISINTERNALID TYPE STRING,
FISCALYEARVARIANT TYPE STRING,
NUMBEROFOPENERRORMESSAGES TYPE STRING,
CREATIONDATETIME TYPE STRING,
APPLICATIONLOG TYPE STRING,
COMPANYCODECURRENCY TYPE STRING,
ACTLCOSTAMT TYPE STRING,
ACTLREVNAMT TYPE STRING,
RECOGNIZEDCOGSAMOUNT TYPE STRING,
RECOGNIZEDREVENUEAMOUNT TYPE STRING,
RECOGNIZEDMARGINAMTINCCCRCY TYPE STRING,
ACCRUEDCOGSAMOUNT TYPE STRING,
ACCRUEDREVENUEAMOUNT TYPE STRING,
DEFERREDCOGSAMOUNT TYPE STRING,
DEFERREDREVENUEAMOUNT TYPE STRING,
REVENUEADJUSTMENTAMOUNT TYPE STRING,
COGSADJUSTMENTAMOUNT TYPE STRING,
UNBILLEDREVNINCOCODECRCY TYPE STRING,
ACCRUEDREVENUECAPAMTINCCCRCY TYPE STRING,
DOWNPAYMENTAMTINCCCRCY TYPE STRING,END OF T_EKKO_STR. DATA: WA_PEBRRPROJRSLT_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_PEBRRPROJRSLT_STR-MANDT sy-vline
WA_PEBRRPROJRSLT_STR-CLOSINGTASKUUID sy-vline
WA_PEBRRPROJRSLT_STR-EVTBSDREVNRECGNCLSGRUNRSLTITEM sy-vline
WA_PEBRRPROJRSLT_STR-PROJECT sy-vline
WA_PEBRRPROJRSLT_STR-WBSELEMENT sy-vline
WA_PEBRRPROJRSLT_STR-COMPANYCODE sy-vline
WA_PEBRRPROJRSLT_STR-COMPANYCODENAME sy-vline
WA_PEBRRPROJRSLT_STR-PROFITCENTER sy-vline
WA_PEBRRPROJRSLT_STR-CONTROLLINGOBJECT sy-vline
WA_PEBRRPROJRSLT_STR-FISCALYEAR sy-vline
WA_PEBRRPROJRSLT_STR-FISCALPERIOD sy-vline
WA_PEBRRPROJRSLT_STR-LEDGER sy-vline
WA_PEBRRPROJRSLT_STR-RESULTANALYSISINTERNALID sy-vline
WA_PEBRRPROJRSLT_STR-FISCALYEARVARIANT sy-vline
WA_PEBRRPROJRSLT_STR-NUMBEROFOPENERRORMESSAGES sy-vline
WA_PEBRRPROJRSLT_STR-CREATIONDATETIME sy-vline
WA_PEBRRPROJRSLT_STR-APPLICATIONLOG sy-vline
WA_PEBRRPROJRSLT_STR-COMPANYCODECURRENCY sy-vline
WA_PEBRRPROJRSLT_STR-ACTLCOSTAMT sy-vline
WA_PEBRRPROJRSLT_STR-ACTLREVNAMT sy-vline
WA_PEBRRPROJRSLT_STR-RECOGNIZEDCOGSAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-RECOGNIZEDREVENUEAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-RECOGNIZEDMARGINAMTINCCCRCY sy-vline
WA_PEBRRPROJRSLT_STR-ACCRUEDCOGSAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-ACCRUEDREVENUEAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-DEFERREDCOGSAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-DEFERREDREVENUEAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-REVENUEADJUSTMENTAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-COGSADJUSTMENTAMOUNT sy-vline
WA_PEBRRPROJRSLT_STR-UNBILLEDREVNINCOCODECRCY sy-vline
WA_PEBRRPROJRSLT_STR-ACCRUEDREVENUECAPAMTINCCCRCY sy-vline
WA_PEBRRPROJRSLT_STR-DOWNPAYMENTAMTINCCCRCY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.