ABAP Select data from SAP table CTE_S_FND_POST_REPORT 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 CTE_S_FND_POST_REPORT 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 CTE_S_FND_POST_REPORT. 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 CTE_S_FND_POST_REPORT 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_CTE_S_FND_POST_REPORT TYPE STANDARD TABLE OF CTE_S_FND_POST_REPORT,
      WA_CTE_S_FND_POST_REPORT TYPE CTE_S_FND_POST_REPORT,
      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: <CTE_S_FND_POST_REPORT> TYPE CTE_S_FND_POST_REPORT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CTE_S_FND_POST_REPORT
*  INTO TABLE @DATA(IT_CTE_S_FND_POST_REPORT2).
*--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_CTE_S_FND_POST_REPORT INDEX 1 INTO DATA(WA_CTE_S_FND_POST_REPORT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CTE_S_FND_POST_REPORT ASSIGNING <CTE_S_FND_POST_REPORT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CTE_S_FND_POST_REPORT>-VERSIONID = 1.
<CTE_S_FND_POST_REPORT>-REVISIONNUMBER = 1.
<CTE_S_FND_POST_REPORT>-REPORTID = 1.
<CTE_S_FND_POST_REPORT>-REPORTKEY = 1.
<CTE_S_FND_POST_REPORT>-LEDGERCODE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CTE_S_FND_POST_REPORT-REIMBURSEMENTCURRENCY_CODE, sy-vline,
WA_CTE_S_FND_POST_REPORT-HOMECOUNTRYCODE, sy-vline,
WA_CTE_S_FND_POST_REPORT-SUBMITDATE, sy-vline,
WA_CTE_S_FND_POST_REPORT-USERDEFINEDDATE, sy-vline,
WA_CTE_S_FND_POST_REPORT-PAYMENTPROCESSING_DATE, sy-vline,
WA_CTE_S_FND_POST_REPORT-REPORTNAME, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CTE_S_FND_POST_REPORT 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_CTE_S_FND_POST_REPORT 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_CTE_S_FND_POST_REPORT INTO WA_CTE_S_FND_POST_REPORT. *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_CTE_S_FND_POST_REPORT_STR,
VERSIONID TYPE STRING,
REVISIONNUMBER TYPE STRING,
REPORTID TYPE STRING,
REPORTKEY TYPE STRING,
LEDGERCODE TYPE STRING,
REIMBURSEMENTCURRENCY_CODE TYPE STRING,
HOMECOUNTRYCODE TYPE STRING,
SUBMITDATE TYPE STRING,
USERDEFINEDDATE TYPE STRING,
PAYMENTPROCESSING_DATE TYPE STRING,
REPORTNAME TYPE STRING,
REPORTSTARTDATE TYPE STRING,
REPORTENDDATE TYPE STRING,
TOTALAPPROVEDAMOUNT TYPE STRING,
CASHADVANCERETURNS_AMOUNT TYPE STRING,
ISTEST TYPE STRING,
PAYROLLPAYINDICATOR TYPE STRING,
PAYROLLPAYMENTGACCOUNTCODE TYPE STRING,
REQUESTID TYPE STRING,
REPORTORGUNIT1CODE TYPE STRING,
REPORTORGUNIT1VALUE TYPE STRING,
REPORTORGUNIT2CODE TYPE STRING,
REPORTORGUNIT2VALUE TYPE STRING,
REPORTORGUNIT3CODE TYPE STRING,
REPORTORGUNIT3VALUE TYPE STRING,
REPORTORGUNIT4CODE TYPE STRING,
REPORTORGUNIT4VALUE TYPE STRING,
REPORTORGUNIT5CODE TYPE STRING,
REPORTORGUNIT5VALUE TYPE STRING,
REPORTORGUNIT6CODE TYPE STRING,
REPORTORGUNIT6VALUE TYPE STRING,
REPORTCUSTOM1CODE TYPE STRING,
REPORTCUSTOM1VALUE TYPE STRING,
REPORTCUSTOM2CODE TYPE STRING,
REPORTCUSTOM2VALUE TYPE STRING,
REPORTCUSTOM3CODE TYPE STRING,
REPORTCUSTOM3VALUE TYPE STRING,
REPORTCUSTOM4CODE TYPE STRING,
REPORTCUSTOM4VALUE TYPE STRING,
REPORTCUSTOM5CODE TYPE STRING,
REPORTCUSTOM5VALUE TYPE STRING,
REPORTCUSTOM6CODE TYPE STRING,
REPORTCUSTOM6VALUE TYPE STRING,
REPORTCUSTOM7CODE TYPE STRING,
REPORTCUSTOM7VALUE TYPE STRING,
REPORTCUSTOM8CODE TYPE STRING,
REPORTCUSTOM8VALUE TYPE STRING,
REPORTCUSTOM9CODE TYPE STRING,
REPORTCUSTOM9VALUE TYPE STRING,
REPORTCUSTOM10CODE TYPE STRING,
REPORTCUSTOM10VALUE TYPE STRING,
REPORTCUSTOM11CODE TYPE STRING,
REPORTCUSTOM11VALUE TYPE STRING,
REPORTCUSTOM12CODE TYPE STRING,
REPORTCUSTOM12VALUE TYPE STRING,
REPORTCUSTOM13CODE TYPE STRING,
REPORTCUSTOM13VALUE TYPE STRING,
REPORTCUSTOM14CODE TYPE STRING,
REPORTCUSTOM14VALUE TYPE STRING,
REPORTCUSTOM15CODE TYPE STRING,
REPORTCUSTOM15VALUE TYPE STRING,
REPORTCUSTOM16CODE TYPE STRING,
REPORTCUSTOM16VALUE TYPE STRING,
REPORTCUSTOM17CODE TYPE STRING,
REPORTCUSTOM17VALUE TYPE STRING,
REPORTCUSTOM18CODE TYPE STRING,
REPORTCUSTOM18VALUE TYPE STRING,
REPORTCUSTOM19CODE TYPE STRING,
REPORTCUSTOM19VALUE TYPE STRING,
REPORTCUSTOM20CODE TYPE STRING,
REPORTCUSTOM20VALUE TYPE STRING,END OF T_EKKO_STR. DATA: WA_CTE_S_FND_POST_REPORT_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_CTE_S_FND_POST_REPORT_STR-VERSIONID sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REVISIONNUMBER sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTID sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTKEY sy-vline
WA_CTE_S_FND_POST_REPORT_STR-LEDGERCODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REIMBURSEMENTCURRENCY_CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-HOMECOUNTRYCODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-SUBMITDATE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-USERDEFINEDDATE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-PAYMENTPROCESSING_DATE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTNAME sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTSTARTDATE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTENDDATE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-TOTALAPPROVEDAMOUNT sy-vline
WA_CTE_S_FND_POST_REPORT_STR-CASHADVANCERETURNS_AMOUNT sy-vline
WA_CTE_S_FND_POST_REPORT_STR-ISTEST sy-vline
WA_CTE_S_FND_POST_REPORT_STR-PAYROLLPAYINDICATOR sy-vline
WA_CTE_S_FND_POST_REPORT_STR-PAYROLLPAYMENTGACCOUNTCODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REQUESTID sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT1CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT1VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT2CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT2VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT3CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT3VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT4CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT4VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT5CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT5VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT6CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTORGUNIT6VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM1CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM1VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM2CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM2VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM3CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM3VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM4CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM4VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM5CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM5VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM6CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM6VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM7CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM7VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM8CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM8VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM9CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM9VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM10CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM10VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM11CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM11VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM12CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM12VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM13CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM13VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM14CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM14VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM15CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM15VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM16CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM16VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM17CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM17VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM18CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM18VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM19CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM19VALUE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM20CODE sy-vline
WA_CTE_S_FND_POST_REPORT_STR-REPORTCUSTOM20VALUE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.