ABAP Select data from SAP table FIAAPTD_FSCLMAP 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 FIAAPTD_FSCLMAP 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 FIAAPTD_FSCLMAP. 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 FIAAPTD_FSCLMAP 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_FIAAPTD_FSCLMAP TYPE STANDARD TABLE OF FIAAPTD_FSCLMAP,
      WA_FIAAPTD_FSCLMAP TYPE FIAAPTD_FSCLMAP,
      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: <FIAAPTD_FSCLMAP> TYPE FIAAPTD_FSCLMAP.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FIAAPTD_FSCLMAP
*  INTO TABLE @DATA(IT_FIAAPTD_FSCLMAP2).
*--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_FIAAPTD_FSCLMAP INDEX 1 INTO DATA(WA_FIAAPTD_FSCLMAP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FIAAPTD_FSCLMAP ASSIGNING <FIAAPTD_FSCLMAP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FIAAPTD_FSCLMAP>-MANDT = 1.
<FIAAPTD_FSCLMAP>-STATRYRPTGENTITY = 1.
<FIAAPTD_FSCLMAP>-STATRYRPTCATEGORY = 1.
<FIAAPTD_FSCLMAP>-STATRYRPTRUNID = 1.
<FIAAPTD_FSCLMAP>-COMPANYCODE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FIAAPTD_FSCLMAP-FISCALYEAR, sy-vline,
WA_FIAAPTD_FSCLMAP-ASSETREPORTFORMCLASS, sy-vline,
WA_FIAAPTD_FSCLMAP-ASSETREPORTFORM, sy-vline,
WA_FIAAPTD_FSCLMAP-ASSETREPORTFORMCATEGORYNAME, sy-vline,
WA_FIAAPTD_FSCLMAP-ASSETRPTFORMRTRMTCATEGORYNAME, sy-vline,
WA_FIAAPTD_FSCLMAP-SEQUENCENUMBER, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FIAAPTD_FSCLMAP 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_FIAAPTD_FSCLMAP 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_FIAAPTD_FSCLMAP INTO WA_FIAAPTD_FSCLMAP. *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 GJAHR, internal->external for field FISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FIAAPTD_FSCLMAP-FISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIAAPTD_FSCLMAP-FISCALYEAR.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit GJAHR, internal->external for field DEPRECIATIONSTARTYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FIAAPTD_FSCLMAP-DEPRECIATIONSTARTYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIAAPTD_FSCLMAP-DEPRECIATIONSTARTYEAR.
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_FIAAPTD_FSCLMAP_STR,
MANDT TYPE STRING,
STATRYRPTGENTITY TYPE STRING,
STATRYRPTCATEGORY TYPE STRING,
STATRYRPTRUNID TYPE STRING,
COMPANYCODE TYPE STRING,
FISCALYEAR TYPE STRING,
ASSETREPORTFORMCLASS TYPE STRING,
ASSETREPORTFORM TYPE STRING,
ASSETREPORTFORMCATEGORYNAME TYPE STRING,
ASSETRPTFORMRTRMTCATEGORYNAME TYPE STRING,
SEQUENCENUMBER TYPE STRING,
MASTERFIXEDASSET TYPE STRING,
FIXEDASSET TYPE STRING,
ASSETTRANSACTIONTYPE TYPE STRING,
ASSETREPORTFORMTYPE TYPE STRING,
ADDITIONALASSETREPORTFORMTYPE TYPE STRING,
ASSETEVALUATIONGROUP TYPE STRING,
FIXEDASSETDESCRIPTION TYPE STRING,
FIRSTACQUISITIONFISCALYEAR TYPE STRING,
DEPRECIATIONSTARTPERIOD TYPE STRING,
DEPRECIATIONSTARTYEAR TYPE STRING,
LANDASSETLINK TYPE STRING,
BIGREPAIRASSETLINK TYPE STRING,
ASSETREALIZATIONAMOUNT TYPE STRING,
BOOKACQUISITIONAMOUNT TYPE STRING,
TAXACQUISITIONAMOUNT TYPE STRING,
BOOKVALUEADJUSTMENTAMOUNT TYPE STRING,
BOOKCAPITALGAINAMOUNTSIGN TYPE STRING,
BOOKCAPITALGAINAMOUNT TYPE STRING,
NOTTAXEDCAPITALGAINAMOUNT TYPE STRING,
TAXVALUEADJUSTMENTAMOUNT TYPE STRING,
DEVALUATIONCOEFFICIENT TYPE STRING,
TAXCAPITALGAINAMOUNTSIGN TYPE STRING,
TAXCAPITALGAINAMOUNT TYPE STRING,
PLANNEDUSEFULLIFEINDCMLYEARS TYPE STRING,
REPORTEDBOOKDEPRECIATIONAMOUNT TYPE STRING,
REPORTEDCUMULATIVETAXDEPRAMT TYPE STRING,
PLANNEDUSEFULLIFEINYEARS TYPE STRING,
TAXDEPRECIATIONRATE TYPE STRING,
REVISEDTAXDEPRECIATIONRATE TYPE STRING,
REPORTEDTAXDEPRECIATIONAMOUNT TYPE STRING,
ACCEPTEDIMPAIRMENTLOSSAMOUNT TYPE STRING,
CUMULATIVELOSSTAXDEPRRATE TYPE STRING,
NOTACCEPTEDDEPRECIATIONAMOUNT TYPE STRING,
RECOVEREDIMPRMTLOSSANDDEPRAMT TYPE STRING,
ACQNPRODNCOSTANDREVALAMOUNT TYPE STRING,
PREVACQNPRODNCOSTANDREVALAMT TYPE STRING,
TOTALACQNPRODNCOSTANDREVALAMT TYPE STRING,
RLTVEXPIREDUSEFULLIFEINYEARS TYPE STRING,
RLTVREMAININGUSEFULLIFEINYEARS TYPE STRING,
ADDLPLANNEDUSEFULLIFEINYEARS TYPE STRING,
ADDITIONALTAXDEPRECIATIONRATE TYPE STRING,
CUMULATIVEDEPRECIATIONAMOUNT TYPE STRING,
TOTALDEPRECIATIONAMOUNT TYPE STRING,
NETBOOKVALUEAMOUNT TYPE STRING,
TAXEXEMPTIONAMOUNT TYPE STRING,
FOREGONEAMOUNT TYPE STRING,
REEVALUATEDASSETDEPRAMOUNT TYPE STRING,END OF T_EKKO_STR. DATA: WA_FIAAPTD_FSCLMAP_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_FIAAPTD_FSCLMAP_STR-MANDT sy-vline
WA_FIAAPTD_FSCLMAP_STR-STATRYRPTGENTITY sy-vline
WA_FIAAPTD_FSCLMAP_STR-STATRYRPTCATEGORY sy-vline
WA_FIAAPTD_FSCLMAP_STR-STATRYRPTRUNID sy-vline
WA_FIAAPTD_FSCLMAP_STR-COMPANYCODE sy-vline
WA_FIAAPTD_FSCLMAP_STR-FISCALYEAR sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETREPORTFORMCLASS sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETREPORTFORM sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETREPORTFORMCATEGORYNAME sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETRPTFORMRTRMTCATEGORYNAME sy-vline
WA_FIAAPTD_FSCLMAP_STR-SEQUENCENUMBER sy-vline
WA_FIAAPTD_FSCLMAP_STR-MASTERFIXEDASSET sy-vline
WA_FIAAPTD_FSCLMAP_STR-FIXEDASSET sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETTRANSACTIONTYPE sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETREPORTFORMTYPE sy-vline
WA_FIAAPTD_FSCLMAP_STR-ADDITIONALASSETREPORTFORMTYPE sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETEVALUATIONGROUP sy-vline
WA_FIAAPTD_FSCLMAP_STR-FIXEDASSETDESCRIPTION sy-vline
WA_FIAAPTD_FSCLMAP_STR-FIRSTACQUISITIONFISCALYEAR sy-vline
WA_FIAAPTD_FSCLMAP_STR-DEPRECIATIONSTARTPERIOD sy-vline
WA_FIAAPTD_FSCLMAP_STR-DEPRECIATIONSTARTYEAR sy-vline
WA_FIAAPTD_FSCLMAP_STR-LANDASSETLINK sy-vline
WA_FIAAPTD_FSCLMAP_STR-BIGREPAIRASSETLINK sy-vline
WA_FIAAPTD_FSCLMAP_STR-ASSETREALIZATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-BOOKACQUISITIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXACQUISITIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-BOOKVALUEADJUSTMENTAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-BOOKCAPITALGAINAMOUNTSIGN sy-vline
WA_FIAAPTD_FSCLMAP_STR-BOOKCAPITALGAINAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-NOTTAXEDCAPITALGAINAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXVALUEADJUSTMENTAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-DEVALUATIONCOEFFICIENT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXCAPITALGAINAMOUNTSIGN sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXCAPITALGAINAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-PLANNEDUSEFULLIFEINDCMLYEARS sy-vline
WA_FIAAPTD_FSCLMAP_STR-REPORTEDBOOKDEPRECIATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-REPORTEDCUMULATIVETAXDEPRAMT sy-vline
WA_FIAAPTD_FSCLMAP_STR-PLANNEDUSEFULLIFEINYEARS sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXDEPRECIATIONRATE sy-vline
WA_FIAAPTD_FSCLMAP_STR-REVISEDTAXDEPRECIATIONRATE sy-vline
WA_FIAAPTD_FSCLMAP_STR-REPORTEDTAXDEPRECIATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-ACCEPTEDIMPAIRMENTLOSSAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-CUMULATIVELOSSTAXDEPRRATE sy-vline
WA_FIAAPTD_FSCLMAP_STR-NOTACCEPTEDDEPRECIATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-RECOVEREDIMPRMTLOSSANDDEPRAMT sy-vline
WA_FIAAPTD_FSCLMAP_STR-ACQNPRODNCOSTANDREVALAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-PREVACQNPRODNCOSTANDREVALAMT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TOTALACQNPRODNCOSTANDREVALAMT sy-vline
WA_FIAAPTD_FSCLMAP_STR-RLTVEXPIREDUSEFULLIFEINYEARS sy-vline
WA_FIAAPTD_FSCLMAP_STR-RLTVREMAININGUSEFULLIFEINYEARS sy-vline
WA_FIAAPTD_FSCLMAP_STR-ADDLPLANNEDUSEFULLIFEINYEARS sy-vline
WA_FIAAPTD_FSCLMAP_STR-ADDITIONALTAXDEPRECIATIONRATE sy-vline
WA_FIAAPTD_FSCLMAP_STR-CUMULATIVEDEPRECIATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TOTALDEPRECIATIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-NETBOOKVALUEAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-TAXEXEMPTIONAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-FOREGONEAMOUNT sy-vline
WA_FIAAPTD_FSCLMAP_STR-REEVALUATEDASSETDEPRAMOUNT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.